glDrawElements(GL_TRIANGLE_STRIP..) and glBegin(GL_TRIANGLE_STRIP)

Hi,

I have tried to see if there is any difference between using vertex array and traditional glBegin() glEnd().

Here is my code for two different methods:

void drawOld()
{
unsigned int index = _indexArray;
int xp = 0, xoffset;
int sizeX2 = _sizeX
2;
int sizeY1 = _sizeY-1;

for(int y=0; y<sizeY1; y++)
{
glBegin(GL_TRIANGLE_STRIP);
for(int x=0; x<sizeX2; x++)
{
xoffset = _indexArray[xp]*3;
glNormal3fv(&_normalArray[xoffset]);
glColor3fv(&_colorArray[xoffset]);
glVertex3fv(&_vertexArray[xoffset]);
xp++;
}
glEnd();

}
}

and

void draw()
{
unsigned int index = _indexArray;
int sizeX2 = _sizeX
2;
int sizeY1 = _sizeY-1;

glVertexPointer(3, GL_FLOAT, 0, _vertexArray);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3, GL_FLOAT, 0, _colorArray);
glEnableClientState(GL_COLOR_ARRAY);
glNormalPointer(GL_FLOAT, 0, _normalArray);
glEnableClientState(GL_NORMAL_ARRAY);

for(int y=0; y<sizeY1; y++)
{
glDrawElements(GL_TRIANGLE_STRIP, sizeX2, GL_UNSIGNED_INT, index);
index += sizeX2;
}
}

I couldn’t see any difference in the performance. They both got almost the same frame rate.

I can only access SGI machines, I have test them on O2 and Octane and the new UltimateVision system.

Thanks all for your input.

[This message has been edited by irix6 (edited 08-26-2003).]

  1. You don’t say what framerate you get. It’s possible that vsync is enabled and both methods are reaching that limit.

  2. You don’t say what the size of your data is. You’re more likely to see performance improvements with larger sets of data. If you only have 3 vertices and are drawing a single triangle, don’t expect to see a dramatic improvement.

  3. You could probably improve the vertex array method slightly by only calling the gl*Pointer methods and glEnableClientState methods once in an init function.

  4. There are extensions that will let you speed up vertex array usage. I don’t remember the extensions offhand, but I know they exist.

[This message has been edited by Deiussum (edited 08-26-2003).]

Please forgive my poor english.

My frame rate is misleading, sorry about it. I was using the time spent on the drawOld(), or draw(), to calculate the frame rate.(call gettimeofday() before and after)

And I have used display list. I just noticed that it may be the reason why I got similiar performance using two different method. The following is the result with or without display list.

_sizeX=_sizeY=256,

window size: 500x500

O2: R5000, 300 MHZ IP32, ~3.1 frames/sec
(the same with or without using display list)

Octane: R1000, 250 MHZ, IP30

  with DL             without DL	

drawOld() 11 10

draw() 11 8.5

UltimateVision: R14000 600 MHZ IP35,

  with DL               without DL	

drawOld() 407 16

draw() 407 30.5

So, if we are using display list, there is no difference in using vertex array or glBegin() glEnd()?

Thanks for your input.

[This message has been edited by irix6 (edited 08-26-2003).]

If you are using vertex arrays in a display list, it will compile the display list in immediate mode with the current values in the array, so you don’t gain anything in this case. So… that would be why you are seeing similar results when you use a display list.

So… if you are using vertex arrays in a display list, change the vertex array later, the display list is still going to have the same vertex information it had at the time it was compiled.

I was going to put that in as an option above, but thought you would have said that originally.

Anyway, it looks like you are getting the results I would expect.