ShaderComposition mechanism on the osg::State fixed

This commit is contained in:
valid-ptr 2020-10-27 17:20:43 +03:00 committed by konstantin.matveyev
parent 300ba7aa02
commit 43724f004e

View File

@ -713,19 +713,19 @@ void State::apply(const StateSet* dstate)
applyAttributeList(_attributeMap,dstate->getAttributeList());
if ((_lastAppliedProgramObject!=0) && (previousLastAppliedProgramObject==_lastAppliedProgramObject) && _defineMap.changed)
{
// OSG_NOTICE<<"State::apply(StateSet*) Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<<std::endl;
_lastAppliedProgramObject->getProgram()->apply(*this);
}
if (_shaderCompositionEnabled)
{
if (previousLastAppliedProgramObject == _lastAppliedProgramObject || _lastAppliedProgramObject==0)
// Checking if there is no program on the stack or the program is not applied from the AttributeStack (StateSet core mechanism)
if (_shaderCompositionEnabled && (_lastAppliedProgramObject == 0 ||
(_lastAppliedProgramObject->getProgram() != _attributeMap[_lastAppliedProgramObject->getProgram()->getTypeMemberPair()].last_applied_attribute)))
{
// No program has been applied by the StateSet stack so assume shader composition is required
applyShaderComposition();
}
if (_lastAppliedProgramObject != 0 && previousLastAppliedProgramObject == _lastAppliedProgramObject && _defineMap.changed)
{
// Pragma(tic) mechanism must be applied after ShaderComposer
// OSG_NOTICE<<"State::apply(StateSet*) Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<<std::endl;
_lastAppliedProgramObject->getProgram()->apply(*this);
}
if (dstate->getUniformList().empty())
@ -784,17 +784,19 @@ void State::apply()
// go through all active StateAttribute's, applying where appropriate.
applyAttributeMap(_attributeMap);
// Checking if there is no program on the stack or the program is not applied from the AttributeStack (StateSet core mechanism)
if (_shaderCompositionEnabled && (_lastAppliedProgramObject == 0 ||
(_lastAppliedProgramObject->getProgram() != _attributeMap[_lastAppliedProgramObject->getProgram()->getTypeMemberPair()].last_applied_attribute)))
{
// No program has been applied by the StateSet stack so assume shader composition is required
applyShaderComposition();
}
if ((_lastAppliedProgramObject != 0) && (previousLastAppliedProgramObject == _lastAppliedProgramObject) && _defineMap.changed)
{
// Pragma(tic) mechanism must be applied after ShaderComposer
//OSG_NOTICE<<"State::apply() Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<<std::endl;
if (_lastAppliedProgramObject) _lastAppliedProgramObject->getProgram()->apply(*this);
}
if (_shaderCompositionEnabled)
{
applyShaderComposition();
_lastAppliedProgramObject->getProgram()->apply(*this);
}
if (_currentShaderCompositionUniformList.empty()) applyUniformMap(_uniformMap);
@ -811,7 +813,7 @@ void State::applyShaderComposition()
{
// if (isNotifyEnabled(osg::INFO)) print(notify(osg::INFO));
// build lits of current ShaderComponents
// build list of current ShaderComponents
ShaderComponents shaderComponents;
// OSG_NOTICE<<"State::applyShaderComposition() : _attributeMap.size()=="<<_attributeMap.size()<<std::endl;
@ -835,7 +837,8 @@ void State::applyShaderComposition()
if (_currentShaderCompositionProgram)
{
Program::PerContextProgram* pcp = _currentShaderCompositionProgram->getPCP(*this);
if (_lastAppliedProgramObject != pcp) applyAttribute(_currentShaderCompositionProgram);
if (_lastAppliedProgramObject != pcp)
_currentShaderCompositionProgram->apply(*this); // NOTE: AttributeStack should not be changed by ShaderComposer
}
}
}