Closed Bug 521667 Opened 12 years ago Closed 11 years ago

Moz-WebGL: required size is calculated wrong for interleaved VBO


(Core :: Canvas: WebGL, defect)

Not set





(Reporter: spam, Unassigned)





(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; de; rv: Gecko/20090909 Fedora/3.5.3-1.fc11 Firefox/3.5.3
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.3a1pre) Gecko/20091011 Minefield/3.7a1pre

Function WebGLContext::ValidateBuffers (in canvas/src/WebGLContextValidate.cpp) does check if an VertexBufferObject (VBO) is large enough before rendering. However, it does calculate it in an wrong way:
 GLuint needed = vd.offset + (vd.stride ? vd.stride : vd.size) * count;

The does lead into problems when using an interleaved VBO where you need offset AND stride. I think it has to be:
 GLuint needed = vd.offset + (vd.stride ? vd.stride : vd.size) * (count-1) + vd.size;

Reproducible: Always

Steps to Reproduce:
VBO with 3 Vertices, 8 floats each (Position, Normal, 2D-TexCoords)
=> 24 floats total.
Now tell OpenGL where to find the attributes:
 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 8, 0);
 gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 8, 3);
 gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 8, 6);
 gl.drawArrays(gl.TRIANGLES, 0, 3);
Actual Results:  
You will get an error like this:
VBO too small for bound attrib index 1: need at least 27 elements, but have only 24

Error: uncaught exception: (...) NS_ERROR_ILLEGAL_VALUE (...) nsICanvasRenderingContextWebGL.drawArrays

Expected Results:  
A buffer of 24 float should be sufficient...

For more details see Discussion Board:
In one of the nightly builds last week the behavior has changed. Now it's even worse!

Function 'vertexAttribPointer' seems to count in bytes now, while the code in WebGLContextValidate.cpp does still count in floats.

=> Now you need 128 elements to render a simple quad where 32 float would be sufficient. I have added two examples.

For some reason this problem does not appear when rendering using function 'drawElements'.
Sorry, you need 140 elements, not 128.
Component: Canvas: 2D → Canvas: WebGL
QA Contact: canvas.2d → canvas.webgl
Ever confirmed: true
The size calculation bug has been fixed, and interleaved arrays are now properly working.

But your webgl program won't work, because it tried to call non-existent function getShaderi at line 114:

                if (!gl.getShaderi(shader, gl.COMPILE_STATUS)) {
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.