I’m working on a Quake 3 level viewer, and I’ve run into a really strange bug.
I have a big list of vertices, say 50,000, with colors and texture coordinates. So, I call glVertexPointer,glTexCoordPointer, glColorPointer, and then lock the arrays using glLockArraysEXT.
When I render, I process shaders, bind textures, set materials, and then call glDrawElements. It works well.
Now, I start to process Q3 visibility data. To save time when rendering, I don’t build the list of polygons dynamically, I just attach a boolean ‘DrawMe’ flag to each face. Instead of calling glDrawElements, I do this:
glBegin(GL_TRIANGLES);
for(i=sipIndex;i<sipIndex+sipCount;i++)
{
if(RD->PolyVis[i]) //<-my boolean flag
{
glArrayElement(RD->Polys[i].V1);
glArrayElement(RD->Polys[i].V2);
glArrayElement(RD->Polys[i].V3);
PolysPerFrame++;
}
}
glEnd();
Now, here comes the weird part:
I started to optimize, and I started keeping track of lists of polys that are ALL visible, so instead of doing the above glArrayElement thing, I could just call glDrawElements, so now, it looks something like this:
if(!DrawWholeChunk)
glBegin(GL_TRIANGLES);
for(i=sipIndex;i<sipIndex+sipCount;i++)
{
if(RD->PolyVis[i]) //<-my boolean flag
{
glArrayElement(RD->Polys[i].V1);
glArrayElement(RD->Polys[i].V2);
glArrayElement(RD->Polys[i].V3);
PolysPerFrame++;
}
}
glEnd();
}
else
{
glDrawElements(GL_TRIANGLES,sipCount*3,GL_UNSIGNED_INT,RD->Polys+sipIndex);
}
OK, this worked, but my frame-rate all of a sudden went down to 2 FPS. I spent a couple of hours trying to track the problem down, but the code seemed perfect. Just out of curiosity, I stopped using compiled vertex arrays, and what do you know, the FPS went back to normal! What the hell is going on? I read the specs, but there was nothing that suggested something like this could happen.
I don’t mind not using compiled arrays, but I was just interested if this is expected behavior.
My system specs:
Dual Pentium III 700s
nVidia GeForce 2 GTS(Elsa Gladiac)
Detonator 28.32 drivers
Thanks in advance.
-Shard