0026005: Problem with transient TFunction_Logbook
[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
2166f0fa
SK
541 if (myTransformation)
542 {
d437b80d 543 OpenGl_Matrix aModelWorld;
544 OpenGl_Transposemat3 (&aModelWorld, myTransformation);
545 aCtx->ModelWorldState.Push();
546 aCtx->ModelWorldState.SetCurrent (OpenGl_Mat4::Map ((Standard_ShortReal* )aModelWorld.mat));
7d9e854b 547
d437b80d 548 Standard_ShortReal aScaleX = OpenGl_Vec3 (myTransformation->mat[0][0],
549 myTransformation->mat[0][1],
550 myTransformation->mat[0][2]).SquareModulus();
7d9e854b 551 // Scale transform detected.
552 if (Abs (aScaleX - 1.f) > Precision::Confusion())
553 {
c827ea3a 554 aCtx->SetGlNormalizeEnabled (Standard_True);
7d9e854b 555 }
2166f0fa 556 }
825aa485 557 if (TransformPersistence.Flags)
558 {
559 OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
560 OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
561 TransformPersistence.Apply (aProjection, aWorldView, theWorkspace->Width(), theWorkspace->Height());
2166f0fa 562
825aa485 563 aCtx->ProjectionState.Push();
564 aCtx->WorldViewState.Push();
565 aCtx->ProjectionState.SetCurrent (aProjection);
566 aCtx->WorldViewState.SetCurrent (aWorldView);
567 aCtx->ApplyProjectionMatrix();
568 }
2166f0fa 569
d437b80d 570 // Take into account transform persistence
571 aCtx->ApplyModelViewMatrix();
c827ea3a 572
2166f0fa 573 // Apply aspects
7d9e854b 574 const OpenGl_AspectLine *anAspectLine = theWorkspace->AspectLine (Standard_False);
575 const OpenGl_AspectFace *anAspectFace = theWorkspace->AspectFace (Standard_False);
576 const OpenGl_AspectMarker *anAspectMarker = theWorkspace->AspectMarker (Standard_False);
577 const OpenGl_AspectText *anAspectText = theWorkspace->AspectText (Standard_False);
2166f0fa 578 if (myAspectLine)
7d9e854b 579 {
580 theWorkspace->SetAspectLine (myAspectLine);
581 }
2166f0fa 582 if (myAspectFace)
7d9e854b 583 {
584 theWorkspace->SetAspectFace (myAspectFace);
585 }
2166f0fa 586 if (myAspectMarker)
7d9e854b 587 {
588 theWorkspace->SetAspectMarker (myAspectMarker);
589 }
2166f0fa 590 if (myAspectText)
7d9e854b 591 {
592 theWorkspace->SetAspectText (myAspectText);
593 }
594
595 // Apply correction for mirror transform
596 if (myIsMirrored)
597 {
c827ea3a 598 aCtx->core11fwd->glFrontFace (GL_CW);
7d9e854b 599 }
2166f0fa 600
2166f0fa 601 // Apply highlight color
7d9e854b 602 const TEL_COLOUR *aHighlightColor = theWorkspace->HighlightColor;
2166f0fa 603 if (myHighlightColor)
7d9e854b 604 theWorkspace->HighlightColor = myHighlightColor;
2166f0fa 605
d4aaad5b 606 // Render instanced structure (if exists)
607 if (myInstancedStructure != NULL)
2166f0fa 608 {
d4aaad5b 609 myInstancedStructure->RenderGeometry (theWorkspace);
2166f0fa
SK
610 }
611
4269bd1b 612 // Set up plane equations for non-structure transformed global model-view matrix
b859a34d 613 // List of planes to be applied to context state
494782f6 614 NCollection_Handle<Graphic3d_SequenceOfHClipPlane> aUserPlanes;
b859a34d 615
616 // Collect clipping planes of structure scope
617 if (!myClipPlanes.IsEmpty())
4269bd1b 618 {
7d9e854b 619 Graphic3d_SequenceOfHClipPlane::Iterator aClippingIter (myClipPlanes);
620 for (; aClippingIter.More(); aClippingIter.Next())
b859a34d 621 {
7d9e854b 622 const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIter.Value();
b859a34d 623 if (!aClipPlane->IsOn())
624 {
625 continue;
626 }
627
628 if (aUserPlanes.IsNull())
629 {
51b10cd4 630 aUserPlanes = new Graphic3d_SequenceOfHClipPlane();
b859a34d 631 }
632
51b10cd4 633 aUserPlanes->Append (aClipPlane);
b859a34d 634 }
4269bd1b 635 }
636
b859a34d 637 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 638 {
b859a34d 639 // add planes at loaded view matrix state
79f4f036 640 aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
30f0ad28 641
642 // Set OCCT state uniform variables
c827ea3a 643 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 644 {
c827ea3a 645 aCtx->ShaderManager()->UpdateClippingState();
30f0ad28 646 }
4269bd1b 647 }
648
2166f0fa 649 // Render groups
b64d84be 650 const Graphic3d_SequenceOfGroup& aGroups = DrawGroups();
651 for (OpenGl_Structure::GroupIterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa 652 {
7d9e854b 653 aGroupIter.Value()->Render (theWorkspace);
2166f0fa
SK
654 }
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
c827ea3a 663 if (!aCtx->Clipping().Planes().IsEmpty())
b859a34d 664 {
7d9e854b 665 OpenGl_CappingAlgo::RenderCapping (theWorkspace, aGroups);
b859a34d 666 }
4269bd1b 667
b859a34d 668 // Revert structure clippings
669 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 670 {
79f4f036 671 aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
30f0ad28 672
673 // Set OCCT state uniform variables
c827ea3a 674 if (!aCtx->ShaderManager()->IsEmpty())
30f0ad28 675 {
c827ea3a 676 aCtx->ShaderManager()->RevertClippingState();
30f0ad28 677 }
4269bd1b 678 }
679
825aa485 680 // Restore local transformation
d437b80d 681 if (myTransformation)
c827ea3a 682 {
683 aCtx->ModelWorldState.Pop();
684 aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
685 }
825aa485 686 if (TransformPersistence.Flags)
687 {
688 aCtx->ProjectionState.Pop();
689 aCtx->WorldViewState.Pop();
690 aCtx->ApplyProjectionMatrix();
691 }
c827ea3a 692
2166f0fa 693 // Restore highlight color
7d9e854b 694 theWorkspace->HighlightColor = aHighlightColor;
2166f0fa
SK
695
696 // Restore aspects
7d9e854b 697 theWorkspace->SetAspectLine (anAspectLine);
698 theWorkspace->SetAspectFace (anAspectFace);
699 theWorkspace->SetAspectMarker (anAspectMarker);
700 theWorkspace->SetAspectText (anAspectText);
2166f0fa 701
b7cd4ba7 702 // Apply highlight box
703 if (!myHighlightBox.IsNull())
704 {
7d9e854b 705 myHighlightBox->Render (theWorkspace);
b7cd4ba7 706 }
707
2166f0fa 708 // Restore named status
7d9e854b 709 theWorkspace->NamedStatus = aNamedStatus;
2166f0fa
SK
710}
711
5e27df78 712// =======================================================================
713// function : Release
714// purpose :
715// =======================================================================
716void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
717{
718 // Release groups
719 Clear (theGlCtx);
10b9c7df 720 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine);
721 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace);
722 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectMarker);
723 OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectText);
b64d84be 724 clearHighlightColor (theGlCtx);
5e27df78 725}
726
dd8a4ce9 727// =======================================================================
728// function : ReleaseGlResources
729// purpose :
730// =======================================================================
731void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
732{
b64d84be 733 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
dd8a4ce9 734 {
b64d84be 735 aGroupIter.ChangeValue()->Release (theGlCtx);
dd8a4ce9 736 }
737 if (myAspectLine != NULL)
738 {
10b9c7df 739 myAspectLine->Release (theGlCtx.operator->());
dd8a4ce9 740 }
741 if (myAspectFace != NULL)
742 {
10b9c7df 743 myAspectFace->Release (theGlCtx.operator->());
dd8a4ce9 744 }
745 if (myAspectMarker != NULL)
746 {
10b9c7df 747 myAspectMarker->Release (theGlCtx.operator->());
dd8a4ce9 748 }
749 if (myAspectText != NULL)
750 {
10b9c7df 751 myAspectText->Release (theGlCtx.operator->());
dd8a4ce9 752 }
b64d84be 753 if (!myHighlightBox.IsNull())
dd8a4ce9 754 {
10b9c7df 755 myHighlightBox->Release (theGlCtx.operator->());
dd8a4ce9 756 }
757}
758
59f45b7c 759//=======================================================================
679ecdee 760//function : ShadowLink
761//purpose :
762//=======================================================================
763Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
764{
765 return new OpenGl_StructureShadow (theManager, this);
766}