multiple vertex arrays

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

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(…)

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?

Sorry. I have to bump this…

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.

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.

I agree. Use VBOs which seem to work across most modern hardware.