You can not switch textures within an vertex array flush. Why do you think the most new engines use only one basetexture per object? So that they don’t need that many API calls and can let the GPU keep working.
But this would make vertex arrays nearly useless, because i would have to switch to the next texture after every single polygon!
If you are too lazy to switch your brain on to find a solution for this that’s half right. Where by glArrayElement is still faster than immediate mode. Vertex Arrays are FAR faster than immediate mode. If you use video or AGP memory for them anyway. But you can’t await of OpenGL to compensate the matter that you are not open to write just one single line of code more than needed.
Following things you can do:
Possibility 1:
If you draw a landscape for example and you have only some less different textures you can create X independent arrays (one for each texture) and always store the new vertices in the adapting array. When it’s filled then you can flush all the way:
select texture 0
draw array 0
select texture 1
draw array 1
…
Possibility 2:
Kicking your 3D graphician into his butt to texturize the models again so that only still one texture is used per object. Then simply storing all models in a queue and sorting them by quicksort before they’re flushed.
Possibility 3:
Would at least help a bit: Sorting your textures within the model, when it’s loaded.
I think the most people use possibility 2… me as well. If you have already many models done then… you have a bunch of work now.
Hm… reading your post I am still waiting for the day someone asks, why OpenGL can’t automatically play a sound, when a primitive is drawn…
For the case you should also be too lazy to write a quicksort yourself, here some code you can modify by your needs:
void C09AphLyxMemoryBank::QuickSortChains(C09AphLyxMemoryChain *data,int from,int to)
{
if(from==to)
return;
int Lo,Hi,Mid;
C09AphLyxMemoryChain T;
Lo = from;
Hi = to;
Mid = (int)data[(Lo + Hi)/2].mlpPointer;
do
{
while((int)data[Lo].mlpPointer < Mid)
Lo++;
while((int)data[Hi].mlpPointer > Mid)
Hi–;
if(Lo <= Hi)
{
T=data[Lo];
data[Lo] = data[Hi];
data[Hi] = T;
Lo++;
Hi--;
};
} while( !(Lo > Hi));
if(Hi > from)
QuickSortChains(data, from, Hi);
if(Lo < to)
QuickSortChains(data, Lo, to);
};
BlackJack