}
// =======================================================================
-// function : UpdateTransformation
+// function : SetTransformation
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateTransformation()
+void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
{
- const OpenGl_Mat4& aMat = Graphic3d_CStructure::Transformation;
- Standard_ShortReal aDet =
- aMat.GetValue(0, 0) * (aMat.GetValue(1, 1) * aMat.GetValue(2, 2) - aMat.GetValue(2, 1) * aMat.GetValue(1, 2)) -
- aMat.GetValue(0, 1) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 2) - aMat.GetValue(2, 0) * aMat.GetValue(1, 2)) +
- aMat.GetValue(0, 2) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 1) - aMat.GetValue(2, 0) * aMat.GetValue(1, 1));
-
- // Determinant of transform matrix less then 0 means that mirror transform applied.
- myIsMirrored = aDet < 0.0f;
+ myTrsf = theTrsf;
+ myIsMirrored = Standard_False;
+ if (!myTrsf.IsNull())
+ {
+ // 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;
+ }
if (IsRaytracable())
{
// =======================================================================
Standard_Boolean OpenGl_Structure::IsRaytracable() const
{
- if (!myGroups.IsEmpty())
+ if (!myGroups.IsEmpty()
+ && myIsRaytracable)
{
- return myIsRaytracable; // geometry structure
- }
- else if (myInstancedStructure != NULL)
- {
- return myInstancedStructure->IsRaytracable(); // instance structure
+ return Standard_True;
}
- return Standard_False; // has no any groups or structures
+ return myInstancedStructure != NULL
+ && myInstancedStructure->IsRaytracable();
}
// =======================================================================
// =======================================================================
void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
{
- myIsRaytracable = !toCheck || OpenGl_Raytrace::IsRaytracedStructure (this);
+ myIsRaytracable = !toCheck;
+ if (!myIsRaytracable)
+ {
+ for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
+ {
+ if (anIter.Value()->IsRaytracable())
+ {
+ myIsRaytracable = Standard_True;
+ break;
+ }
+ }
+ }
if (IsRaytracable())
{
}
}
-// =======================================================================
-// function : renderClosedGeometry
-// purpose :
-// =======================================================================
-void OpenGl_Structure::renderClosedGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const
-{
- if (myInstancedStructure != NULL)
- {
- myInstancedStructure->renderClosedGeometry (theWorkspace);
- }
-
- for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
- {
- if (aGroupIter.Value()->IsClosed())
- {
- aGroupIter.Value()->Render (theWorkspace);
- }
- }
-}
-
// =======================================================================
// function : Render
// purpose :
// Apply local transformation
aCtx->ModelWorldState.Push();
- aCtx->ModelWorldState.SetCurrent (Transformation);
+ OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent();
+ if (!myTrsf.IsNull())
+ {
+ myTrsf->Trsf().GetMat4 (aModelWorld);
+ }
+ else
+ {
+ aModelWorld.InitIdentity();
+ }
const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
#if !defined(GL_ES_VERSION_2_0)
// detect scale transform
- if (aCtx->core11 != NULL)
+ if (aCtx->core11 != NULL
+ && !myTrsf.IsNull())
{
- const Standard_ShortReal aScaleX = Transformation.GetRow (0).xyz().SquareModulus();
- if (Abs (aScaleX - 1.f) > Precision::Confusion())
+ const Standard_Real aScale = myTrsf->ScaleFactor();
+ if (Abs (aScale - 1.0) > Precision::Confusion())
{
aCtx->SetGlNormalizeEnabled (Standard_True);
}
}
#endif
- if (TransformPersistence.Flags)
+ if (!myTrsfPers.IsNull())
{
- OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
- OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
- TransformPersistence.Apply (aProjection, aWorldView, theWorkspace->Width(), theWorkspace->Height());
+ OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
+ myTrsfPers->Apply (theWorkspace->View()->Camera(), aCtx->ProjectionState.Current(), aWorldView,
+ aCtx->Viewport()[2], aCtx->Viewport()[3]);
- aCtx->ProjectionState.Push();
aCtx->WorldViewState.Push();
- aCtx->ProjectionState.SetCurrent (aProjection);
aCtx->WorldViewState.SetCurrent (aWorldView);
- aCtx->ApplyProjectionMatrix();
#if !defined(GL_ES_VERSION_2_0)
if (!aCtx->IsGlNormalizeEnabled()
if (myHighlightColor)
theWorkspace->HighlightColor = myHighlightColor;
- // Set up plane equations for non-structure transformed global model-view matrix
- // List of planes to be applied to context state
- NCollection_Handle<Graphic3d_SequenceOfHClipPlane> aUserPlanes;
-
// 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 aClippingIter (myClipPlanes);
- for (; aClippingIter.More(); aClippingIter.Next())
+ const Graphic3d_BndBox4f& aBBox = BoundingBox();
+ if ((!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d())
+ || (!myClipPlanes.IsNull() && myClipPlanes->ToOverrideGlobal()))
{
- const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIter.Value();
- if (!aClipPlane->IsOn())
- {
- continue;
- }
+ aCtx->ChangeClipping().DisableGlobal (aCtx);
+ hasDisabled = aCtx->Clipping().HasDisabled();
+ }
- if (aUserPlanes.IsNull())
+ // 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
- aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
- // Set OCCT state uniform variables
- aCtx->ShaderManager()->UpdateClippingState();
+ if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
+ || hasDisabled)
+ {
+ // Set OCCT state uniform variables
+ aCtx->ShaderManager()->UpdateClippingState();
+ }
}
// Render groups
bool hasClosedPrims = false;
- renderGeometry (theWorkspace, hasClosedPrims);
+ if (!isClipped)
+ {
+ renderGeometry (theWorkspace, hasClosedPrims);
+ }
// Reset correction for mirror transform
if (myIsMirrored)
// Render capping for structure groups
if (hasClosedPrims
- && !aCtx->Clipping().Planes().IsEmpty())
+ && aCtx->Clipping().IsCappingOn())
{
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);
+ }
+ aCtx->ChangeClipping().SetLocalPlanes (aCtx, Handle(Graphic3d_SequenceOfHClipPlane)());
+ if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
+ || hasDisabled)
{
- aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
-
// Set OCCT state uniform variables
aCtx->ShaderManager()->RevertClippingState();
}
// Restore local transformation
aCtx->ModelWorldState.Pop();
aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
- if (TransformPersistence.Flags)
+ if (!myTrsfPers.IsNull())
{
- aCtx->ProjectionState.Pop();
aCtx->WorldViewState.Pop();
- aCtx->ApplyProjectionMatrix();
}
// Restore highlight color