diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-05-06 15:08:35 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-05-06 15:08:35 -0700 |
commit | 1d32c296019da719f323d340882c12900e85a3c2 (patch) | |
tree | 268376e1d4571fa34c4506254238e44515641f22 | |
parent | 81711e103d690bbe17e859ffa1524b126a5d408a (diff) |
only set color and texture attribs if they exist
-rw-r--r-- | src/library_gl.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 5cb4b79a..ce1b5c84 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -1316,8 +1316,6 @@ var LibraryGL = { var useCurrProgram = !!GL.currProgram; var ret = { vertexSize: vertexSize, - hasTexture: textureSize > 0, - hasColor: colorSize > 0, init: function() { if (useCurrProgram) { @@ -1370,6 +1368,10 @@ var LibraryGL = { this.projectionLocation = Module.ctx.getUniformLocation(this.program, 'u_projection'); this.hasColorAttribLocation = Module.ctx.getUniformLocation(this.program, 'u_hasColorAttrib'); this.colorUniformLocation = Module.ctx.getUniformLocation(this.program, 'u_color'); + + this.hasTexture = textureSize > 0 && this.texCoordLocation >= 0; + this.hasColorAttrib = colorSize > 0 && this.colorLocation >= 0; + this.hasColorUniform = !!this.colorUniformLocation; }, prepare: function() { @@ -1384,12 +1386,12 @@ var LibraryGL = { vertexSize, textureOffset); Module.ctx.enableVertexAttribArray(this.texCoordLocation); } - if (this.hasColor) { + if (this.hasColorAttrib) { Module.ctx.vertexAttribPointer(this.colorLocation, colorSize, Module.ctx.UNSIGNED_BYTE, true, vertexSize, colorOffset); Module.ctx.enableVertexAttribArray(this.colorLocation); Module.ctx.uniform1i(this.hasColorAttribLocation, 1); - } else { + } else if (this.hasColorUniform) { Module.ctx.uniform1i(this.hasColorAttribLocation, 0); Module.ctx.uniform4fv(this.colorUniformLocation, GL.immediate.clientColor); } @@ -1406,7 +1408,7 @@ var LibraryGL = { if (this.hasTexture) { Module.ctx.disableVertexAttribArray(this.texCoordLocation); } - if (this.hasColor) { + if (this.hasColorAttrib) { Module.ctx.disableVertexAttribArray(this.colorLocation); } } |