0026885: Visualization - drop redundant aspects from structure level
[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// =======================================================================
4269bd1b 118// function : OpenGl_Structure
119// purpose :
120// =======================================================================
63bcc448 121OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
122: Graphic3d_CStructure (theManager),
d4aaad5b 123 myHighlightColor (NULL),
124 myInstancedStructure (NULL),
125 myIsRaytracable (Standard_False),
126 myModificationState (0),
127 myIsCulled (Standard_True),
128 myIsMirrored (Standard_False)
2166f0fa 129{
a1954302 130 //
2166f0fa
SK
131}
132
4269bd1b 133// =======================================================================
134// function : ~OpenGl_Structure
135// purpose :
136// =======================================================================
5e27df78 137OpenGl_Structure::~OpenGl_Structure()
2166f0fa 138{
5e27df78 139 Release (Handle(OpenGl_Context)());
2166f0fa
SK
140}
141
4269bd1b 142// =======================================================================
63bcc448 143// function : UpdateTransformation
144// purpose :
145// =======================================================================
146void OpenGl_Structure::UpdateTransformation()
147{
6bd94e0d 148 const OpenGl_Mat4& aMat = Graphic3d_CStructure::Transformation;
7d9e854b 149 Standard_ShortReal aDet =
6bd94e0d 150 aMat.GetValue(0, 0) * (aMat.GetValue(1, 1) * aMat.GetValue(2, 2) - aMat.GetValue(2, 1) * aMat.GetValue(1, 2)) -
151 aMat.GetValue(0, 1) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 2) - aMat.GetValue(2, 0) * aMat.GetValue(1, 2)) +
152 aMat.GetValue(0, 2) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 1) - aMat.GetValue(2, 0) * aMat.GetValue(1, 1));
7d9e854b 153
154 // Determinant of transform matrix less then 0 means that mirror transform applied.
155 myIsMirrored = aDet < 0.0f;
156
d4aaad5b 157 if (IsRaytracable())
e276548b 158 {
d4aaad5b 159 ++myModificationState;
e276548b 160 }
2166f0fa
SK
161}
162
4269bd1b 163// =======================================================================
b64d84be 164// function : clearHighlightBox
4269bd1b 165// purpose :
166// =======================================================================
b64d84be 167void OpenGl_Structure::clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 168{
b64d84be 169 if (!myHighlightBox.IsNull())
5e27df78 170 {
171 myHighlightBox->Release (theGlCtx);
b64d84be 172 myHighlightBox.Nullify();
2166f0fa
SK
173 }
174}
175
4269bd1b 176// =======================================================================
63bcc448 177// function : HighlightWithColor
178// purpose :
179// =======================================================================
180void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
181 const Standard_Boolean theToCreate)
182{
7d9e854b 183 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
63bcc448 184 if (theToCreate)
7d9e854b 185 setHighlightColor (aContext, theColor);
63bcc448 186 else
7d9e854b 187 clearHighlightColor (aContext);
63bcc448 188}
189
190// =======================================================================
191// function : HighlightWithBndBox
192// purpose :
193// =======================================================================
b64d84be 194void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
195 const Standard_Boolean theToCreate)
63bcc448 196{
7d9e854b 197 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
b64d84be 198 if (!theToCreate)
199 {
7d9e854b 200 clearHighlightBox (aContext);
b64d84be 201 return;
202 }
203
204 if (!myHighlightBox.IsNull())
205 {
7d9e854b 206 myHighlightBox->Release (aContext);
b64d84be 207 }
63bcc448 208 else
b64d84be 209 {
210 myHighlightBox = new OpenGl_Group (theStruct);
211 }
212
213 CALL_DEF_CONTEXTLINE& aContextLine = myHighlightBox->ChangeContextLine();
214 aContextLine.IsDef = 1;
b7cd4ba7 215 aContextLine.Color = HighlightColor;
b64d84be 216 aContextLine.LineType = Aspect_TOL_SOLID;
217 aContextLine.Width = 1.0f;
218 myHighlightBox->UpdateAspectLine (Standard_True);
219
b7cd4ba7 220 OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox);
b64d84be 221 myHighlightBox->AddElement (aBndBoxPrs);
63bcc448 222}
223
224// =======================================================================
b64d84be 225// function : setHighlightColor
4269bd1b 226// purpose :
227// =======================================================================
b64d84be 228void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 229 const Graphic3d_Vec3& theColor)
2166f0fa 230{
b64d84be 231 clearHighlightBox (theGlCtx);
5e27df78 232 if (myHighlightColor == NULL)
233 {
234 myHighlightColor = new TEL_COLOUR();
235 }
2166f0fa 236
63bcc448 237 myHighlightColor->rgb[0] = theColor.r();
238 myHighlightColor->rgb[1] = theColor.g();
239 myHighlightColor->rgb[2] = theColor.b();
2166f0fa
SK
240 myHighlightColor->rgb[3] = 1.F;
241}
242
4269bd1b 243// =======================================================================
b64d84be 244// function : clearHighlightColor
4269bd1b 245// purpose :
246// =======================================================================
b64d84be 247void OpenGl_Structure::clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 248{
b64d84be 249 clearHighlightBox(theGlCtx);
5e27df78 250 delete myHighlightColor;
251 myHighlightColor = NULL;
2166f0fa
SK
252}
253
4269bd1b 254// =======================================================================
a1954302 255// function : OnVisibilityChanged
e276548b 256// purpose :
257// =======================================================================
a1954302 258void OpenGl_Structure::OnVisibilityChanged()
e276548b 259{
d4aaad5b 260 if (IsRaytracable())
e276548b 261 {
d4aaad5b 262 ++myModificationState;
e276548b 263 }
e276548b 264}
265
e276548b 266// =======================================================================
d4aaad5b 267// function : IsRaytracable
e276548b 268// purpose :
269// =======================================================================
d4aaad5b 270Standard_Boolean OpenGl_Structure::IsRaytracable() const
e276548b 271{
d4aaad5b 272 if (!myGroups.IsEmpty())
e276548b 273 {
d4aaad5b 274 return myIsRaytracable; // geometry structure
e276548b 275 }
d4aaad5b 276 else if (myInstancedStructure != NULL)
e276548b 277 {
d4aaad5b 278 return myInstancedStructure->IsRaytracable(); // instance structure
e276548b 279 }
d5af8626 280
d4aaad5b 281 return Standard_False; // has no any groups or structures
d5af8626 282}
283
284// =======================================================================
d4aaad5b 285// function : UpdateRaytracableState
e276548b 286// purpose :
287// =======================================================================
d4aaad5b 288void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
e276548b 289{
d4aaad5b 290 myIsRaytracable = !toCheck || OpenGl_Raytrace::IsRaytracedStructure (this);
e276548b 291
d4aaad5b 292 if (IsRaytracable())
e276548b 293 {
d4aaad5b 294 ++myModificationState;
e276548b 295 }
296}
297
e276548b 298// =======================================================================
4269bd1b 299// function : Connect
300// purpose :
301// =======================================================================
63bcc448 302void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
2166f0fa 303{
d4aaad5b 304 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
305
306 Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
307 "Error! Instanced structure is already defined");
308
309 myInstancedStructure = aStruct;
e276548b 310
63bcc448 311 if (aStruct->IsRaytracable())
e276548b 312 {
d4aaad5b 313 UpdateStateIfRaytracable (Standard_False);
e276548b 314 }
2166f0fa
SK
315}
316
4269bd1b 317// =======================================================================
318// function : Disconnect
319// purpose :
320// =======================================================================
63bcc448 321void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
2166f0fa 322{
d4aaad5b 323 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
e276548b 324
d4aaad5b 325 if (myInstancedStructure == aStruct)
326 {
327 myInstancedStructure = NULL;
e276548b 328
d4aaad5b 329 if (aStruct->IsRaytracable())
330 {
331 UpdateStateIfRaytracable();
2166f0fa 332 }
2166f0fa
SK
333 }
334}
335
4269bd1b 336// =======================================================================
b64d84be 337// function : NewGroup
4269bd1b 338// purpose :
339// =======================================================================
b64d84be 340Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
2166f0fa 341{
b64d84be 342 Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
343 myGroups.Append (aGroup);
344 return aGroup;
2166f0fa
SK
345}
346
4269bd1b 347// =======================================================================
348// function : RemoveGroup
349// purpose :
350// =======================================================================
b64d84be 351void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
2166f0fa 352{
b64d84be 353 if (theGroup.IsNull())
354 {
355 return;
356 }
357
358 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa
SK
359 {
360 // Check for the given group
b64d84be 361 if (aGroupIter.Value() == theGroup)
2166f0fa 362 {
d4aaad5b 363 const Standard_Boolean wasRaytracable =
364 static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
365
b64d84be 366 theGroup->Clear (Standard_False);
e276548b 367
d4aaad5b 368 if (wasRaytracable)
e276548b 369 {
d4aaad5b 370 UpdateStateIfRaytracable();
e276548b 371 }
e276548b 372
b64d84be 373 myGroups.Remove (aGroupIter);
2166f0fa
SK
374 return;
375 }
2166f0fa
SK
376 }
377}
378
4269bd1b 379// =======================================================================
380// function : Clear
381// purpose :
382// =======================================================================
63bcc448 383void OpenGl_Structure::Clear()
384{
385 Clear (GlDriver()->GetSharedContext());
386}
387
388// =======================================================================
389// function : Clear
390// purpose :
391// =======================================================================
5e27df78 392void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 393{
e276548b 394 Standard_Boolean aRaytracableGroupDeleted (Standard_False);
e276548b 395
5e27df78 396 // Release groups
b64d84be 397 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa 398 {
b64d84be 399 aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
5322131b 400
2166f0fa 401 // Delete objects
b64d84be 402 aGroupIter.ChangeValue()->Release (theGlCtx);
2166f0fa
SK
403 }
404 myGroups.Clear();
e276548b 405
e276548b 406 if (aRaytracableGroupDeleted)
407 {
d4aaad5b 408 myIsRaytracable = Standard_False;
e276548b 409 }
b7cd4ba7 410
411 Is2dText = Standard_False;
412 IsForHighlight = Standard_False;
2166f0fa
SK
413}
414
4269bd1b 415// =======================================================================
cc6852f3 416// function : renderGeometry
0717ddc1 417// purpose :
418// =======================================================================
cc6852f3 419void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
420 bool& theHasClosed) const
0717ddc1 421{
cc6852f3 422 if (myInstancedStructure != NULL)
0717ddc1 423 {
cc6852f3 424 myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
425 }
426
427 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
428 {
429 theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
7d9e854b 430 aGroupIter.Value()->Render (theWorkspace);
0717ddc1 431 }
432}
433
434// =======================================================================
cc6852f3 435// function : renderClosedGeometry
436// purpose :
437// =======================================================================
438void OpenGl_Structure::renderClosedGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const
439{
440 if (myInstancedStructure != NULL)
441 {
442 myInstancedStructure->renderClosedGeometry (theWorkspace);
443 }
444
445 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
446 {
447 if (aGroupIter.Value()->IsClosed())
448 {
449 aGroupIter.Value()->Render (theWorkspace);
450 }
451 }
452}
453
454// =======================================================================
4269bd1b 455// function : Render
456// purpose :
457// =======================================================================
7d9e854b 458void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
2166f0fa
SK
459{
460 // Process the structure only if visible
a1954302 461 if (!visible)
7d9e854b 462 {
2166f0fa 463 return;
7d9e854b 464 }
2166f0fa 465
c827ea3a 466 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
b7cd4ba7 467
2166f0fa 468 // Render named status
7d9e854b 469 const Standard_Integer aNamedStatus = theWorkspace->NamedStatus;
a1954302 470 if (highlight)
471 {
472 theWorkspace->NamedStatus |= OPENGL_NS_HIGHLIGHT;
473 }
2166f0fa 474
2166f0fa 475 // Apply local transformation
6bd94e0d 476 aCtx->ModelWorldState.Push();
477 aCtx->ModelWorldState.SetCurrent (Transformation);
478
479 // detect scale transform
480 const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
481 const Standard_ShortReal aScaleX = Transformation.GetRow (0).xyz().SquareModulus();
482 if (Abs (aScaleX - 1.f) > Precision::Confusion())
483 {
484 aCtx->SetGlNormalizeEnabled (Standard_True);
2166f0fa 485 }
6bd94e0d 486
825aa485 487 if (TransformPersistence.Flags)
488 {
489 OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
490 OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
491 TransformPersistence.Apply (aProjection, aWorldView, theWorkspace->Width(), theWorkspace->Height());
2166f0fa 492
825aa485 493 aCtx->ProjectionState.Push();
494 aCtx->WorldViewState.Push();
495 aCtx->ProjectionState.SetCurrent (aProjection);
496 aCtx->WorldViewState.SetCurrent (aWorldView);
497 aCtx->ApplyProjectionMatrix();
498 }
2166f0fa 499
d437b80d 500 // Take into account transform persistence
501 aCtx->ApplyModelViewMatrix();
c827ea3a 502
2166f0fa 503 // Apply aspects
7d9e854b 504 const OpenGl_AspectLine *anAspectLine = theWorkspace->AspectLine (Standard_False);
505 const OpenGl_AspectFace *anAspectFace = theWorkspace->AspectFace (Standard_False);
506 const OpenGl_AspectMarker *anAspectMarker = theWorkspace->AspectMarker (Standard_False);
507 const OpenGl_AspectText *anAspectText = theWorkspace->AspectText (Standard_False);
7d9e854b 508
509 // Apply correction for mirror transform
510 if (myIsMirrored)
511 {
c827ea3a 512 aCtx->core11fwd->glFrontFace (GL_CW);
7d9e854b 513 }
2166f0fa 514
2166f0fa 515 // Apply highlight color
7d9e854b 516 const TEL_COLOUR *aHighlightColor = theWorkspace->HighlightColor;
2166f0fa 517 if (myHighlightColor)
7d9e854b 518 theWorkspace->HighlightColor = myHighlightColor;
2166f0fa 519
4269bd1b 520 // Set up plane equations for non-structure transformed global model-view matrix
b859a34d 521 // List of planes to be applied to context state
494782f6 522 NCollection_Handle<Graphic3d_SequenceOfHClipPlane> aUserPlanes;
b859a34d 523
524 // Collect clipping planes of structure scope
525 if (!myClipPlanes.IsEmpty())
4269bd1b 526 {
7d9e854b 527 Graphic3d_SequenceOfHClipPlane::Iterator aClippingIter (myClipPlanes);
528 for (; aClippingIter.More(); aClippingIter.Next())
b859a34d 529 {
7d9e854b 530 const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIter.Value();
b859a34d 531 if (!aClipPlane->IsOn())
532 {
533 continue;
534 }
535
536 if (aUserPlanes.IsNull())
537 {
51b10cd4 538 aUserPlanes = new Graphic3d_SequenceOfHClipPlane();
b859a34d 539 }
540
51b10cd4 541 aUserPlanes->Append (aClipPlane);
b859a34d 542 }
4269bd1b 543 }
544
b859a34d 545 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 546 {
b859a34d 547 // add planes at loaded view matrix state
79f4f036 548 aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
30f0ad28 549
550 // Set OCCT state uniform variables
c827ea3a 551 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 552 {
c827ea3a 553 aCtx->ShaderManager()->UpdateClippingState();
30f0ad28 554 }
4269bd1b 555 }
556
2166f0fa 557 // Render groups
cc6852f3 558 bool hasClosedPrims = false;
559 renderGeometry (theWorkspace, hasClosedPrims);
2166f0fa 560
7d9e854b 561 // Reset correction for mirror transform
562 if (myIsMirrored)
c827ea3a 563 {
564 aCtx->core11fwd->glFrontFace (GL_CCW);
565 }
7d9e854b 566
b859a34d 567 // Render capping for structure groups
cc6852f3 568 if (hasClosedPrims
569 && !aCtx->Clipping().Planes().IsEmpty())
b859a34d 570 {
cc6852f3 571 OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
b859a34d 572 }
4269bd1b 573
b859a34d 574 // Revert structure clippings
575 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 576 {
79f4f036 577 aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
30f0ad28 578
579 // Set OCCT state uniform variables
c827ea3a 580 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 581 {
c827ea3a 582 aCtx->ShaderManager()->RevertClippingState();
30f0ad28 583 }
4269bd1b 584 }
585
825aa485 586 // Restore local transformation
6bd94e0d 587 aCtx->ModelWorldState.Pop();
588 aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
825aa485 589 if (TransformPersistence.Flags)
590 {
591 aCtx->ProjectionState.Pop();
592 aCtx->WorldViewState.Pop();
593 aCtx->ApplyProjectionMatrix();
594 }
c827ea3a 595
2166f0fa 596 // Restore highlight color
7d9e854b 597 theWorkspace->HighlightColor = aHighlightColor;
2166f0fa
SK
598
599 // Restore aspects
7d9e854b 600 theWorkspace->SetAspectLine (anAspectLine);
601 theWorkspace->SetAspectFace (anAspectFace);
602 theWorkspace->SetAspectMarker (anAspectMarker);
603 theWorkspace->SetAspectText (anAspectText);
2166f0fa 604
b7cd4ba7 605 // Apply highlight box
606 if (!myHighlightBox.IsNull())
607 {
7d9e854b 608 myHighlightBox->Render (theWorkspace);
b7cd4ba7 609 }
610
2166f0fa 611 // Restore named status
7d9e854b 612 theWorkspace->NamedStatus = aNamedStatus;
2166f0fa
SK
613}
614
5e27df78 615// =======================================================================
616// function : Release
617// purpose :
618// =======================================================================
619void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
620{
621 // Release groups
622 Clear (theGlCtx);
b64d84be 623 clearHighlightColor (theGlCtx);
5e27df78 624}
625
dd8a4ce9 626// =======================================================================
627// function : ReleaseGlResources
628// purpose :
629// =======================================================================
630void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
631{
b64d84be 632 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
dd8a4ce9 633 {
b64d84be 634 aGroupIter.ChangeValue()->Release (theGlCtx);
dd8a4ce9 635 }
b64d84be 636 if (!myHighlightBox.IsNull())
dd8a4ce9 637 {
10b9c7df 638 myHighlightBox->Release (theGlCtx.operator->());
dd8a4ce9 639 }
640}
641
59f45b7c 642//=======================================================================
679ecdee 643//function : ShadowLink
644//purpose :
645//=======================================================================
646Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
647{
648 return new OpenGl_StructureShadow (theManager, this);
649}