diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-13 11:46:29 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-13 11:46:29 -0700 |
commit | 80def15592ce9d96209cd2c68ec3b57151fb6cfa (patch) | |
tree | c5d72d1ae50571270557dded9f753e7bc012fe15 /src | |
parent | b653efa58b67621469a56686365f99121e41e2f5 (diff) |
render proxied gl command buffers in a requestAnimationFrame callback, not onmessge
Diffstat (limited to 'src')
-rw-r--r-- | src/webGLClient.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/webGLClient.js b/src/webGLClient.js index 91fdd97d..10433729 100644 --- a/src/webGLClient.js +++ b/src/webGLClient.js @@ -54,11 +54,26 @@ function WebGLClient() { } } + var commandBuffers = []; + + function renderAllCommands() { + // TODO: we can avoid running commands from buffers that are not the last, if they + // have no side effects, as each buffer is from a different frame + for (var i = 0; i < commandBuffers.length; i++) { + renderCommands(commandBuffers[i]); + } + commandBuffers.length = 0; + } + this.onmessage = function(msg) { //dump('client GL got ' + JSON.stringify(msg) + '\n'); switch(msg.op) { case 'render': { - renderCommands(msg.commandBuffer); + if (commandBuffers.length === 0) { + // requestion a new frame, we will clear the buffers after rendering them + window.requestAnimationFrame(renderAllCommands); + } + commandBuffers.push(msg.commandBuffer); break; } default: throw 'weird gl onmessage ' + JSON.stringify(msg); |