Added State::s/getRootStateSet() that enables applications to insert a StateSet above all rendering for a graphics context. Utilized in the new shadper pipeline functionality

This commit is contained in:
Robert Osfield 2016-11-02 11:13:57 +00:00
parent 172ca9bae5
commit a99b05ff87
2 changed files with 40 additions and 3 deletions

View File

@ -806,6 +806,12 @@ class OSG_EXPORT State : public Referenced
inline const DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); } inline const DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
/** Set the root StateSet this is applied above all StateSet that are pushed and popped during the draw traversal.*/
void setRootStateSet(osg::StateSet* stateset);
/** Get the root StateSet.*/
osg::StateSet* getRootStateSet() { return _rootStateSet.get(); }
/** Set flag for early termination of the draw traversal.*/ /** Set flag for early termination of the draw traversal.*/
void setAbortRenderingPtr(bool* abortPtr) { _abortRenderingPtr = abortPtr; } void setAbortRenderingPtr(bool* abortPtr) { _abortRenderingPtr = abortPtr; }
@ -1047,6 +1053,8 @@ class OSG_EXPORT State : public Referenced
GraphicsContext* _graphicsContext; GraphicsContext* _graphicsContext;
unsigned int _contextID; unsigned int _contextID;
osg::ref_ptr<osg::StateSet> _rootStateSet;
osg::ref_ptr<VertexArrayState> _globalVertexArrayState; osg::ref_ptr<VertexArrayState> _globalVertexArrayState;
VertexArrayState* _vas; VertexArrayState* _vas;

View File

@ -507,9 +507,36 @@ void State::setMaxBufferObjectPoolSize(unsigned int size)
OSG_INFO<<"osg::State::_maxBufferObjectPoolSize="<<_maxBufferObjectPoolSize<<std::endl; OSG_INFO<<"osg::State::_maxBufferObjectPoolSize="<<_maxBufferObjectPoolSize<<std::endl;
} }
void State::setRootStateSet(osg::StateSet* stateset)
{
if (_rootStateSet == stateset) return;
_rootStateSet = stateset;
if (_stateStateStack.empty())
{
if (stateset) pushStateSet(stateset);
}
else
{
StateSetStack previousStateSetStack = _stateStateStack;
// we want to reset all the various state stacks, inserting the new root StateSet as the topmost one automatically (popeAllStateSet() does this.)
popAllStateSets();
// now we have to add back in all the StateSet's to make sure the state is consistent
for(StateSetStack::iterator itr = previousStateSetStack.begin();
itr != previousStateSetStack.end();
++itr)
{
pushStateSet(*itr);
}
}
}
void State::pushStateSet(const StateSet* dstate) void State::pushStateSet(const StateSet* dstate)
{ {
_stateStateStack.push_back(dstate); _stateStateStack.push_back(dstate);
if (dstate) if (dstate)
{ {
@ -551,6 +578,8 @@ void State::popAllStateSets()
applyModelViewMatrix(0); applyModelViewMatrix(0);
_lastAppliedProgramObject = 0; _lastAppliedProgramObject = 0;
if (_rootStateSet.valid()) pushStateSet(_rootStateSet.get());
} }
void State::popStateSet() void State::popStateSet()
@ -678,7 +707,7 @@ void State::captureCurrentState(StateSet& stateset) const
void State::apply(const StateSet* dstate) void State::apply(const StateSet* dstate)
{ {
// OSG_NOTICE<<__PRETTY_FUNCTION__<<std::endl; // OSG_NOTICE<<__PRETTY_FUNCTION__<<" _stateStateStack.size()="<<_stateStateStack.size()<<std::endl;
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply(StateSet*)"); if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply(StateSet*)");
@ -774,7 +803,7 @@ void State::apply(const StateSet* dstate)
void State::apply() void State::apply()
{ {
// OSG_NOTICE<<__PRETTY_FUNCTION__<<std::endl; // OSG_NOTICE<<__PRETTY_FUNCTION__<<" _stateStateStack.size()="<<_stateStateStack.size()<<std::endl;
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply()"); if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply()");