myself
myself

Reputation: 502

OpenGL ES: glBufferSubData fills meshes into VBO/IBO, then glDrawElements renders only the first mesh instead of all of them

My problem seems to be really simple but I just can't get the reason behind it:

Problem is, only first mesh gets rendered - and multiple times - in places where each of those different meshes should be!!!

Following info may be useful:

I create VBO this way

gl.glGenBuffers(1, buffers_, 0);
gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, buffers_[0]);
gl.glBufferData(GL11.GL_ARRAY_BUFFER, sizeInBytes, null, GL11.GL_DYNAMIC_DRAW);

Then each mesh is filled into the VBO like this

gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, name);
gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, startOffsetInBytes, numBytesToCopy, nioBuffer);

And meshes are rendered in this fasion

I debugged the code and I'm sure that sizeInBytes, startOffsetInBytes, numBytesToCopy and startIndexOffsetInBytes are correct values (in bytes:))) and indicesNum is the number of indices/vertices in the mesh (to render).

One suspicious place is setting vertex/normal/texcoord pointers - they get set only once - and set to the beginning of the VBO. Maybe I need to set them each time before calling glDrawElements?

Upvotes: 1

Views: 1316

Answers (1)

myself
myself

Reputation: 502

:D Found that reason. Everything I described is correct indeed. Problem is in the way meshes are being added into the VBO/IBO - indices for each new mesh were restarted from 0!! So only the first mesh in VBO was getting rendered.

Upvotes: 1

Related Questions