From 1715282638c2512d2179d32f4b19cbfdffab74bb Mon Sep 17 00:00:00 2001 From: Natalia Ermolaeva Date: Tue, 15 Jun 2021 10:25:17 +0300 Subject: [PATCH] Auto Zfit for group with own transform persistent; improve performance in OpenGl text element (cherry picked from commit df00f8a5a43f4f04a4760954ecde42c607c709d6) # Conflicts: # src/OpenGl/OpenGl_Text.cxx (cherry picked from commit 6d88e69e1514bd64b807bfc194f258e2505c382b) --- src/Graphic3d/Graphic3d_Group.cxx | 2 + src/Graphic3d/Graphic3d_Layer.cxx | 66 +++++++++++++++++++++++++------ src/OpenGl/OpenGl_Text.cxx | 24 +++++------ 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/Graphic3d/Graphic3d_Group.cxx b/src/Graphic3d/Graphic3d_Group.cxx index 9ea7a7d29b..687dcf4d60 100644 --- a/src/Graphic3d/Graphic3d_Group.cxx +++ b/src/Graphic3d/Graphic3d_Group.cxx @@ -458,6 +458,8 @@ void Graphic3d_Group::DumpJson (Standard_OStream& theOStream, Standard_Integer t OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, this) + OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTrsfPers.get()) + OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStructure) OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBounds) diff --git a/src/Graphic3d/Graphic3d_Layer.cxx b/src/Graphic3d/Graphic3d_Layer.cxx index 6b723c8f31..60fe23a165 100644 --- a/src/Graphic3d/Graphic3d_Layer.cxx +++ b/src/Graphic3d/Graphic3d_Layer.cxx @@ -171,6 +171,38 @@ inline bool isInfiniteBndBox (const Graphic3d_BndBox3d& theBndBox) || Abs (theBndBox.CornerMin().z()) >= ShortRealLast(); } +// ======================================================================= +// function : updateBoundingBox +// purpose : +// ======================================================================= +void updateBoundingBox(const Handle(Graphic3d_Camera)& theCamera, + const Graphic3d_Mat4d& aProjectionMat, + const Graphic3d_Mat4d& aWorldViewMat, + Standard_Integer theWindowWidth, + Standard_Integer theWindowHeight, + const Handle(Graphic3d_TransformPers)& aTrsfPers, + Graphic3d_BndBox3d& aBox, + Bnd_Box& aResBox) +{ + if (aTrsfPers.IsNull()) + { + return; + } + + if (!aBox.IsValid()) + { + return; + } + + aTrsfPers->Apply(theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); + if (aBox.IsValid() + && !isInfiniteBndBox(aBox)) + { + aResBox.Add(gp_Pnt(aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z())); + aResBox.Add(gp_Pnt(aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z())); + } +} + // ======================================================================= // function : BoundingBox // purpose : @@ -268,27 +300,35 @@ Bnd_Box Graphic3d_Layer::BoundingBox (Standard_Integer theViewId, { continue; } - else if (aStructure->TransformPersistence().IsNull() - || !aStructure->TransformPersistence()->IsTrihedronOr2d()) + for (Graphic3d_SequenceOfGroup::Iterator aGroupIter(aStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) { - continue; + const Handle(Graphic3d_Group)& aGroup = aGroupIter.Value(); + if (aGroup->TransformPersistence().IsNull()) + { + continue; + } + + const Graphic3d_BndBox4f& aBoxF = aGroup->BoundingBox(); + Graphic3d_BndBox3d aBox = Graphic3d_BndBox3d (Graphic3d_Vec3d ((Standard_Real)aBoxF.CornerMin().x(), + (Standard_Real)aBoxF.CornerMin().y(), + (Standard_Real)aBoxF.CornerMin().z()), + Graphic3d_Vec3d ((Standard_Real)aBoxF.CornerMax().x(), + (Standard_Real)aBoxF.CornerMax().y(), + (Standard_Real)aBoxF.CornerMax().z())); + updateBoundingBox(theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, + aGroup->TransformPersistence(), aBox, aResBox); } - Graphic3d_BndBox3d aBox = aStructure->BoundingBox(); - if (!aBox.IsValid()) + if (aStructure->TransformPersistence().IsNull() + || !aStructure->TransformPersistence()->IsTrihedronOr2d()) { continue; } - aStructure->TransformPersistence()->Apply (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); - if (aBox.IsValid() - && !isInfiniteBndBox (aBox)) - { - aResBox.Add (gp_Pnt (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z())); - aResBox.Add (gp_Pnt (aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z())); - } + Graphic3d_BndBox3d aBox = aStructure->BoundingBox(); + updateBoundingBox (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, + aStructure->TransformPersistence(), aBox, aResBox); } - return aResBox; } diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 5fa52b6568..83d8b1bb8d 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -780,16 +780,16 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, } #if !defined(GL_ES_VERSION_2_0) // activate texture unit - GLint aTexEnvParam = GL_REPLACE; + ////GLint aTexEnvParam = GL_REPLACE; if (theCtx->core11ffp != NULL) { theCtx->core11fwd->glDisable (GL_TEXTURE_1D); theCtx->core11fwd->glEnable (GL_TEXTURE_2D); - theCtx->core11ffp->glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam); - if (aTexEnvParam != GL_REPLACE) - { - theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - } + ////theCtx->core11ffp->glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam); + ////if (aTexEnvParam != GL_REPLACE) + ////{ + //// theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + ////} } #endif @@ -860,12 +860,12 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, theCtx->ApplyProjectionMatrix(); } -#if !defined(GL_ES_VERSION_2_0) - if (theCtx->core11ffp != NULL) - { - theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam); - } -#endif +//#if !defined(GL_ES_VERSION_2_0) + //if (theCtx->core11ffp != NULL) + //{ + // theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam); + //} +//#endif if (theTextAspect.Aspect()->TextDisplayType() == Aspect_TODT_DIMENSION) { -- 2.39.5