Added support for passing on uniforms from StateAttribute
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <osg/ShaderAttribute>
|
||||
#include <osg/Notify>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/State>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
@@ -78,7 +80,12 @@ bool ShaderAttribute::getModeUsage(StateAttribute::ModeUsage& usage) const
|
||||
|
||||
void ShaderAttribute::apply(State& state) const
|
||||
{
|
||||
OSG_NOTICE<<"ShaderAttribute::apply(..)"<<std::endl;
|
||||
for(Uniforms::const_iterator itr = _uniforms.begin();
|
||||
itr != _uniforms.end();
|
||||
++itr)
|
||||
{
|
||||
state.applyShaderCompositionUniform(itr->get());
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderAttribute::compose(ShaderComposer& composer) const
|
||||
|
||||
@@ -37,7 +37,7 @@ osg::Program* ShaderComposer::getOrCreateProgram(const ShaderComponents& shaderC
|
||||
ProgramMap::iterator itr = _programMap.find(shaderComponents);
|
||||
if (itr != _programMap.end())
|
||||
{
|
||||
OSG_NOTICE<<"ShaderComposer::getOrCreateProgram(..) using cached Program"<<std::endl;
|
||||
// OSG_NOTICE<<"ShaderComposer::getOrCreateProgram(..) using cached Program"<<std::endl;
|
||||
return itr->second.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -495,6 +495,7 @@ void State::apply(const StateSet* dstate)
|
||||
|
||||
if (dstate)
|
||||
{
|
||||
_currentShaderCompositionUniformList.clear();
|
||||
|
||||
applyModeList(_modeMap,dstate->getModeList());
|
||||
applyAttributeList(_attributeMap,dstate->getAttributeList());
|
||||
@@ -515,9 +516,32 @@ void State::apply(const StateSet* dstate)
|
||||
else if (unit<_textureAttributeMapList.size()) applyAttributeMapOnTexUnit(unit,_textureAttributeMapList[unit]);
|
||||
}
|
||||
|
||||
applyShaderComposition();
|
||||
if (_shaderCompositionEnabled)
|
||||
{
|
||||
applyShaderComposition();
|
||||
|
||||
if (dstate->getUniformList().empty())
|
||||
{
|
||||
if (_currentShaderCompositionUniformList.empty()) applyUniformMap(_uniformMap);
|
||||
else applyUniformList(_uniformMap, _currentShaderCompositionUniformList);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_currentShaderCompositionUniformList.empty()) applyUniformList(_uniformMap, dstate->getUniformList());
|
||||
else
|
||||
{
|
||||
// need top merge uniforms lists, but cheat for now by just applying both.
|
||||
_currentShaderCompositionUniformList.insert(dstate->getUniformList().begin(), dstate->getUniformList().end());
|
||||
applyUniformList(_uniformMap, _currentShaderCompositionUniformList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
applyUniformList(_uniformMap,dstate->getUniformList());
|
||||
}
|
||||
|
||||
applyUniformList(_uniformMap,dstate->getUniformList());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -533,6 +557,8 @@ void State::apply()
|
||||
|
||||
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply()");
|
||||
|
||||
if (_shaderCompositionEnabled) _currentShaderCompositionUniformList.clear();
|
||||
|
||||
// go through all active OpenGL modes, enabling/disable where
|
||||
// appropriate.
|
||||
applyModeMap(_modeMap);
|
||||
@@ -548,9 +574,15 @@ void State::apply()
|
||||
if (unit<_textureAttributeMapList.size()) applyAttributeMapOnTexUnit(unit,_textureAttributeMapList[unit]);
|
||||
}
|
||||
|
||||
applyShaderComposition();
|
||||
|
||||
applyUniformMap(_uniformMap);
|
||||
if (_shaderCompositionEnabled)
|
||||
{
|
||||
applyShaderComposition();
|
||||
applyUniformList(_uniformMap, _currentShaderCompositionUniformList);
|
||||
}
|
||||
else
|
||||
{
|
||||
applyUniformMap(_uniformMap);
|
||||
}
|
||||
|
||||
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("end of State::apply()");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user