From 3f33016854f5d94fa503156f9fc5f49a49ce55a2 Mon Sep 17 00:00:00 2001 From: yelper Date: Mon, 27 Jan 2014 15:31:56 -0600 Subject: [PATCH 1/2] adding support for int type in shaders --- src/shader.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shader.js b/src/shader.js index 4ed6314..937e296 100644 --- a/src/shader.js +++ b/src/shader.js @@ -123,6 +123,12 @@ function Shader(vertexSource, fragmentSource) { regexMap(/uniform\s+sampler(1D|2D|3D|Cube)\s+(\w+)\s*;/g, vertexSource + fragmentSource, function(groups) { isSampler[groups[2]] = 1; }); + + // also do this for items that are explicitly marked as `int` types + regexMap(/uniform\s+int\s+(\w+)\s*;/g, vertexSource + fragmentSource, function(groups) { + isSampler[groups[1]] = 1; + }); + this.isSampler = isSampler; } From 9892c9b3ec22cbda050e21821d3b6dfb42f54d87 Mon Sep 17 00:00:00 2001 From: yelper Date: Thu, 6 Feb 2014 16:31:16 -0600 Subject: [PATCH 2/2] fixing bug that prevents multiple shaders to be used with vertex buffers at different locations --- src/shader.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shader.js b/src/shader.js index 937e296..63f1706 100644 --- a/src/shader.js +++ b/src/shader.js @@ -264,7 +264,16 @@ Shader.prototype = { } else { gl.drawArrays(mode, 0, length); } - } + } + + // release any buffers; + // if the shader is switched, some attributes could still be linked to buffers, causing + // GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute [location]: + // see http://stackoverflow.com/questions/12427880/is-it-important-to-call-gldisablevertexattribarray + gl.bindBuffer(gl.ARRAY_BUFFER, null); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); + for (var attribute in vertexBuffers) + gl.disableVertexAttribArray(this.attributes[attribute]); return this; }