Hi,
I posted late last year a message regarding deferred shading having issues to determine if a certain object is using a texture or not. Somehow the message never reached the mailing list.
In the meantime I found a solution to pass this information to the appropriate shaders automatically via OSGShaderVariable. Please find attached the source modifications and let me know your thoughts.
The attached Diff for OSGSimpleSHLChunk.h/.cpp additionally contains changes due to shader variable update problems when using more than one window (see forceVariableUpdate). We already dicussed them in May 2014, see thread http://sourceforge.net/p/opensg/mailman/message/32336956/. Gerrit wanted to investigate that issue in detail. Do you have any news on that?
Thanks,
Michael
.../ComputeShader/OSGComputeShaderChunk.cpp | 3 +++ Source/System/RenderingBackend/OSGDrawEnv.cpp | 8 ++++--- Source/System/RenderingBackend/OSGDrawEnv.h | 4 ++++ Source/System/RenderingBackend/OSGDrawEnv.inl | 6 +++++ Source/System/State/Base/OSGStateChunk.cpp | 5 +++++ Source/System/State/Base/OSGStateChunk.h | 3 +++ .../Shader/Chunks/OSGShaderExecutableChunk.cpp | 11 +++++++++ .../State/Shader/Chunks/OSGShaderExecutableChunk.h | 3 +++ .../Shader/Chunks/OSGShaderExecutableVarChunk.cpp | 1 + .../System/State/Shader/SHL/OSGSimpleSHLChunk.cpp | 19 +++++++++++++--- Source/System/State/Shader/SHL/OSGSimpleSHLChunk.h | 6 ++++- .../State/Shader/Variables/OSGShaderProcVariable.h | 3 ++- .../Shader/Variables/OSGShaderVariableOSG.cpp | 26 ++++++++++++++++++++++ .../State/Shader/Variables/OSGShaderVariableOSG.h | 3 ++- 14 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderChunk.cpp b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderChunk.cpp index d74aed5..9dbb029 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderChunk.cpp +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderChunk.cpp @@ -480,6 +480,7 @@ void ComputeShaderChunk::activate(DrawEnv *pEnv, return; pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); if(0x0000 == (uiValRes & ProgActive)) { @@ -524,6 +525,7 @@ void ComputeShaderChunk::changeFrom(DrawEnv *pEnv, return; pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); if(0x0000 == (uiValRes & ProgActive)) { @@ -558,6 +560,7 @@ void ComputeShaderChunk::deactivate(DrawEnv *pEnv, return; pEnv->setActiveShader(0); + pEnv->setActiveShaderChunk(NULL); OSGGETGLFUNC_GL3_ES(glUseProgram, osgGlUseProgram, diff --git a/Source/System/RenderingBackend/OSGDrawEnv.cpp b/Source/System/RenderingBackend/OSGDrawEnv.cpp index 895a7d0..bd3eb14 100644 --- a/Source/System/RenderingBackend/OSGDrawEnv.cpp +++ b/Source/System/RenderingBackend/OSGDrawEnv.cpp @@ -43,6 +43,7 @@ #include "OSGDrawEnv.h" #include "OSGState.h" +#include "OSGStateChunk.h" #include "OSGStateOverride.h" #include "OSGBaseFunctions.h" #include "OSGFullStateChunk.h" @@ -126,6 +127,7 @@ DrawEnv::DrawEnv(void) : _pStatCollector (NULL ), _uiActiveShader (0 ), + _pActiveShaderChunk (NULL ), _uiActiveFBO (0 ), _eTargetBufferFormat (GL_RGBA), _uiRequiredOGLFeature (0 ) @@ -401,11 +403,12 @@ void DrawEnv::activateState(State *pNewState, _pActiveState = pNewState; _pActiveStateOverride = pNewStateOverride; } + + if(_pActiveShaderChunk) + _pActiveShaderChunk->updateStateDependencies(this); } } - - void DrawEnv::activate(State *pState) { pState->activate(this); @@ -1047,7 +1050,6 @@ void DrawEnv::updateChunk(State *pState, if(c != NULL && c->getIgnore() == false && c->getClassId() < climit) { - c->updateObjectDependencies(this); } } diff --git a/Source/System/RenderingBackend/OSGDrawEnv.h b/Source/System/RenderingBackend/OSGDrawEnv.h index 004fbe5..741911d 100644 --- a/Source/System/RenderingBackend/OSGDrawEnv.h +++ b/Source/System/RenderingBackend/OSGDrawEnv.h @@ -60,6 +60,7 @@ class RenderPartition; class Window; class State; class StateOverride; +class StateChunk; /*! \ingroup GrpSystemRenderingBackendBase \ingroup GrpLibOSGSystem @@ -197,6 +198,8 @@ class OSG_SYSTEM_DLLMAPPING DrawEnv void setActiveShader ( UInt32 uiActiveShader); UInt32 getActiveShader ( void ); + void setActiveShaderChunk ( StateChunk *pShaderChunk ); + void setActiveFBO ( UInt32 uiActiveFBO ); UInt32 getActiveFBO ( void ); @@ -441,6 +444,7 @@ class OSG_SYSTEM_DLLMAPPING DrawEnv GLenum _aActiveTexTargets[osgMaxTexImages]; UInt32 _uiActiveShader; + StateChunk* _pActiveShaderChunk; UInt32 _uiActiveFBO; GLenum _eTargetBufferFormat; UInt32 _uiRequiredOGLFeature; diff --git a/Source/System/RenderingBackend/OSGDrawEnv.inl b/Source/System/RenderingBackend/OSGDrawEnv.inl index 4eb453c..3d00e19 100644 --- a/Source/System/RenderingBackend/OSGDrawEnv.inl +++ b/Source/System/RenderingBackend/OSGDrawEnv.inl @@ -227,6 +227,12 @@ UInt32 DrawEnv::getActiveShader(void) } inline +void DrawEnv::setActiveShaderChunk(StateChunk* pShaderChunk) +{ + _pActiveShaderChunk = pShaderChunk; +} + +inline void DrawEnv::setActiveFBO(UInt32 uiActiveFBO) { _uiActiveFBO = uiActiveFBO; diff --git a/Source/System/State/Base/OSGStateChunk.cpp b/Source/System/State/Base/OSGStateChunk.cpp index 8c821c4..40dc32f 100644 --- a/Source/System/State/Base/OSGStateChunk.cpp +++ b/Source/System/State/Base/OSGStateChunk.cpp @@ -304,6 +304,11 @@ void StateChunk::updateObjectDependencies(DrawEnv *pEnv, { } +void StateChunk::updateStateDependencies (DrawEnv *pEnv, + UInt32 index) +{ +} + /*---------------------- Chunk Class Access -------------------------------*/ const StateChunkClass *StateChunk::getClass(void) const diff --git a/Source/System/State/Base/OSGStateChunk.h b/Source/System/State/Base/OSGStateChunk.h index c65ad12..0c4c7c3 100644 --- a/Source/System/State/Base/OSGStateChunk.h +++ b/Source/System/State/Base/OSGStateChunk.h @@ -212,6 +212,9 @@ class OSG_SYSTEM_DLLMAPPING StateChunk : public StateChunkBase virtual void updateObjectDependencies(DrawEnv *pEnv, UInt32 index = 0); + virtual void updateStateDependencies (DrawEnv *pEnv, + UInt32 index = 0); + /*! \} */ /*---------------------------------------------------------------------*/ /*! \name Comparison */ diff --git a/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.cpp b/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.cpp index df030dd..e57c5af 100644 --- a/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.cpp +++ b/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.cpp @@ -576,6 +576,7 @@ UInt32 ShaderExecutableChunk::handleGL(DrawEnv *pEnv, pWin); pEnv->setActiveShader(uiProgram); + pEnv->setActiveShaderChunk(this); osgGlUseProgram (uiProgram); updateVariables(pEnv, uiProgram); @@ -583,6 +584,7 @@ UInt32 ShaderExecutableChunk::handleGL(DrawEnv *pEnv, if(0x0000 == (uiOptions & KeepProgActive)) { pEnv->setActiveShader(0); + pEnv->setActiveShaderChunk(NULL); osgGlUseProgram (0); } else @@ -764,6 +766,7 @@ void ShaderExecutableChunk::activate(DrawEnv *pEnv, pWin); pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); osgGlUseProgram (uiProgId); } @@ -817,6 +820,7 @@ void ShaderExecutableChunk::changeFrom(DrawEnv *pEnv, pWin); pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); osgGlUseProgram (uiProgId); } @@ -874,6 +878,7 @@ void ShaderExecutableChunk::deactivate(DrawEnv *pEnv, } pEnv->setActiveShader(0); + pEnv->setActiveShaderChunk(NULL); pEnv->subRequiredOGLFeature(HardwareContext::HasAttribAliasing); @@ -898,6 +903,12 @@ void ShaderExecutableChunk::updateObjectDependencies(DrawEnv *pEnv, updateProceduralVariables(pEnv, ShaderProcVariable::SHDObject); } +void ShaderExecutableChunk::updateStateDependencies (DrawEnv *pEnv, + UInt32 index) +{ + updateProceduralVariables(pEnv, ShaderProcVariable::SHDState); +} + void ShaderExecutableChunk::merge(const ShaderProgramChunk *pChunk) { editMField(VertexShaderFieldMask, _mfVertexShader ); diff --git a/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.h b/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.h index db3d91e..4783451 100644 --- a/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.h +++ b/Source/System/State/Shader/Chunks/OSGShaderExecutableChunk.h @@ -122,6 +122,9 @@ class OSG_SYSTEM_DLLMAPPING ShaderExecutableChunk : virtual void updateObjectDependencies(DrawEnv *pEnv, UInt32 index = 0); + virtual void updateStateDependencies (DrawEnv *pEnv, + UInt32 index = 0); + /*! \} */ /*---------------------------------------------------------------------*/ /*! \name Output */ diff --git a/Source/System/State/Shader/Chunks/OSGShaderExecutableVarChunk.cpp b/Source/System/State/Shader/Chunks/OSGShaderExecutableVarChunk.cpp index 8bb265e..fb53c29 100644 --- a/Source/System/State/Shader/Chunks/OSGShaderExecutableVarChunk.cpp +++ b/Source/System/State/Shader/Chunks/OSGShaderExecutableVarChunk.cpp @@ -237,6 +237,7 @@ void ShaderExecutableVarChunk::updateVariables(DrawEnv *pEnv) #ifdef OSG_MULTISHADER_VARCHUNK this->setActiveShader(uiProgram); + pEnv->setActiveShaderChunk(this); #endif pEnv->incNumShaderParamChanges(); diff --git a/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.cpp b/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.cpp index 46140c9..cc03ef7 100644 --- a/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.cpp +++ b/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.cpp @@ -105,6 +105,7 @@ UInt32 SimpleSHLChunk::handleGL(DrawEnv *pEnv, { GLuint uiProgram = GLuint(pWin->getGLObjectId(getGLId()));; + bool forceVariableUpdate = false; if(mode != Window::needrefresh) { if(uiProgram != 0) @@ -276,6 +277,8 @@ UInt32 SimpleSHLChunk::handleGL(DrawEnv *pEnv, pWin->setGLObjectId(getGLId(), uiProgram); updateVariableLocations(pEnv, uiProgram); + + forceVariableUpdate = true; } if(uiProgram != 0) @@ -287,7 +290,7 @@ UInt32 SimpleSHLChunk::handleGL(DrawEnv *pEnv, osgGlUseProgram(uiProgram); - updateVariables(pEnv, uiProgram); + updateVariables(pEnv, uiProgram, forceVariableUpdate); if(0x0000 == (uiOptions & KeepProgActive)) { @@ -678,6 +681,7 @@ void SimpleSHLChunk::activate(DrawEnv *pEnv, return; pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); if(0x0000 == (uiValRes & ProgActive)) { @@ -753,6 +757,7 @@ void SimpleSHLChunk::changeFrom(DrawEnv *pEnv, return; pEnv->setActiveShader(uiProgId); + pEnv->setActiveShaderChunk(this); if(0x0000 == (uiValRes & ProgActive)) { @@ -802,6 +807,7 @@ void SimpleSHLChunk::deactivate(DrawEnv *pEnv, return; pEnv->setActiveShader(0); + pEnv->setActiveShaderChunk(NULL); OSGGETGLFUNC_GL3_ES(glUseProgram, osgGlUseProgram, @@ -821,6 +827,12 @@ void SimpleSHLChunk::updateObjectDependencies(DrawEnv *pEnv, updateProceduralVariables(pEnv, ShaderProcVariable::SHDObject); } +void SimpleSHLChunk::updateStateDependencies (DrawEnv *pEnv, + UInt32 index) +{ + updateProceduralVariables(pEnv, ShaderProcVariable::SHDState); +} + void SimpleSHLChunk::dump( UInt32 , const BitVector ) const { @@ -1311,7 +1323,8 @@ void SimpleSHLChunk::updateVariableLocations(DrawEnv *pEnv, } void SimpleSHLChunk::updateVariables(DrawEnv *pEnv, - UInt32 uiProgram) + UInt32 uiProgram, + bool forceUpdate ) { if(uiProgram == 0) return; @@ -1355,7 +1368,7 @@ void SimpleSHLChunk::updateVariables(DrawEnv *pEnv, if(pVar == NULL) continue; - if(*mVarChgIt == false) + if(*mVarChgIt == false && !forceUpdate) continue; *mVarChgIt = false; diff --git a/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.h b/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.h index b714f88..05fd8e4 100644 --- a/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.h +++ b/Source/System/State/Shader/SHL/OSGSimpleSHLChunk.h @@ -131,6 +131,9 @@ class OSG_SYSTEM_DLLMAPPING SimpleSHLChunk : public SimpleSHLChunkBase virtual void updateObjectDependencies(DrawEnv *pEnv, UInt32 index = 0); + virtual void updateStateDependencies (DrawEnv *pEnv, + UInt32 index = 0); + /*! \} */ /*---------------------------------------------------------------------*/ /*! \name Output */ @@ -362,7 +365,8 @@ class OSG_SYSTEM_DLLMAPPING SimpleSHLChunk : public SimpleSHLChunkBase void updateVariableLocations (DrawEnv *pEnv, UInt32 uiProgram); void updateVariables (DrawEnv *pEnv, - UInt32 uiProgram); + UInt32 uiProgram, + bool forceUpdate = false); void updateParameters (DrawEnv *pEnv, UInt32 uiProgram); void updateProceduralVariables(DrawEnv *pEnv, diff --git a/Source/System/State/Shader/Variables/OSGShaderProcVariable.h b/Source/System/State/Shader/Variables/OSGShaderProcVariable.h index 7c415db..05edc72 100644 --- a/Source/System/State/Shader/Variables/OSGShaderProcVariable.h +++ b/Source/System/State/Shader/Variables/OSGShaderProcVariable.h @@ -67,8 +67,9 @@ class OSG_SYSTEM_DLLMAPPING ShaderProcVariable : public ShaderProcVariableBase { SHDScene = 0x0001, SHDObject = 0x0002, + SHDState = 0x0004, - SHDAll = 0x0003 + SHDAll = 0x0007 }; /*---------------------------------------------------------------------*/ diff --git a/Source/System/State/Shader/Variables/OSGShaderVariableOSG.cpp b/Source/System/State/Shader/Variables/OSGShaderVariableOSG.cpp index bb068ef..e2c0763 100644 --- a/Source/System/State/Shader/Variables/OSGShaderVariableOSG.cpp +++ b/Source/System/State/Shader/Variables/OSGShaderVariableOSG.cpp @@ -268,6 +268,11 @@ void ShaderVariableOSG::changed(ConstFieldMaskArg whichField, setOsgVarType(OSGLight7Active); setDependency(SHDObject ); } + else if(_sfName.getValue() == "OSGTexture0Active") + { + setOsgVarType(OSGTexture0Active); + setDependency(SHDState ); + } else { setOsgVarType(OSGUnknown); @@ -448,6 +453,11 @@ void ShaderVariableOSG::setName(const std::string &value) setOsgVarType(OSGLight7Active); setDependency(SHDObject ); } + else if(_sfName.getValue() == "OSGTexture0Active") + { + setOsgVarType(OSGTexture0Active); + setDependency(SHDObject ); + } else { setOsgVarType(OSGUnknown); @@ -1021,6 +1031,22 @@ void ShaderVariableOSG::evaluate(DrawEnv *pEnv, } break; + case OSGTexture0Active: + { + if(iLocation > -1) + { + OSGGETGLFUNCBYID_GL3_ES(glUniform1i, + osgGlUniform1i, + ShaderProgram::getFuncIdUniform1i(), + pWin); + + osgGlUniform1i(iLocation, + GLint(pEnv->getActiveTexTarget(0)!=GL_NONE)); + + } + } + break; + default: { } diff --git a/Source/System/State/Shader/Variables/OSGShaderVariableOSG.h b/Source/System/State/Shader/Variables/OSGShaderVariableOSG.h index 9314965..11fd776 100644 --- a/Source/System/State/Shader/Variables/OSGShaderVariableOSG.h +++ b/Source/System/State/Shader/Variables/OSGShaderVariableOSG.h @@ -100,7 +100,8 @@ class OSG_SYSTEM_DLLMAPPING ShaderVariableOSG : public ShaderVariableOSGBase OSGLight4Active, OSGLight5Active, OSGLight6Active, - OSGLight7Active + OSGLight7Active, + OSGTexture0Active };
------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users