PDA

View Full Version : changing viewport at each frame is bad ?



{MSX}
27-06-2005, 12:27 PM
Hi, is it bad to change the viewport and call gluPerspective at each frame ?
Is it too consuming or i can do that ? :P

thanks

Bart
27-06-2005, 01:51 PM
I don't think it's too consuming but I guess you better use glRotate and glTranslate functions if possible.

Paulius
27-06-2005, 10:48 PM
Premature optimisation is the root of all evil, really. Theres a ton of stuff that you are probablly doing thausands of times per frame and that is worth optimiseing, stuff you do only once per frame isn't. gluPerspective does some multiplications, some divisions and a matrix multiply, you're likelly doing this kind of stuff for every model yourself.

{MSX}
28-06-2005, 06:49 AM
Premature optimisation is the root of all evil, really. Theres a ton of stuff that you are probablly doing thausands of times per frame and that is worth optimiseing, stuff you do only once per frame isn't. gluPerspective does some multiplications, some divisions and a matrix multiply, you're likelly doing this kind of stuff for every model yourself.

This is a great true :P
Thanks paulius!

Sly
28-06-2005, 12:17 PM
What I have done, and what we do in our commercial game engine, is to store the matrix and only recalculate it if something changed. To avoid recalculating on every change though, we just set a flag that lets us know the matrix is "dirty" and needs to be recalculated.

Say we change the camera position. We set the vector describing the camera position and set a dirty flag. The next time the scene is drawn, we check the dirty flag. Because it is set, we recalculate the projection matrix, use it, and store it. Next frame, if the camera didn't move, we just use the stored matrix.

We do this for our views, our models, animations, everything that can be stored and re-used without having to recalculate the same thing over and over if nothing changed.