[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Unused but enabled VertexAttribs
----- "Gregg Tavares" <email@example.com> wrote:
So it turns out that if you just enable a vertex attrib, even though your shader doesn't use it, you can crash some OpenGL drivers.
Example: this is just the modified triangle sample from here.
Just before draw, add the following line
gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
gl.viewport(0, 0, 50, 50);
var vertexObject = gl.createBuffer();
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(3); // added line
gl.drawArrays(gl.TRIANGLES, 0, 3); // CRASH! (depending on GL driver)
Catching this issue in WebGL 2 paths come to mind.
#1) Generate INVALID_OPERATION on drawArrays because the enabled vertex attrib is not used by the current shader program
#2) Generate INVALID_OPERATION on drawArrays because the enabled vertex attrib does not have a buffer bound that has enough elements to satisfy the drawArray call (as though it was used by the current shader program)
#2 seems like the better option as many programs probably enable 4 to 8 attribs and never disable them and after that just manipulate what they point to through vertexAttribPointer()
Hmm... so the issue is that /something/ needs to be bound if the array is enabled? Option #2 sounds fine to me; I was trying to come up with any situations where we don't have enough information to determine that, but I think that the check should be relatively straightforward.