-// File: OpenGl_Structure.cxx
-// Created: 1 August 2011
-// Author: Sergey ZERCHANINOV
-// Copyright: OPEN CASCADE 2011
-
+// Created on: 2011-08-01
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2012 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.
+//
+// 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.
+//
+// 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
+
+
+#include <OpenGl_CappingAlgo.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_GlCore11.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_Structure.hxx>
-
-#include <OpenGl_Polyline.hxx>
-#include <OpenGl_Workspace.hxx>
+#include <OpenGl_telem_util.hxx>
+#include <OpenGl_Vec.hxx>
#include <OpenGl_View.hxx>
+#include <OpenGl_Workspace.hxx>
-#include <OpenGl_tgl_all.hxx>
-#include <OpenGl_telem_util.hxx>
+#include <Graphic3d_SetOfHClipPlane_Handle.hxx>
+
+//! 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
+};
/*----------------------------------------------------------------------*/
+// =======================================================================
+// function : call_util_transpose_mat
+// purpose :
+// =======================================================================
static void call_util_transpose_mat (float tmat[16], float mat[4][4])
{
int i, j;
tmat[j*4+i] = mat[i][j];
}
-/*----------------------------------------------------------------------*/
-
+// =======================================================================
+// function : OpenGl_Structure
+// purpose :
+// =======================================================================
OpenGl_Structure::OpenGl_Structure ()
: myTransformation(NULL),
myTransPers(NULL),
- myDegenerateModel(NULL),
myAspectLine(NULL),
myAspectFace(NULL),
myAspectMarker(NULL),
myNamedStatus(0),
myZLayer(0)
{
+#if HAVE_OPENCL
+ myIsRaytracable = Standard_False;
+ myModificationState = 0;
+#endif
}
-/*----------------------------------------------------------------------*/
-
-OpenGl_Structure::~OpenGl_Structure ()
+// =======================================================================
+// function : ~OpenGl_Structure
+// purpose :
+// =======================================================================
+OpenGl_Structure::~OpenGl_Structure()
{
- if (myTransformation)
- {
- delete myTransformation;
- myTransformation = NULL;
- }
- if (myTransPers)
- {
- delete myTransPers;
- myTransPers = NULL;
- }
- if (myDegenerateModel)
- {
- delete myDegenerateModel;
- myDegenerateModel = NULL;
- }
- if (myAspectLine)
- {
- delete myAspectLine;
- myAspectLine = NULL;
- }
- if (myAspectFace)
- {
- delete myAspectFace;
- myAspectFace = NULL;
- }
- if (myAspectMarker)
- {
- delete myAspectMarker;
- myAspectMarker = NULL;
- }
- if (myAspectText)
- {
- delete myAspectText;
- myAspectText = NULL;
- }
- ClearHighlightColor();
- // Delete groups
- Clear();
+ Release (Handle(OpenGl_Context)());
+ delete myTransformation; myTransformation = NULL;
+ delete myTransPers; myTransPers = NULL;
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetTransformation(const float *AMatrix)
+// =======================================================================
+// function : SetTransformation
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetTransformation (const float *theMatrix)
{
if (!myTransformation)
- myTransformation = new OpenGl_Matrix;
+ {
+ myTransformation = new OpenGl_Matrix();
+ }
- matcpy( myTransformation->mat, AMatrix );
-}
+ 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->pointZ = ATransPers.Point.z;
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetDegenerateModel (const Standard_Integer AMode, const float ASkipRatio)
-{
- if (!myDegenerateModel)
- myDegenerateModel = new DEGENERATION;
-
- myDegenerateModel->mode = AMode;
- myDegenerateModel->skipRatio = ASkipRatio;
-}
-
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &AContext)
+// =======================================================================
+// function : SetAspectLine
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect)
{
if (!myAspectLine)
- myAspectLine = new OpenGl_AspectLine;
- myAspectLine->SetContext( AContext );
+ {
+ myAspectLine = new OpenGl_AspectLine();
+ }
+ myAspectLine->SetAspect (theAspect);
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA &AContext)
+// =======================================================================
+// function : SetAspectFace
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect)
{
if (!myAspectFace)
- myAspectFace = new OpenGl_AspectFace;
- myAspectFace->SetContext( AContext );
-}
+ {
+ myAspectFace = new OpenGl_AspectFace();
+ }
+ myAspectFace->SetAspect (theAspect);
-/*----------------------------------------------------------------------*/
+#ifdef HAVE_OPENCL
+ if (myIsRaytracable)
+ {
+ UpdateStateWithAncestorStructures();
+ }
+#endif
+}
-void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER &AContext)
+// =======================================================================
+// function : SetAspectMarker
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
{
if (!myAspectMarker)
- myAspectMarker = new OpenGl_AspectMarker;
- myAspectMarker->SetContext( AContext );
+ {
+ myAspectMarker = new OpenGl_AspectMarker();
+ }
+ myAspectMarker->SetAspect (theAspect);
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &AContext)
+// =======================================================================
+// function : SetAspectText
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
{
if (!myAspectText)
- myAspectText = new OpenGl_AspectText;
- myAspectText->SetContext( AContext );
+ {
+ myAspectText = new OpenGl_AspectText();
+ }
+ myAspectText->SetAspect (theAspect);
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetHighlightBox (const CALL_DEF_BOUNDBOX &ABoundBox)
+// =======================================================================
+// function : SetHighlightBox
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
+ const CALL_DEF_BOUNDBOX& theBoundBox)
{
- if (!myHighlightBox)
- myHighlightBox = new OpenGl_Group;
+ if (myHighlightBox != NULL)
+ {
+ myHighlightBox->Release (theGlCtx);
+ }
else
- myHighlightBox->Clear();
-
- CALL_DEF_CONTEXTLINE context_line;
- context_line.Color = ABoundBox.Color;
- context_line.LineType = Aspect_TOL_SOLID;
- context_line.Width = 1.0f;
- myHighlightBox->SetAspectLine( context_line );
-
-#define CALL_MAX_BOUNDBOXSIZE 16
-
- Graphic3d_Array1OfVertex points(1,CALL_MAX_BOUNDBOXSIZE);
- const float Xm = ABoundBox.Pmin.x;
- const float Ym = ABoundBox.Pmin.y;
- const float Zm = ABoundBox.Pmin.z;
- const float XM = ABoundBox.Pmax.x;
- const float YM = ABoundBox.Pmax.y;
- const float ZM = ABoundBox.Pmax.z;
- points( 1).SetCoord(Xm,Ym,Zm);
- points( 2).SetCoord(Xm,Ym,ZM);
- points( 3).SetCoord(Xm,YM,ZM);
- points( 4).SetCoord(Xm,YM,Zm);
- points( 5).SetCoord(Xm,Ym,Zm);
- points( 6).SetCoord(XM,Ym,Zm);
- points( 7).SetCoord(XM,Ym,ZM);
- points( 8).SetCoord(XM,YM,ZM);
- points( 9).SetCoord(XM,YM,Zm);
- points(10).SetCoord(XM,Ym,Zm);
- points(11).SetCoord(XM,YM,Zm);
- points(12).SetCoord(Xm,YM,Zm);
- points(13).SetCoord(Xm,YM,ZM);
- points(14).SetCoord(XM,YM,ZM);
- points(15).SetCoord(XM,Ym,ZM);
- points(16).SetCoord(Xm,Ym,ZM);
-
- OpenGl_Polyline *apolyline = new OpenGl_Polyline(points);
- myHighlightBox->AddElement( TelPolyline, apolyline );
-}
+ {
+#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 (TelParray, aBndBoxPrs);
+}
-void OpenGl_Structure::ClearHighlightBox ()
+// =======================================================================
+// function : ClearHighlightBox
+// purpose :
+// =======================================================================
+void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
{
- if (myHighlightBox)
+ if (myHighlightBox != NULL)
{
- delete myHighlightBox;
- myHighlightBox = NULL;
+ OpenGl_Element::Destroy (theGlCtx, myHighlightBox);
}
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::SetHighlightColor (const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B)
+// =======================================================================
+// 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();
- if (!myHighlightColor)
- myHighlightColor = new TEL_COLOUR;
+ ClearHighlightBox (theGlCtx);
+ if (myHighlightColor == NULL)
+ {
+ myHighlightColor = new TEL_COLOUR();
+ }
myHighlightColor->rgb[0] = R;
myHighlightColor->rgb[1] = G;
myHighlightColor->rgb[3] = 1.F;
}
-/*----------------------------------------------------------------------*/
+// =======================================================================
+// function : ClearHighlightColor
+// purpose :
+// =======================================================================
+void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
+{
+ ClearHighlightBox(theGlCtx);
+ delete myHighlightColor;
+ myHighlightColor = NULL;
+}
-void OpenGl_Structure::ClearHighlightColor ()
+// =======================================================================
+// function : SetNamedStatus
+// purpose :
+// =======================================================================
+void OpenGl_Structure::SetNamedStatus (const Standard_Integer aStatus)
{
- ClearHighlightBox();
- if (myHighlightColor)
+ myNamedStatus = aStatus;
+
+#ifdef HAVE_OPENCL
+ if (myIsRaytracable)
{
- delete myHighlightColor;
- myHighlightColor = NULL;
+ UpdateStateWithAncestorStructures();
}
+#endif
}
-/*----------------------------------------------------------------------*/
+#ifdef HAVE_OPENCL
-void OpenGl_Structure::Connect (const OpenGl_Structure *AStructure)
+// =======================================================================
+// function : RegisterAncestorStructure
+// purpose :
+// =======================================================================
+void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const
{
- Disconnect (AStructure);
- myConnected.Append(AStructure);
+ 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;
+ }
+ }
+}
-void OpenGl_Structure::Disconnect (const OpenGl_Structure *AStructure)
+// =======================================================================
+// function : UpdateStateWithAncestorStructures
+// purpose :
+// =======================================================================
+void OpenGl_Structure::UpdateStateWithAncestorStructures() const
{
- OpenGl_ListOfStructure::Iterator its(myConnected);
+ 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 (!anIt.Value()->IsRaytracable())
+ {
+ anIt.Value()->SetRaytracableWithAncestorStructures();
+ }
+ }
+}
+
+#endif
+
+// =======================================================================
+// function : Connect
+// purpose :
+// =======================================================================
+void OpenGl_Structure::Connect (const OpenGl_Structure *theStructure)
+{
+ Disconnect (theStructure);
+ myConnected.Append (theStructure);
+
+#ifdef HAVE_OPENCL
+ if (theStructure->IsRaytracable())
+ {
+ UpdateStateWithAncestorStructures();
+ SetRaytracableWithAncestorStructures();
+ }
+
+ theStructure->RegisterAncestorStructure (this);
+#endif
+}
+
+// =======================================================================
+// function : Disconnect
+// purpose :
+// =======================================================================
+void OpenGl_Structure::Disconnect (const OpenGl_Structure *theStructure)
+{
+ OpenGl_ListOfStructure::Iterator its (myConnected);
while (its.More())
{
// Check for the given structure
- if (its.Value() == AStructure)
+ if (its.Value() == theStructure)
{
- myConnected.Remove(its);
+ myConnected.Remove (its);
+
+#ifdef HAVE_OPENCL
+ if (theStructure->IsRaytracable())
+ {
+ UpdateStateWithAncestorStructures();
+ UpdateRaytracableWithAncestorStructures();
+ }
+
+ theStructure->UnregisterAncestorStructure (this);
+#endif
+
return;
}
its.Next();
}
}
-/*----------------------------------------------------------------------*/
-
-OpenGl_Group * OpenGl_Structure::AddGroup ()
+// =======================================================================
+// function : AddGroup
+// purpose :
+// =======================================================================
+OpenGl_Group * OpenGl_Structure::AddGroup()
{
// Create new group
- OpenGl_Group *g = new OpenGl_Group;
+#ifndef HAVE_OPENCL
+ OpenGl_Group *g = new OpenGl_Group();
+#else
+ OpenGl_Group *g = new OpenGl_Group (this);
+#endif
+
myGroups.Append(g);
return g;
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::RemoveGroup (const OpenGl_Group *AGroup)
+// =======================================================================
+// function : RemoveGroup
+// purpose :
+// =======================================================================
+void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
+ const OpenGl_Group* theGroup)
{
- OpenGl_ListOfGroup::Iterator itg(myGroups);
- while (itg.More())
+ for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
{
// Check for the given group
- if (itg.Value() == AGroup)
+ if (anIter.Value() == theGroup)
{
+ myGroups.Remove (anIter);
+
+#ifdef HAVE_OPENCL
+ if (theGroup->IsRaytracable())
+ {
+ UpdateStateWithAncestorStructures();
+ UpdateRaytracableWithAncestorStructures();
+ }
+#endif
+
// Delete object
- delete AGroup;
- myGroups.Remove(itg);
+ OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup));
return;
}
- itg.Next();
}
}
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Structure::Clear ()
+// =======================================================================
+// function : Clear
+// purpose :
+// =======================================================================
+void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
{
- OpenGl_ListOfGroup::Iterator itg(myGroups);
- while (itg.More())
+#ifdef HAVE_OPENCL
+ Standard_Boolean aRaytracableGroupDeleted (Standard_False);
+#endif
+
+ // Release groups
+ for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
{
+#ifdef HAVE_OPENCL
+ aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable();
+#endif
+
// Delete objects
- delete itg.Value();
- itg.Next();
+ OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue()));
}
myGroups.Clear();
-}
-/*----------------------------------------------------------------------*/
+#ifdef HAVE_OPENCL
+ if (aRaytracableGroupDeleted)
+ {
+ UpdateStateWithAncestorStructures();
+ UpdateRaytracableWithAncestorStructures();
+ }
+#endif
+}
+// =======================================================================
+// function : Render
+// purpose :
+// =======================================================================
void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
{
// Process the structure only if visible
// 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();
+
// Apply local transformation
GLint matrix_mode = 0;
const OpenGl_Matrix *local_trsf = NULL;
{
if (isImmediate)
{
- float mat16[16];
- call_util_transpose_mat (mat16, myTransformation->mat);
+ 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);
+ }
+
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glScalef (1.F, 1.F, 1.F);
- glMultMatrixf (mat16);
+ glMultMatrixf (*aModelWorld);
}
else
{
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
- local_trsf = AWorkspace->SetStructureMatrix(myTransformation);
+ local_trsf = AWorkspace->SetStructureMatrix (myTransformation);
}
}
const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL;
if ( myTransPers && myTransPers->mode != 0 )
{
- trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence( myTransPers );
- }
-
- // Apply degeneration
- if (myDegenerateModel)
- {
- if ( AWorkspace->NamedStatus & OPENGL_NS_DEGENERATION )
- {
- AWorkspace->DegenerateModel = myDegenerateModel->mode;
- switch ( AWorkspace->DegenerateModel )
- {
- case 0: break;
-
- default:
- glLineWidth ( 1.0 );
- glDisable ( GL_LINE_STIPPLE );
-
- case 1:
- AWorkspace->SkipRatio = myDegenerateModel->skipRatio;
- }
- }
+ trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers);
}
// Apply aspects
its.Next();
}
+ // 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;
+
+ // Collect clipping planes of structure scope
+ if (!myClipPlanes.IsEmpty())
+ {
+ Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes);
+ for (; aClippingIt.More(); aClippingIt.Next())
+ {
+ const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
+ if (!aClipPlane->IsOn())
+ {
+ continue;
+ }
+
+ if (aUserPlanes.IsNull())
+ {
+ aUserPlanes = new Graphic3d_SetOfHClipPlane();
+ }
+
+ 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())
+ {
+ aContext->ShaderManager()->UpdateClippingState();
+ }
+ }
+
// Render groups
OpenGl_ListOfGroup::Iterator itg(myGroups);
while (itg.More())
itg.Next();
}
+ // Render capping for structure groups
+ if (!aContext->Clipping().Planes().IsEmpty())
+ {
+ OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups);
+ }
+
+ // Revert structure clippings
+ if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
+ {
+ aContext->ChangeClipping().Remove (*aUserPlanes);
+
+ // Set OCCT state uniform variables
+ if (!aContext->ShaderManager()->IsEmpty())
+ {
+ aContext->ShaderManager()->RevertClippingState();
+ }
+ }
+
// Restore highlight color
AWorkspace->HighlightColor = highlight_color;
// Restore transform persistence
if ( myTransPers && myTransPers->mode != 0 )
{
- AWorkspace->ActiveView()->BeginTransformPersistence( trans_pers );
+ AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers);
}
// Restore local transformation
{
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);
+ AWorkspace->SetStructureMatrix (local_trsf, true);
glMatrixMode (GL_MODELVIEW);
glPopMatrix();
AWorkspace->NamedStatus = named_status;
}
+// =======================================================================
+// function : Release
+// purpose :
+// =======================================================================
+void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
+{
+ // 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);
+}
+
+// =======================================================================
+// function : ReleaseGlResources
+// purpose :
+// =======================================================================
+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)
+ {
+ myAspectText->Release (theGlCtx);
+ }
+ if (myHighlightBox != NULL)
+ {
+ myHighlightBox->Release (theGlCtx);
+ }
+}
+
//=======================================================================
//function : SetZLayer
-//purpose :
+//purpose :
//=======================================================================
-
void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex)
{
myZLayer = theLayerIndex;
//=======================================================================
//function : GetZLayer
-//purpose :
+//purpose :
//=======================================================================
-
Standard_Integer OpenGl_Structure::GetZLayer () const
{
return myZLayer;