Sign in to follow this  

glMultiDrawElements and constants

This topic is 4360 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

void glMultiDrawElements(unsigned int,const int *,unsigned int,const void ** ,int)
glMultiDrawElements seems to be just what I want except that the two arrays passed to it are constants. I'm building that data ever frame, they can't be constants. I'm missing something, right?

Share this post


Link to post
Share on other sites
Quote:
I'm building that data ever frame, they can't be constants.

These parameters imply the function promises not to modify the data pointed to by the passed pointer. They don't necessarily mean you can't modify it's content.

I prefer writing the function like this:
void glMultiDrawElements(unsigned int const,int const*const,unsigned int const,void const*const*const ,int const)
It seems to be a lot of constants, but as long as you follow the const-correctness, you will save a lot of headaches when debugging later.

Share this post


Link to post
Share on other sites
Thanks for the link, it explains the concept but I'm not understanding how this is supposed to work. Here's some working code:
for(int i = 0; i < HEIGHTM_WIDTH-1; i++)
glDrawElements(GL_TRIANGLE_STRIP, HEIGHTM_WIDTH*2,
GL_UNSIGNED_INT, (unsigned int *)(i*HEIGHTM_WIDTH*2*sizeof(unsigned int)) );


which I want to look like this instead:
unsigned int *meshIndicesArrays[HEIGHTM_WIDTH];
int meshIndicesListLengths[HEIGHTM_WIDTH];
//...//
glMultiDrawElements(GL_TRIANGLE_STRIP, meshIndicesListLengths, GL_UNSIGNED_INT, meshIndicesArrays, 512);


I don't understand why the compiler won't take that. It says it can't convert param 4 'unsigned int *[512]' to 'const void ** '.

[Edited by - avocados on January 10, 2006 12:43:46 AM]

Share this post


Link to post
Share on other sites
You'll need to change it roughly to:

glMultiDrawElements(GL_TRIANGLE_STRIP, reinterpret_cast<void **> (&meshIndicesListLengths), GL_FLOAT, meshIndicesArrays, 512);


In the case you don't want to bother with reinterpret_cast, just take it as an ordinary C-style cast (but using reinterpret_cast<> reminds you better later):
glMultiDrawElements(GL_TRIANGLE_STRIP, (void **) (&meshIndicesListLengths), GL_FLOAT, meshIndicesArrays, 512);


When you declare unsigned int *meshIndicesArrays[HEIGHTM_WIDTH]; and pass it to glDrawElements (), the compiler can not make sure that function will behave nicely to your array as it doesn't specify how many elements it will manipulate (i.e: It accesses the #1024 element while your array has only 512). So you'll provide a cast to shut the compiler up, it is safe as long as you know your array is sufficiently large for the function.

If you declare your variable as unsigned int **pp_meshIndices ;, the compiler won't complain anymore.

Share this post


Link to post
Share on other sites
Thanks for the solution and for adding the proper c-style cast, I do prefer it that way. I had to use (const void **) &meshIndicesList to get it to compile though.

Edit: Oops, we were talking about param 4, not 2. Proper usage:
unsigned int *meshIndicesArrays[HEIGHTM_WIDTH];
int meshIndicesArrayLengths[HEIGHTM_WIDTH];
//...//
glMultiDrawElements(GL_TRIANGLE_STRIP, meshIndicesArrayLengths,
GL_UNSIGNED_INT, (const void **) &meshIndicesArrays, HEIGHTM_WIDTH);


[Edited by - avocados on January 10, 2006 3:19:33 PM]

Share this post


Link to post
Share on other sites

This topic is 4360 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this