Severe Bug Updating Already Bound Buffer Object

From Android Game Development Wiki

Jump to: navigation, search

[edit] The Problem

When using buffer objects in OpenGL ES, e.g. vertex buffer objects or index buffer objects, it is advised to minimize glBindBuffer() calls as much as possible. One common use case is to update the vertex data stored in a vertex buffer object multiple times while the vertex buffer object is bound. See the following example pseudo code:

// bind vbo and ibo and enable vertex array client state
gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, vboHandle);
gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, iboHandle);		
gl.glEnableClientState(GL11.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL11.GL_FLOAT, 5 * 4, 0);
 
// upload data of vertices1 to vbo. contains 2 rectangles.
gl.glBufferData(GL11.GL_ARRAY_BUFFER, vertices1.limit() * 4, vertices1, GL11.GL_DYNAMIC_DRAW);									
gl.glDrawElements(GL11.GL_TRIANGLES, 12, GL11.GL_UNSIGNED_SHORT, 0);
 
// upload data of vertices2 to vbo, contains 1 rectangle.
gl.glBufferData(GL11.GL_ARRAY_BUFFER, vertices2.limit() * 4, vertices2, GL11.GL_DYNAMIC_DRAW);		
gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_SHORT, 0);
 
// unbind buffers
gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);


On Qualcomm's MSM720xa chips this does not work. It is unclear what the problem actually is, the bug is highly undeterministic and appears only when interacting with the touch screen(!).

[edit] The Solution

No solution is known at this point.

[edit] Sample Code

The above pseudo code is taken from an example found in the Android Game Development Wiki Samples project. The source file can be found here. The desired output looks like this:

Correct-vbo.png

The actual output might look like this after dragging the finger across the screen (yes, it is indeed silly...)

Incorrect-vbo.png

The second screenshot was taken on an HTC Hero running stock Android 1.5.

Personal tools