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