Hi,
We have situation where we want to change uniform values in DrawCallback before
rendering some geometry. It looks as there is no state::applyUniform method.
We have come up with following code (our code was much more complex this is
simplified example ) :
-----------------------------------------------------------------------------------------------------
class CounterDrawCallback: public Drawable::DrawCallback
{
public:
CounterDrawCallback( Uniform * uniform )
{
_counter = 0.0f;
_uniform = uniform;
_stateset = new StateSet;
_stateset->addUniform( uniform );
}
void drawImplementation( State & state, Drawable * drawable )
{
_counter += 1.0f;
_uniform->set( _counter );
state.apply( _stateset.get() );
drawable->drawImplementation( state );
}
protected:
ref_ptr< Uniform > _uniform;
ref_ptr< StateSet > _stateset;
float _counter;
}
-----------------------------------------------------------------------------------------------------
But above code does not work. Uniform is not applied by state.apply(
_stateset.get() ). Is this a bug ? Somehow state:: _lastAppliedProgramObject
variable gets reset in state::apply before appying new uniform value.
Instaed we come up with updated version which applies Program as well:
-----------------------------------------------------------------------------------------------------
class CounterDrawCallback: public Drawable::DrawCallback
{
public:
CounterDrawCallback( Program * program, Uniform * uniform )
{
_counter = 0.0f;
_uniform = uniform;
_stateset = new StateSet;
_stateset->setAttributeAndModes( program, StateAtribute::ON );
_stateset->addUniform( uniform );
}
void drawImplementation( State & state, Drawable * drawable )
{
_counter += 1.0f;
_uniform->set( _counter );
state.apply( _stateset.get() );
drawable->drawImplementation( state );
}
protected:
ref_ptr< Uniform > _uniform;
ref_ptr< StateSet > _stateset;
float _counter;
}
-----------------------------------------------------------------------------------------------------
This method works but I suspect that is far from optimal. So what is recomended
method to minimize state changes ?
Regards,
Wojtek Lewandowski_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/