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
//! 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;
//! 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;
//! 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;
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:
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <NCollection_Mat4.hxx>
-
#include <OpenGl_ShaderStates.hxx>
+#include <NCollection_Mat4.hxx>
+
// =======================================================================
// 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
// 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;
+ }
+}
{
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<Standard_Size> myStateStack; //!< Stack of previous states.
+ Standard_Size myIndex; //!< current state index
};
};
//! 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<Standard_Size> myStateStack; //!< Stack of previous states
+
};
#endif // _OpenGl_State_HeaderFile
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);
/*----------------------------------------------------------------------*/
-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) )