Effective multitexturing

Hello

I am currently developping a 3D model player using opengl ES.
I found good way to optimize my code with storing all my vertices in one array and the same for a texture.
It works perfectly but i’m encountering a problem then…

How am i supposed to do this with multitexturing ??

Here’s a pseudo code example since my question is not very accurate…

int main()
{
loading_textures_and_vertices(glfloat *tex_vertices, glfloat vertices);

while (42)
{
setting stuff…
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1); //only using one texture
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glTexCoordPointer(2, GL_FLOAT, 0, tex_vertices);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLES, 0, total_face_nbr);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

}
}

Now i am wondering if it won’t cost me too much performance to store vertices and tex_coords with their appropriate textures in a structure array and then looping through it (code coming after) while switching textures ?

it would look like this (assuming the first example)

for (int a = 0; a < struct_array_size; a++)
{
glBindTexture(GL_TEXTURE_2D, struct_array[a].tex_id);
glTexCoordPointer(2, GL_FLOAT, 0, struct_array[a].tex_vertices);

glVertexPointer(3, GL_FLOAT, 0, struct_array[a].vertices);

glDrawArrays(GL_TRIANGLES, 0, struct_array[a].face_nbr);
}

Do you know a better way to do this ?
Since there are a lot of useful things (like display lists) that are not avaiable in opengl ES ?

Thanks a lot for your time !

Because 42…

No seriously, if you search how to specify different texture coordinates per texture unit using vertex arrays, look at the glClientActiveTexture function

you can use it like this if I am right:


glClientActiveTexture( GL_TEXTURE0_ARB );

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer0 );

glTexCoordPointer(2, GL_FLOAT, 0, NULL);

        

glActiveTexture( GL_TEXTURE0_ARB );

glEnable( GL_TEXTURE_2D );

// bind texture

...

glClientActiveTexture( GL_TEXTURE1_ARB );

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glBindBuffer( GL_ARRAY_BUFFER, texCoordBuffer1 );

glTexCoordPointer(2, GL_FLOAT, 0, NULL);

        

glActiveTexture( GL_TEXTURE1_ARB );

glEnable( GL_TEXTURE_2D );

// bind texture

...


This just an example, I don’t know if it is exactly what you are looking for.

Great !
I think it will be just fine for what i need !
But does this procedure is performance costing ?
Thanks.

I don’t really know, just try it,:stuck_out_tongue: I don’t think there is actually another option to do that.