I'm creating a voxel-like game. I'm not sure if I am using VBO/EBO's correctly. I am creating a new VBO & EBO for every chunk. This is done once, but chunks call a render function in every block inside, and the block calls glDrawElements (Is there a more efficient way?). How can I specify which VBO & EBO each is supposed to use? Is this possible?

Thank you!


Regarding "EBOs" that is the only binding that is important at the time that you call glDrawElements (...). That is because a non-zero value assigned to GL_ELEMENT_ARRAY_BUFFER means that the pointer you pass to that function will point to memory owned by the buffer object you have bound to GL_ELEMENT_ARRAY_BUFFER.

Vertex Buffers are different, you only have to bind a buffer object to GL_ARRAY_BUFFER prior to calling glVertexAttribPointer (...). Just like glDrawElements (...), this function will setup a pointer to memory relative to the currently bound GL_ARRAY_BUFFER.

However, after glVertexAttribPointer (...) returns it no longer matters what is bound to GL_ARRAY_BUFFER; you already established what the source of the vertex pointer's memory is and changing the thing bound to GL_ARRAY_BUFFER after the fact will not change anything.

Long story short, your vertex pointers specify which VBO(s) is/are used and the GL_ELEMENT_ARRAY_BUFFER binding establishes the EBO. You can coalesce multiple buffers into one and then draw specific ranges at a time if you want to do this more efficiently (e.g. fewer buffer object binds). The thing is, buffer object bindings are a really cheap state to change - draw calls become expensive primarily because you change other more complicated things like textures or render targets.

  • \$\begingroup\$ For every render of every block I should call glVertexAttribPointer? \$\endgroup\$
    – badcc
    Jun 21 '14 at 1:35
  • \$\begingroup\$ You can if need be, or you could just combine everything into one buffer and draw different parts of that buffer. Ultimately I think what you may want is instancing, but to make instancing work efficiently you need to be drawing hundreds if not thousands of voxels with the same basic properties (e.g. texture, shader, etc.). \$\endgroup\$ Jun 21 '14 at 1:37
  • \$\begingroup\$ I got it working! And my criteria meets those demands, so I'm going to research instancing, now. Thank you for the help! \$\endgroup\$
    – badcc
    Jun 21 '14 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.