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