Sign in to follow this  
stein

glMultMatrixf performance?

Recommended Posts

From: http://www.gamedev.net/community/forums/topic.asp?topic_id=281360
Quote:
Original post by hoLogramm ...glTranslate*, glRotate* and glScale* Functions. They might seem to create overhead but they are much more efficient than a single call to glMultMatrix*.
Can anyone confirm this?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quite the oposite. glTranslate*, glRotate* and glScale* will have to create a matrix and multiply it with the current one. Yes, this can be optimized a bit but all combined it's still not faster than just giving it matrix in one glMultMatrix*. Specialy becouse alot of rendering techniques require this matrix for other purposes.

edit: My results form GLBench
[code]
MATRIX Time(us)
glMatrixMode 0.01
glLoadIdentity 0.05
glTranslate 0.07
glRotate 0.30
glGetFloat 0.08
glMultMatrix 0.16
glLoadMatrix 0.10
glScale 0.07
[code]
glRotate + glTranslate + glScale => 0.44
glMultMatrix => 0.16

Share this post


Link to post
Share on other sites
Sorry, I formulated it too sloppy.

@_DarkWIng_: Thx for the Benchmark. I didn't know that the glRotate* Command takes up so much time.

But you see that two function calls to glTranslate* and glScale* are nearly equal to one call to glMultMatrix*.
Quote:

glTranslate 0.07 + glScale 0.07 <= glMultMatrix 0.16
glRotate 0.30


And you may not forget the time you need to calculate your own Transformation Matrix which is all included in the call to glTranslate, glScale and glRotate!!


Performance Tips from the OpenGL Reference Guide The Red Book

Follow the Link:
http://fly.cc.fer.hr/~unreal/theredbook/appendixh.html

Quote:

OpenGL Performance Tips

Use glLoadIdentity() to initialize a matrix, rather than loading your own copy of the identity matrix.


Use specific matrix calls such as glRotate*(), glTranslate*(), and glScale*(), rather than composing your own rotation, translation, and scale matrices and calling glMultMatrix().


[Edited by - hoLogramm on November 8, 2004 6:30:32 AM]

Share this post


Link to post
Share on other sites
errm... welcome to the world of somewhat pointless micro-opterminsations [oh]

yes, the gltranslate, glrotate et al will have over head as for each one you have to make a function call, vs 1 function call for the glmultmatrix, however as someone said you still need to construct that matrix.

Now, if you have the matrix laying around already it will be faster to just glmultmatrix, rather than attempting to apply a series of rotations and translations etc to get the same effect (a good example of this is producing reflections when you're projection transformation doesnt change, you need to use it the projection matrix to ensure things appear right, so instead of calling a routine to setup you can store the matrix earlier in the program and just glmultmatrix it onto the texture stack).

However, in priniple I really wouldnt worry about this at all, if you get to the point where simple transforms are your bottle neck you've either got the fastest program in the world or a horrible design. Things like texture swaps will take ALOT longer to perform when rendering so you should worry about that more than transformation.

Just use whats right for the sitution at hand so the code works, if you really need to change it it will show up in a profile later once its working

Share this post


Link to post
Share on other sites
it's all doesn't matter if you code something "real". You have to deal with quaternions, or you have your own matrices pre-ready, or both, etc. and there's nearly no use for matrix stack as result.

I think in performance tips they mean that if you make your own translation matrix and do glMulMatrix, computer will do complete 4x4 matrix multiplication. And if you call glTranslate, computer will update only 3 cells of rightmost column, and it's much faster.
Same with rotation, but benefit is bit smaller. Any sane implementation will not do complete 4x4 matrix multiplication for rotation, only 3x3 multiplication. And same with scale.

Share this post


Link to post
Share on other sites
ill back up _the_phantom_ , this shouldnt be a bottleneck + if it is somethings buggered. but anyways i use multmatrix cause i like doing the calculations myself (so i have access to this info) but doing these calculations ofcourse takes time. thus u should be comparing

matrix calculations +
multmatrix

vs

rotate
translate

Share this post


Link to post
Share on other sites
zedzeek: True. One thing to note is that you need to rebuild matrix only for dynamic objects and even only a part of then per frame in any real world scenario. But in general, speed-wise this is a null point. I use then becouse I need matrices anyway.

Share this post


Link to post
Share on other sites
i think glTranslate alone is faster than making translation matrix and multiplying *only* because glTranslate doesn't have to multiply 4x4 matrices together. But of course for complete transforms(rotation&translation) it's faster to compute matrix yourself and then glMultMatrix.

It's just matter of math optimizations for incomplete transforms. If optimizations in glTranslate and glRotate give no benefit (you gonna to do complete transform) , it will be faster if you'll make your own matrix, but only if you do it in not too stupid way.(if you'll make translation and rotation matrices, then ordinarly multiply 'em together, then glMultMatrix , it will be slower, if you'll make rotation&translation matrix in one step and without doing unnecessary math operations, it might be faster)

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