From e6804ff7c000c1917c81356c16fa43dff87b2e0b Mon Sep 17 00:00:00 2001 From: duv Date: Thu, 20 Mar 2014 14:39:23 +0400 Subject: [PATCH] 0024687: TKOpenGl shader programs - same view state for different v3d views OpenGl_ShaderManager::IsSameView() - add const --- src/OpenGl/OpenGl_ShaderManager.cxx | 5 +++-- src/OpenGl/OpenGl_ShaderManager.hxx | 17 ++++++++++++++++- src/OpenGl/OpenGl_View_2.cxx | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 92a4c2d15b..55dc4d4015 100755 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -33,8 +33,9 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderManager, Standard_Transient) // purpose : Creates new empty shader manager // ======================================================================= OpenGl_ShaderManager::OpenGl_ShaderManager (OpenGl_Context* theContext) -: myContext (theContext), - myIsPP (Standard_False) +: myContext (theContext), + myIsPP (Standard_False), + myLastView (NULL) { // } diff --git a/src/OpenGl/OpenGl_ShaderManager.hxx b/src/OpenGl/OpenGl_ShaderManager.hxx index 8acf35a9b7..4ea5d32165 100755 --- a/src/OpenGl/OpenGl_ShaderManager.hxx +++ b/src/OpenGl/OpenGl_ShaderManager.hxx @@ -25,6 +25,8 @@ #include #include +class OpenGl_View; + //! List of shader programs. typedef NCollection_Sequence OpenGl_ShaderProgramList; @@ -165,6 +167,19 @@ public: myContext = theCtx; } + //! Sets last view manger used with. + //! Helps to handle matrix states in multi-view configurations. + void SetLastView (const OpenGl_View* theLastView) + { + myLastView = theLastView; + } + + //! Returns true when provided view is the same as cached one. + bool IsSameView (const OpenGl_View* theView) const + { + return myLastView == theView; + } + protected: OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs @@ -173,7 +188,7 @@ protected: private: Standard_Boolean myIsPP; //!< Is any program object bound (programmable pipeline)? - + const OpenGl_View* myLastView; //!< Pointer to the last view shader manager used with. }; #endif // _OpenGl_ShaderManager_HeaderFile diff --git a/src/OpenGl/OpenGl_View_2.cxx b/src/OpenGl/OpenGl_View_2.cxx index 2292b91eae..46014e1d1a 100644 --- a/src/OpenGl/OpenGl_View_2.cxx +++ b/src/OpenGl/OpenGl_View_2.cxx @@ -421,6 +421,19 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext, } } + if (!aManager.IsNull()) + { + if (!aManager->IsSameView (this)) + { + // Force update camera states + myProjectionState = myCamera->ProjectionState(); + aManager->UpdateProjectionStateTo ((const Tmatrix3*)myCamera->ProjectionMatrixF().GetData()); + + myModelViewState = myCamera->ModelViewState(); + aManager->UpdateWorldViewStateTo ((const Tmatrix3*)myCamera->OrientationMatrixF().GetData()); + } + } + // ==================================== // Step 2: Redraw background // ==================================== @@ -624,6 +637,15 @@ void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext, } delete[] aOldPlanes; + + // ============================================================== + // Step 8: Keep shader manager informed about last View + // ============================================================== + + if (!aManager.IsNull()) + { + aManager->SetLastView (this); + } } /*----------------------------------------------------------------------*/