diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-23 13:13:25 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-23 13:13:25 -0700 |
commit | 302b11b0fceba685b2a87e92b39540a5207b6af9 (patch) | |
tree | 1d7d87ef6221537636d2a72a695fc1f6cf181285 | |
parent | b53a1352479177dc7bb0646be1a3ace72eba3755 (diff) |
remove number of args from gl proxy protocol
-rw-r--r-- | src/webGLClient.js | 135 | ||||
-rw-r--r-- | src/webGLWorker.js | 129 |
2 files changed, 132 insertions, 132 deletions
diff --git a/src/webGLClient.js b/src/webGLClient.js index 1ae7332d..b3aa57b5 100644 --- a/src/webGLClient.js +++ b/src/webGLClient.js @@ -8,71 +8,71 @@ function WebGLClient() { var objects = {}; var calls = { - 0: { name: 'NULL' }, - 1: { name: 'getExtension' }, - 2: { name: 'enable' }, - 3: { name: 'disable' }, - 4: { name: 'clear' }, - 5: { name: 'clearColor' }, - 6: { name: 'createShader' }, - 7: { name: 'deleteShader' }, - 8: { name: 'shaderSource' }, - 9: { name: 'compileShader' }, - 10: { name: 'createProgram' }, - 11: { name: 'deleteProgram' }, - 12: { name: 'attachShader' }, - 13: { name: 'bindAttribLocation' }, - 14: { name: 'linkProgram' }, - 15: { name: 'getProgramParameter' }, - 16: { name: 'getUniformLocation' }, - 17: { name: 'useProgram' }, - 18: { name: 'uniform1i' }, - 19: { name: 'uniform1f' }, - 20: { name: 'uniform3fv' }, - 21: { name: 'uniform4fv' }, - 22: { name: 'uniformMatrix4fv' }, - 23: { name: 'vertexAttrib4fv' }, - 24: { name: 'createBuffer' }, - 25: { name: 'deleteBuffer' }, - 26: { name: 'bindBuffer' }, - 27: { name: 'bufferData' }, - 28: { name: 'bufferSubData' }, - 29: { name: 'viewport' }, - 30: { name: 'vertexAttribPointer' }, - 31: { name: 'enableVertexAttribArray' }, - 32: { name: 'disableVertexAttribArray' }, - 33: { name: 'drawArrays' }, - 34: { name: 'drawElements' }, - 35: { name: 'getError' }, - 36: { name: 'createTexture' }, - 37: { name: 'deleteTexture' }, - 38: { name: 'bindTexture' }, - 39: { name: 'texParameteri' }, - 40: { name: 'texImage2D' }, - 41: { name: 'compressedTexImage2D' }, - 42: { name: 'activeTexture' }, - 43: { name: 'getShaderParameter' }, - 44: { name: 'clearDepth' }, - 45: { name: 'depthFunc' }, - 46: { name: 'frontFace' }, - 47: { name: 'cullFace' }, - 48: { name: 'pixelStorei' }, - 49: { name: 'depthMask' }, - 50: { name: 'depthRange' }, - 51: { name: 'blendFunc' }, - 52: { name: 'scissor' }, - 53: { name: 'colorMask' }, - 54: { name: 'lineWidth' }, - 55: { name: 'createFramebuffer' }, - 56: { name: 'deleteFramebuffer' }, - 57: { name: 'bindFramebuffer' }, - 58: { name: 'framebufferTexture2D' }, - 59: { name: 'createRenderbuffer' }, - 60: { name: 'deleteRenderbuffer' }, - 61: { name: 'bindRenderbuffer' }, - 62: { name: 'renderbufferStorage' }, - 63: { name: 'framebufferRenderbuffer' }, - 64: { name: 'debugPrint' }, + 0: { name: 'NULL', args: 0 }, + 1: { name: 'getExtension', args: 1 }, + 2: { name: 'enable', args: 1 }, + 3: { name: 'disable', args: 1 }, + 4: { name: 'clear', args: 1 }, + 5: { name: 'clearColor', args: 4 }, + 6: { name: 'createShader', args: -2 }, + 7: { name: 'deleteShader', args: 1 }, + 8: { name: 'shaderSource', args: 2 }, + 9: { name: 'compileShader', args: 1 }, + 10: { name: 'createProgram', args: -1 }, + 11: { name: 'deleteProgram', args: 1 }, + 12: { name: 'attachShader', args: 2 }, + 13: { name: 'bindAttribLocation', args: 3 }, + 14: { name: 'linkProgram', args: 1 }, + 15: { name: 'getProgramParameter', args: 2 }, + 16: { name: 'getUniformLocation', args: -3 }, + 17: { name: 'useProgram', args: 1 }, + 18: { name: 'uniform1i', args: 2 }, + 19: { name: 'uniform1f', args: 2 }, + 20: { name: 'uniform3fv', args: 2 }, + 21: { name: 'uniform4fv', args: 2 }, + 22: { name: 'uniformMatrix4fv', args: 3 }, + 23: { name: 'vertexAttrib4fv', args: 2 }, + 24: { name: 'createBuffer', args: -1 }, + 25: { name: 'deleteBuffer', args: 1 }, + 26: { name: 'bindBuffer', args: 2 }, + 27: { name: 'bufferData', args: 3 }, + 28: { name: 'bufferSubData', args: 3 }, + 29: { name: 'viewport', args: 4 }, + 30: { name: 'vertexAttribPointer', args: 6 }, + 31: { name: 'enableVertexAttribArray', args: 1 }, + 32: { name: 'disableVertexAttribArray', args: 1 }, + 33: { name: 'drawArrays', args: 3 }, + 34: { name: 'drawElements', args: 4 }, + 35: { name: 'getError', args: 0 }, + 36: { name: 'createTexture', args: -1 }, + 37: { name: 'deleteTexture', args: 1 }, + 38: { name: 'bindTexture', args: 2 }, + 39: { name: 'texParameteri', args: 3 }, + 40: { name: 'texImage2D', args: 9 }, + 41: { name: 'compressedTexImage2D', args: 7 }, + 42: { name: 'activeTexture', args: 1 }, + 43: { name: 'getShaderParameter', args: 2 }, + 44: { name: 'clearDepth', args: 1 }, + 45: { name: 'depthFunc', args: 1 }, + 46: { name: 'frontFace', args: 1 }, + 47: { name: 'cullFace', args: 1 }, + 48: { name: 'pixelStorei', args: 2 }, + 49: { name: 'depthMask', args: 1 }, + 50: { name: 'depthRange', args: 2 }, + 51: { name: 'blendFunc', args: 2 }, + 52: { name: 'scissor', args: 4 }, + 53: { name: 'colorMask', args: 4 }, + 54: { name: 'lineWidth', args: 1 }, + 55: { name: 'createFramebuffer', args: -1 }, + 56: { name: 'deleteFramebuffer', args: 1 }, + 57: { name: 'bindFramebuffer', args: 2 }, + 58: { name: 'framebufferTexture2D', args: 5 }, + 59: { name: 'createRenderbuffer', args: -1 }, + 60: { name: 'deleteRenderbuffer', args: 1 }, + 61: { name: 'bindRenderbuffer', args: 2 }, + 62: { name: 'renderbufferStorage', args: 4 }, + 63: { name: 'framebufferRenderbuffer', args: 4 }, + 64: { name: 'debugPrint', args: 1 }, }; function fixArgs(command, args) { @@ -118,9 +118,10 @@ function WebGLClient() { var len = buffer.length; //dump('issuing commands, buffer len: ' + len + '\n'); while (i < len) { - var command = calls[buffer[i++]].name; + var info = calls[buffer[i++]]; + var command = info.name; assert(typeof command === 'string') - var numArgs = buffer[i++]; + var numArgs = info.args; assert(typeof numArgs === 'number', command); //dump('issue ' + [command, numArgs, 'peek:' + buffer.slice(i, i+5)] + '\n'); if (numArgs === 0) { diff --git a/src/webGLWorker.js b/src/webGLWorker.js index 4ca28fa9..90a1bed9 100644 --- a/src/webGLWorker.js +++ b/src/webGLWorker.js @@ -513,61 +513,60 @@ function WebGLWorker() { this.getExtension = function(name) { var i = this.prefetchedExtensions.indexOf(name); if (i < 0) return null; - commandBuffer.push(1, 1, name); + commandBuffer.push(1, name); return true; // TODO: return an object here }; this.getSupportedExtensions = function() { return this.prefetchedExtensions; }; this.enable = function(cap) { - commandBuffer.push(2, 1, cap); + commandBuffer.push(2, cap); }; this.disable = function(cap) { - commandBuffer.push(3, 1, cap); + commandBuffer.push(3, cap); }; this.clear = function(mask) { - commandBuffer.push(4, 1, mask); + commandBuffer.push(4, mask); }; this.clearColor = function(r, g, b, a) { - commandBuffer.push(5, 4, r, g, b, a); + commandBuffer.push(5, r, g, b, a); }; this.createShader = function(type) { var id = nextId++; - commandBuffer.push(6, -2, type, id); + commandBuffer.push(6, type, id); return { id: id, what: 'shader', type: type }; }; this.deleteShader = function(shader) { if (!shader) return; - commandBuffer.push(7, 1, shader.id); + commandBuffer.push(7, shader.id); }; this.shaderSource = function(shader, source) { shader.source = source; - commandBuffer.push(8, 2, shader.id, source); + commandBuffer.push(8, shader.id, source); }; this.compileShader = function(shader) { - commandBuffer.push(9, 1, shader.id); + commandBuffer.push(9, shader.id); }; this.getShaderInfoLog = function(shader) { return ''; // optimistic assumption of success; no proxying }; this.createProgram = function() { var id = nextId++; - commandBuffer.push(10, -1, id); + commandBuffer.push(10, id); return new WebGLProgram(id); }; this.deleteProgram = function(program) { if (!program) return; - commandBuffer.push(11, 1, program.id); + commandBuffer.push(11, program.id); }; this.attachShader = function(program, shader) { program.shaders.push(shader); - commandBuffer.push(12, 2, program.id, shader.id); + commandBuffer.push(12, program.id, shader.id); }; this.bindAttribLocation = function(program, index, name) { program.attributes[name] = { what: 'attribute', name: name, size: -1, location: index }; // fill in size later program.attributeVec[index] = name; - - commandBuffer.push(13, 3, program.id, index, name); + commandBuffer.push(13, program.id, index, name); }; this.getAttribLocation = function(program, name) { // all existing attribs are cached locally @@ -621,7 +620,7 @@ function WebGLWorker() { program.attributes[attr].size = existingAttributes[attr].size; } - commandBuffer.push(14, 1, program.id); + commandBuffer.push(14, program.id); }; this.getProgramParameter = function(program, name) { switch (name) { @@ -629,7 +628,7 @@ function WebGLWorker() { case this.ACTIVE_ATTRIBUTES: return program.attributeVec.length; case this.LINK_STATUS: { // optimisticaly return success; client will abort on an actual error. we assume an error-free async workflow - commandBuffer.push(15, 2, program.id, name); + commandBuffer.push(15, program.id, name); return true; } default: throw 'bad getProgramParameter ' + revname(name); @@ -656,50 +655,50 @@ function WebGLWorker() { } if (!(name in program.uniforms)) return null; var id = nextId++; - commandBuffer.push(16, -3, program.id, fullname, id); + commandBuffer.push(16, program.id, fullname, id); return { what: 'location', uniform: program.uniforms[name], id: id, index: index }; }; this.getProgramInfoLog = function(shader) { return ''; // optimistic assumption of success; no proxying }; this.useProgram = function(program) { - commandBuffer.push(17, 1, program ? program.id : 0); + commandBuffer.push(17, program ? program.id : 0); bindings.program = program; }; this.uniform1i = function(location, data) { if (!location) return; - commandBuffer.push(18, 2, location.id, data); + commandBuffer.push(18, location.id, data); }; this.uniform1f = function(location, data) { if (!location) return; - commandBuffer.push(19, 2, location.id, data); + commandBuffer.push(19, location.id, data); }; this.uniform3fv = function(location, data) { if (!location) return; - commandBuffer.push(20, 2, location.id, new Float32Array(data)); + commandBuffer.push(20, location.id, new Float32Array(data)); }; this.uniform4fv = function(location, data) { if (!location) return; - commandBuffer.push(21, 2, location.id, new Float32Array(data)); + commandBuffer.push(21, location.id, new Float32Array(data)); }; this.uniformMatrix4fv = function(location, transpose, data) { if (!location) return; - commandBuffer.push(22, 3, location.id, transpose, new Float32Array(data)); + commandBuffer.push(22, location.id, transpose, new Float32Array(data)); }; this.vertexAttrib4fv = function(index, values) { - commandBuffer.push(23, 2, index, new Float32Array(values)); + commandBuffer.push(23, index, new Float32Array(values)); }; this.createBuffer = function() { var id = nextId++; - commandBuffer.push(24, -1, id); + commandBuffer.push(24, id); return new WebGLBuffer(id); }; this.deleteBuffer = function(buffer) { if (!buffer) return; - commandBuffer.push(25, 1, buffer.id); + commandBuffer.push(25, buffer.id); }; this.bindBuffer = function(target, buffer) { - commandBuffer.push(26, 2, target, buffer ? buffer.id : 0); + commandBuffer.push(26, target, buffer ? buffer.id : 0); switch (target) { case this.ARRAY_BUFFER_BINDING: { bindings.arrayBuffer = buffer; @@ -713,43 +712,43 @@ function WebGLWorker() { }; this.bufferData = function(target, something, usage) { if (typeof something !== 'number') something = new something.constructor(something); - commandBuffer.push(27, 3, target, something, usage); + commandBuffer.push(27, target, something, usage); }; this.bufferSubData = function(target, offset, something) { if (typeof something !== 'number') something = new something.constructor(something); - commandBuffer.push(28, 3, target, offset, something); + commandBuffer.push(28, target, offset, something); }; this.viewport = function(x, y, w, h) { - commandBuffer.push(29, 4, x, y, w, h); + commandBuffer.push(29, x, y, w, h); }; this.vertexAttribPointer = function(index, size, type, normalized, stride, offset) { - commandBuffer.push(30, 6, index, size, type, normalized, stride, offset); + commandBuffer.push(30, index, size, type, normalized, stride, offset); }; this.enableVertexAttribArray = function(index) { - commandBuffer.push(31, 1, index); + commandBuffer.push(31, index); }; this.disableVertexAttribArray = function(index) { - commandBuffer.push(32, 1, index); + commandBuffer.push(32, index); }; this.drawArrays = function(mode, first, count) { - commandBuffer.push(33, 3, mode, first, count); + commandBuffer.push(33, mode, first, count); }; this.drawElements = function(mode, count, type, offset) { - commandBuffer.push(34, 4, mode, count, type, offset); + commandBuffer.push(34, mode, count, type, offset); }; this.getError = function() { // optimisticaly return success; client will abort on an actual error. we assume an error-free async workflow - commandBuffer.push(35, 0); + commandBuffer.push(35); return this.NO_ERROR; }; this.createTexture = function() { var id = nextId++; - commandBuffer.push(36, -1, id); + commandBuffer.push(36, id); return new WebGLTexture(id); }; this.deleteTexture = function(texture) { if (!texture) return; - commandBuffer.push(37, 1, texture.id); + commandBuffer.push(37, texture.id); texture.id = 0; }; this.isTexture = function(texture) { @@ -763,106 +762,106 @@ function WebGLWorker() { } } texture.binding = target; - commandBuffer.push(38, 2, target, texture ? texture.id : 0); + commandBuffer.push(38, target, texture ? texture.id : 0); }; this.texParameteri = function(target, pname, param) { - commandBuffer.push(39, 3, target, pname, param); + commandBuffer.push(39, target, pname, param); }; this.texImage2D = function(target, level, internalformat, width, height, border, format, type, pixels) { assert(pixels || pixels === null); // we do not support the overloads that have fewer params - commandBuffer.push(40, 9, target, level, internalformat, width, height, border, format, type, pixels ? new pixels.constructor(pixels) : pixels); + commandBuffer.push(40, target, level, internalformat, width, height, border, format, type, pixels ? new pixels.constructor(pixels) : pixels); }; this.compressedTexImage2D = function(target, level, internalformat, width, height, border, pixels) { - commandBuffer.push(41, 7, target, level, internalformat, width, height, border, new pixels.constructor(pixels)); + commandBuffer.push(41, target, level, internalformat, width, height, border, new pixels.constructor(pixels)); }; this.activeTexture = function(texture) { - commandBuffer.push(42, 1, texture); + commandBuffer.push(42, texture); }; this.getShaderParameter = function(shader, pname) { switch (pname) { case this.SHADER_TYPE: return shader.type; case this.COMPILE_STATUS: { // optimisticaly return success; client will abort on an actual error. we assume an error-free async workflow - commandBuffer.push(43, 2, shader.id, pname); + commandBuffer.push(43, shader.id, pname); return true; } default: throw 'unsupported getShaderParameter ' + pname; } }; this.clearDepth = function(depth) { - commandBuffer.push(44, 1, depth); + commandBuffer.push(44, depth); }; this.depthFunc = function(depth) { - commandBuffer.push(45, 1, depth); + commandBuffer.push(45, depth); }; this.frontFace = function(depth) { - commandBuffer.push(46, 1, depth); + commandBuffer.push(46, depth); }; this.cullFace = function(depth) { - commandBuffer.push(47, 1, depth); + commandBuffer.push(47, depth); }; this.readPixels = function(depth) { abort('readPixels is impossible, we are async GL'); }; this.pixelStorei = function(pname, param) { - commandBuffer.push(48, 2, pname, param); + commandBuffer.push(48, pname, param); }; this.depthMask = function(flag) { - commandBuffer.push(49, 1, flag); + commandBuffer.push(49, flag); }; this.depthRange = function(near, far) { - commandBuffer.push(50, 2, near, far); + commandBuffer.push(50, near, far); }; this.blendFunc = function(sfactor, dfactor) { - commandBuffer.push(51, 2, sfactor, dfactor); + commandBuffer.push(51, sfactor, dfactor); }; this.scissor = function(x, y, width, height) { - commandBuffer.push(52, 4, x, y, width, height); + commandBuffer.push(52, x, y, width, height); }; this.colorMask = function(red, green, blue, alpha) { - commandBuffer.push(53, 4, red, green, blue, alpha); + commandBuffer.push(53, red, green, blue, alpha); }; this.lineWidth = function(width) { - commandBuffer.push(54, 1, width); + commandBuffer.push(54, width); }; this.createFramebuffer = function() { var id = nextId++; - commandBuffer.push(55, -1, id); + commandBuffer.push(55, id); return new WebGLFramebuffer(id); }; this.deleteFramebuffer = function(framebuffer) { if (!framebuffer) return; - commandBuffer.push(56, 1, framebuffer.id); + commandBuffer.push(56, framebuffer.id); }; this.bindFramebuffer = function(target, framebuffer) { - commandBuffer.push(57, 2, target, framebuffer ? framebuffer.id : 0); + commandBuffer.push(57, target, framebuffer ? framebuffer.id : 0); }; this.framebufferTexture2D = function(target, attachment, textarget, texture, level) { - commandBuffer.push(58, 5, target, attachment, textarget, texture ? texture.id : 0, level); + commandBuffer.push(58, target, attachment, textarget, texture ? texture.id : 0, level); }; this.checkFramebufferStatus = function(target) { return this.FRAMEBUFFER_COMPLETE; // XXX totally wrong }; this.createRenderbuffer = function() { var id = nextId++; - commandBuffer.push(59, -1, id); + commandBuffer.push(59, id); return new WebGLRenderbuffer(id); }; this.deleteRenderbuffer = function(renderbuffer) { if (!renderbuffer) return; - commandBuffer.push(60, 1, renderbuffer.id); + commandBuffer.push(60, renderbuffer.id); }; this.bindRenderbuffer = function(target, renderbuffer) { - commandBuffer.push(61, 2, target, renderbuffer ? renderbuffer.id : 0); + commandBuffer.push(61, target, renderbuffer ? renderbuffer.id : 0); }; this.renderbufferStorage = function(target, internalformat, width, height) { - commandBuffer.push(62, 4, target, internalformat, width, height); + commandBuffer.push(62, target, internalformat, width, height); }; this.framebufferRenderbuffer = function(target, attachment, renderbuffertarget, renderbuffer) { - commandBuffer.push(63, 4, target, attachment, renderbuffertarget, renderbuffer ? renderbuffer.id : 0); + commandBuffer.push(63, target, attachment, renderbuffertarget, renderbuffer ? renderbuffer.id : 0); }; //this.debugPrint = function(text) { // useful to interleave debug output properly with client GL commands - // commandBuffer.push(64, 1, text); + // commandBuffer.push(64, text); //}; // Setup |