diff --git a/src/OpenGl/OpenGl_Flipper.cxx b/src/OpenGl/OpenGl_Flipper.cxx index bf9f8fb10d..56d6f42053 100644 --- a/src/OpenGl/OpenGl_Flipper.cxx +++ b/src/OpenGl/OpenGl_Flipper.cxx @@ -18,6 +18,9 @@ // and conditions governing the rights and limitations under the License. #include + +#include +#include #include #include @@ -65,13 +68,73 @@ void OpenGl_Flipper::Release (const Handle(OpenGl_Context)& ) // ======================================================================= void OpenGl_Flipper::Render (const Handle(OpenGl_Workspace)& theWorkspace) const { + // Check if rendering is to be in immediate mode + const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0; + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + GLint aCurrMode = GL_MODELVIEW; + glGetIntegerv (GL_MATRIX_MODE, &aCurrMode); + if (!myIsEnabled) { - glMatrixMode (GL_MODELVIEW); - glLoadMatrixf ((GLfloat*) theWorkspace->ViewMatrix()); + // Restore transformation + if (isImmediate) + { + if (aCurrMode != GL_MODELVIEW) + { + glMatrixMode (GL_MODELVIEW); + } + + glPopMatrix(); + + if (aCurrMode != GL_MODELVIEW) + { + glMatrixMode (aCurrMode); + } + + Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f }, + { 0.f, 1.f, 0.f, 0.f }, + { 0.f, 0.f, 1.f, 0.f }, + { 0.f, 0.f, 0.f, 1.f } }; + + aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState); + } + else + { + // Update current model-view matrix in the top of the stack + // replacing it with StructureMatrixT*ViewMatrix from the workspace. + theWorkspace->UpdateModelViewMatrix(); + } return; } + if (isImmediate) + { + + if (!aContext->ShaderManager()->IsEmpty()) + { + Tmatrix3 aWorldView; + glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView); + + Tmatrix3 aProjection; + glGetFloatv (GL_PROJECTION_MATRIX, *aProjection); + + aContext->ShaderManager()->UpdateWorldViewStateTo (aWorldView); + aContext->ShaderManager()->UpdateProjectionStateTo (aProjection); + } + + if (aCurrMode != GL_MODELVIEW) + { + glMatrixMode (GL_MODELVIEW); + } + + glPushMatrix(); + + if (aCurrMode != GL_MODELVIEW) + { + glMatrixMode (aCurrMode); + } + } + OpenGl_Mat4 aMatrixMV; glGetFloatv (GL_MODELVIEW_MATRIX, aMatrixMV.ChangeData()); @@ -128,8 +191,6 @@ void OpenGl_Flipper::Render (const Handle(OpenGl_Workspace)& theWorkspace) const aMatrixMV = aMatrixMV * aTransform; // load transformed model-view matrix - GLint aCurrMode = GL_MODELVIEW; - glGetIntegerv (GL_MATRIX_MODE, &aCurrMode); if (aCurrMode != GL_MODELVIEW) { glMatrixMode (GL_MODELVIEW); diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index e6fdf678d6..6da4e05184 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -104,6 +104,7 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay, TextParam_applied (NULL), ViewMatrix_applied (&myDefaultMatrix), StructureMatrix_applied (&myDefaultMatrix), + myModelViewMatrix (myDefaultMatrix), PolygonOffset_applied (NULL) { theDisplay->InitAttributes(); diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index 4f13dbda6b..3b56bda448 100644 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -155,6 +155,10 @@ public: 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); @@ -413,6 +417,9 @@ protected: //! @name fields related to status const OpenGl_Matrix* ViewMatrix_applied; const OpenGl_Matrix* StructureMatrix_applied; + //! Model matrix with applied structure transformations + OpenGl_Matrix myModelViewMatrix; + const TEL_POFFSET_PARAM* PolygonOffset_applied; OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect diff --git a/src/OpenGl/OpenGl_Workspace_5.cxx b/src/OpenGl/OpenGl_Workspace_5.cxx index 718147b939..a84655dd02 100644 --- a/src/OpenGl/OpenGl_Workspace_5.cxx +++ b/src/OpenGl/OpenGl_Workspace_5.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H # include @@ -425,18 +426,13 @@ const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectTex /*----------------------------------------------------------------------*/ -const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix(const OpenGl_Matrix *AMatrix) +const OpenGl_Matrix * OpenGl_Workspace::SetViewMatrix (const OpenGl_Matrix *AMatrix) { const OpenGl_Matrix *ViewMatrix_old = ViewMatrix_applied; ViewMatrix_applied = AMatrix; - OpenGl_Matrix lmat; - OpenGl_Transposemat3( &lmat, StructureMatrix_applied ); - - glMatrixMode (GL_MODELVIEW); - OpenGl_Matrix rmat; - OpenGl_Multiplymat3 (&rmat, &lmat, ViewMatrix_applied); - glLoadMatrixf ((const GLfloat* )rmat.mat); + // Update model-view matrix with new view matrix + UpdateModelViewMatrix(); return ViewMatrix_old; } @@ -451,10 +447,8 @@ const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix (const OpenGl_Matrix OpenGl_Matrix lmat; OpenGl_Transposemat3( &lmat, AMatrix ); - glMatrixMode (GL_MODELVIEW); - OpenGl_Matrix rmat; - OpenGl_Multiplymat3 (&rmat, &lmat, ViewMatrix_applied); - glLoadMatrixf ((const GLfloat* )rmat.mat); + // Update model-view matrix with new structure matrix + UpdateModelViewMatrix(); if (!myGlContext->ShaderManager()->IsEmpty()) { @@ -473,6 +467,18 @@ const OpenGl_Matrix * OpenGl_Workspace::SetStructureMatrix (const OpenGl_Matrix /*----------------------------------------------------------------------*/ +const void OpenGl_Workspace::UpdateModelViewMatrix() +{ + OpenGl_Matrix aStructureMatT; + OpenGl_Transposemat3( &aStructureMatT, StructureMatrix_applied); + + glMatrixMode (GL_MODELVIEW); + OpenGl_Multiplymat3 (&myModelViewMatrix, &aStructureMatT, ViewMatrix_applied); + glLoadMatrixf ((const GLfloat* )&myModelViewMatrix.mat); +} + +/*----------------------------------------------------------------------*/ + const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply) { if ( WithApply && (AspectLine_set != AspectLine_applied) ) diff --git a/tests/bugs/vis/bug24374 b/tests/bugs/vis/bug24374 new file mode 100644 index 0000000000..1a82b1932c --- /dev/null +++ b/tests/bugs/vis/bug24374 @@ -0,0 +1,28 @@ +puts "============" +puts "CR24374" +puts "============" +puts "" +####################################################################### +# Flipping affects highlight presentation of dimension +####################################################################### +pload ALL +pload QAcommands +box b 100 100 100 +explode b e +vdisplay b +vdisplay b_9 +vdim -length -name=dim1 b_9 -text=3d -plane=zox +vdisplay dim1 +vselmode b 2 1 +vfit +vmoveto 110 352 + +set x_coord 161 +set y_coord 372 +checkcolor $x_coord $y_coord 0 1 1 + +if { $stat != 1 } { + puts "Error : Highlighting of dimension with flipping in local context failed." +} + +set only_screen 1 \ No newline at end of file