PDA

View Full Version : Enabling/Disabaling



LostInTheWoods
11-21-2003, 04:54 AM
If I am going to render a couple different meshs, each with there own texture, is the method below correct, I only ask cause I am currious if I should only turn some of these things on ONCE, cause the command is good for any texture or mesh, or if I realy should turn everything on and off each loop....

for(a=0; a<NumMeshs; a++)
{
//Texture 0
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture[a]);

//Texture 1
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D, Texture1D[a]);

//Setup Vertex info
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, Mesh[a].Verts);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, Mesh[a].TxCoords);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(1, GL_FLOAT, 0, Mesh[a].TxCoords1D);

if(CompiledVertexArraySupport == true)
{
glLockArraysEXT(0, Mesh[a].NumIndicies);
glDrawElements(GL_TRIANGLES, Mesh[a].NumIndicies, GL_UNSIGNED_INT, Mesh[a].Indicies);
glUnlockArraysEXT();
}

else
{
glDrawElements(GL_TRIANGLES, Mesh[a].NumIndicies, GL_UNSIGNED_INT, Mesh[a].Indicies);
}

//Disable vert info
glDisableClientState(GL_VERTEX_ARRAY);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_1D);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

Should I realy be enable/disable GL_TEXTURE_xD each time for each mesh, or can this be just left active, also do i need to disable the clientstates for the array types, ie: texture coord arrays, or vert arrays, or is this once again something I would only need to turn on once, and then just tell it which array im currently using with glVertexPointer etc etc..

Relic
11-21-2003, 05:07 AM
OpenGL is a state machine. Do not set state which hasn't changed to reduce calling overhead and validation. Period.

Means, if all drawelements in your code use the same enables, enable them once.
Disable only if required.
If textures and attribute arrays are also shared among meshes, set them once, draw all your stuff in a tight loop.
If attribute array pointers change per mesh, you need to set the pointers. Maybe you should think about restructuring your models then.