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