OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
SceneUtil::StateSetUpdater Class Reference

Implements efficient per-frame updating of StateSets. More...

#include <statesetupdater.hpp>

Inheritance diagram for SceneUtil::StateSetUpdater:
Collaboration diagram for SceneUtil::StateSetUpdater:

Public Member Functions

 StateSetUpdater ()
 
 StateSetUpdater (const StateSetUpdater &copy, const osg::CopyOp &copyop)
 
virtual META_Object(SceneUtil,
StateSetUpdater) virtual void
operator()(osg 
apply (osg::StateSet *stateset, osg::NodeVisitor *nv) void
 
virtual void setDefaults (osg::StateSet *stateset)
 

Protected Member Functions

void reset ()
 Reset mStateSets, forcing a setDefaults() on the next frame. Can be used to change the defaults if needed. More...
 

Private Attributes

osg::ref_ptr< osg::StateSet > mStateSets [2]
 

Detailed Description

Implements efficient per-frame updating of StateSets.

With a naive update there would be race conditions when the OSG draw thread of the last frame
queues up a StateSet that we want to modify for the next frame. To solve this we could set the StateSet to DYNAMIC data variance but that would undo all the benefits of the threading model - having the cull and draw traversals run in parallel can yield up to 200% framerates.
Race conditions are prevented using a "double buffering" scheme - we have two StateSets that take turns,
one StateSet we can write to, the second one is currently in use by the draw traversal of the last frame.
Must be set as UpdateCallback on a Node.
Note
Do not add the same StateSetUpdater to multiple nodes.
Do not add multiple StateSetControllers on the same Node as they will conflict - instead use the CompositeStateSetUpdater.

Constructor & Destructor Documentation

SceneUtil::StateSetUpdater::StateSetUpdater ( )
SceneUtil::StateSetUpdater::StateSetUpdater ( const StateSetUpdater copy,
const osg::CopyOp &  copyop 
)

Member Function Documentation

virtual META_Object (SceneUtil, StateSetUpdater) virtual void operator()(osg SceneUtil::StateSetUpdater::apply ( osg::StateSet *  stateset,
osg::NodeVisitor *  nv 
)
inlinevirtual

Apply state - to override in derived classes

Note
Due to the double buffering approach you have to apply all state even if it has not changed since the last frame.

Reimplemented in MWRender::AlphaFader, MWRender::Moon::Updater, MWRender::Sun::Updater, NifOsg::FlipController, MWRender::GlowUpdater, NifOsg::AlphaController, MWRender::CloudUpdater, MWRender::AtmosphereNightUpdater, MWRender::AtmosphereUpdater, MWRender::StateUpdater, and SceneUtil::CompositeStateSetUpdater.

void SceneUtil::StateSetUpdater::reset ( )
protected

Reset mStateSets, forcing a setDefaults() on the next frame. Can be used to change the defaults if needed.

Here is the caller graph for this function:

virtual void SceneUtil::StateSetUpdater::setDefaults ( osg::StateSet *  stateset)
inlinevirtual

Member Data Documentation

osg::ref_ptr<osg::StateSet> SceneUtil::StateSetUpdater::mStateSets[2]
private

The documentation for this class was generated from the following files: