开发者

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:

  • I have a vertex and an index buffer that get filled in with glBufferSubData. There are a couple of meshes that get filled in one-by-one into this big VBO and its corresponding IBO
  • Then I try to render those small meshes with glDrawElements one-by-one

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

  • bind VBO/IBO and set appropriate client states
  • then set vertex, normal开发者_StackOverflow, and texcoord "pointers" - they point at the beginning of VBO plus their offsets in vertex "structure"
  • and call gl.glDrawElements(GL10.GL_TRIANGLES, indicesNum, GL10.GL_UNSIGNED_SHORT, startIndexOffsetInBytes);
  • then finally, unbind VBO/IBO and disable client states

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?


: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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜