glMultiDrawElements problems

Started by
-1 comments, last by rewolfer 13 years, 6 months ago
I am wanting to render a list of indexed triangles. The index buffer is partitioned into regions representing different meshes which I call "blocks".
Only some of these blocks need to be rendered in a given frame, and I therefore felt that glMultiDrawElements was the perfect function. Unfortunately I have had little luck. Instead of this, for testing, I've been looping through glDrawElements calls, but I assume that it is more efficient to use glMultiDrawElements.

When I try to use it I get inconsistent results, such as:
1) It seems to render correctly, but when I end the application I get (SIGABRT) accused of "double-freeing" or memory corruption along with a lovely memory dump.
2) Everything initializes but nothing gets rendered. Exiting the application is clean and nice.
3) It dies during initializing the vertex buffers system memory (I use std::vector for these) usually during a push_back call.
4) Finally, I sometimes get a segfault when trying to access a vertex that should definitely have been placed in the vertex std::vector.

All the above problems seem strangely unrelated and don't ever occur if I use the simple glDrawElements approach.

My Method for the glMultiDrawElements:

1) I have two static arrays to store offsets and counts:
GLsizei   m_draw_count [128];  // number of indices per primitiveGLvoid*   m_draw_starts[128];  // byte-offsets into index VBOint       m_primcount;

NB. 128 is an arbitrarily chosen maximum.

2) These are changed every frame according to a culling scheme
3) The draw call references the arrays:
glMultiDrawElements(GL_TRIANGLES, (GLsizei*)(m_draw_count), GL_UNSIGNED_INT, (const GLvoid**)(m_draw_starts), m_primcount);


Now, if I instead want to use a looped glDrawElements:

1) The draw_starts array is changed to GLuint
GLuint    m_draw_starts[128];

2) The draw call is converted to
for (int i = 0; i < m_primcount; i++)  glDrawElements(GL_TRIANGLES, m_draw_count, GL_UNSIGNED_INT, (GLvoid*)(m_draw_starts));


Then everything works without issues, and I've checked for memory leaks etc. with valgrind. From my point of view, changing the draw call should have no effect on initialisation and thus the data type member variable m_draw_starts must have some bad effect (GLvoid*[]). But honestly I have no idea what's wrong.

If someone can help me, I'll buy them a chocolate next time I see them.

Thanks a stack

rewolf

This topic is closed to new replies.

Advertisement