Jump to content
  • Advertisement
Sign in to follow this  
avocados

OpenGL glDrawMultiElements usage

This topic is 2834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This function correctly renders 9 strips with 20 vertices when it uses glDrawElements but makes my entire screen flicker (outside the openGL window) when using glMultiDrawElements. I don't understand what is going on.

GLsizei counts[9];
const GLvoid *starts[9];
unsigned int strip_num = 9;
for(int i = 0; i < 9; i++) {
counts = 20;
starts = (GLvoid*)(i * 20*sizeof(unsigned int) + indices_offset);
}
if( multi_draw )
glMultiDrawElements( GL_TRIANGLE_STRIP, &counts[9], GL_UNSIGNED_INT, &starts[0], strip_num);
else {
for(int i = 0; i < 9; i++)
glDrawElements(GL_TRIANGLE_STRIP, counts, GL_UNSIGNED_INT, starts);
}

Share this post


Link to post
Share on other sites
Advertisement
glMultiDrawElements is for reducing the number of calls to glDrawElements.
However, it is useless since it doesn't give a performance advantage.

As for your problem, your starts variable is bad.
It is suppose to be a pointer to pointer array. Something like

uint myarray_1[X];
uint myarray_2[X];
uint myarray_3[X];

uint *starts[3];
starts[0]=myarray_1;
starts[1]=myarray_2;
starts[2]=myarray_3;

Share this post


Link to post
Share on other sites
I rewrote my post while you were responding. It wasn't clear before the edit that my pointer array references a vertex array buffer on the gpu and not system memory.

Share this post


Link to post
Share on other sites
In that case

glMultiDrawElements( GL_TRIANGLE_STRIP, &counts[9], GL_UNSIGNED_INT, &starts[0], strip_num);

needs to be

glMultiDrawElements( GL_TRIANGLE_STRIP, &counts[0], GL_UNSIGNED_INT, &starts[0], strip_num);

because &counts[9] points to some random memory location.

Share this post


Link to post
Share on other sites
Hah wow that was dumb. Too much copy & pasting when I was trying to fix something else. I had been confused when the compiler complained that GLvoid** can't be converted to const GLvoid** and I started changing arguments around a lot. Still not sure why it can't automatically convert that but I see i can typecast it and it works.

Thanks for finding my simple error there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!