PDA

View Full Version : Whats Faster?



Jmoses
03-27-2002, 03:58 PM
1) Whats the differnt between glFloat and float? Why should I use glFloat?

2) If I had the coords of a million polygons stored in an array and the numbers wern't being modified, would it draw any faster if i stuck them in a glList instead and used GL_compile?

3) What would be faster?
glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x+1, y+1, z+1);
glEnd();

- OR -

glTranslatef(1, 1, 1);
glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x+1, y+1, z+1);
glEnd();

Once again, thanks for your time.

Old GLman
03-27-2002, 04:07 PM
Hi. Using the gl data types make it easier to port from one platform to another. Using the gl data types stops various compilers and environments changing the size and memory layouts of C variables. a float in one enviroment might be different in another. Using glFloat will ensure it is always the same size.

Yes, display lists are always faster. It stores the data in memory ready to be called at any time. It is basically a preprocessed set of commands.

The only difference between the two routines I can see is the glTranslatef(). I dont think either of them would be any faster or slower than the other. glTranslatef() just takes information on how to translate along either the x, y, or z axis, respectively. It then constructs the appropriate matrix, and waalaa, your object is where you want it. The only difference between the code is your translating one and not the other.

Hope I answered your questions.

Old GLman

[This message has been edited by Old GLman (edited 03-27-2002).]

nemesis
03-28-2002, 02:44 AM
Hello!



2) If I had the coords of a million polygons stored in an array and the numbers wern't being modified, would it draw any faster if i stuck them in a glList instead and used GL_compile?



Yes, display list are faster than raw triangles. But you can try an even faster method using compiled vertex arrays (CVA). The idea is the same behind display lists. They are pre-compiled and stored in memory, ready to be called as a block.

hope it helps.

-nemesis-

[This message has been edited by nemesis (edited 03-28-2002).]

Furrage
03-28-2002, 08:25 AM
By any chance did you mean..

glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x+1, y+1, z+1);
glEnd();

vs.

glTranslatef(1, 1, 1);
glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x, y, z);
glEnd();

and not

Originally posted by Jmoses:
glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x+1, y+1, z+1);
glEnd();

- OR -

glTranslatef(1, 1, 1);
glBegin(GL_TRIANGLES);
for(i = 0; i < map.objects; i++)
glVertex3f(x+1, y+1, z+1);
glEnd();



If so, I suspect the glTranslate version is faster since all it does is update the matrix once while you do map.objects * 3 additions the other way. Also, based on the documentation, whether you do transforms or not you still multiply vertices by the model view matrix. So that's overhead you can't get away from.

[This message has been edited by Furrage (edited 03-28-2002).]

Jmoses
03-29-2002, 05:32 AM
whoops. I didn't catch my typo, Furrage, I'm glad you did.
Thanks foe the help again, I'm trying to optimize my program as much as I can...