0027317: Some visualisation tests failed because of exceptions generated by FP signals.
[occt.git] / src / OpenGl / OpenGl_Structure.cxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
4269bd1b 16#include <OpenGl_CappingAlgo.hxx>
17#include <OpenGl_Context.hxx>
30f0ad28 18#include <OpenGl_GlCore11.hxx>
63bcc448 19#include <OpenGl_GraphicDriver.hxx>
30f0ad28 20#include <OpenGl_ShaderManager.hxx>
21#include <OpenGl_ShaderProgram.hxx>
2bd4bfac 22#include <OpenGl_StructureShadow.hxx>
30f0ad28 23#include <OpenGl_Vec.hxx>
24#include <OpenGl_View.hxx>
25#include <OpenGl_Workspace.hxx>
2166f0fa 26
494782f6 27#include <Graphic3d_SequenceOfHClipPlane.hxx>
b859a34d 28
63bcc448 29
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure)
31
27eed937 32//! Auxiliary class for bounding box presentation
33class OpenGl_BndBoxPrs : public OpenGl_Element
34{
35
36public:
37
38 //! Main constructor
b7cd4ba7 39 OpenGl_BndBoxPrs (const Graphic3d_BndBox4f& theBndBox)
40 {
41 const float Xm = theBndBox.CornerMin().x();
42 const float Ym = theBndBox.CornerMin().y();
43 const float Zm = theBndBox.CornerMin().z();
44 const float XM = theBndBox.CornerMax().x();
45 const float YM = theBndBox.CornerMax().y();
46 const float ZM = theBndBox.CornerMax().z();
47
27eed937 48 myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm);
49 myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM);
50 myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM);
51 myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm);
52 myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm);
53 myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm);
54 myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM);
55 myVerts[7] = OpenGl_Vec3 (XM, YM, ZM);
56 myVerts[8] = OpenGl_Vec3 (XM, YM, Zm);
57 myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm);
58 myVerts[10] = OpenGl_Vec3 (XM, YM, Zm);
59 myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm);
60 myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM);
61 myVerts[13] = OpenGl_Vec3 (XM, YM, ZM);
62 myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM);
63 myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM);
64 }
65
66 //! Render presentation
67 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
68 {
ca3c13d1 69 #if !defined(GL_ES_VERSION_2_0)
27eed937 70 // Apply line aspect
71 const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
72 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
73
74 glDisable (GL_LIGHTING);
27eed937 75
76 // Use highlight colors
ca3c13d1 77 theWorkspace->GetGlContext()->core11->glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb);
27eed937 78
79 glEnableClientState (GL_VERTEX_ARRAY);
80 glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
81 glDrawArrays (GL_LINE_STRIP, 0, 16);
82 glDisableClientState (GL_VERTEX_ARRAY);
83
84 // restore aspects
85 if (!aPrevTexture.IsNull())
86 {
87 theWorkspace->EnableTexture (aPrevTexture);
88 }
20aeeb7b 89 #else
90 (void )theWorkspace;
ca3c13d1 91 #endif
27eed937 92 }
93
94 //! Release graphical resources
10b9c7df 95 virtual void Release (OpenGl_Context*)
27eed937 96 {
97 //
98 }
99
100protected:
101
102 //! Protected destructor
103 virtual ~OpenGl_BndBoxPrs() {}
104
105private:
106
107 OpenGl_Vec3 myVerts[16]; //!< vertices array
108
109public:
110
111 DEFINE_STANDARD_ALLOC
112
113};
2166f0fa
SK
114
115/*----------------------------------------------------------------------*/
116
4269bd1b 117// =======================================================================
118// function : OpenGl_Structure
119// purpose :
120// =======================================================================
63bcc448 121OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
122: Graphic3d_CStructure (theManager),
d4aaad5b 123 myAspectLine (NULL),
124 myAspectFace (NULL),
125 myAspectMarker (NULL),
126 myAspectText (NULL),
127 myHighlightColor (NULL),
128 myInstancedStructure (NULL),
129 myIsRaytracable (Standard_False),
130 myModificationState (0),
131 myIsCulled (Standard_True),
132 myIsMirrored (Standard_False)
2166f0fa 133{
a1954302 134 //
2166f0fa
SK
135}
136
4269bd1b 137// =======================================================================
138// function : ~OpenGl_Structure
139// purpose :
140// =======================================================================
5e27df78 141OpenGl_Structure::~OpenGl_Structure()
2166f0fa 142{
5e27df78 143 Release (Handle(OpenGl_Context)());
2166f0fa
SK
144}
145
4269bd1b 146// =======================================================================
63bcc448 147// function : UpdateAspects
4269bd1b 148// purpose :
149// =======================================================================
63bcc448 150void OpenGl_Structure::UpdateAspects()
2166f0fa 151{
63bcc448 152 if (ContextLine.IsDef)
153 SetAspectLine (ContextLine);
154
155 if (ContextFillArea.IsDef)
156 SetAspectFace (ContextFillArea);
157
158 if (ContextMarker.IsDef)
159 SetAspectMarker (ContextMarker);
160
161 if (ContextText.IsDef)
162 SetAspectText (ContextText);
163}
164
165// =======================================================================
166// function : UpdateTransformation
167// purpose :
168// =======================================================================
169void OpenGl_Structure::UpdateTransformation()
170{
6bd94e0d 171 const OpenGl_Mat4& aMat = Graphic3d_CStructure::Transformation;
7d9e854b 172 Standard_ShortReal aDet =
6bd94e0d 173 aMat.GetValue(0, 0) * (aMat.GetValue(1, 1) * aMat.GetValue(2, 2) - aMat.GetValue(2, 1) * aMat.GetValue(1, 2)) -
174 aMat.GetValue(0, 1) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 2) - aMat.GetValue(2, 0) * aMat.GetValue(1, 2)) +
175 aMat.GetValue(0, 2) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 1) - aMat.GetValue(2, 0) * aMat.GetValue(1, 1));
7d9e854b 176
177 // Determinant of transform matrix less then 0 means that mirror transform applied.
178 myIsMirrored = aDet < 0.0f;
179
d4aaad5b 180 if (IsRaytracable())
e276548b 181 {
d4aaad5b 182 ++myModificationState;
e276548b 183 }
2166f0fa
SK
184}
185
4269bd1b 186// =======================================================================
187// function : SetAspectLine
188// purpose :
189// =======================================================================
fd4a6963 190void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect)
2166f0fa
SK
191{
192 if (!myAspectLine)
fd4a6963 193 {
5e27df78 194 myAspectLine = new OpenGl_AspectLine();
fd4a6963 195 }
196 myAspectLine->SetAspect (theAspect);
2166f0fa
SK
197}
198
4269bd1b 199// =======================================================================
200// function : SetAspectFace
201// purpose :
202// =======================================================================
fd4a6963 203void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect)
2166f0fa
SK
204{
205 if (!myAspectFace)
bf75be98 206 {
5e27df78 207 myAspectFace = new OpenGl_AspectFace();
bf75be98 208 }
fd4a6963 209 myAspectFace->SetAspect (theAspect);
e276548b 210
d4aaad5b 211 if (IsRaytracable())
e276548b 212 {
d4aaad5b 213 ++myModificationState;
e276548b 214 }
2166f0fa
SK
215}
216
4269bd1b 217// =======================================================================
218// function : SetAspectMarker
219// purpose :
220// =======================================================================
fd4a6963 221void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
2166f0fa
SK
222{
223 if (!myAspectMarker)
a577aaab 224 {
5e27df78 225 myAspectMarker = new OpenGl_AspectMarker();
a577aaab 226 }
fd4a6963 227 myAspectMarker->SetAspect (theAspect);
2166f0fa
SK
228}
229
4269bd1b 230// =======================================================================
231// function : SetAspectText
232// purpose :
233// =======================================================================
fd4a6963 234void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
2166f0fa
SK
235{
236 if (!myAspectText)
fd4a6963 237 {
5e27df78 238 myAspectText = new OpenGl_AspectText();
fd4a6963 239 }
240 myAspectText->SetAspect (theAspect);
2166f0fa
SK
241}
242
4269bd1b 243// =======================================================================
b64d84be 244// function : clearHighlightBox
4269bd1b 245// purpose :
246// =======================================================================
b64d84be 247void OpenGl_Structure::clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 248{
b64d84be 249 if (!myHighlightBox.IsNull())
5e27df78 250 {
251 myHighlightBox->Release (theGlCtx);
b64d84be 252 myHighlightBox.Nullify();
2166f0fa
SK
253 }
254}
255
63bcc448 256// =======================================================================
257// function : HighlightWithColor
258// purpose :
259// =======================================================================
260void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
261 const Standard_Boolean theToCreate)
262{
7d9e854b 263 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
63bcc448 264 if (theToCreate)
7d9e854b 265 setHighlightColor (aContext, theColor);
63bcc448 266 else
7d9e854b 267 clearHighlightColor (aContext);
63bcc448 268}
269
270// =======================================================================
271// function : HighlightWithBndBox
272// purpose :
273// =======================================================================
b64d84be 274void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
275 const Standard_Boolean theToCreate)
63bcc448 276{
7d9e854b 277 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
b64d84be 278 if (!theToCreate)
279 {
7d9e854b 280 clearHighlightBox (aContext);
b64d84be 281 return;
282 }
283
284 if (!myHighlightBox.IsNull())
285 {
7d9e854b 286 myHighlightBox->Release (aContext);
b64d84be 287 }
63bcc448 288 else
b64d84be 289 {
290 myHighlightBox = new OpenGl_Group (theStruct);
291 }
292
293 CALL_DEF_CONTEXTLINE& aContextLine = myHighlightBox->ChangeContextLine();
294 aContextLine.IsDef = 1;
b7cd4ba7 295 aContextLine.Color = HighlightColor;
b64d84be 296 aContextLine.LineType = Aspect_TOL_SOLID;
297 aContextLine.Width = 1.0f;
298 myHighlightBox->UpdateAspectLine (Standard_True);
299
b7cd4ba7 300 OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox);
b64d84be 301 myHighlightBox->AddElement (aBndBoxPrs);
63bcc448 302}
303
4269bd1b 304// =======================================================================
b64d84be 305// function : setHighlightColor
4269bd1b 306// purpose :
307// =======================================================================
b64d84be 308void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 309 const Graphic3d_Vec3& theColor)
2166f0fa 310{
b64d84be 311 clearHighlightBox (theGlCtx);
5e27df78 312 if (myHighlightColor == NULL)
313 {
314 myHighlightColor = new TEL_COLOUR();
315 }
2166f0fa 316
63bcc448 317 myHighlightColor->rgb[0] = theColor.r();
318 myHighlightColor->rgb[1] = theColor.g();
319 myHighlightColor->rgb[2] = theColor.b();
2166f0fa
SK
320 myHighlightColor->rgb[3] = 1.F;
321}
322
4269bd1b 323// =======================================================================
b64d84be 324// function : clearHighlightColor
4269bd1b 325// purpose :
326// =======================================================================
b64d84be 327void OpenGl_Structure::clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 328{
b64d84be 329 clearHighlightBox(theGlCtx);
5e27df78 330 delete myHighlightColor;
331 myHighlightColor = NULL;
2166f0fa
SK
332}
333
e276548b 334// =======================================================================
a1954302 335// function : OnVisibilityChanged
e276548b 336// purpose :
337// =======================================================================
a1954302 338void OpenGl_Structure::OnVisibilityChanged()
e276548b 339{
d4aaad5b 340 if (IsRaytracable())
e276548b 341 {
d4aaad5b 342 ++myModificationState;
e276548b 343 }
e276548b 344}
345
e276548b 346// =======================================================================
d4aaad5b 347// function : IsRaytracable
e276548b 348// purpose :
349// =======================================================================
d4aaad5b 350Standard_Boolean OpenGl_Structure::IsRaytracable() const
e276548b 351{
d4aaad5b 352 if (!myGroups.IsEmpty())
e276548b 353 {
d4aaad5b 354 return myIsRaytracable; // geometry structure
e276548b 355 }
d4aaad5b 356 else if (myInstancedStructure != NULL)
e276548b 357 {
d4aaad5b 358 return myInstancedStructure->IsRaytracable(); // instance structure
e276548b 359 }
d5af8626 360
d4aaad5b 361 return Standard_False; // has no any groups or structures
d5af8626 362}
363
e276548b 364// =======================================================================
d4aaad5b 365// function : UpdateRaytracableState
e276548b 366// purpose :
367// =======================================================================
d4aaad5b 368void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
e276548b 369{
d4aaad5b 370 myIsRaytracable = !toCheck || OpenGl_Raytrace::IsRaytracedStructure (this);
e276548b 371
d4aaad5b 372 if (IsRaytracable())
e276548b 373 {
d4aaad5b 374 ++myModificationState;
e276548b 375 }
376}
377
4269bd1b 378// =======================================================================
379// function : Connect
380// purpose :
381// =======================================================================
63bcc448 382void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
2166f0fa 383{
d4aaad5b 384 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
385
386 Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
387 "Error! Instanced structure is already defined");
388
389 myInstancedStructure = aStruct;
e276548b 390
63bcc448 391 if (aStruct->IsRaytracable())
e276548b 392 {
d4aaad5b 393 UpdateStateIfRaytracable (Standard_False);
e276548b 394 }
2166f0fa
SK
395}
396
4269bd1b 397// =======================================================================
398// function : Disconnect
399// purpose :
400// =======================================================================
63bcc448 401void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
2166f0fa 402{
d4aaad5b 403 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
e276548b 404
d4aaad5b 405 if (myInstancedStructure == aStruct)
406 {
407 myInstancedStructure = NULL;
e276548b 408
d4aaad5b 409 if (aStruct->IsRaytracable())
410 {
411 UpdateStateIfRaytracable();
2166f0fa 412 }
2166f0fa
SK
413 }
414}
415
4269bd1b 416// =======================================================================
b64d84be 417// function : NewGroup
4269bd1b 418// purpose :
419// =======================================================================
b64d84be 420Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
2166f0fa 421{
b64d84be 422 Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
423 myGroups.Append (aGroup);
424 return aGroup;
2166f0fa
SK
425}
426
4269bd1b 427// =======================================================================
428// function : RemoveGroup
429// purpose :
430// =======================================================================
b64d84be 431void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
2166f0fa 432{
b64d84be 433 if (theGroup.IsNull())
434 {
435 return;
436 }
437
438 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa
SK
439 {
440 // Check for the given group
b64d84be 441 if (aGroupIter.Value() == theGroup)
2166f0fa 442 {
d4aaad5b 443 const Standard_Boolean wasRaytracable =
444 static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
445
b64d84be 446 theGroup->Clear (Standard_False);
e276548b 447
d4aaad5b 448 if (wasRaytracable)
e276548b 449 {
d4aaad5b 450 UpdateStateIfRaytracable();
e276548b 451 }
e276548b 452
b64d84be 453 myGroups.Remove (aGroupIter);
2166f0fa
SK
454 return;
455 }
2166f0fa
SK
456 }
457}
458
63bcc448 459// =======================================================================
460// function : Clear
461// purpose :
462// =======================================================================
463void OpenGl_Structure::Clear()
464{
465 Clear (GlDriver()->GetSharedContext());
466}
467
4269bd1b 468// =======================================================================
469// function : Clear
470// purpose :
471// =======================================================================
5e27df78 472void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 473{
e276548b 474 Standard_Boolean aRaytracableGroupDeleted (Standard_False);
e276548b 475
5e27df78 476 // Release groups
b64d84be 477 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa 478 {
b64d84be 479 aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
5322131b 480
2166f0fa 481 // Delete objects
b64d84be 482 aGroupIter.ChangeValue()->Release (theGlCtx);
2166f0fa
SK
483 }
484 myGroups.Clear();
e276548b 485
e276548b 486 if (aRaytracableGroupDeleted)
487 {
d4aaad5b 488 myIsRaytracable = Standard_False;
e276548b 489 }
b7cd4ba7 490
491 Is2dText = Standard_False;
492 IsForHighlight = Standard_False;
2166f0fa
SK
493}
494
0717ddc1 495// =======================================================================
cc6852f3 496// function : renderGeometry
0717ddc1 497// purpose :
498// =======================================================================
cc6852f3 499void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
500 bool& theHasClosed) const
0717ddc1 501{
cc6852f3 502 if (myInstancedStructure != NULL)
0717ddc1 503 {
cc6852f3 504 myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
505 }
506
507 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
508 {
509 theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
7d9e854b 510 aGroupIter.Value()->Render (theWorkspace);
0717ddc1 511 }
512}
513
cc6852f3 514// =======================================================================
515// function : renderClosedGeometry
516// purpose :
517// =======================================================================
518void OpenGl_Structure::renderClosedGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const
519{
520 if (myInstancedStructure != NULL)
521 {
522 myInstancedStructure->renderClosedGeometry (theWorkspace);
523 }
524
525 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
526 {
527 if (aGroupIter.Value()->IsClosed())
528 {
529 aGroupIter.Value()->Render (theWorkspace);
530 }
531 }
532}
533
4269bd1b 534// =======================================================================
535// function : Render
536// purpose :
537// =======================================================================
7d9e854b 538void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
2166f0fa
SK
539{
540 // Process the structure only if visible
a1954302 541 if (!visible)
7d9e854b 542 {
2166f0fa 543 return;
7d9e854b 544 }
2166f0fa 545
c827ea3a 546 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
b7cd4ba7 547
2166f0fa 548 // Render named status
7d9e854b 549 const Standard_Integer aNamedStatus = theWorkspace->NamedStatus;
a1954302 550 if (highlight)
551 {
552 theWorkspace->NamedStatus |= OPENGL_NS_HIGHLIGHT;
553 }
2166f0fa 554
2166f0fa 555 // Apply local transformation
6bd94e0d 556 aCtx->ModelWorldState.Push();
557 aCtx->ModelWorldState.SetCurrent (Transformation);
558
559 // detect scale transform
560 const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
561 const Standard_ShortReal aScaleX = Transformation.GetRow (0).xyz().SquareModulus();
562 if (Abs (aScaleX - 1.f) > Precision::Confusion())
563 {
564 aCtx->SetGlNormalizeEnabled (Standard_True);
2166f0fa 565 }
6bd94e0d 566
825aa485 567 if (TransformPersistence.Flags)
568 {
569 OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
570 OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
571 TransformPersistence.Apply (aProjection, aWorldView, theWorkspace->Width(), theWorkspace->Height());
2166f0fa 572
825aa485 573 aCtx->ProjectionState.Push();
574 aCtx->WorldViewState.Push();
575 aCtx->ProjectionState.SetCurrent (aProjection);
576 aCtx->WorldViewState.SetCurrent (aWorldView);
577 aCtx->ApplyProjectionMatrix();
578 }
2166f0fa 579
d437b80d 580 // Take into account transform persistence
581 aCtx->ApplyModelViewMatrix();
c827ea3a 582
2166f0fa 583 // Apply aspects
7d9e854b 584 const OpenGl_AspectLine *anAspectLine = theWorkspace->AspectLine (Standard_False);
585 const OpenGl_AspectFace *anAspectFace = theWorkspace->AspectFace (Standard_False);
586 const OpenGl_AspectMarker *anAspectMarker = theWorkspace->AspectMarker (Standard_False);
587 const OpenGl_AspectText *anAspectText = theWorkspace->AspectText (Standard_False);
2166f0fa 588 if (myAspectLine)
7d9e854b 589 {
590 theWorkspace->SetAspectLine (myAspectLine);
591 }
2166f0fa 592 if (myAspectFace)
7d9e854b 593 {
594 theWorkspace->SetAspectFace (myAspectFace);
595 }
2166f0fa 596 if (myAspectMarker)
7d9e854b 597 {
598 theWorkspace->SetAspectMarker (myAspectMarker);
599 }
2166f0fa 600 if (myAspectText)
7d9e854b 601 {
602 theWorkspace->SetAspectText (myAspectText);
603 }
604
605 // Apply correction for mirror transform
606 if (myIsMirrored)
607 {
c827ea3a 608 aCtx->core11fwd->glFrontFace (GL_CW);
7d9e854b 609 }
2166f0fa 610
2166f0fa 611 // Apply highlight color
7d9e854b 612 const TEL_COLOUR *aHighlightColor = theWorkspace->HighlightColor;
2166f0fa 613 if (myHighlightColor)
7d9e854b 614 theWorkspace->HighlightColor = myHighlightColor;
2166f0fa 615
4269bd1b 616 // Set up plane equations for non-structure transformed global model-view matrix
b859a34d 617 // List of planes to be applied to context state
494782f6 618 NCollection_Handle<Graphic3d_SequenceOfHClipPlane> aUserPlanes;
b859a34d 619
620 // Collect clipping planes of structure scope
621 if (!myClipPlanes.IsEmpty())
4269bd1b 622 {
7d9e854b 623 Graphic3d_SequenceOfHClipPlane::Iterator aClippingIter (myClipPlanes);
624 for (; aClippingIter.More(); aClippingIter.Next())
b859a34d 625 {
7d9e854b 626 const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIter.Value();
b859a34d 627 if (!aClipPlane->IsOn())
628 {
629 continue;
630 }
631
632 if (aUserPlanes.IsNull())
633 {
51b10cd4 634 aUserPlanes = new Graphic3d_SequenceOfHClipPlane();
b859a34d 635 }
636
51b10cd4 637 aUserPlanes->Append (aClipPlane);
b859a34d 638 }
4269bd1b 639 }
640
b859a34d 641 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 642 {
b859a34d 643 // add planes at loaded view matrix state
79f4f036 644 aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
30f0ad28 645
646 // Set OCCT state uniform variables
c827ea3a 647 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 648 {
c827ea3a 649 aCtx->ShaderManager()->UpdateClippingState();
30f0ad28 650 }
4269bd1b 651 }
652
2166f0fa 653 // Render groups
cc6852f3 654 bool hasClosedPrims = false;
655 renderGeometry (theWorkspace, hasClosedPrims);
2166f0fa 656
7d9e854b 657 // Reset correction for mirror transform
658 if (myIsMirrored)
c827ea3a 659 {
660 aCtx->core11fwd->glFrontFace (GL_CCW);
661 }
7d9e854b 662
b859a34d 663 // Render capping for structure groups
cc6852f3 664 if (hasClosedPrims
665 && !aCtx->Clipping().Planes().IsEmpty())
b859a34d 666 {
cc6852f3 667 OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
b859a34d 668 }
4269bd1b 669
b859a34d 670 // Revert structure clippings
671 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 672 {
79f4f036 673 aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
30f0ad28 674
675 // Set OCCT state uniform variables
c827ea3a 676 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 677 {
c827ea3a 678 aCtx->ShaderManager()->RevertClippingState();
30f0ad28 679 }
4269bd1b 680 }
681
825aa485 682 // Restore local transformation
6bd94e0d 683 aCtx->ModelWorldState.Pop();
684 aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
825aa485 685 if (TransformPersistence.Flags)
686 {
687 aCtx->ProjectionState.Pop();
688 aCtx->WorldViewState.Pop();
689 aCtx->ApplyProjectionMatrix();
690 }
c827ea3a 691
2166f0fa 692 // Restore highlight color
7d9e854b 693 theWorkspace->HighlightColor = aHighlightColor;
2166f0fa
SK
694
695 // Restore aspects
7d9e854b 696 theWorkspace->SetAspectLine (anAspectLine);
697 theWorkspace->SetAspectFace (anAspectFace);
698 theWorkspace->SetAspectMarker (anAspectMarker);
699 theWorkspace->SetAspectText (anAspectText);
2166f0fa 700
b7cd4ba7 701 // Apply highlight box
702 if (!myHighlightBox.IsNull())
703 {
7d9e854b 704 myHighlightBox->Render (theWorkspace);
b7cd4ba7 705 }
706
2166f0fa 707 // Restore named status
7d9e854b 708 theWorkspace->NamedStatus = aNamedStatus;
2166f0fa
SK
709}
710
5e27df78 711// =======================================================================
712// function : Release
713// purpose :
714// =======================================================================
715void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
716{
717 // Release groups
718 Clear (theGlCtx);
10b9c7df 719 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine);
720 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace);
721 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectMarker);
722 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectText);
b64d84be 723 clearHighlightColor (theGlCtx);
5e27df78 724}
725
dd8a4ce9 726// =======================================================================
727// function : ReleaseGlResources
728// purpose :
729// =======================================================================
730void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
731{
b64d84be 732 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
dd8a4ce9 733 {
b64d84be 734 aGroupIter.ChangeValue()->Release (theGlCtx);
dd8a4ce9 735 }
736 if (myAspectLine != NULL)
737 {
10b9c7df 738 myAspectLine->Release (theGlCtx.operator->());
dd8a4ce9 739 }
740 if (myAspectFace != NULL)
741 {
10b9c7df 742 myAspectFace->Release (theGlCtx.operator->());
dd8a4ce9 743 }
744 if (myAspectMarker != NULL)
745 {
10b9c7df 746 myAspectMarker->Release (theGlCtx.operator->());
dd8a4ce9 747 }
748 if (myAspectText != NULL)
749 {
10b9c7df 750 myAspectText->Release (theGlCtx.operator->());
dd8a4ce9 751 }
b64d84be 752 if (!myHighlightBox.IsNull())
dd8a4ce9 753 {
10b9c7df 754 myHighlightBox->Release (theGlCtx.operator->());
dd8a4ce9 755 }
756}
757
679ecdee 758//=======================================================================
759//function : ShadowLink
760//purpose :
761//=======================================================================
762Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
763{
764 return new OpenGl_StructureShadow (theManager, this);
765}