[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] Re: Unused but enabled VertexAttribs

On Mon, May 10, 2010 at 10:53 AM, Gregg Tavares <gman@google.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.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
            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()


So Ken Russell suggested that WebGL should do something under the hood to hide this issue from WebGL programs instead of reporting an error.  There are various solutions. For example, disable the unused arrays, draw, re-enable. How doesn't matter. What matters is that we decide what the correct behavior is for the WebGL spec.