Sign in to follow this  
hellraiser

OpenGL Loading or pushing and popping matrices?

Recommended Posts

Hi, I'd like to know which of the following methods is faster in OpenGL when it comes to loading/resetting the modelview and projection matrices: - to load the matrix by using glLoadMatrixf - to rely on a set of glPushMatrix/glPopMatrix calls At the moment I am using a combination of the two, but I tend to self-convince myself that glLoadMatrixf should be faster. Which is the fastest method in your personal experience?

Share this post


Link to post
Share on other sites
i would think that push/pop is faster

since loadmatrix would result in sending the matrix to the gpu, while push/pop tells the gpu with a command what to do..

i dont know if this is true, but it should be correct

Share this post


Link to post
Share on other sites
If the GPU supports a matrix stack on board, then glPush and pop will be faster but I doubt that any of them do.

Also, don't worry about it. Don't optimize too early.
If you have the matrix ready, just use glLoadMatrix. It's only 16 floats that will be sent.

Share this post


Link to post
Share on other sites
GPUs don't have hardware matrix stacks. The current matrices are pushed down to the card when you make a draw call, along with other relevant state.

LoadMatrix is essentially a memory copy. PushMatrix is essentially a pointer increment and a memory copy. (I don't know if drivers implement some kind of adaptive growth strategy, but even if they do, the costs will get amortized quickly.) Either way, it doesn't matter at all. Don't concern yourself with such trivial nonsense.

Share this post


Link to post
Share on other sites
I was thinking that maybe OpenGL does some sort of 'state init' processing whenever a modelview or projection matrix is loaded and that maybe pushing/popping simply pushed/popped that 'state' making it the fastest method of the two.

But I'm glad I was overcomplicating this issue and that there are no performance issues involved!

Thanks to all for the invaluable input given.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this