From 5b8fcfe4bd557899867605d24bcd4745e5819dc0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 23 Jun 2014 14:01:33 -0700 Subject: remove fixArgs --- src/webGLClient.js | 101 +++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/src/webGLClient.js b/src/webGLClient.js index 25938398..3b2a1f08 100644 --- a/src/webGLClient.js +++ b/src/webGLClient.js @@ -47,6 +47,36 @@ function WebGLClient() { i += 9; } + // lookuppers, convert integer ids to cached objects for some args + function func1L0(name) { + ctx[name](objects[buffer[i]]); + i++; + } + function func2L0(name) { + ctx[name](objects[buffer[i]], buffer[i+1]); + i += 2; + } + function func2L0L1(name) { + ctx[name](objects[buffer[i]], objects[buffer[i+1]]); + i += 2; + } + function func2L1_(name) { + ctx[name](buffer[i], buffer[i+1] ? objects[buffer[i+1]] : null); + i += 2; + } + function func3L0(name) { + ctx[name](objects[buffer[i]], buffer[i+1], buffer[i+2]); + i += 3; + } + function func4L3_(name) { + ctx[name](buffer[i], buffer[i+1], buffer[i+2], buffer[i+3] ? objects[buffer[i+3]] : null); + i += 4; + } + function func5L3_(name) { + ctx[name](buffer[i], buffer[i+1], buffer[i+2], buffer[i+3] ? objects[buffer[i+3]] : null, buffer[i+4]); + i += 5; + } + // constructors, last argument is the id to save as function funcC0(name) { var object = ctx[name](); @@ -63,6 +93,11 @@ function WebGLClient() { var id = buffer[i++]; objects[id] = object; } + function funcC2L0(name) { + var object = ctx[name](objects[buffer[i++]], buffer[i++]); + var id = buffer[i++]; + objects[id] = object; + } // destructors, stop holding on to the object in the cache function funcD0(name) { @@ -81,25 +116,25 @@ function WebGLClient() { 5: { name: 'clearColor', func: func4 }, 6: { name: 'createShader', func: funcC1 }, 7: { name: 'deleteShader', func: funcD0 }, - 8: { name: 'shaderSource', func: func2 }, - 9: { name: 'compileShader', func: func1 }, + 8: { name: 'shaderSource', func: func2L0 }, + 9: { name: 'compileShader', func: func1L0 }, 10: { name: 'createProgram', func: funcC0 }, 11: { name: 'deleteProgram', func: funcD0 }, - 12: { name: 'attachShader', func: func2 }, - 13: { name: 'bindAttribLocation', func: func3 }, - 14: { name: 'linkProgram', func: func1 }, - 15: { name: 'getProgramParameter', func: function() { assert(ctx.getProgramParameter(buffer[i++], buffer[i++]), 'we cannot handle errors, we are async proxied WebGL'); } }, - 16: { name: 'getUniformLocation', func: funcC2 }, - 17: { name: 'useProgram', func: func1 }, - 18: { name: 'uniform1i', func: func2 }, - 19: { name: 'uniform1f', func: func2 }, - 20: { name: 'uniform3fv', func: func2 }, - 21: { name: 'uniform4fv', func: func2 }, - 22: { name: 'uniformMatrix4fv', func: func3 }, + 12: { name: 'attachShader', func: func2L0L1 }, + 13: { name: 'bindAttribLocation', func: func3L0 }, + 14: { name: 'linkProgram', func: func1L0 }, + 15: { name: 'getProgramParameter', func: function() { assert(ctx.getProgramParameter(objects[buffer[i++]], buffer[i++]), 'we cannot handle errors, we are async proxied WebGL'); } }, + 16: { name: 'getUniformLocation', func: funcC2L0 }, + 17: { name: 'useProgram', func: func1L0 }, + 18: { name: 'uniform1i', func: func2L0 }, + 19: { name: 'uniform1f', func: func2L0 }, + 20: { name: 'uniform3fv', func: func2L0 }, + 21: { name: 'uniform4fv', func: func2L0 }, + 22: { name: 'uniformMatrix4fv', func: func3L0 }, 23: { name: 'vertexAttrib4fv', func: func2 }, 24: { name: 'createBuffer', func: funcC0 }, 25: { name: 'deleteBuffer', func: funcD0 }, - 26: { name: 'bindBuffer', func: func2 }, + 26: { name: 'bindBuffer', func: func2L1_ }, 27: { name: 'bufferData', func: func3 }, 28: { name: 'bufferSubData', func: func3 }, 29: { name: 'viewport', func: func4 }, @@ -111,12 +146,12 @@ function WebGLClient() { 35: { name: 'getError', func: function() { assert(ctx.getError() === ctx.NO_ERROR, 'we cannot handle errors, we are async proxied WebGL') } }, 36: { name: 'createTexture', func: funcC0 }, 37: { name: 'deleteTexture', func: funcD0 }, - 38: { name: 'bindTexture', func: func2 }, + 38: { name: 'bindTexture', func: func2L1_ }, 39: { name: 'texParameteri', func: func3 }, 40: { name: 'texImage2D', func: func9 }, 41: { name: 'compressedTexImage2D', func: func7 }, 42: { name: 'activeTexture', func: func1 }, - 43: { name: 'getShaderParameter', func: function() { assert(ctx.getShaderParameter(buffer[i++], buffer[i++]), 'we cannot handle errors, we are async proxied WebGL'); } }, + 43: { name: 'getShaderParameter', func: function() { assert(ctx.getShaderParameter(objects[buffer[i++]], buffer[i++]), 'we cannot handle errors, we are async proxied WebGL'); } }, 44: { name: 'clearDepth', func: func1 }, 45: { name: 'depthFunc', func: func1 }, 46: { name: 'frontFace', func: func1 }, @@ -130,41 +165,16 @@ function WebGLClient() { 54: { name: 'lineWidth', func: func1 }, 55: { name: 'createFramebuffer', func: funcC0 }, 56: { name: 'deleteFramebuffer', func: funcD0 }, - 57: { name: 'bindFramebuffer', func: func2 }, - 58: { name: 'framebufferTexture2D', func: func5 }, + 57: { name: 'bindFramebuffer', func: func2L1_ }, + 58: { name: 'framebufferTexture2D', func: func5L3_ }, 59: { name: 'createRenderbuffer', func: funcC0 }, 60: { name: 'deleteRenderbuffer', func: funcD0 }, - 61: { name: 'bindRenderbuffer', func: func2 }, + 61: { name: 'bindRenderbuffer', func: func2L1_ }, 62: { name: 'renderbufferStorage', func: func4 }, - 63: { name: 'framebufferRenderbuffer', func: func4 }, + 63: { name: 'framebufferRenderbuffer', func: func4L3_ }, 64: { name: 'debugPrint', func: func1 }, }; - function fixArgs(name, args) { - switch (name) { - case 'getProgramParameter': - case 'getShaderParameter': - case 'uniform1i': - case 'uniform1f': - case 'uniform3fv': - case 'uniform4fv': - case 'uniformMatrix4fv': - case 'getUniformLocation': - case 'useProgram': - case 'linkProgram': - case 'bindAttribLocation': - case 'compileShader': - case 'shaderSource': buffer[i] = objects[buffer[i]]; break; - case 'attachShader': buffer[i] = objects[buffer[i]]; buffer[i+1] = objects[buffer[i+1]]; break; - case 'bindRenderbuffer': - case 'bindFramebuffer': - case 'bindTexture': - case 'bindBuffer': buffer[i+1] = buffer[i+1] ? objects[buffer[i+1]] : null; break; - case 'framebufferRenderbuffer': - case 'framebufferTexture2D': buffer[i+3] = buffer[i+3] ? objects[buffer[i+3]] : null; break; - } - } - function renderCommands(buf) { ctx = Module.ctx; i = 0; @@ -175,7 +185,6 @@ function WebGLClient() { var info = calls[buffer[i++]]; var name = info.name; assert(typeof name === 'string'); - fixArgs(name); info.func(name); //var err; //while ((err = ctx.getError()) !== ctx.NO_ERROR) { -- cgit v1.2.3-18-g5258