Hi,

I'm currently writing an OpenGL ES 1.0 application for Windows Mobile (6.5.5, on a HTC Touch Pro 2), but I'm getting some weird behaviour when rendering multiple primitives out of the same vertex buffer. What I'm basically doing is allocating a static vertex buffer, calling glBufferData() a single time with a NULL datapointer to create the data storage, and then do two separate glBufferSubData() calls to update specific pieces of the buffer. In the render loop I'm doing two glDrawArrays() calls, but the second one always seems to render exactly the same vertices as the first one.

So, in pseudocode, when rendering two quads, it goes something like:
Code :
uint bufferName;
void Init()
{
	glGenBuffers(1, &bufferName);
	glBindBuffer(GL_ARRAY_BUFFER, bufferName);
	glBufferData(GL_ARRAY_BUFFER, 16384, 0,GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
	// ...
 
	// update first 4 verts in the buffer
	glBindBuffer(GL_ARRAY_BUFFER, bufferName);
	glBufferSubData(GL_ARRAY_BUFFER, 0, 4 * 20, pQuadA);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
 
	// ...
 
	// update second 4 verts in the buffer
	glBindBuffer(GL_ARRAY_BUFFER, bufferName);
	glBufferSubData(GL_ARRAY_BUFFER, 80, 4 * 20, pQuadB);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
void Draw()
{
	glBindBuffer(GL_ARRAY_BUFFER, bufferName);
	glEnableClientState(gl.GL_VERTEX_ARRAY);
	glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
 
	// render quad A
	glVertexPointer(3, gl.GL_FIXED, 20, (void*)0);
	glTexCoordPointer(2, gl.GL_FIXED, 20, (void*)12);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
	// render quad B
	glVertexPointer(3, gl.GL_FIXED, 20, (void*)80);
	glTexCoordPointer(2, gl.GL_FIXED, 20, (void*)92);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
This will always make quad A render twice (the call for quad B appears to be using same vertices as for A - this becomes evident when I set a different matrix before drawing B). However, if I reverse the draw order it will make quad B always render twice. And if I make the rendering of A conditional (like to no longer render after I tapped the screen), it will continue rendering B with the verts of A, until I update the buffer with glBufferSubData(). After that, it will render B as normal, but if I then enable A again by another screen tap it will render A with the verts of B.

In other words, it looks like that the driver detects that a certain buffer is being rendered and it caches it somewhere else, and a buffer update invalidates the cache. But what the driver is missing is that the offsets for the various arrays are also updated in the mean time, but it doesn't see that, so it keeps rendering with the first cached buffer.

Is this to spec, or is the OpenGL ES implementation on my phone buggy?