Last Comment Bug 521667 - Moz-WebGL: required size is calculated wrong for interleaved VBO
: Moz-WebGL: required size is calculated wrong for interleaved VBO
Product: Core
Classification: Components
Component: Canvas: WebGL (show other bugs)
: unspecified
: All All
: -- normal with 2 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
: Milan Sreckovic [:milan]
Depends on:
  Show dependency treegraph
Reported: 2009-10-11 12:22 PDT by Martin Weusten
Modified: 2010-06-16 11:10 PDT (History)
6 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

This WebGl app should work, but doesn't. (7.80 KB, text/html)
2009-11-06 05:48 PST, Martin Weusten
no flags Details
Added 108 zeros => does work (8.73 KB, text/html)
2009-11-06 05:49 PST, Martin Weusten
no flags Details

Description Martin Weusten 2009-10-11 12:22:42 PDT
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:
Comment 1 Martin Weusten 2009-11-06 05:48:13 PST
Created attachment 410771 [details]
This WebGl app should work, but doesn't.
Comment 2 Martin Weusten 2009-11-06 05:49:29 PST
Created attachment 410772 [details]
Added 108 zeros => does work
Comment 3 Martin Weusten 2009-11-06 05:55:12 PST
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'.
Comment 4 Martin Weusten 2009-11-06 06:02:06 PST
Sorry, you need 140 elements, not 128.
Comment 5 Benoit Jacob [:bjacob] (mostly away) 2010-06-16 11:10:23 PDT
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)) {

Note You need to log in before you can comment on or make changes to this bug.