diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-16 14:49:26 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-16 14:49:26 -0700 |
commit | 29b99763d0d303ddbb1b8b4d49ed52af1149b521 (patch) | |
tree | f0d586b0b7a7ff3b044e710746ad40a744300f9e /src | |
parent | 65e62141a955420e10c22b14579c99aa07027e29 (diff) |
skip main loop iterations when gl buffer is stalled, instead of gl frames which may be incorrect to drop
Diffstat (limited to 'src')
-rw-r--r-- | src/webGLWorker.js | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/webGLWorker.js b/src/webGLWorker.js index c16caa00..86bdf206 100644 --- a/src/webGLWorker.js +++ b/src/webGLWorker.js @@ -704,17 +704,23 @@ function WebGLWorker() { // Setup var dropped = 0; - var postMainLoop = Module['postMainLoop']; - Module['postMainLoop'] = function() { - if (postMainLoop) postMainLoop(); - // frame complete, send the command buffer - if (Math.abs(frameId - clientFrameId) <= 3) { - // only send if not throttling - postMessage({ target: 'gl', op: 'render', commandBuffer: commandBuffer }); - } else { + var preMainLoop = Module['preMainLoop']; + Module['preMainLoop'] = function() { + if (preMainLoop) { + var ret = preMainLoop(); + if (ret === false) return ret; + } + // if too many frames in queue, skip a main loop iter + if (Math.abs(frameId - clientFrameId) >= 3) { //dropped++; //if (dropped % 1000 === 0) dump('dropped: ' + [dropped, frameId, Math.round(100*dropped/frameId) + '%\n']); + return false; } + }; + var postMainLoop = Module['postMainLoop']; + Module['postMainLoop'] = function() { + if (postMainLoop) postMainLoop(); + postMessage({ target: 'gl', op: 'render', commandBuffer: commandBuffer }); commandBuffer = []; }; } |