Torque3D Documentation / _generateds / GFXTransformSaver

GFXTransformSaver

Engine/source/gfx/gfxTransformSaver.h

Helper class to store viewport and matrix stack state, and restore it later.

More...

Public Functions

GFXTransformSaver(bool saveDataNow, bool restoreDataOnDestruct)

Constructor - controls how data is saved.

Returns the saved projection matrix.

Returns the saved projection matrix.

Returns the saved viewport.

Detailed Description

Helper class to store viewport and matrix stack state, and restore it later.

When doing complex out-of-scene rendering, for instance, doing a render to texture operation that needs its own transform state, it is very easy to nuke important rendering state, like the viewport or the projection matrix stored in vertex shader constant zero.

This class simplifies save and cleanup of those properties. You can either treat it as a stack helper, e.g.

void myFunc()
{
   GFXTransformSaver saver;

   // Lots of nasty render state changes...

   // Everything is magically cleaned up when saver is destructed!
}

Or you can manually control when you do saves or restores:

void myFunc()
{
   GFXTransformSaver saver(false, false);

   if(!somePrecondition)
      return false;     // Note early out.

   saver.save();

   // Lots of nasty render state changes...

   // If we had passed (false, true) to the constructor then it would
   // clean up automagically for us; but we want to do it manually.
   saver.restore();
}

Protected Attributes

bool mHaveSavedData 
bool mRestoreSavedDataOnDestruct 
MatrixF mSavedProjectionMatrix 
MatrixF mSavedViewMatrix 
RectI mSavedViewport 

Public Functions

GFXTransformSaver(bool saveDataNow, bool restoreDataOnDestruct)

Constructor - controls how data is saved.

Parameters:

saveDataNow

If true, indicates that saveData() should be called immediately. Otherwise, you can do it manually.

restoreDataOnDestruct

If true, indicates that restoreData() should be called on destruct. Otherwise, you'll have to do it manually.

~GFXTransformSaver()

getProjectionMatrix()

Returns the saved projection matrix.

getViewMatrix()

Returns the saved projection matrix.

getViewport()

Returns the saved viewport.

restore()

save()