#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>
+#include <Graphic3d_SequenceOfHClipPlane.hxx>
-IMPLEMENT_STANDARD_HANDLE (OpenGl_Structure, Graphic3d_CStructure)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
+
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure)
//! Auxiliary class for bounding box presentation
class OpenGl_BndBoxPrs : public OpenGl_Element
//! Render presentation
virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
+ #if !defined(GL_ES_VERSION_2_0)
// 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_IMMEDIATE) != 0)
- {
- glDepthMask (GL_FALSE);
- }
// Use highlight colors
- glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb);
+ theWorkspace->GetGlContext()->core11->glColor3fv (theWorkspace->LineColor().GetData());
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
{
theWorkspace->EnableTexture (aPrevTexture);
}
+ #else
+ (void )theWorkspace;
+ #endif
}
//! Release graphical resources
- virtual void Release (const Handle(OpenGl_Context)& )
+ virtual void Release (OpenGl_Context*)
{
//
}
/*----------------------------------------------------------------------*/
-// =======================================================================
-// function : call_util_transpose_mat
-// purpose :
-// =======================================================================
-static void call_util_transpose_mat (float tmat[16], float mat[4][4])
-{
- int i, j;
-
- for (i=0; i<4; i++)
- for (j=0; j<4; j++)
- tmat[j*4+i] = mat[i][j];
-}
-
// =======================================================================
// function : OpenGl_Structure
// purpose :
// =======================================================================
OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
: Graphic3d_CStructure (theManager),
- myTransformation(NULL),
- myTransPers(NULL),
- myAspectLine(NULL),
- myAspectFace(NULL),
- myAspectMarker(NULL),
- myAspectText(NULL),
- myHighlightColor(NULL),
- myNamedStatus(0),
- myZLayer(0),
- myIsRaytracable (Standard_False),
- myModificationState (0),
- myIsCulled (Standard_True)
+ myInstancedStructure (NULL),
+ myIsRaytracable (Standard_False),
+ myModificationState (0),
+ myIsCulled (Standard_True),
+ myIsMirrored (Standard_False)
{
- UpdateNamedStatus();
+ //
}
// =======================================================================
OpenGl_Structure::~OpenGl_Structure()
{
Release (Handle(OpenGl_Context)());
- delete myTransformation; myTransformation = NULL;
- delete myTransPers; myTransPers = NULL;
-}
-
-// =======================================================================
-// function : UpdateAspects
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UpdateAspects()
-{
- SetTransformPersistence (TransformPersistence);
-
- if (ContextLine.IsDef)
- SetAspectLine (ContextLine);
-
- if (ContextFillArea.IsDef)
- SetAspectFace (ContextFillArea);
-
- if (ContextMarker.IsDef)
- SetAspectMarker (ContextMarker);
-
- if (ContextText.IsDef)
- SetAspectText (ContextText);
}
// =======================================================================
-// 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]);
-
- if (myIsRaytracable)
+ if (IsRaytracable())
{
- UpdateStateWithAncestorStructures();
+ ++myModificationState;
}
}
-// =======================================================================
-// 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;
- MarkAsNotCulled();
-}
-
-// =======================================================================
-// 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);
-
- if (myIsRaytracable)
- {
- UpdateStateWithAncestorStructures();
- }
-}
-
-// =======================================================================
-// function : SetAspectMarker
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
-{
- if (!myAspectMarker)
- {
- myAspectMarker = new OpenGl_AspectMarker();
- }
- myAspectMarker->SetAspect (theAspect);
-}
-
-// =======================================================================
-// function : SetAspectText
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
-{
- if (!myAspectText)
- {
- myAspectText = new OpenGl_AspectText();
- }
- myAspectText->SetAspect (theAspect);
-}
-
// =======================================================================
// function : clearHighlightBox
// purpose :
}
}
-// =======================================================================
-// function : HighlightWithColor
-// purpose :
-// =======================================================================
-void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
- const Standard_Boolean theToCreate)
-{
- const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext();
- if (theToCreate)
- setHighlightColor (aCtx, theColor);
- else
- clearHighlightColor (aCtx);
-}
-
// =======================================================================
// function : HighlightWithBndBox
// purpose :
// =======================================================================
-void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
- const Standard_Boolean theToCreate)
+void OpenGl_Structure::highlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct)
{
- const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext();
- if (!theToCreate)
- {
- clearHighlightBox (aCtx);
- return;
- }
+ const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
if (!myHighlightBox.IsNull())
{
- myHighlightBox->Release (aCtx);
+ myHighlightBox->Release (aContext);
}
else
{
myHighlightBox = new OpenGl_Group (theStruct);
}
- CALL_DEF_CONTEXTLINE& aContextLine = myHighlightBox->ChangeContextLine();
- aContextLine.IsDef = 1;
- aContextLine.Color = HighlightColor;
- aContextLine.LineType = Aspect_TOL_SOLID;
- aContextLine.Width = 1.0f;
- myHighlightBox->UpdateAspectLine (Standard_True);
+ myHighlightBox->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (myHighlightStyle->Color(), Aspect_TOL_SOLID, 1.0));
OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox);
myHighlightBox->AddElement (aBndBoxPrs);
}
// =======================================================================
-// function : setHighlightColor
-// purpose :
-// =======================================================================
-void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
- const Graphic3d_Vec3& theColor)
-{
- clearHighlightBox (theGlCtx);
- if (myHighlightColor == NULL)
- {
- myHighlightColor = new TEL_COLOUR();
- }
-
- 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 : GraphicHighlight
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateNamedStatus()
+void OpenGl_Structure::GraphicHighlight (const Handle(Graphic3d_HighlightStyle)& theStyle,
+ const Handle(Graphic3d_Structure)& theStruct)
{
- myNamedStatus = 0;
- if (highlight) myNamedStatus |= OPENGL_NS_HIGHLIGHT;
- if (!visible) myNamedStatus |= OPENGL_NS_HIDE;
+ myHighlightStyle = theStyle;
- if (myIsRaytracable)
+ highlight = 1;
+ if (myHighlightStyle->Method() == Aspect_TOHM_BOUNDBOX)
{
- UpdateStateWithAncestorStructures();
+ highlightWithBndBox (theStruct);
}
}
// =======================================================================
-// function : RegisterAncestorStructure
+// function : GraphicUnhighlight
// purpose :
// =======================================================================
-void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const
+void OpenGl_Structure::GraphicUnhighlight()
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ highlight = 0;
+
+ if (myHighlightStyle->Method() == Aspect_TOHM_BOUNDBOX)
{
- if (anIt.Value() == theStructure)
- {
- return;
- }
+ const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
+ clearHighlightBox (aContext);
}
- myAncestorStructures.Append (theStructure);
+ myHighlightStyle.Nullify();
}
// =======================================================================
-// function : UnregisterAncestorStructure
+// function : OnVisibilityChanged
// purpose :
// =======================================================================
-void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const
+void OpenGl_Structure::OnVisibilityChanged()
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ if (IsRaytracable())
{
- if (anIt.Value() == theStructure)
- {
- myAncestorStructures.Remove (anIt);
- return;
- }
+ ++myModificationState;
}
}
// =======================================================================
-// function : UnregisterFromAncestorStructure
+// function : IsRaytracable
// purpose :
// =======================================================================
-void OpenGl_Structure::UnregisterFromAncestorStructure() const
+Standard_Boolean OpenGl_Structure::IsRaytracable() const
{
- for (OpenGl_ListOfStructure::Iterator anIta (myAncestorStructures); anIta.More(); anIta.Next())
+ if (!myGroups.IsEmpty()
+ && myIsRaytracable)
{
- OpenGl_Structure* anAncestor = const_cast<OpenGl_Structure*> (anIta.ChangeValue());
-
- for (OpenGl_ListOfStructure::Iterator anIts (anAncestor->myConnected); anIts.More(); anIts.Next())
- {
- if (anIts.Value() == this)
- {
- anAncestor->myConnected.Remove (anIts);
- return;
- }
- }
+ return Standard_True;
}
-}
-
-// =======================================================================
-// function : UpdateStateWithAncestorStructures
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UpdateStateWithAncestorStructures() const
-{
- myModificationState++;
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- anIt.Value()->UpdateStateWithAncestorStructures();
- }
+ return myInstancedStructure != NULL
+ && myInstancedStructure->IsRaytracable();
}
// =======================================================================
-// function : UpdateRaytracableWithAncestorStructures
+// function : UpdateRaytracableState
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const
+void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
{
- myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this);
-
+ myIsRaytracable = !toCheck;
if (!myIsRaytracable)
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
{
- anIt.Value()->UpdateRaytracableWithAncestorStructures();
+ if (anIter.Value()->IsRaytracable())
+ {
+ myIsRaytracable = Standard_True;
+ break;
+ }
}
}
-}
-
-// =======================================================================
-// 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;
}
}
// =======================================================================
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;
if (aStruct->IsRaytracable())
{
- UpdateStateWithAncestorStructures();
- SetRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable (Standard_False);
}
-
- aStruct->RegisterAncestorStructure (this);
}
// =======================================================================
// =======================================================================
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);
- if (aStruct->IsRaytracable())
- {
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
- }
+ if (myInstancedStructure == aStruct)
+ {
+ myInstancedStructure = NULL;
- aStruct->UnregisterAncestorStructure (this);
- return;
+ if (aStruct->IsRaytracable())
+ {
+ UpdateStateIfRaytracable();
}
}
}
// Check for the given group
if (aGroupIter.Value() == theGroup)
{
+ const Standard_Boolean wasRaytracable =
+ static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
+
theGroup->Clear (Standard_False);
- if (((OpenGl_Group* )theGroup.operator->())->IsRaytracable())
+ if (wasRaytracable)
{
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable();
}
myGroups.Remove (aGroupIter);
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);
+ }
+}
+
// =======================================================================
// 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;
+ }
- const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
// 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_IMMEDIATE) != 0;
+ if (highlight && myHighlightBox.IsNull())
+ {
+ theWorkspace->SetHighlight (true);
+ }
// Apply local transformation
- GLint matrix_mode = 0;
- const OpenGl_Matrix *local_trsf = NULL;
- if (myTransformation)
+ aCtx->ModelWorldState.Push();
+ OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent();
+ if (!myTrsf.IsNull())
{
- 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);
+ myTrsf->Trsf().GetMat4 (aModelWorld);
+ }
+ else
+ {
+ aModelWorld.InitIdentity();
+ }
- aCtx->ShaderManager()->UpdateModelWorldStateTo (&aModelWorld);
- aCtx->ShaderManager()->UpdateWorldViewStateTo (&aWorldView);
- aCtx->ShaderManager()->UpdateProjectionStateTo (&aProjection);
- }
+ const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- glScalef (1.F, 1.F, 1.F);
- glMultMatrixf (*aModelWorld);
- }
- else
+#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);
+ OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
+ myTrsfPers->Apply (theWorkspace->View()->Camera(), aCtx->ProjectionState.Current(), aWorldView,
+ aCtx->Viewport()[2], aCtx->Viewport()[3]);
+
+ aCtx->WorldViewState.Push();
+ aCtx->WorldViewState.SetCurrent (aWorldView);
+
+ #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.0f) > Precision::Confusion())
+ {
+ aCtx->SetGlNormalizeEnabled (Standard_True);
+ }
+ }
+ #endif
}
- // 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);
+ // 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_AspectLine* aPrevAspectLine = theWorkspace->AspectLine();
+ const OpenGl_AspectFace* aPrevAspectFace = theWorkspace->AspectFace();
+ const OpenGl_AspectMarker* aPrevAspectMarker = theWorkspace->AspectMarker();
+ const OpenGl_AspectText* aPrevAspectText = theWorkspace->AspectText();
- // 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;
+ // Apply highlight color
+ const OpenGl_Vec4* aHighlightColor = theWorkspace->HighlightColor;
+ if (!myHighlightStyle.IsNull())
+ theWorkspace->HighlightColor = myHighlightStyle->ColorFltPtr();
// Collect clipping planes of structure scope
- if (!myClipPlanes.IsEmpty())
+ aCtx->ChangeClipping().SetLocalPlanes (aCtx, 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_BndBox4f& aBBox = BoundingBox();
+ if (!myClipPlanes.IsNull()
+ && myClipPlanes->ToOverrideGlobal())
+ {
+ aCtx->ChangeClipping().DisableGlobal (aCtx);
+ 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& aPlaneEquation = aPlane->GetEquation();
+ const Graphic3d_Vec4d aCheckPnt (anAnchor.X(), anAnchor.Y(), anAnchor.Z(), 1.0);
+ if (aPlaneEquation.Dot (aCheckPnt) < 0.0) // vertex is outside the half-space
+ {
+ isClipped = true;
+ break;
+ }
+ }
}
- if (aUserPlanes.IsNull())
+ aCtx->ChangeClipping().DisableGlobal (aCtx);
+ 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 (!aPlane->IsOn())
+ {
+ continue;
+ }
+
+ // check for clipping
+ const Graphic3d_Vec4d& aPlaneEquation = aPlane->GetEquation();
+ const Graphic3d_Vec4d aMaxPnt (aPlaneEquation.x() > 0.0 ? aBBox.CornerMax().x() : aBBox.CornerMin().x(),
+ aPlaneEquation.y() > 0.0 ? aBBox.CornerMax().y() : aBBox.CornerMin().y(),
+ aPlaneEquation.z() > 0.0 ? aBBox.CornerMax().z() : aBBox.CornerMin().z(),
+ 1.0);
+ if (aPlaneEquation.Dot (aMaxPnt) < 0.0) // max vertex is outside the half-space
+ {
+ isClipped = true;
+ break;
+ }
+
+ // check for no intersection (e.g. object is "entirely not clipped")
+ const Graphic3d_Vec4d aMinPnt (aPlaneEquation.x() > 0.0 ? aBBox.CornerMin().x() : aBBox.CornerMax().x(),
+ aPlaneEquation.y() > 0.0 ? aBBox.CornerMin().y() : aBBox.CornerMax().y(),
+ aPlaneEquation.z() > 0.0 ? aBBox.CornerMin().z() : aBBox.CornerMax().z(),
+ 1.0);
+ if (aPlaneEquation.Dot (aMinPnt) > 0.0) // min vertex is inside the half-space
+ {
+ aCtx->ChangeClipping().SetEnabled (aCtx, aPlaneIt, Standard_False);
+ hasDisabled = true;
+ }
}
-
- 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
- const Graphic3d_SequenceOfGroup& aGroups = DrawGroups();
- for (OpenGl_Structure::GroupIterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next())
+ bool hasClosedPrims = false;
+ if (!isClipped)
+ {
+ renderGeometry (theWorkspace, hasClosedPrims);
+ }
+
+ // Reset correction for mirror transform
+ if (myIsMirrored)
{
- aGroupIter.Value()->Render (AWorkspace);
+ aCtx->core11fwd->glFrontFace (GL_CCW);
}
// Render capping for structure groups
- if (!aContext->Clipping().Planes().IsEmpty())
+ if (hasClosedPrims
+ && aCtx->Clipping().IsCappingOn())
{
- OpenGl_CappingAlgo::RenderCapping (AWorkspace, aGroups);
+ OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
}
// Revert structure clippings
- if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
+ if (hasDisabled)
{
- aContext->ChangeClipping().Remove (*aUserPlanes);
-
- // Set OCCT state uniform variables
- if (!aContext->ShaderManager()->IsEmpty())
- {
- aContext->ShaderManager()->RevertClippingState();
- }
+ // enable planes that were previously disabled
+ aCtx->ChangeClipping().RestoreDisabled (aCtx);
}
-
- // Restore highlight color
- AWorkspace->HighlightColor = highlight_color;
-
- // Restore aspects
- AWorkspace->SetAspectLine(aspect_line);
- AWorkspace->SetAspectFace(aspect_face);
- AWorkspace->SetAspectMarker(aspect_marker);
- AWorkspace->SetAspectText(aspect_text);
-
- // Restore transform persistence
- if ( myTransPers && myTransPers->mode != 0 )
+ aCtx->ChangeClipping().SetLocalPlanes (aCtx, Handle(Graphic3d_SequenceOfHClipPlane)());
+ if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
+ || hasDisabled)
{
- AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers);
+ // Set OCCT state uniform variables
+ aCtx->ShaderManager()->RevertClippingState();
}
// Restore local transformation
- if (myTransformation)
+ aCtx->ModelWorldState.Pop();
+ aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
+ 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 } };
+ aCtx->WorldViewState.Pop();
+ }
- aContext->ShaderManager()->RevertModelWorldStateTo (&aModelWorldState);
- }
- else
- {
- AWorkspace->SetStructureMatrix (local_trsf, true);
+ // Restore highlight color
+ theWorkspace->HighlightColor = aHighlightColor;
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- }
- }
+ // Restore aspects
+ theWorkspace->SetAspectLine (aPrevAspectLine);
+ theWorkspace->SetAspectFace (aPrevAspectFace);
+ theWorkspace->SetAspectMarker (aPrevAspectMarker);
+ theWorkspace->SetAspectText (aPrevAspectText);
// Apply highlight box
if (!myHighlightBox.IsNull())
{
- myHighlightBox->Render (AWorkspace);
+ myHighlightBox->Render (theWorkspace);
}
// Restore named status
- AWorkspace->NamedStatus = named_status;
+ theWorkspace->SetHighlight (false);
}
// =======================================================================
{
// 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);
-
- // Remove from connected list of ancestor
- UnregisterFromAncestorStructure();
+ clearHighlightBox (theGlCtx);
+ myHighlightStyle.Nullify();
}
// =======================================================================
{
aGroupIter.ChangeValue()->Release (theGlCtx);
}
- if (myAspectLine != NULL)
- {
- myAspectLine->Release (theGlCtx);
- }
- if (myAspectFace != NULL)
- {
- myAspectFace->Release (theGlCtx);
- }
- if (myAspectMarker != NULL)
- {
- myAspectMarker->Release (theGlCtx);
- }
- if (myAspectText != NULL)
- {
- myAspectText->Release (theGlCtx);
- }
if (!myHighlightBox.IsNull())
{
- myHighlightBox->Release (theGlCtx);
+ myHighlightBox->Release (theGlCtx.operator->());
}
}
-//=======================================================================
-//function : SetZLayer
-//purpose :
-//=======================================================================
-void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex)
-{
- myZLayer = theLayerIndex;
-}
-
-//=======================================================================
-//function : GetZLayer
-//purpose :
-//=======================================================================
-Standard_Integer OpenGl_Structure::GetZLayer () const
-{
- return myZLayer;
-}
-
-//! Dummy structure which just redirects to groups of another structure.
-class OpenGl_StructureShadow : public OpenGl_Structure
-{
-
-public:
-
- //! Create empty structure
- OpenGl_StructureShadow (const Handle(Graphic3d_StructureManager)& theManager,
- const Handle(OpenGl_Structure)& theStructure);
-
- virtual const Graphic3d_SequenceOfGroup& DrawGroups() const { return myParent->DrawGroups(); }
-
-private:
-
- Handle(OpenGl_Structure) myParent;
-
-public:
-
- DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
-
-};
-
-DEFINE_STANDARD_HANDLE(OpenGl_StructureShadow, OpenGl_Structure)
-
-IMPLEMENT_STANDARD_HANDLE (OpenGl_StructureShadow, OpenGl_Structure)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_StructureShadow, OpenGl_Structure)
-
-//=======================================================================
-//function : OpenGl_StructureShadow
-//purpose :
-//=======================================================================
-OpenGl_StructureShadow::OpenGl_StructureShadow (const Handle(Graphic3d_StructureManager)& theManager,
- const Handle(OpenGl_Structure)& theStructure)
-: OpenGl_Structure (theManager)
-{
- Handle(OpenGl_StructureShadow) aShadow = Handle(OpenGl_StructureShadow)::DownCast (theStructure);
- myParent = aShadow.IsNull() ? theStructure : aShadow->myParent;
-
-
- Composition = myParent->Composition;
- ContainsFacet = myParent->ContainsFacet;
- IsInfinite = myParent->IsInfinite;
- for (Standard_Integer i = 0; i <= 3; ++i)
- {
- for (Standard_Integer j = 0; j <= 3; ++j)
- {
- Graphic3d_CStructure::Transformation[i][j] = myParent->Graphic3d_CStructure::Transformation[i][j];
- }
- }
-
- TransformPersistence.IsSet = myParent->TransformPersistence.IsSet;
- TransformPersistence.Flag = myParent->TransformPersistence.Flag;
- TransformPersistence.Point = myParent->TransformPersistence.Point;
-}
-
//=======================================================================
//function : ShadowLink
//purpose :