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