Jump to content
  • Advertisement
Sign in to follow this  
stein

glMultMatrixf performance?

This topic is 4975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

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

glRotate + glTranslate + glScale => 0.44
glMultMatrix => 0.16

Share this post


Link to post
Share on other sites
Yea, that's excactly what I thought... Didn't really make sense to me!

Thanks for the nice bench-results - quite useful knowledge :)

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
I confirm that 1 glMultMatrix is a lot faster than doing 1 glTranslate + 1 glRotate + 1 glScale (or even translate + rotate "only").

Y.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!