From d3332c666208a8674053870df89da9b1506e56b0 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 26 Jul 2021 14:05:06 -0400 Subject: [PATCH 1/7] ignore lock file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d1b0b0..6342e05 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ logs results npm-debug.log +package-lock.json node_modules/* \ No newline at end of file From 83002d47550cba2b84debc3788d44bf41f241aa9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 26 Jul 2021 16:46:37 -0400 Subject: [PATCH 2/7] remove breaks while default is present --- lib/create-uniforms.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/create-uniforms.js b/lib/create-uniforms.js index 1d0870b..4468974 100644 --- a/lib/create-uniforms.js +++ b/lib/create-uniforms.js @@ -65,7 +65,6 @@ function createUniformWrapper(gl, wrapper, uniforms, locations) { } else { throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type) } - break } } @@ -137,7 +136,6 @@ function createUniformWrapper(gl, wrapper, uniforms, locations) { } else { throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type) } - break } } From 578d33c126ae6bdc76586901a6e5a6c36f5ba687 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 27 Jul 2021 11:02:47 -0400 Subject: [PATCH 3/7] rewrite first function - avoid runtime constructors --- lib/create-uniforms.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/create-uniforms.js b/lib/create-uniforms.js index 4468974..80513bd 100644 --- a/lib/create-uniforms.js +++ b/lib/create-uniforms.js @@ -7,8 +7,9 @@ module.exports = createUniformWrapper //Binds a function and returns a value function identity(x) { - var c = new Function('y', 'return function(){return y}') - return c(x) + return function() { + return x + } } function makeVector(length, fill) { From eb01932f20d44240e4e1d7c62c9968fc96df8a20 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 27 Jul 2021 11:03:40 -0400 Subject: [PATCH 4/7] rewrite second function - avoid runtime constructors --- lib/create-uniforms.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/create-uniforms.js b/lib/create-uniforms.js index 80513bd..77f4bee 100644 --- a/lib/create-uniforms.js +++ b/lib/create-uniforms.js @@ -23,13 +23,10 @@ function makeVector(length, fill) { //Create shims for uniforms function createUniformWrapper(gl, wrapper, uniforms, locations) { - function makeGetter(index) { - var proc = new Function( - 'gl' - , 'wrapper' - , 'locations' - , 'return function(){return gl.getUniform(wrapper.program,locations[' + index + '])}') - return proc(gl, wrapper, locations) + function makeGetter(idx) { + return function(gl, wrapper, locations) { + return gl.getUniform(wrapper.program, locations[idx]) + } } function makePropSetter(path, index, type) { From 77c35c39c8b24ac27a9118d451621d15f2c2f59a Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 27 Jul 2021 11:05:06 -0400 Subject: [PATCH 5/7] rewrite third function - avoid runtime constructors --- lib/create-uniforms.js | 112 ++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 45 deletions(-) diff --git a/lib/create-uniforms.js b/lib/create-uniforms.js index 77f4bee..8ccb23b 100644 --- a/lib/create-uniforms.js +++ b/lib/create-uniforms.js @@ -29,40 +29,77 @@ function createUniformWrapper(gl, wrapper, uniforms, locations) { } } - function makePropSetter(path, index, type) { - switch(type) { - case 'bool': - case 'int': - case 'sampler2D': - case 'samplerCube': - return 'gl.uniform1i(locations[' + index + '],obj' + path + ')' - case 'float': - return 'gl.uniform1f(locations[' + index + '],obj' + path + ')' - default: - var vidx = type.indexOf('vec') - if(0 <= vidx && vidx <= 1 && type.length === 4 + vidx) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new GLError('', 'Invalid data type') + function makeSetter(type) { + return function updateProperty(obj){ + var indices = enumerateIndices('', type) + for(var i=0; i 4) { + throw new GLError('', 'Invalid data type') + } + switch(t.charAt(0)) { + case 'b': + case 'i': + gl['uniform' + d + 'iv'](locations[idx], objPath) + break + case 'v': + gl['uniform' + d + 'fv'](locations[idx], objPath) + break + default: + throw new GLError('', 'Unrecognized data type for vector ' + name + ': ' + t) + } + } else if(t.indexOf('mat') === 0 && t.length === 4) { + d = t.charCodeAt(t.length-1) - 48 + if(d < 2 || d > 4) { + throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + t) + } + gl['uniformMatrix' + d + 'fv'](locations[idx], false, objPath) + break + } else { + throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + t) + } } - } else if(type.indexOf('mat') === 0 && type.length === 4) { - var d = type.charCodeAt(type.length-1) - 48 - if(d < 2 || d > 4) { - throw new GLError('', 'Invalid uniform dimension type for matrix ' + name + ': ' + type) - } - return 'gl.uniformMatrix' + d + 'fv(locations[' + index + '],false,obj' + path + ')' - } else { - throw new GLError('', 'Unknown uniform data type for ' + name + ': ' + type) } + } } } @@ -88,21 +125,6 @@ function createUniformWrapper(gl, wrapper, uniforms, locations) { return indices } - function makeSetter(type) { - var code = [ 'return function updateProperty(obj){' ] - var indices = enumerateIndices('', type) - for(var i=0; i Date: Tue, 27 Jul 2021 13:20:43 -0400 Subject: [PATCH 6/7] bump version as a minor --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93d6475..2ab8881 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gl-shader", - "version": "4.2.1", + "version": "4.3.0", "description": "WebGL shader wrapper", "main": "index.js", "directories": { From 3a80df3b6c2411e335da1120c29fed0984e893fe Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 27 Jul 2021 18:33:57 -0400 Subject: [PATCH 7/7] do not rely on Function.apply to construct functions --- lib/create-attributes.js | 50 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/create-attributes.js b/lib/create-attributes.js index dfc1649..bf6847a 100644 --- a/lib/create-attributes.js +++ b/lib/create-attributes.js @@ -58,6 +58,40 @@ Object.defineProperty(proto, 'location', { } }) +var allFns = [ + function (gl, v, x0) { + if (x0.length === undefined) { + return gl.vertexAttrib1f(v, x0) + } else { + return gl.vertexAttrib1fv(v, x0) + } + }, + + function (gl, v, x0, x1) { + if (x0.length === undefined) { + return gl.vertexAttrib2f(v, x0, x1) + } else { + return gl.vertexAttrib2fv(v, x0) + } + }, + + function (gl, v, x0, x1, x2) { + if (x0.length === undefined) { + return gl.vertexAttrib3f(v, x0, x1, x2) + } else { + return gl.vertexAttrib3fv(v, x0) + } + }, + + function (gl, v, x0, x1, x2, x3) { + if (x0.length === undefined) { + return gl.vertexAttrib4f(v, x0, x1, x2, x3) + } else { + return gl.vertexAttrib4fv(v, x0) + } + } +] + //Adds a vector attribute to obj function addVectorAttribute( gl @@ -68,21 +102,7 @@ function addVectorAttribute( , obj , name) { - //Construct constant function - var constFuncArgs = [ 'gl', 'v' ] - var varNames = [] - for(var i=0; i