1
\$\begingroup\$

I have been learning how to make a game with LWJGL for a while now by following YouTube tutorials online but I've recently been having a problem understanding Vertex Buffer Objects. I've looked at several tutorials including the one at the LWJGL Wiki, but I still don't understand how to use them.

Can someone please clarify how Vertex Buffer Objects should be used? I understand the code behind it but I don't know how it should be used. I know that the VBO should only be created once and be rendered every frame/loop. But my main question is, is there one Vertex Buffer Object per game or one per Object to be drawn? Also, what's the difference between VBOs and Interleaved VBOs?

\$\endgroup\$
4
  • \$\begingroup\$ I've searched for the same thing before but didn't come up with anything. You may need to search for tutorials on the C version of OpenGL. The LWJGL functions aren't a 100% mirror of it, but it's close enough and there are some that provide good explanations on the topic. \$\endgroup\$ Mar 28, 2014 at 14:39
  • \$\begingroup\$ See my answer to the same question on Stackoverflow: stackoverflow.com/questions/6172308/opengl-java-vbo/… \$\endgroup\$
    – msell
    Mar 28, 2014 at 18:36
  • \$\begingroup\$ @msell That still doesn't answer my two major questions: Is there one VBO per game or one per Object to be drawn? Also, what's the difference between VBOs and Interleaved VBOs? \$\endgroup\$ Mar 28, 2014 at 20:12
  • \$\begingroup\$ @Gamefreak0 Sorry I read your question too quickly. I hope my new answer is more helpful. \$\endgroup\$
    – msell
    Mar 29, 2014 at 5:31

1 Answer 1

1
\$\begingroup\$

Interleaved VBOs

Let's assume you have vertices V_1, V_2, ... V_i each having position p and normal n. Positions and normals are called vertex attributes. Vertex attributes can be stored in an array, e.g. positions = {p_1, p_2, ..., p_i} and normals = {n_1, n_2, ..., n_i}. If you feed these arrays to OpenGL, you are using non-interleaved VBOs. You can also combine them to a single array as attributes = {p_1, p_2, ..., p_i, n_1, n_2, ..., n_i} and tell OpenGL the offset in the array where each attribute starts.

Alternatively, if you store them as attributes = {p_1, n_1, p_2, n_2, ..., p_i, n_i}, you are using interleaved VBOs. In this case you again feed a single array to OpenGL, tell where the first element of each attribute starts, and how many elements to skip to find the next element of the same attribute type.

See this answer about the benefits and downsides of interleaved VBOs. For performance reasons I would recommend to implement only interleaved VBOs from the beginning, unless it is considerably easier for your data to be used with non-interleaved VBOs.

Sharing VBOs

Every time you change a binding (e.g. current VBO) in OpenGL requires some processing. Usually you want to avoid unnecessary bindings if you want to maximize performance. It's possible to have a unique VBO per object or combine all of the meshes in a single VBO. I can't say which is usually better approach, but I would say a unique VBO per mesh is at least easier to implement and I would recommend that as your first implementation. Combining multiple meshes in a single VBO can become ugly when the meshes have different attributes, e.g. one mesh having positions and normals and other one having positions and texture coordinates. Also in OpenGL ES you can quickly reach the limitation of 65536 vertices per VBO, as the indices in index buffer are 16 bit.

See this answer for a better breakdown.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .