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

0031015: Visualization, TKOpenGl - OpenGl_WorldViewState does not cache inverted matrix

Implementation has been fixed to proprely set myInverseNeedUpdate flag.
This commit is contained in:
kgv 2019-10-01 08:27:57 +03:00 committed by bugmaster
parent 4eff0c0480
commit 14a356b178
2 changed files with 15 additions and 48 deletions

View File

@ -45,28 +45,17 @@ void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
myInverseNeedUpdate = true; myInverseNeedUpdate = true;
} }
// =======================================================================
// function : ProjectionMatrix
// purpose : Returns current projection matrix
// =======================================================================
const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
{
return myProjectionMatrix;
}
// ======================================================================= // =======================================================================
// function : ProjectionMatrixInverse // function : ProjectionMatrixInverse
// purpose : Returns inverse of current projection matrix // purpose : Returns inverse of current projection matrix
// ======================================================================= // =======================================================================
const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
{ {
if (!myInverseNeedUpdate) if (myInverseNeedUpdate)
{ {
return myProjectionMatrixInverse; myInverseNeedUpdate = false;
myProjectionMatrix.Inverted (myProjectionMatrixInverse);
} }
myProjectionMatrix.Inverted (myProjectionMatrixInverse);
return myProjectionMatrixInverse; return myProjectionMatrixInverse;
} }
@ -90,28 +79,17 @@ void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
myInverseNeedUpdate = true; myInverseNeedUpdate = true;
} }
// =======================================================================
// function : ModelWorldMatrix
// purpose : Returns current model-world matrix
// =======================================================================
const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
{
return myModelWorldMatrix;
}
// ======================================================================= // =======================================================================
// function : ModelWorldMatrixInverse // function : ModelWorldMatrixInverse
// purpose : Returns inverse of current model-world matrix // purpose : Returns inverse of current model-world matrix
// ======================================================================= // =======================================================================
const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
{ {
if (!myInverseNeedUpdate) if (myInverseNeedUpdate)
{ {
return myModelWorldMatrix; myInverseNeedUpdate = false;
myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
} }
myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
return myModelWorldMatrixInverse; return myModelWorldMatrixInverse;
} }
@ -135,28 +113,17 @@ void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
myInverseNeedUpdate = true; myInverseNeedUpdate = true;
} }
// =======================================================================
// function : WorldViewMatrix
// purpose : Returns current world-view matrix
// =======================================================================
const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
{
return myWorldViewMatrix;
}
// ======================================================================= // =======================================================================
// function : WorldViewMatrixInverse // function : WorldViewMatrixInverse
// purpose : Returns inverse of current world-view matrix // purpose : Returns inverse of current world-view matrix
// ======================================================================= // =======================================================================
const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
{ {
if (!myInverseNeedUpdate) if (myInverseNeedUpdate)
{ {
return myWorldViewMatrix; myInverseNeedUpdate = false;
myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
} }
myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
return myWorldViewMatrixInverse; return myWorldViewMatrixInverse;
} }

View File

@ -53,7 +53,7 @@ public:
Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix); Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix);
//! Returns current projection matrix. //! Returns current projection matrix.
Standard_EXPORT const OpenGl_Mat4& ProjectionMatrix() const; const OpenGl_Mat4& ProjectionMatrix() const { return myProjectionMatrix; }
//! Returns inverse of current projection matrix. //! Returns inverse of current projection matrix.
Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const; Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const;
@ -62,7 +62,7 @@ private:
OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix
mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
bool myInverseNeedUpdate; //!< Is inversed matrix outdated? mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
}; };
@ -78,7 +78,7 @@ public:
Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix); Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix);
//! Returns current model-world matrix. //! Returns current model-world matrix.
Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrix() const; const OpenGl_Mat4& ModelWorldMatrix() const { return myModelWorldMatrix; }
//! Returns inverse of current model-world matrix. //! Returns inverse of current model-world matrix.
Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const; Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const;
@ -87,7 +87,7 @@ private:
OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix
mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
bool myInverseNeedUpdate; //!< Is inversed matrix outdated? mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
}; };
@ -103,7 +103,7 @@ public:
Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix); Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix);
//! Returns current world-view matrix. //! Returns current world-view matrix.
Standard_EXPORT const OpenGl_Mat4& WorldViewMatrix() const; const OpenGl_Mat4& WorldViewMatrix() const { return myWorldViewMatrix; }
//! Returns inverse of current world-view matrix. //! Returns inverse of current world-view matrix.
Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const; Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const;
@ -112,7 +112,7 @@ private:
OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix
mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
bool myInverseNeedUpdate; //!< Is inversed matrix outdated? mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
}; };