From 6bddbdf074e4d8fa4c50375dcff4e054601a60ee Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 13 Feb 2015 12:50:43 +0000 Subject: [PATCH] Improvements to the #pragma(tic) shader composition support git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14694 16af8721-9629-0410-8352-f15c8da7e697 --- include/osg/Program | 2 ++ include/osg/State | 1 - src/osg/Shader.cpp | 35 ++++++++++++++++++++++++----------- src/osg/State.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/include/osg/Program b/include/osg/Program index 2f1a1fc68..0cd786a08 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -283,6 +283,8 @@ class OSG_EXPORT Program : public osg::StateAttribute GLuint getHandle() const {return _glProgramHandle;} + const osg::Program* getProgram() const { return _program; } + void setDefineString(const std::string& defStr) { _defineStr = defStr; } const std::string& getDefineString() const { return _defineStr; } diff --git a/include/osg/State b/include/osg/State index ae6181399..4f0e938d3 100644 --- a/include/osg/State +++ b/include/osg/State @@ -1914,7 +1914,6 @@ class OSG_EXPORT State : public Referenced inline void applyModeMap(ModeMap& modeMap); inline void applyAttributeMap(AttributeMap& attributeMap); inline void applyUniformMap(UniformMap& uniformMap); - inline void applyUniformMap(DefineMap& defineMap); inline void applyModeListOnTexUnit(unsigned int unit,ModeMap& modeMap,const StateSet::ModeList& modeList); inline void applyAttributeListOnTexUnit(unsigned int unit,AttributeMap& attributeMap,const StateSet::AttributeList& attributeList); diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index d271f3596..ed6b50f7e 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -667,6 +667,7 @@ void Shader::PerContextShader::compileShader(osg::State& state) { // OSG_NOTICE<<"Shader::PerContextShader::compileShader() : Found #version, lineNum = "<(versionLine.c_str()); sourceText[1] = reinterpret_cast(_defineStr.c_str()); sourceText[2] = reinterpret_cast(source.c_str()); @@ -675,6 +676,7 @@ void Shader::PerContextShader::compileShader(osg::State& state) else { const GLchar* sourceText[2]; + //OSG_NOTICE<<"glShaderSource() ["<<_defineStr<<"], ["<(_defineStr.c_str()); sourceText[1] = reinterpret_cast(source.c_str()); _extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL ); @@ -725,6 +727,7 @@ void Shader::PerContextShader::detachShader(GLuint program) const void Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines) { + OSG_NOTICE<<"Shader::_parseShaderDefines("<getModeList()); +#if 1 + pushDefineList(_defineMap, dstate->getDefineList()); +#else applyDefineList(_defineMap, dstate->getDefineList()); +#endif + 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<getProgram()->apply(*this); + } + if (_shaderCompositionEnabled) { if (previousLastAppliedProgramObject == _lastAppliedProgramObject || _lastAppliedProgramObject==0) @@ -545,6 +556,10 @@ void State::apply(const StateSet* dstate) } } +#if 1 + popDefineList(_defineMap, dstate->getDefineList()); +#endif + // pop the stateset from the stack _stateStateStack.pop_back(); } @@ -576,10 +591,19 @@ void State::apply() // appropriate. applyModeMap(_modeMap); + const Program::PerContextProgram* previousLastAppliedProgramObject = _lastAppliedProgramObject; + // go through all active StateAttribute's, applying where appropriate. applyAttributeMap(_attributeMap); + if ((_lastAppliedProgramObject!=0) && (previousLastAppliedProgramObject==_lastAppliedProgramObject) && _defineMap.changed) + { + //OSG_NOTICE<<"State::apply() Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<getProgram()->apply(*this); + } + + if (_shaderCompositionEnabled) { applyShaderComposition();