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

[Public WebGL] Unused but enabled VertexAttribs



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.
https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/tests/fast/triangle.html

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.enableVertexAttribArray(0);
            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()

Thoughts?