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