PDA

View Full Version : multiple vertex arrays



hugo4711
01-30-2004, 10:31 AM
I have several different objects in my scene and would like to render them as vertex arrays. Since I use different arrays for different objects I have to do this for each object in every frame:

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT, 0,vertex_array);
glNormalPointer(GL_FLOAT, 0, normal_array);
glTexCoordPointer(2, GL_FLOAT, 0,texcoords_array);

glDrawArrays(GL_TRIANGLES, 0,num_verticies);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);


I would guess that this is very inefficient but have no other idea how to do this, because I have to switch the pointers to the different arrays...

Is there a better way to do this when using multiple vertex arrays?

Thank you in advance

Vlasko
01-30-2004, 11:40 AM
You don't have to do glEnableClientState(...) and glDisableClientState(...) every frame just use glEnableClientState once in initialization and then switch arrays with glVertex(Normal,TexCoord)Pointer(....)

hugo4711
01-30-2004, 12:26 PM
Thank you for that quick answer!

Some of my objects have no normal verticies. When I switch the pointers, what would I do with the normal array pointer? Does it work like that:

glNormalPointer(GL_FLOAT, 0, NULL);

Or do I have to disable that client state explicitly before setting the pointers and drawing the arrays?

Another question is: how I can lock some of the arrays while others wont be locked (glLockArraysEXT)? Do I have to do this every frame (because the pointers change)? Or is there an internal reference set, the first time I init the arrays?

hugo4711
01-31-2004, 12:11 AM
Sorry. I have to *bump* this...

maximian
01-31-2004, 08:10 PM
vertex array locking provides a benifit only if your rendering more than once per lock. That is if your locking and unlocking every time you render you will get little benefit. Take a look at the reference document, available on the opengl extensions registry web site.

Obli
02-02-2004, 09:22 AM
Originally posted by maximian:
vertex array locking provides a benifit only if your rendering more than once per lock. That is if your locking and unlocking every time you render you will get little benefit. Take a look at the reference document, available on the opengl extensions registry web site.
If you are referring to EXT_compiled_vertex_array, I must say this extension is badly out of date (that's why it's not in core GL). In the tests I ran some time ago (should be about 2-3 months) CVAs proved to be slower than non-compiled arrays.
Possibly, the gain/loss is dependant from the application, system and implementation.
I personally suggest to drop them.

maximian
02-02-2004, 09:27 AM
I agree. Use VBOs which seem to work across most modern hardware.