// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#ifdef HAVE_CONFIG_H
- #include <config.h>
-#endif
-
#include <OpenGl_CappingAlgo.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_GlCore11.hxx>
+#include <OpenGl_ClippingIterator.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
-#include <OpenGl_Structure.hxx>
-#include <OpenGl_telem_util.hxx>
+#include <OpenGl_StructureShadow.hxx>
#include <OpenGl_Vec.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
-#include <Graphic3d_SequenceOfHClipPlane_Handle.hxx>
-
-IMPLEMENT_STANDARD_HANDLE (OpenGl_Structure, Graphic3d_CStructure)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
-
-//! Auxiliary class for bounding box presentation
-class OpenGl_BndBoxPrs : public OpenGl_Element
-{
-
-public:
-
- //! Main constructor
- OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox)
- {
- const float Xm = theBndBox.Pmin.x;
- const float Ym = theBndBox.Pmin.y;
- const float Zm = theBndBox.Pmin.z;
- const float XM = theBndBox.Pmax.x;
- const float YM = theBndBox.Pmax.y;
- const float ZM = theBndBox.Pmax.z;
- myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm);
- myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM);
- myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM);
- myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm);
- myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm);
- myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm);
- myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM);
- myVerts[7] = OpenGl_Vec3 (XM, YM, ZM);
- myVerts[8] = OpenGl_Vec3 (XM, YM, Zm);
- myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm);
- myVerts[10] = OpenGl_Vec3 (XM, YM, Zm);
- myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm);
- myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM);
- myVerts[13] = OpenGl_Vec3 (XM, YM, ZM);
- myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM);
- myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM);
- }
-
- //! Render presentation
- virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
- {
- // Apply line aspect
- const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
- const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
-
- glDisable (GL_LIGHTING);
- if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0)
- {
- glDepthMask (GL_FALSE);
- }
-
- // Use highlight colors
- glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb);
-
- glEnableClientState (GL_VERTEX_ARRAY);
- glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
- glDrawArrays (GL_LINE_STRIP, 0, 16);
- glDisableClientState (GL_VERTEX_ARRAY);
-
- // restore aspects
- if (!aPrevTexture.IsNull())
- {
- theWorkspace->EnableTexture (aPrevTexture);
- }
- }
-
- //! Release graphical resources
- virtual void Release (const Handle(OpenGl_Context)& )
- {
- //
- }
-
-protected:
-
- //! Protected destructor
- virtual ~OpenGl_BndBoxPrs() {}
-
-private:
-
- OpenGl_Vec3 myVerts[16]; //!< vertices array
-
-public:
-
- DEFINE_STANDARD_ALLOC
-
-};
-
-/*----------------------------------------------------------------------*/
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure)
// =======================================================================
-// function : call_util_transpose_mat
+// function : renderBoundingBox
// purpose :
// =======================================================================
-static void call_util_transpose_mat (float tmat[16], float mat[4][4])
+void OpenGl_Structure::renderBoundingBox (const Handle(OpenGl_Workspace)& theWorkspace) const
{
- int i, j;
+ if (!myBndBox.IsValid())
+ {
+ return;
+ }
- for (i=0; i<4; i++)
- for (j=0; j<4; j++)
- tmat[j*4+i] = mat[i][j];
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+ const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
+ const Graphic3d_ZLayerSettings& aLayer = myGraphicDriver->ZLayerSettings (myZLayer);
+ const Graphic3d_Vec3d aMoveVec = myTrsfPers.IsNull()
+ && !aLayer.OriginTransformation().IsNull()
+ ? -Graphic3d_Vec3d (aLayer.Origin().X(), aLayer.Origin().Y(), aLayer.Origin().Z())
+ : Graphic3d_Vec3d (0.0, 0.0, 0.0);
+ if (aCtx->core20fwd != NULL
+ && aCtx->ShaderManager()->BindBoundBoxProgram())
+ {
+ const Graphic3d_Vec3d aCenter = myBndBox.Center() + aMoveVec;
+ const Graphic3d_Vec3d aSize = myBndBox.Size();
+ aCtx->ActiveProgram()->SetUniform (aCtx, "occBBoxCenter", Graphic3d_Vec3 ((float )aCenter.x(), (float )aCenter.y(), (float )aCenter.z()));
+ aCtx->ActiveProgram()->SetUniform (aCtx, "occBBoxSize", Graphic3d_Vec3 ((float )aSize.x(), (float )aSize.y(), (float )aSize.z()));
+ aCtx->SetColor4fv (theWorkspace->InteriorColor());
+
+ const Handle(OpenGl_VertexBuffer)& aBoundBoxVertBuffer = aCtx->ShaderManager()->BoundBoxVertBuffer();
+ aBoundBoxVertBuffer->BindAttribute (aCtx, Graphic3d_TOA_POS);
+ aCtx->core20fwd->glDrawArrays (GL_LINES, 0, aBoundBoxVertBuffer->GetElemsNb());
+ aBoundBoxVertBuffer->UnbindAttribute(aCtx, Graphic3d_TOA_POS);
+ }
+#if !defined(GL_ES_VERSION_2_0)
+ else if (aCtx->core11 != NULL)
+ {
+ const Graphic3d_Vec3d aMind = myBndBox.CornerMin() + aMoveVec;
+ const Graphic3d_Vec3d aMaxd = myBndBox.CornerMax() + aMoveVec;
+ const Graphic3d_Vec3 aMin ((float )aMind.x(), (float )aMind.y(), (float )aMind.z());
+ const Graphic3d_Vec3 aMax ((float )aMaxd.x(), (float )aMaxd.y(), (float )aMaxd.z());
+ const OpenGl_Vec3 aVerts[16] =
+ {
+ OpenGl_Vec3 (aMin.x(), aMin.y(), aMin.z()),
+ OpenGl_Vec3 (aMin.x(), aMin.y(), aMax.z()),
+ OpenGl_Vec3 (aMin.x(), aMax.y(), aMax.z()),
+ OpenGl_Vec3 (aMin.x(), aMax.y(), aMin.z()),
+ OpenGl_Vec3 (aMin.x(), aMin.y(), aMin.z()),
+ OpenGl_Vec3 (aMax.x(), aMin.y(), aMin.z()),
+ OpenGl_Vec3 (aMax.x(), aMin.y(), aMax.z()),
+ OpenGl_Vec3 (aMax.x(), aMax.y(), aMax.z()),
+ OpenGl_Vec3 (aMax.x(), aMax.y(), aMin.z()),
+ OpenGl_Vec3 (aMax.x(), aMin.y(), aMin.z()),
+ OpenGl_Vec3 (aMax.x(), aMax.y(), aMin.z()),
+ OpenGl_Vec3 (aMin.x(), aMax.y(), aMin.z()),
+ OpenGl_Vec3 (aMin.x(), aMax.y(), aMax.z()),
+ OpenGl_Vec3 (aMax.x(), aMax.y(), aMax.z()),
+ OpenGl_Vec3 (aMax.x(), aMin.y(), aMax.z()),
+ OpenGl_Vec3 (aMin.x(), aMin.y(), aMax.z())
+ };
+
+ aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID, Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, false, Handle(OpenGl_ShaderProgram)());
+ aCtx->SetColor4fv (theWorkspace->InteriorColor());
+ aCtx->core11fwd->glDisable (GL_LIGHTING);
+ aCtx->core11->glEnableClientState (GL_VERTEX_ARRAY);
+ aCtx->core11->glVertexPointer (3, GL_FLOAT, 0, aVerts[0].GetData());
+ aCtx->core11fwd->glDrawArrays (GL_LINE_STRIP, 0, 16);
+ aCtx->core11->glDisableClientState (GL_VERTEX_ARRAY);
+ }
+#endif
+ aCtx->BindTextures (aPrevTexture);
}
// =======================================================================
// =======================================================================
OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
: Graphic3d_CStructure (theManager),
- myTransformation(NULL),
- myTransPers(NULL),
- myAspectLine(NULL),
- myAspectFace(NULL),
- myAspectMarker(NULL),
- myAspectText(NULL),
- myHighlightBox(NULL),
- myHighlightColor(NULL),
- myNamedStatus(0),
- myZLayer(0)
+ myInstancedStructure (NULL),
+ myIsRaytracable (Standard_False),
+ myModificationState (0),
+ myIsMirrored (Standard_False)
{
- UpdateNamedStatus();
-#if HAVE_OPENCL
- myIsRaytracable = Standard_False;
- myModificationState = 0;
-#endif
+ updateLayerTransformation();
}
// =======================================================================
OpenGl_Structure::~OpenGl_Structure()
{
Release (Handle(OpenGl_Context)());
- delete myTransformation; myTransformation = NULL;
- delete myTransPers; myTransPers = NULL;
}
// =======================================================================
-// function : UpdateAspects
+// function : SetZLayer
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateAspects()
+void OpenGl_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerIndex)
{
- SetTransformPersistence (TransformPersistence);
-
- if (ContextLine.IsDef)
- SetAspectLine (ContextLine);
-
- if (ContextFillArea.IsDef)
- SetAspectFace (ContextFillArea);
-
- if (ContextMarker.IsDef)
- SetAspectMarker (ContextMarker);
-
- if (ContextText.IsDef)
- SetAspectText (ContextText);
+ Graphic3d_CStructure::SetZLayer (theLayerIndex);
+ updateLayerTransformation();
}
// =======================================================================
-// function : UpdateTransformation
+// function : SetTransformation
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateTransformation()
+void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
{
- if (myTransformation == NULL)
+ myTrsf = theTrsf;
+ myIsMirrored = Standard_False;
+ if (!myTrsf.IsNull())
{
- myTransformation = new OpenGl_Matrix();
+ // Determinant of transform matrix less then 0 means that mirror transform applied.
+ const Standard_Real aDet = myTrsf->Value(1, 1) * (myTrsf->Value (2, 2) * myTrsf->Value (3, 3) - myTrsf->Value (3, 2) * myTrsf->Value (2, 3))
+ - myTrsf->Value(1, 2) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 3) - myTrsf->Value (3, 1) * myTrsf->Value (2, 3))
+ + myTrsf->Value(1, 3) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 2) - myTrsf->Value (3, 1) * myTrsf->Value (2, 2));
+ myIsMirrored = aDet < 0.0;
}
- matcpy (myTransformation->mat, &Graphic3d_CStructure::Transformation[0][0]);
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
+ updateLayerTransformation();
+ if (IsRaytracable())
{
- UpdateStateWithAncestorStructures();
+ ++myModificationState;
}
-#endif
}
// =======================================================================
// function : SetTransformPersistence
// purpose :
// =======================================================================
-void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers)
-{
- if (!myTransPers)
- myTransPers = new TEL_TRANSFORM_PERSISTENCE;
-
- myTransPers->mode = ATransPers.Flag;
- myTransPers->pointX = ATransPers.Point.x;
- myTransPers->pointY = ATransPers.Point.y;
- myTransPers->pointZ = ATransPers.Point.z;
-}
-
-// =======================================================================
-// function : SetAspectLine
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect)
-{
- if (!myAspectLine)
- {
- myAspectLine = new OpenGl_AspectLine();
- }
- myAspectLine->SetAspect (theAspect);
-}
-
-// =======================================================================
-// function : SetAspectFace
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect)
-{
- if (!myAspectFace)
- {
- myAspectFace = new OpenGl_AspectFace();
- }
- myAspectFace->SetAspect (theAspect);
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
- {
- UpdateStateWithAncestorStructures();
- }
-#endif
-}
-
-// =======================================================================
-// function : SetAspectMarker
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
+void OpenGl_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
{
- if (!myAspectMarker)
- {
- myAspectMarker = new OpenGl_AspectMarker();
- }
- myAspectMarker->SetAspect (theAspect);
+ myTrsfPers = theTrsfPers;
+ updateLayerTransformation();
}
// =======================================================================
-// function : SetAspectText
+// function : updateLayerTransformation
// purpose :
// =======================================================================
-void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
+void OpenGl_Structure::updateLayerTransformation()
{
- if (!myAspectText)
+ gp_Trsf aRenderTrsf;
+ if (!myTrsf.IsNull())
{
- myAspectText = new OpenGl_AspectText();
+ aRenderTrsf = myTrsf->Trsf();
}
- myAspectText->SetAspect (theAspect);
-}
-// =======================================================================
-// function : SetHighlightBox
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
- const CALL_DEF_BOUNDBOX& theBoundBox)
-{
- if (myHighlightBox != NULL)
+ const Graphic3d_ZLayerSettings& aLayer = myGraphicDriver->ZLayerSettings (myZLayer);
+ if (!aLayer.OriginTransformation().IsNull()
+ && myTrsfPers.IsNull())
{
- myHighlightBox->Release (theGlCtx);
+ aRenderTrsf.SetTranslationPart (aRenderTrsf.TranslationPart() - aLayer.Origin());
}
- else
- {
-#ifndef HAVE_OPENCL
- myHighlightBox = new OpenGl_Group();
-#else
- myHighlightBox = new OpenGl_Group (this);
-#endif
- }
-
- CALL_DEF_CONTEXTLINE aContextLine;
- aContextLine.Color = theBoundBox.Color;
- aContextLine.LineType = Aspect_TOL_SOLID;
- aContextLine.Width = 1.0f;
- myHighlightBox->SetAspectLine (aContextLine);
-
- OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox);
- myHighlightBox->AddElement (aBndBoxPrs);
+ aRenderTrsf.GetMat4 (myRenderTrsf);
}
// =======================================================================
-// function : ClearHighlightBox
+// function : GraphicHighlight
// purpose :
// =======================================================================
-void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_Structure::GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle)
{
- if (myHighlightBox != NULL)
- {
- OpenGl_Element::Destroy (theGlCtx, myHighlightBox);
- }
+ myHighlightStyle = theStyle;
+ highlight = 1;
}
// =======================================================================
-// function : HighlightWithColor
+// function : GraphicUnhighlight
// purpose :
// =======================================================================
-void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
- const Standard_Boolean theToCreate)
+void OpenGl_Structure::GraphicUnhighlight()
{
- const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext();
- if (theToCreate)
- SetHighlightColor (aCtx, theColor);
- else
- ClearHighlightColor (aCtx);
+ highlight = 0;
+ myHighlightStyle.Nullify();
}
// =======================================================================
-// function : HighlightWithBndBox
+// function : OnVisibilityChanged
// purpose :
// =======================================================================
-void OpenGl_Structure::HighlightWithBndBox (const Standard_Boolean theToCreate)
+void OpenGl_Structure::OnVisibilityChanged()
{
- const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext();
- if (theToCreate)
- SetHighlightBox (aCtx, BoundBox);
- else
- ClearHighlightBox (aCtx);
-}
-
-// =======================================================================
-// function : SetHighlightColor
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
- const Graphic3d_Vec3& theColor)
-{
- ClearHighlightBox (theGlCtx);
- if (myHighlightColor == NULL)
+ if (IsRaytracable())
{
- myHighlightColor = new TEL_COLOUR();
+ ++myModificationState;
}
-
- myHighlightColor->rgb[0] = theColor.r();
- myHighlightColor->rgb[1] = theColor.g();
- myHighlightColor->rgb[2] = theColor.b();
- myHighlightColor->rgb[3] = 1.F;
-}
-
-// =======================================================================
-// function : ClearHighlightColor
-// purpose :
-// =======================================================================
-void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
-{
- ClearHighlightBox(theGlCtx);
- delete myHighlightColor;
- myHighlightColor = NULL;
}
// =======================================================================
-// function : UpdateNamedStatus
+// function : IsRaytracable
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateNamedStatus()
+Standard_Boolean OpenGl_Structure::IsRaytracable() const
{
- myNamedStatus = 0;
- if (highlight) myNamedStatus |= OPENGL_NS_HIGHLIGHT;
- if (!visible) myNamedStatus |= OPENGL_NS_HIDE;
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
+ if (!myGroups.IsEmpty()
+ && myIsRaytracable)
{
- UpdateStateWithAncestorStructures();
+ return Standard_True;
}
-#endif
-}
-
-#ifdef HAVE_OPENCL
-// =======================================================================
-// function : RegisterAncestorStructure
-// purpose :
-// =======================================================================
-void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const
-{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- if (anIt.Value() == theStructure)
- {
- return;
- }
- }
-
- myAncestorStructures.Append (theStructure);
-}
-
-// =======================================================================
-// function : UnregisterAncestorStructure
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const
-{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- if (anIt.Value() == theStructure)
- {
- myAncestorStructures.Remove (anIt);
- return;
- }
- }
+ return myInstancedStructure != NULL
+ && myInstancedStructure->IsRaytracable();
}
// =======================================================================
-// function : UnregisterFromAncestorStructure
+// function : UpdateRaytracableState
// purpose :
// =======================================================================
-void OpenGl_Structure::UnregisterFromAncestorStructure() const
+void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
{
- for (OpenGl_ListOfStructure::Iterator anIta (myAncestorStructures); anIta.More(); anIta.Next())
+ myIsRaytracable = !toCheck;
+ if (!myIsRaytracable)
{
- OpenGl_Structure* anAncestor = const_cast<OpenGl_Structure*> (anIta.ChangeValue());
-
- for (OpenGl_ListOfStructure::Iterator anIts (anAncestor->myConnected); anIts.More(); anIts.Next())
+ for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
{
- if (anIts.Value() == this)
+ if (anIter.Value()->IsRaytracable())
{
- anAncestor->myConnected.Remove (anIts);
- return;
+ myIsRaytracable = Standard_True;
+ break;
}
}
}
-}
-
-// =======================================================================
-// function : UpdateStateWithAncestorStructures
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UpdateStateWithAncestorStructures() const
-{
- myModificationState++;
-
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- anIt.Value()->UpdateStateWithAncestorStructures();
- }
-}
-
-// =======================================================================
-// function : UpdateRaytracableWithAncestorStructures
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const
-{
- myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this);
-
- if (!myIsRaytracable)
- {
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- anIt.Value()->UpdateRaytracableWithAncestorStructures();
- }
- }
-}
-
-// =======================================================================
-// function : SetRaytracableWithAncestorStructures
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetRaytracableWithAncestorStructures() const
-{
- myIsRaytracable = Standard_True;
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ if (IsRaytracable())
{
- if (!anIt.Value()->IsRaytracable())
- {
- anIt.Value()->SetRaytracableWithAncestorStructures();
- }
+ ++myModificationState;
}
}
-#endif
-
// =======================================================================
// function : Connect
// purpose :
// =======================================================================
void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
{
- OpenGl_Structure* aStruct = (OpenGl_Structure* )&theStructure;
- Disconnect (theStructure);
- myConnected.Append (aStruct);
+ OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
+
+ Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
+ "Error! Instanced structure is already defined");
+
+ myInstancedStructure = aStruct;
-#ifdef HAVE_OPENCL
if (aStruct->IsRaytracable())
{
- UpdateStateWithAncestorStructures();
- SetRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable (Standard_False);
}
-
- aStruct->RegisterAncestorStructure (this);
-#endif
}
// =======================================================================
// =======================================================================
void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
{
- OpenGl_Structure* aStruct = (OpenGl_Structure* )&theStructure;
- for (OpenGl_ListOfStructure::Iterator anIter (myConnected); anIter.More(); anIter.Next())
- {
- // Check for the given structure
- if (anIter.Value() == aStruct)
- {
- myConnected.Remove (anIter);
+ OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
-#ifdef HAVE_OPENCL
- if (aStruct->IsRaytracable())
- {
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
- }
+ if (myInstancedStructure == aStruct)
+ {
+ myInstancedStructure = NULL;
- aStruct->UnregisterAncestorStructure (this);
-#endif
- return;
+ if (aStruct->IsRaytracable())
+ {
+ UpdateStateIfRaytracable();
}
}
}
// =======================================================================
-// function : AddGroup
+// function : NewGroup
// purpose :
// =======================================================================
-OpenGl_Group * OpenGl_Structure::AddGroup()
+Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
{
- // Create new group
-#ifndef HAVE_OPENCL
- OpenGl_Group *g = new OpenGl_Group();
-#else
- OpenGl_Group *g = new OpenGl_Group (this);
-#endif
-
- myGroups.Append(g);
- return g;
+ Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
+ myGroups.Append (aGroup);
+ return aGroup;
}
// =======================================================================
// function : RemoveGroup
// purpose :
// =======================================================================
-void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
- const OpenGl_Group* theGroup)
+void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
{
- for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
+ if (theGroup.IsNull())
+ {
+ return;
+ }
+
+ for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
// Check for the given group
- if (anIter.Value() == theGroup)
+ if (aGroupIter.Value() == theGroup)
{
- myGroups.Remove (anIter);
+ const Standard_Boolean wasRaytracable =
+ static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
+
+ theGroup->Clear (Standard_False);
-#ifdef HAVE_OPENCL
- if (theGroup->IsRaytracable())
+ if (wasRaytracable)
{
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable();
}
-#endif
- // Delete object
- OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup));
+ myGroups.Remove (aGroupIter);
return;
}
}
// =======================================================================
void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
{
-#ifdef HAVE_OPENCL
Standard_Boolean aRaytracableGroupDeleted (Standard_False);
-#endif
// Release groups
- for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
-#ifdef HAVE_OPENCL
- aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable();
-#endif
+ aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
// Delete objects
- OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue()));
+ aGroupIter.ChangeValue()->Release (theGlCtx);
}
myGroups.Clear();
-#ifdef HAVE_OPENCL
if (aRaytracableGroupDeleted)
{
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
+ myIsRaytracable = Standard_False;
+ }
+
+ Is2dText = Standard_False;
+ IsForHighlight = Standard_False;
+}
+
+// =======================================================================
+// function : renderGeometry
+// purpose :
+// =======================================================================
+void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
+ bool& theHasClosed) const
+{
+ if (myInstancedStructure != NULL)
+ {
+ myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
+ }
+
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
+ {
+ theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
+ aGroupIter.Value()->Render (theWorkspace);
}
-#endif
}
// =======================================================================
// function : Render
// purpose :
// =======================================================================
-void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
+void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
{
// Process the structure only if visible
- if ( myNamedStatus & OPENGL_NS_HIDE )
+ if (!visible)
+ {
return;
+ }
- // Render named status
- const Standard_Integer named_status = AWorkspace->NamedStatus;
- AWorkspace->NamedStatus |= myNamedStatus;
-
- // Is rendering in ADD or IMMEDIATE mode?
- const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
-
- const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
- // Apply local transformation
- GLint matrix_mode = 0;
- const OpenGl_Matrix *local_trsf = NULL;
- if (myTransformation)
+ // Render named status
+ if (highlight && !myHighlightStyle.IsNull() && myHighlightStyle->Method() != Aspect_TOHM_BOUNDBOX)
{
- if (isImmediate)
- {
- Tmatrix3 aModelWorld;
- call_util_transpose_mat (*aModelWorld, myTransformation->mat);
- glGetIntegerv (GL_MATRIX_MODE, &matrix_mode);
-
- if (!aCtx->ShaderManager()->IsEmpty())
- {
- Tmatrix3 aWorldView;
- glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView);
-
- Tmatrix3 aProjection;
- glGetFloatv (GL_PROJECTION_MATRIX, *aProjection);
-
- aCtx->ShaderManager()->UpdateModelWorldStateTo (&aModelWorld);
- aCtx->ShaderManager()->UpdateWorldViewStateTo (&aWorldView);
- aCtx->ShaderManager()->UpdateProjectionStateTo (&aProjection);
- }
+ theWorkspace->SetHighlightStyle (myHighlightStyle);
+ }
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- glScalef (1.F, 1.F, 1.F);
- glMultMatrixf (*aModelWorld);
- }
- else
+ // Apply local transformation
+ aCtx->ModelWorldState.Push();
+ OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent();
+ aModelWorld = myRenderTrsf;
+
+ const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
+#if !defined(GL_ES_VERSION_2_0)
+ // detect scale transform
+ if (aCtx->core11 != NULL
+ && !myTrsf.IsNull())
+ {
+ const Standard_Real aScale = myTrsf->ScaleFactor();
+ if (Abs (aScale - 1.0) > Precision::Confusion())
{
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix();
-
- local_trsf = AWorkspace->SetStructureMatrix (myTransformation);
+ aCtx->SetGlNormalizeEnabled (Standard_True);
}
}
+#endif
- // Apply transform persistence
- const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL;
- if ( myTransPers && myTransPers->mode != 0 )
+ if (!myTrsfPers.IsNull())
{
- trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers);
- }
+ aCtx->WorldViewState.Push();
+ OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent();
+ myTrsfPers->Apply (theWorkspace->View()->Camera(),
+ aCtx->ProjectionState.Current(), aWorldView,
+ aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
- // Apply aspects
- const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False);
- const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False);
- const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False);
- const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False);
- if (myAspectLine)
- AWorkspace->SetAspectLine(myAspectLine);
- if (myAspectFace)
- AWorkspace->SetAspectFace(myAspectFace);
- if (myAspectMarker)
- AWorkspace->SetAspectMarker(myAspectMarker);
- if (myAspectText)
- AWorkspace->SetAspectText(myAspectText);
+ #if !defined(GL_ES_VERSION_2_0)
+ if (!aCtx->IsGlNormalizeEnabled()
+ && aCtx->core11 != NULL)
+ {
+ const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor<Standard_ShortReal> (aWorldView);
+ if (Abs (aScale - 1.0) > Precision::Confusion())
+ {
+ aCtx->SetGlNormalizeEnabled (Standard_True);
+ }
+ }
+ #endif
+ }
- // Apply highlight box
- if (myHighlightBox)
- myHighlightBox->Render( AWorkspace );
+ // Take into account transform persistence
+ aCtx->ApplyModelViewMatrix();
- // Apply highlight color
- const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor;
- if (myHighlightColor)
- AWorkspace->HighlightColor = myHighlightColor;
+ // remember aspects
+ const OpenGl_Aspects* aPrevAspectFace = theWorkspace->Aspects();
- // Render connected structures
- OpenGl_ListOfStructure::Iterator its(myConnected);
- while (its.More())
+ // Apply correction for mirror transform
+ if (myIsMirrored)
{
- its.Value()->Render(AWorkspace);
- its.Next();
+ aCtx->core11fwd->glFrontFace (GL_CW);
}
- // Set up plane equations for non-structure transformed global model-view matrix
- const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext();
-
- // List of planes to be applied to context state
- Handle(Graphic3d_SequenceOfHClipPlane) aUserPlanes;
-
// Collect clipping planes of structure scope
- if (!myClipPlanes.IsEmpty())
+ aCtx->ChangeClipping().SetLocalPlanes (myClipPlanes);
+
+ // True if structure is fully clipped
+ bool isClipped = false;
+ bool hasDisabled = false;
+ if (aCtx->Clipping().IsClippingOrCappingOn())
{
- Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes);
- for (; aClippingIt.More(); aClippingIt.Next())
+ const Graphic3d_BndBox3d& aBBox = BoundingBox();
+ if (!myClipPlanes.IsNull()
+ && myClipPlanes->ToOverrideGlobal())
+ {
+ aCtx->ChangeClipping().DisableGlobal();
+ hasDisabled = aCtx->Clipping().HasDisabled();
+ }
+ else if (!myTrsfPers.IsNull())
{
- const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
- if (!aClipPlane->IsOn())
+ if (myTrsfPers->IsZoomOrRotate())
{
- continue;
+ // Zoom/rotate persistence object lives in two worlds at the same time.
+ // Global clipping planes can not be trivially applied without being converted
+ // into local space of transformation persistence object.
+ // As more simple alternative - just clip entire object by its anchor point defined in the world space.
+ const gp_Pnt anAnchor = myTrsfPers->AnchorPoint();
+ for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More() && aPlaneIt.IsGlobal(); aPlaneIt.Next())
+ {
+ const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+ if (!aPlane->IsOn())
+ {
+ continue;
+ }
+
+ // check for clipping
+ const Graphic3d_Vec4d aCheckPnt (anAnchor.X(), anAnchor.Y(), anAnchor.Z(), 1.0);
+ if (aPlane->ProbePoint (aCheckPnt) == Graphic3d_ClipState_Out)
+ {
+ isClipped = true;
+ break;
+ }
+ }
}
- if (aUserPlanes.IsNull())
+ aCtx->ChangeClipping().DisableGlobal();
+ hasDisabled = aCtx->Clipping().HasDisabled();
+ }
+
+ // Set of clipping planes that do not intersect the structure,
+ // and thus can be disabled to improve rendering performance
+ if (aBBox.IsValid()
+ && myTrsfPers.IsNull())
+ {
+ for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next())
{
- aUserPlanes = new Graphic3d_SequenceOfHClipPlane();
+ const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+ if (aPlaneIt.IsDisabled())
+ {
+ continue;
+ }
+
+ const Graphic3d_ClipState aBoxState = aPlane->ProbeBox (aBBox);
+ if (aBoxState == Graphic3d_ClipState_In)
+ {
+ aCtx->ChangeClipping().SetEnabled (aPlaneIt, false);
+ hasDisabled = true;
+ }
+ else if (aBoxState == Graphic3d_ClipState_Out && myBndBoxClipCheck)
+ {
+ isClipped = true;
+ break;
+ }
}
-
- aUserPlanes->Append (aClipPlane);
}
- }
- if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
- {
- // add planes at loaded view matrix state
- aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace);
-
- // Set OCCT state uniform variables
- if (!aContext->ShaderManager()->IsEmpty())
+ if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
+ || hasDisabled)
{
- aContext->ShaderManager()->UpdateClippingState();
+ // Set OCCT state uniform variables
+ aCtx->ShaderManager()->UpdateClippingState();
}
}
// Render groups
- OpenGl_ListOfGroup::Iterator itg(myGroups);
- while (itg.More())
+ bool hasClosedPrims = false;
+ if (!isClipped)
+ {
+ renderGeometry (theWorkspace, hasClosedPrims);
+ }
+
+ // Reset correction for mirror transform
+ if (myIsMirrored)
{
- itg.Value()->Render(AWorkspace);
- itg.Next();
+ aCtx->core11fwd->glFrontFace (GL_CCW);
}
// Render capping for structure groups
- if (!aContext->Clipping().Planes().IsEmpty())
+ if (hasClosedPrims
+ && aCtx->Clipping().IsCappingOn())
{
- OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups);
+ OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
}
// Revert structure clippings
- if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
+ if (hasDisabled)
+ {
+ // enable planes that were previously disabled
+ aCtx->ChangeClipping().RestoreDisabled();
+ }
+ aCtx->ChangeClipping().SetLocalPlanes (Handle(Graphic3d_SequenceOfHClipPlane)());
+ if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
+ || hasDisabled)
{
- aContext->ChangeClipping().Remove (*aUserPlanes);
-
// Set OCCT state uniform variables
- if (!aContext->ShaderManager()->IsEmpty())
- {
- aContext->ShaderManager()->RevertClippingState();
- }
+ aCtx->ShaderManager()->RevertClippingState();
}
- // Restore highlight color
- AWorkspace->HighlightColor = highlight_color;
+ // Restore local transformation
+ aCtx->ModelWorldState.Pop();
+ aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
// Restore aspects
- AWorkspace->SetAspectLine(aspect_line);
- AWorkspace->SetAspectFace(aspect_face);
- AWorkspace->SetAspectMarker(aspect_marker);
- AWorkspace->SetAspectText(aspect_text);
+ theWorkspace->SetAspects (aPrevAspectFace);
- // Restore transform persistence
- if ( myTransPers && myTransPers->mode != 0 )
+ // Apply highlight box
+ if (!isClipped
+ && !myHighlightStyle.IsNull()
+ && myHighlightStyle->Method() == Aspect_TOHM_BOUNDBOX)
{
- AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers);
+ aCtx->ApplyModelViewMatrix();
+ theWorkspace->SetHighlightStyle (myHighlightStyle);
+ renderBoundingBox (theWorkspace);
}
- // Restore local transformation
- if (myTransformation)
+ if (!myTrsfPers.IsNull())
{
- if (isImmediate)
- {
- glPopMatrix ();
- glMatrixMode (matrix_mode);
-
- 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
- {
- AWorkspace->SetStructureMatrix (local_trsf, true);
-
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- }
+ aCtx->WorldViewState.Pop();
}
// Restore named status
- AWorkspace->NamedStatus = named_status;
+ theWorkspace->SetHighlightStyle (Handle(Graphic3d_PresentationAttributes)());
}
// =======================================================================
{
// Release groups
Clear (theGlCtx);
- OpenGl_Element::Destroy (theGlCtx, myAspectLine);
- OpenGl_Element::Destroy (theGlCtx, myAspectFace);
- OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
- OpenGl_Element::Destroy (theGlCtx, myAspectText);
- ClearHighlightColor (theGlCtx);
-
-#ifdef HAVE_OPENCL
- // Remove from connected list of ancestor
- UnregisterFromAncestorStructure();
-#endif
+ myHighlightStyle.Nullify();
}
// =======================================================================
// =======================================================================
void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
{
- for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
- {
- OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue());
- if (aGroup != NULL)
- {
- aGroup->Release (theGlCtx);
- }
- }
- if (myAspectLine != NULL)
- {
- myAspectLine->Release (theGlCtx);
- }
- if (myAspectFace != NULL)
- {
- myAspectFace->Release (theGlCtx);
- }
- if (myAspectMarker != NULL)
- {
- myAspectMarker->Release (theGlCtx);
- }
- if (myAspectText != NULL)
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
- myAspectText->Release (theGlCtx);
+ aGroupIter.ChangeValue()->Release (theGlCtx);
}
- if (myHighlightBox != NULL)
- {
- myHighlightBox->Release (theGlCtx);
- }
-}
-
-//=======================================================================
-//function : SetZLayer
-//purpose :
-//=======================================================================
-void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex)
-{
- myZLayer = theLayerIndex;
}
//=======================================================================
-//function : GetZLayer
+//function : ShadowLink
//purpose :
//=======================================================================
-Standard_Integer OpenGl_Structure::GetZLayer () const
+Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
{
- return myZLayer;
+ return new OpenGl_StructureShadow (theManager, this);
}