// Created on: 2011-08-01
// Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2012 OPEN CASCADE SAS
+// Copyright (c) 2011-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#ifdef HAVE_CONFIG_H
- #include <config.h>
-#endif
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <OpenGl_CappingAlgo.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_GlCore11.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_SetOfHClipPlane_Handle.hxx>
+#include <Graphic3d_SequenceOfHClipPlane.hxx>
+
+
+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;
+ OpenGl_BndBoxPrs (const Graphic3d_BndBox4f& theBndBox)
+ {
+ const float Xm = theBndBox.CornerMin().x();
+ const float Ym = theBndBox.CornerMin().y();
+ const float Zm = theBndBox.CornerMin().z();
+ const float XM = theBndBox.CornerMax().x();
+ const float YM = theBndBox.CornerMax().y();
+ const float ZM = theBndBox.CornerMax().z();
+
myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm);
myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM);
myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM);
//! 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_ADD | 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 ()
-: myTransformation(NULL),
- myTransPers(NULL),
- myAspectLine(NULL),
- myAspectFace(NULL),
- myAspectMarker(NULL),
- myAspectText(NULL),
- myHighlightBox(NULL),
- myHighlightColor(NULL),
- myNamedStatus(0),
- myZLayer(0)
+OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
+: Graphic3d_CStructure (theManager),
+ myHighlightColor (NULL),
+ myInstancedStructure (NULL),
+ myIsRaytracable (Standard_False),
+ myModificationState (0),
+ myIsCulled (Standard_True),
+ myIsMirrored (Standard_False)
{
-#if HAVE_OPENCL
- myIsRaytracable = Standard_False;
- myModificationState = 0;
-#endif
+ //
}
// =======================================================================
OpenGl_Structure::~OpenGl_Structure()
{
Release (Handle(OpenGl_Context)());
- delete myTransformation; myTransformation = NULL;
- delete myTransPers; myTransPers = NULL;
}
// =======================================================================
// function : SetTransformation
// purpose :
// =======================================================================
-void OpenGl_Structure::SetTransformation (const float *theMatrix)
+void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
{
- if (!myTransformation)
+ 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, theMatrix);
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
- {
- UpdateStateWithAncestorStructures();
- }
-#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)
+ if (IsRaytracable())
{
- myAspectLine = new OpenGl_AspectLine();
+ ++myModificationState;
}
- myAspectLine->SetAspect (theAspect);
}
// =======================================================================
-// function : SetAspectFace
+// function : clearHighlightBox
// purpose :
// =======================================================================
-void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect)
+void OpenGl_Structure::clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
{
- if (!myAspectFace)
- {
- myAspectFace = new OpenGl_AspectFace();
- }
- myAspectFace->SetAspect (theAspect);
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
+ if (!myHighlightBox.IsNull())
{
- UpdateStateWithAncestorStructures();
+ myHighlightBox->Release (theGlCtx);
+ myHighlightBox.Nullify();
}
-#endif
}
// =======================================================================
-// function : SetAspectMarker
+// function : HighlightWithColor
// purpose :
// =======================================================================
-void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
+void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
+ const Standard_Boolean theToCreate)
{
- if (!myAspectMarker)
- {
- myAspectMarker = new OpenGl_AspectMarker();
- }
- myAspectMarker->SetAspect (theAspect);
+ const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
+ if (theToCreate)
+ setHighlightColor (aContext, theColor);
+ else
+ clearHighlightColor (aContext);
}
// =======================================================================
-// function : SetAspectText
+// function : HighlightWithBndBox
// purpose :
// =======================================================================
-void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
+void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
+ const Standard_Boolean theToCreate)
{
- if (!myAspectText)
+ const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
+ if (!theToCreate)
{
- myAspectText = new OpenGl_AspectText();
+ clearHighlightBox (aContext);
+ return;
}
- myAspectText->SetAspect (theAspect);
-}
-// =======================================================================
-// function : SetHighlightBox
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
- const CALL_DEF_BOUNDBOX& theBoundBox)
-{
- if (myHighlightBox != NULL)
+ if (!myHighlightBox.IsNull())
{
- myHighlightBox->Release (theGlCtx);
+ myHighlightBox->Release (aContext);
}
else
{
-#ifndef HAVE_OPENCL
- myHighlightBox = new OpenGl_Group();
-#else
- myHighlightBox = new OpenGl_Group (this);
-#endif
+ myHighlightBox = new OpenGl_Group (theStruct);
}
- CALL_DEF_CONTEXTLINE aContextLine;
- aContextLine.Color = theBoundBox.Color;
- aContextLine.LineType = Aspect_TOL_SOLID;
- aContextLine.Width = 1.0f;
- myHighlightBox->SetAspectLine (aContextLine);
+ myHighlightBox->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (HighlightColor, Aspect_TOL_SOLID, 1.0));
- OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox);
- myHighlightBox->AddElement (TelParray, aBndBoxPrs);
+ OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox);
+ myHighlightBox->AddElement (aBndBoxPrs);
}
// =======================================================================
-// function : ClearHighlightBox
+// function : setHighlightColor
// purpose :
// =======================================================================
-void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
+ const Graphic3d_Vec3& theColor)
{
- if (myHighlightBox != NULL)
+ clearHighlightBox (theGlCtx);
+ if (myHighlightColor == NULL)
{
- OpenGl_Element::Destroy (theGlCtx, myHighlightBox);
+ myHighlightColor = new OpenGl_Vec4 (theColor, 1.0f);
}
-}
-
-// =======================================================================
-// function : SetHighlightColor
-// purpose :
-// =======================================================================
-void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
- const Standard_ShortReal R,
- const Standard_ShortReal G,
- const Standard_ShortReal B)
-{
- ClearHighlightBox (theGlCtx);
- if (myHighlightColor == NULL)
+ else
{
- myHighlightColor = new TEL_COLOUR();
+ myHighlightColor->xyz() = theColor;
}
-
- myHighlightColor->rgb[0] = R;
- myHighlightColor->rgb[1] = G;
- myHighlightColor->rgb[2] = B;
- myHighlightColor->rgb[3] = 1.F;
}
// =======================================================================
-// function : ClearHighlightColor
+// function : clearHighlightColor
// purpose :
// =======================================================================
-void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_Structure::clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
{
- ClearHighlightBox(theGlCtx);
+ clearHighlightBox(theGlCtx);
delete myHighlightColor;
myHighlightColor = NULL;
}
// =======================================================================
-// function : SetNamedStatus
+// function : OnVisibilityChanged
// purpose :
// =======================================================================
-void OpenGl_Structure::SetNamedStatus (const Standard_Integer aStatus)
+void OpenGl_Structure::OnVisibilityChanged()
{
- myNamedStatus = aStatus;
-
-#ifdef HAVE_OPENCL
- if (myIsRaytracable)
+ if (IsRaytracable())
{
- UpdateStateWithAncestorStructures();
+ ++myModificationState;
}
-#endif
}
-#ifdef HAVE_OPENCL
-
// =======================================================================
-// function : RegisterAncestorStructure
+// function : IsRaytracable
// purpose :
// =======================================================================
-void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const
+Standard_Boolean OpenGl_Structure::IsRaytracable() const
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ if (!myGroups.IsEmpty()
+ && myIsRaytracable)
{
- if (anIt.Value() == theStructure)
- {
- return;
- }
+ return Standard_True;
}
- myAncestorStructures.Append (theStructure);
+ return myInstancedStructure != NULL
+ && myInstancedStructure->IsRaytracable();
}
// =======================================================================
-// function : UnregisterAncestorStructure
+// function : UpdateRaytracableState
// purpose :
// =======================================================================
-void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const
+void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ myIsRaytracable = !toCheck;
+ if (!myIsRaytracable)
{
- if (anIt.Value() == theStructure)
+ for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
{
- myAncestorStructures.Remove (anIt);
- return;
- }
+ if (anIter.Value()->IsRaytracable())
+ {
+ myIsRaytracable = Standard_True;
+ break;
+ }
+ }
}
-}
-// =======================================================================
-// function : UnregisterFromAncestorStructure
-// purpose :
-// =======================================================================
-void OpenGl_Structure::UnregisterFromAncestorStructure() const
-{
- for (OpenGl_ListOfStructure::Iterator anIta (myAncestorStructures); anIta.More(); anIta.Next())
+ if (IsRaytracable())
{
- 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;
- }
- }
+ ++myModificationState;
}
}
// =======================================================================
-// function : UpdateStateWithAncestorStructures
+// function : Connect
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateStateWithAncestorStructures() const
+void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
{
- myModificationState++;
+ OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
+
+ Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
+ "Error! Instanced structure is already defined");
+
+ myInstancedStructure = aStruct;
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ if (aStruct->IsRaytracable())
{
- anIt.Value()->UpdateStateWithAncestorStructures();
+ UpdateStateIfRaytracable (Standard_False);
}
}
// =======================================================================
-// function : UpdateRaytracableWithAncestorStructures
+// function : Disconnect
// purpose :
// =======================================================================
-void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const
+void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
{
- myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this);
+ OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
- if (!myIsRaytracable)
+ if (myInstancedStructure == aStruct)
{
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
+ myInstancedStructure = NULL;
+
+ if (aStruct->IsRaytracable())
{
- anIt.Value()->UpdateRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable();
}
}
}
// =======================================================================
-// function : SetRaytracableWithAncestorStructures
+// function : NewGroup
// purpose :
// =======================================================================
-void OpenGl_Structure::SetRaytracableWithAncestorStructures() const
+Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
{
- myIsRaytracable = Standard_True;
-
- for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
- {
- if (!anIt.Value()->IsRaytracable())
- {
- anIt.Value()->SetRaytracableWithAncestorStructures();
- }
- }
+ Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
+ myGroups.Append (aGroup);
+ return aGroup;
}
-#endif
-
// =======================================================================
-// function : Connect
+// function : RemoveGroup
// purpose :
// =======================================================================
-void OpenGl_Structure::Connect (const OpenGl_Structure *theStructure)
+void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
{
- Disconnect (theStructure);
- myConnected.Append (theStructure);
-
-#ifdef HAVE_OPENCL
- if (theStructure->IsRaytracable())
+ if (theGroup.IsNull())
{
- UpdateStateWithAncestorStructures();
- SetRaytracableWithAncestorStructures();
+ return;
}
- theStructure->RegisterAncestorStructure (this);
-#endif
-}
-
-// =======================================================================
-// function : Disconnect
-// purpose :
-// =======================================================================
-void OpenGl_Structure::Disconnect (const OpenGl_Structure *theStructure)
-{
- OpenGl_ListOfStructure::Iterator its (myConnected);
- while (its.More())
+ for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
- // Check for the given structure
- if (its.Value() == theStructure)
+ // Check for the given group
+ if (aGroupIter.Value() == theGroup)
{
- myConnected.Remove (its);
+ const Standard_Boolean wasRaytracable =
+ static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
+
+ theGroup->Clear (Standard_False);
-#ifdef HAVE_OPENCL
- if (theStructure->IsRaytracable())
+ if (wasRaytracable)
{
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
+ UpdateStateIfRaytracable();
}
- theStructure->UnregisterAncestorStructure (this);
-#endif
-
+ myGroups.Remove (aGroupIter);
return;
}
- its.Next();
}
}
// =======================================================================
-// function : AddGroup
+// function : Clear
// purpose :
// =======================================================================
-OpenGl_Group * OpenGl_Structure::AddGroup()
+void OpenGl_Structure::Clear()
{
- // 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;
+ Clear (GlDriver()->GetSharedContext());
}
// =======================================================================
-// function : RemoveGroup
+// function : Clear
// purpose :
// =======================================================================
-void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
- const OpenGl_Group* theGroup)
+void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
{
- for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
+ Standard_Boolean aRaytracableGroupDeleted (Standard_False);
+
+ // Release groups
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
- // Check for the given group
- if (anIter.Value() == theGroup)
- {
- myGroups.Remove (anIter);
+ aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
-#ifdef HAVE_OPENCL
- if (theGroup->IsRaytracable())
- {
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
- }
-#endif
+ // Delete objects
+ aGroupIter.ChangeValue()->Release (theGlCtx);
+ }
+ myGroups.Clear();
- // Delete object
- OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup));
- return;
- }
+ if (aRaytracableGroupDeleted)
+ {
+ myIsRaytracable = Standard_False;
}
+
+ Is2dText = Standard_False;
+ IsForHighlight = Standard_False;
}
// =======================================================================
-// function : Clear
+// function : renderGeometry
// purpose :
// =======================================================================
-void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
+void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
+ bool& theHasClosed) const
{
-#ifdef HAVE_OPENCL
- Standard_Boolean aRaytracableGroupDeleted (Standard_False);
-#endif
-
- // Release groups
- for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
+ if (myInstancedStructure != NULL)
{
-#ifdef HAVE_OPENCL
- aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable();
-#endif
-
- // Delete objects
- OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue()));
+ myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
}
- myGroups.Clear();
-#ifdef HAVE_OPENCL
- if (aRaytracableGroupDeleted)
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
- UpdateStateWithAncestorStructures();
- UpdateRaytracableWithAncestorStructures();
+ 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 = theWorkspace->GetGlContext();
- const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext();
+ // Render named status
+ if (highlight)
+ {
+ 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]);
- // 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);
+ aCtx->WorldViewState.Push();
+ aCtx->WorldViewState.SetCurrent (aWorldView);
- // Apply highlight box
- if (myHighlightBox)
- myHighlightBox->Render( AWorkspace );
+ #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 highlight color
- const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor;
- if (myHighlightColor)
- AWorkspace->HighlightColor = myHighlightColor;
+ // Take into account transform persistence
+ aCtx->ApplyModelViewMatrix();
+
+ // 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_SetOfHClipPlane) aUserPlanes;
+ // Apply highlight color
+ const OpenGl_Vec4* aHighlightColor = theWorkspace->HighlightColor;
+ if (myHighlightColor)
+ theWorkspace->HighlightColor = myHighlightColor;
// 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_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes);
- for (; aClippingIt.More(); aClippingIt.Next())
+ const Graphic3d_BndBox4f& aBBox = BoundingBox();
+ if ((!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d())
+ || (!myClipPlanes.IsNull() && myClipPlanes->ToOverrideGlobal()))
{
- const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.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_SetOfHClipPlane();
+ 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->Add (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)
{
- 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);
+ aCtx->WorldViewState.Pop();
+ }
- 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 } };
+ // Restore highlight color
+ theWorkspace->HighlightColor = aHighlightColor;
- aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState);
- }
- else
- {
- AWorkspace->SetStructureMatrix (local_trsf, true);
+ // Restore aspects
+ theWorkspace->SetAspectLine (aPrevAspectLine);
+ theWorkspace->SetAspectFace (aPrevAspectFace);
+ theWorkspace->SetAspectMarker (aPrevAspectMarker);
+ theWorkspace->SetAspectText (aPrevAspectText);
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- }
+ // Apply highlight box
+ if (!myHighlightBox.IsNull())
+ {
+ 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);
-
-#ifdef HAVE_OPENCL
- // Remove from connected list of ancestor
- UnregisterFromAncestorStructure();
-#endif
+ clearHighlightColor (theGlCtx);
}
// =======================================================================
// =======================================================================
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)
+ for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
{
- myAspectLine->Release (theGlCtx);
+ aGroupIter.ChangeValue()->Release (theGlCtx);
}
- if (myAspectFace != NULL)
+ if (!myHighlightBox.IsNull())
{
- myAspectFace->Release (theGlCtx);
+ myHighlightBox->Release (theGlCtx.operator->());
}
- if (myAspectMarker != NULL)
- {
- myAspectMarker->Release (theGlCtx);
- }
- if (myAspectText != NULL)
- {
- myAspectText->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);
}