I just spent some hours to isolate a behavior of WebGL which i don't understand.
Let's assume a vertex shader with integer attribute:
precision highp int;
in vec4 vtx_pos;
in vec3 vtx_nrm;
in ivec4 vtx_int; // <- integer attribute
void main() {
// blah blah...
}
With the following shader attributes binding:
var p = gl.createProgram();
gl.bindAttribLocation(p, 0, "vtx_pos");
gl.bindAttribLocation(p, 1, "vtx_nrm");
gl.bindAttribLocation(p, 2, "vtx_int"); // <- ivec4 on array #2
And finally the following AttribPointer configuration:
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 28, 0);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 28, 16);
gl.enableVertexAttribArray(1);
gl.disableVertexAttribArray(2); // <- here is the devil
With this configuration (VertexAttribArray(2) disabled), browsers throws type error for the attribute 2:
Chrome: GL_INVALID_OPERATION : glDrawElements: vertexAttrib function must match shader attrib type
Firefox: drawElements: Vertex attrib 2 requires data of type INT, but is being supplied with type FLOAT.
What I understood is that when the VertexAttribArray is not explicitly enabled with the proper vertexAttribIPointer, WebGL consideres it be "supplied as FLOAT" by default, and so, throws a type error.
What I don't understand is: Why it checks the supplied type of an disabled VertexAttribArray where, logicaly, nothing is supplied ?
Except by enabling the VertexAttribArray as dummy, is there some magic to avoid this error ?