1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0025483: Visualization, TKOpenGl - fix memory leak due to unused stack in OpenGl_StateInterface

This commit is contained in:
kgv 2014-11-14 17:24:56 +03:00 committed by bugmaster
parent 0da4579283
commit 8cf06aa236
6 changed files with 56 additions and 154 deletions

View File

@ -410,36 +410,6 @@ void OpenGl_ShaderManager::UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldVi
myWorldViewState.Update(); 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 // function : LightSourceState
// purpose : Returns current state of OCCT light sources // purpose : Returns current state of OCCT light sources

View File

@ -164,9 +164,6 @@ public:
//! Updates state of OCCT projection transform. //! Updates state of OCCT projection transform.
Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix); 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. //! Pushes current state of OCCT projection transform to specified program.
Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const; Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
@ -178,9 +175,6 @@ public:
//! Updates state of OCCT model-world transform. //! Updates state of OCCT model-world transform.
Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix); 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. //! Pushes current state of OCCT model-world transform to specified program.
Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const; Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
@ -192,9 +186,6 @@ public:
//! Updates state of OCCT world-view transform. //! Updates state of OCCT world-view transform.
Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix); 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. //! Pushes current state of OCCT world-view transform to specified program.
Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const; Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
@ -349,7 +340,7 @@ protected:
OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view 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 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
private: private:

View File

@ -13,58 +13,20 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <NCollection_Mat4.hxx>
#include <OpenGl_ShaderStates.hxx> #include <OpenGl_ShaderStates.hxx>
#include <NCollection_Mat4.hxx>
// ======================================================================= // =======================================================================
// function : OpenGl_StateInterface // function : OpenGl_StateInterface
// purpose : Creates new OCCT state // purpose :
// ======================================================================= // =======================================================================
OpenGl_StateInterface::OpenGl_StateInterface() OpenGl_StateInterface::OpenGl_StateInterface()
: myIndex (0), : myIndex (0)
myNextIndex (1)
{ {
// //
} }
// =======================================================================
// 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 // function : OpenGl_ProjectionState
// purpose : Creates uninitialized projection state // purpose : Creates uninitialized projection state
@ -261,6 +223,36 @@ const OpenGl_Element* OpenGl_MaterialState::Aspect() const
// purpose : Creates new clipping state // purpose : Creates new clipping state
// ======================================================================= // =======================================================================
OpenGl_ClippingState::OpenGl_ClippingState() 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;
}
}

View File

@ -29,23 +29,18 @@ class OpenGl_StateInterface
{ {
public: public:
//! Creates new OCCT state. //! Creates new state.
OpenGl_StateInterface(); OpenGl_StateInterface();
//! Returns current state index. //! Returns current state index.
Standard_Size Index() const; Standard_Size Index() const { return myIndex; }
//! Updates current state. //! Increment current state.
void Update(); void Update() { ++myIndex; }
//! Reverts current state.
void Revert();
protected: protected:
Standard_Size myIndex; //!< Current state index Standard_Size myIndex; //!< current state index
Standard_Size myNextIndex; //!< Next state index
NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states.
}; };
@ -165,13 +160,28 @@ private:
}; };
//! Defines generic state of OCCT clipping state. //! Defines generic state of OCCT clipping state.
class OpenGl_ClippingState : public OpenGl_StateInterface class OpenGl_ClippingState
{ {
public: public:
//! Creates new clipping state. //! Creates new clipping state.
OpenGl_ClippingState(); 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 #endif // _OpenGl_State_HeaderFile

View File

@ -197,13 +197,6 @@ public:
const TEL_COLOUR* HighlightColor; 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_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);

View File

@ -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) const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply)
{ {
if ( WithApply && (AspectLine_set != AspectLine_applied) ) if ( WithApply && (AspectLine_set != AspectLine_applied) )