diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 7112469a81..0298b497ec 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -410,36 +410,6 @@ void OpenGl_ShaderManager::UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldVi myWorldViewState.Update(); } -// ======================================================================= -// function : RevertProjectionStateTo -// purpose : Reverts state of OCCT projection transform -// ======================================================================= -void OpenGl_ShaderManager::RevertProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix) -{ - myProjectionState.Set (theProjectionMatrix); - myProjectionState.Revert(); -} - -// ======================================================================= -// function : RevertModelWorldStateTo -// purpose : Reverts state of OCCT model-world transform -// ======================================================================= -void OpenGl_ShaderManager::RevertModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix) -{ - myModelWorldState.Set (theModelWorldMatrix); - myModelWorldState.Revert(); -} - -// ======================================================================= -// function : RevertWorldViewStateTo -// purpose : Reverts state of OCCT world-view transform -// ======================================================================= -void OpenGl_ShaderManager::RevertWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix) -{ - myWorldViewState.Set (theWorldViewMatrix); - myWorldViewState.Revert(); -} - // ======================================================================= // function : LightSourceState // purpose : Returns current state of OCCT light sources diff --git a/src/OpenGl/OpenGl_ShaderManager.hxx b/src/OpenGl/OpenGl_ShaderManager.hxx index acb058ad62..3d2be8cf8f 100644 --- a/src/OpenGl/OpenGl_ShaderManager.hxx +++ b/src/OpenGl/OpenGl_ShaderManager.hxx @@ -164,9 +164,6 @@ public: //! Updates state of OCCT projection transform. Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix); - //! Reverts state of OCCT projection transform. - Standard_EXPORT void RevertProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix); - //! Pushes current state of OCCT projection transform to specified program. Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const; @@ -178,9 +175,6 @@ public: //! Updates state of OCCT model-world transform. Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix); - //! Reverts state of OCCT model-world transform. - Standard_EXPORT void RevertModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix); - //! Pushes current state of OCCT model-world transform to specified program. Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const; @@ -192,9 +186,6 @@ public: //! Updates state of OCCT world-view transform. Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix); - //! Reverts state of OCCT world-view transform. - Standard_EXPORT void RevertWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix); - //! Pushes current state of OCCT world-view transform to specified program. Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const; @@ -349,7 +340,7 @@ protected: OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation - OpenGl_LightSourceState myClippingState; //!< State of OCCT clipping planes + OpenGl_ClippingState myClippingState; //!< State of OCCT clipping planes OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources private: diff --git a/src/OpenGl/OpenGl_ShaderStates.cxx b/src/OpenGl/OpenGl_ShaderStates.cxx index cc07c89457..0439246e06 100755 --- a/src/OpenGl/OpenGl_ShaderStates.cxx +++ b/src/OpenGl/OpenGl_ShaderStates.cxx @@ -13,58 +13,20 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include - #include +#include + // ======================================================================= // function : OpenGl_StateInterface -// purpose : Creates new OCCT state +// purpose : // ======================================================================= OpenGl_StateInterface::OpenGl_StateInterface() -: myIndex (0), - myNextIndex (1) +: myIndex (0) { // } -// ======================================================================= -// function : Index -// purpose : Returns current state index -// ======================================================================= -Standard_Size OpenGl_StateInterface::Index() const -{ - return myIndex; -} - -// ======================================================================= -// function : Update -// purpose : Updates current state -// ======================================================================= -void OpenGl_StateInterface::Update() -{ - myStateStack.Prepend (myIndex); - myIndex = myNextIndex; - ++myNextIndex; -} - -// ======================================================================= -// function : Revert -// purpose : Reverts current state -// ======================================================================= -void OpenGl_StateInterface::Revert() -{ - if (!myStateStack.IsEmpty()) - { - myIndex = myStateStack.First(); - myStateStack.RemoveFirst(); - } - else - { - myIndex = 0; - } -} - // ======================================================================= // function : OpenGl_ProjectionState // purpose : Creates uninitialized projection state @@ -261,6 +223,36 @@ const OpenGl_Element* OpenGl_MaterialState::Aspect() const // purpose : Creates new clipping state // ======================================================================= OpenGl_ClippingState::OpenGl_ClippingState() +: myIndex (0), + myNextIndex (1) { // } + +// ======================================================================= +// function : Update +// purpose : Updates current state +// ======================================================================= +void OpenGl_ClippingState::Update() +{ + myStateStack.Prepend (myIndex); + myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert() + ++myNextIndex; +} + +// ======================================================================= +// function : Revert +// purpose : Reverts current state +// ======================================================================= +void OpenGl_ClippingState::Revert() +{ + if (!myStateStack.IsEmpty()) + { + myIndex = myStateStack.First(); + myStateStack.RemoveFirst(); + } + else + { + myIndex = 0; + } +} diff --git a/src/OpenGl/OpenGl_ShaderStates.hxx b/src/OpenGl/OpenGl_ShaderStates.hxx index 61e6fb5083..ef35e62004 100755 --- a/src/OpenGl/OpenGl_ShaderStates.hxx +++ b/src/OpenGl/OpenGl_ShaderStates.hxx @@ -29,23 +29,18 @@ class OpenGl_StateInterface { public: - //! Creates new OCCT state. + //! Creates new state. OpenGl_StateInterface(); //! Returns current state index. - Standard_Size Index() const; + Standard_Size Index() const { return myIndex; } - //! Updates current state. - void Update(); - - //! Reverts current state. - void Revert(); + //! Increment current state. + void Update() { ++myIndex; } protected: - Standard_Size myIndex; //!< Current state index - Standard_Size myNextIndex; //!< Next state index - NCollection_List myStateStack; //!< Stack of previous states. + Standard_Size myIndex; //!< current state index }; @@ -165,13 +160,28 @@ private: }; //! Defines generic state of OCCT clipping state. -class OpenGl_ClippingState : public OpenGl_StateInterface +class OpenGl_ClippingState { public: //! Creates new clipping state. OpenGl_ClippingState(); + //! Returns current state index. + Standard_Size Index() const { return myIndex; } + + //! Updates current state. + void Update(); + + //! Reverts current state. + void Revert(); + +protected: + + Standard_Size myIndex; //!< Current state index + Standard_Size myNextIndex; //!< Next state index + NCollection_List myStateStack; //!< Stack of previous states + }; #endif // _OpenGl_State_HeaderFile diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index 805d577e09..0479381c8a 100644 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -197,13 +197,6 @@ public: const TEL_COLOUR* HighlightColor; - const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* ); - const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix*, bool aRevert = false); - - //! Updates current model-view matrix - //! replacing it with StructureMatrixT*ViewMatrix from the workspace. - const void UpdateModelViewMatrix(); - const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); diff --git a/src/OpenGl/OpenGl_Workspace_5.cxx b/src/OpenGl/OpenGl_Workspace_5.cxx index dfac729108..fed57817e8 100644 --- a/src/OpenGl/OpenGl_Workspace_5.cxx +++ b/src/OpenGl/OpenGl_Workspace_5.cxx @@ -251,60 +251,6 @@ const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectTex /*----------------------------------------------------------------------*/ -const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix (const OpenGl_Matrix *AMatrix) -{ - const OpenGl_Matrix *ViewMatrix_old = ViewMatrix_applied; - ViewMatrix_applied = AMatrix; - - // Update model-view matrix with new view matrix - UpdateModelViewMatrix(); - - return ViewMatrix_old; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix (const OpenGl_Matrix *AMatrix, bool aRevert) -{ - const OpenGl_Matrix *StructureMatrix_old = StructureMatrix_applied; - StructureMatrix_applied = AMatrix; - - OpenGl_Matrix lmat; - OpenGl_Transposemat3( &lmat, AMatrix ); - - // Update model-view matrix with new structure matrix - UpdateModelViewMatrix(); - - if (!myGlContext->ShaderManager()->IsEmpty()) - { - if (aRevert) - { - myGlContext->ShaderManager()->RevertModelWorldStateTo (OpenGl_Mat4::Map (*lmat.mat)); - } - else - { - myGlContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4::Map (*lmat.mat)); - } - } - - return StructureMatrix_old; -} - -/*----------------------------------------------------------------------*/ - -const void OpenGl_Workspace::UpdateModelViewMatrix() -{ - OpenGl_Matrix aStructureMatT; - OpenGl_Transposemat3( &aStructureMatT, StructureMatrix_applied); - OpenGl_Multiplymat3 (&myModelViewMatrix, &aStructureMatT, ViewMatrix_applied); -#if !defined(GL_ES_VERSION_2_0) - glMatrixMode (GL_MODELVIEW); - glLoadMatrixf ((const GLfloat* )&myModelViewMatrix.mat); -#endif -} - -/*----------------------------------------------------------------------*/ - const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply) { if ( WithApply && (AspectLine_set != AspectLine_applied) )