diff options
Diffstat (limited to 'src/proxyClient.js')
-rw-r--r-- | src/proxyClient.js | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/proxyClient.js b/src/proxyClient.js index 2d1c76fe..94d8161a 100644 --- a/src/proxyClient.js +++ b/src/proxyClient.js @@ -1,8 +1,6 @@ // proxy to/from worker -Module.ctx = Module.canvas.getContext('2d'); - // render var renderFrameData = null; @@ -24,13 +22,41 @@ window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequest window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || renderFrame; +/* +var trueRAF = window.requestAnimationFrame; +var lastRAF = 0; +var meanFPS = 0; +window.requestAnimationFrame = function(func) { + trueRAF(function() { + var now = performance.now(); + if (lastRAF > 0) { + var diff = now - lastRAF; + var fps = 1000/diff; + meanFPS = 0.95*meanFPS + 0.05*fps; + dump('client fps ' + meanFPS + '\n'); + } + lastRAF = now; + func(); + }); +} +*/ + // end render +// Frame throttling + +var frameId = 0; + +// Worker + var worker = new Worker('{{{ filename }}}.js'); +WebGLClient.prefetch(); // XXX not guaranteed to be before worker main() + var workerResponded = false; worker.onmessage = function worker_onmessage(event) { + //dump('\nclient got ' + JSON.stringify(event.data).substr(0, 150) + '\n'); if (!workerResponded) { workerResponded = true; if (Module.setStatus) Module.setStatus(''); @@ -52,10 +78,18 @@ worker.onmessage = function worker_onmessage(event) { } case 'canvas': { switch (data.op) { + case 'getContext': { + Module.ctx = Module.canvas.getContext(data.type, data.attributes); + if (data.type !== '2d') { + // possible GL_DEBUG entry point: Module.ctx = wrapDebugGL(Module.ctx); + Module.glClient = new WebGLClient(); + } + break; + } case 'resize': { Module.canvas.width = data.width; Module.canvas.height = data.height; - Module.canvasData = Module.ctx.getImageData(0, 0, data.width, data.height); + if (Module.ctx && Module.ctx.getImageData) Module.canvasData = Module.ctx.getImageData(0, 0, data.width, data.height); worker.postMessage({ target: 'canvas', boundingClientRect: cloneObject(Module.canvas.getBoundingClientRect()) }); break; } @@ -74,6 +108,15 @@ worker.onmessage = function worker_onmessage(event) { } break; } + case 'gl': { + Module.glClient.onmessage(data); + break; + } + case 'tick': { + frameId = data.id; + worker.postMessage({ target: 'tock', id: frameId }); + break; + } default: throw 'what?'; } }; |