Skip to content

Commit 3a80df3

Browse files
committed
do not rely on Function.apply to construct functions
1 parent 03d718c commit 3a80df3

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

lib/create-attributes.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,40 @@ Object.defineProperty(proto, 'location', {
5858
}
5959
})
6060

61+
var allFns = [
62+
function (gl, v, x0) {
63+
if (x0.length === undefined) {
64+
return gl.vertexAttrib1f(v, x0)
65+
} else {
66+
return gl.vertexAttrib1fv(v, x0)
67+
}
68+
},
69+
70+
function (gl, v, x0, x1) {
71+
if (x0.length === undefined) {
72+
return gl.vertexAttrib2f(v, x0, x1)
73+
} else {
74+
return gl.vertexAttrib2fv(v, x0)
75+
}
76+
},
77+
78+
function (gl, v, x0, x1, x2) {
79+
if (x0.length === undefined) {
80+
return gl.vertexAttrib3f(v, x0, x1, x2)
81+
} else {
82+
return gl.vertexAttrib3fv(v, x0)
83+
}
84+
},
85+
86+
function (gl, v, x0, x1, x2, x3) {
87+
if (x0.length === undefined) {
88+
return gl.vertexAttrib4f(v, x0, x1, x2, x3)
89+
} else {
90+
return gl.vertexAttrib4fv(v, x0)
91+
}
92+
}
93+
]
94+
6195
//Adds a vector attribute to obj
6296
function addVectorAttribute(
6397
gl
@@ -68,21 +102,7 @@ function addVectorAttribute(
68102
, obj
69103
, name) {
70104

71-
//Construct constant function
72-
var constFuncArgs = [ 'gl', 'v' ]
73-
var varNames = []
74-
for(var i=0; i<dimension; ++i) {
75-
constFuncArgs.push('x'+i)
76-
varNames.push('x'+i)
77-
}
78-
constFuncArgs.push(
79-
'if(x0.length===void 0){return gl.vertexAttrib' +
80-
dimension + 'f(v,' +
81-
varNames.join() +
82-
')}else{return gl.vertexAttrib' +
83-
dimension +
84-
'fv(v,x0)}')
85-
var constFunc = Function.apply(null, constFuncArgs)
105+
var constFunc = allFns[dimension]
86106

87107
//Create attribute wrapper
88108
var attr = new ShaderAttribute(

0 commit comments

Comments
 (0)