3
\$\begingroup\$

I've got multiple buffers in OpenGL holding data on position, normals and texcoords.

I also have an equal number of buffers holding distinct index data for each of those buffers.

I quite like this format (indvidual indexes for each buffer) utilised by COLLADA since it strikes me as optimally efficient at accessing each buffer.

I've set up pointers to the relevant data arrays using VertexPointer, NormalPointer, etc however I have no way to assign pointers to the index buffers since DrawElements appear to only look at one ElementArrayBuffer.

Can I utilise multiple indices some way or will I be better off using a different technique which can support this? I'd prefer to keep the distinct indices if at all possible.

\$\endgroup\$
1
\$\begingroup\$

You can have bound only one index array at a time. So you cann't use separate index array for each vertex attribute. So only choice is to rearrange all arrays according to one index array.

\$\endgroup\$
1
  • \$\begingroup\$ Ouch. I almost might as well not bother with the indices... I'll accept shortly failing any other suggestions. \$\endgroup\$ – Rushyo Jun 19 '11 at 20:07
1
\$\begingroup\$

I know this is really old, but for those googling.

I'm fairly sure you can just bind multiple EBO's to a single VAO.

(in OpenTK, but it would be something like this):

        GL.BindVertexArray(vao);

        // Vertices
        GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.SizeInBytes), vertices, BufferUsageHint.StaticDraw);
        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

        // Indices
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(uint)), indices, BufferUsageHint.StaticDraw);

        // Second lot of indices
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo2);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices2.Length * sizeof(float)), indices2, BufferUsageHint.StaticDraw);

        GL.BindVertexArray(0);

        // Remember to unbind ebo AFTER vao, not before
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

Now all you have to do is use the DrawElements function for each set of indices, or like The Fiddler said above use MultiDrawElements.

\$\endgroup\$
0
\$\begingroup\$

GL.MultiDrawElements should be able to do this. Check out the documentation for this function.

\$\endgroup\$
2
  • \$\begingroup\$ This can be used for more models (geometry), but not for attributes. Attributes of one model are using the same index array. \$\endgroup\$ – zacharmarz Jun 22 '11 at 11:50
  • \$\begingroup\$ My understanding of this method concurs with zacharmarz's statement. \$\endgroup\$ – Rushyo Jun 22 '11 at 12:26

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.