Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
For every render of every block I should call glVertexAttribPointer? –  badcc Jun 21 at 1:35
    
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.). –  Andon M. Coleman Jun 21 at 1:37
    
I got it working! And my criteria meets those demands, so I'm going to research instancing, now. Thank you for the help! –  badcc Jun 21 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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