View Full Version : Which is faster?
Which is faster? A glLoadIdentety() or a glPushMatrix()/glPopMatrix combination. The reason I wonder is that I load the identity matrix and then push the matrix before I draw anything and then pop it again, and I do this for each frame. Wouldn't it be the same as loading the identity matrix at the beginning of each frrame instead?
02-02-2001, 02:33 AM
I think when you do a glPushMatrix(), gl put it on the stack and loads a new identity matrix.
but on the other hand, glLoadIdentity() afaik clears up the stack...
a benchmark here would be nice http://www.opengl.org/discussion_boards/ubb/wink.gif
02-02-2001, 02:41 AM
glPushMatrix() only pushes the current matrix onto the stack and glPopMatrix() pops the current matrix from the stack. It doesn't reload the matrix with identity after calling glPushMatrix()
02-02-2001, 02:59 AM
just to for understanding
Osku you want to do something like
i am not sure if that is a good way of doing it, since most cards don't multiply with the identity matrix and i am not sure if the card recognizes a that the matrix you just popped out the stack is a ident matrix.
glPushMatrix just puts the current matrix on the stack and doesn't load the ident matrix and loading the identmatrix doesn't do anything with your stack
02-02-2001, 03:00 AM
ups...you're right...I forgot that :-)
It won't be funny if glPushMatrix loads an identity-matrix http://www.opengl.org/discussion_boards/ubb/smile.gif
sorry, my fault http://www.opengl.org/discussion_boards/ubb/smile.gif
02-02-2001, 04:25 AM
If you load an identity and then push it onto the stack, you should get it back when you pop it off. As I understand it, not multiplying with the identity matrix is a shortcut since it would be pointless - what you end up with is the matrix that you multiplied it by, so you could just bypass the multiplication step and say the answer is the matrix that you were multiplying the identity by (did that sentence make sense? http://www.opengl.org/discussion_boards/ubb/smile.gif ) This should have no effect on whether or not the identity matrix ended up on the stack - If the current matrix is the identity and you push it onto the stack, it ends up on the stack, no matter which matrix it happens to be. At least that's near as I can tell from playing around with it a bit. Someone please let me know if I'm just on crack here.
Here is my understanding of it.
PushMatrix creates a new matrix with the current matrix's state. PopMatrix will pop off the matrix and return you to the original state before you pushed. Loadidentity just changes the current matrix to the identity matrix. ( I guess that means 1's in a diagonal and the rest zeroes in the matrix ) So, it just clears everything out.
So, if your keeping some sort of initial state in your matrix then calling load identity would erase it. Now if you wanted to keep that initial state then you could push...do stuff..pop and that would preserve the initial state. Otherwise, I guess you could call loadidentity if you were not keeping track of a state.
//copy of matrix A
//matrix A is now altered...
//you cleared out altered matrix A to identity
//matrix A is restored to state before push
Or if you did not care about matrix A then
Hmmm I bet glLoadIdentity might be faster because your not doing a push/pop but if you have to create some initial state each time then it could make it slower I suppose.
This is what I do :
Now I call the InitGL once and the identity matrix is loaded and i just push it and the pop it. Wouldn't it be faster to just load the identity matrix each time instead of pushing and popping it?
02-04-2001, 08:14 AM
The right answer is: Bench it!
glPushMatrix and glPopMatrix copy memory around on the matrix stacks.
glLoadIdentity just initializes the current matrix (and not to forget, there is no need to calculate an inverse of that). My guess is glLoadIdentity is faster in this case.
I think you're wasting too many thoughts in this little detail. The main work will definitely be in another place, if you'll have only those two calls.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.