0024377: [Regression-like] OCC 6.7.0 beta contaminates log with more unnecessary...
[occt.git] / src / OpenGl / OpenGl_Structure.cxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
e276548b 20#ifdef HAVE_CONFIG_H
21 #include <config.h>
22#endif
23
2166f0fa 24
4269bd1b 25#include <OpenGl_CappingAlgo.hxx>
26#include <OpenGl_Context.hxx>
30f0ad28 27#include <OpenGl_GlCore11.hxx>
28#include <OpenGl_ShaderManager.hxx>
29#include <OpenGl_ShaderProgram.hxx>
30#include <OpenGl_Structure.hxx>
2166f0fa 31#include <OpenGl_telem_util.hxx>
30f0ad28 32#include <OpenGl_Vec.hxx>
33#include <OpenGl_View.hxx>
34#include <OpenGl_Workspace.hxx>
2166f0fa 35
b859a34d 36#include <Graphic3d_SetOfHClipPlane_Handle.hxx>
37
27eed937 38//! Auxiliary class for bounding box presentation
39class OpenGl_BndBoxPrs : public OpenGl_Element
40{
41
42public:
43
44 //! Main constructor
45 OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox)
46 {
47 const float Xm = theBndBox.Pmin.x;
48 const float Ym = theBndBox.Pmin.y;
49 const float Zm = theBndBox.Pmin.z;
50 const float XM = theBndBox.Pmax.x;
51 const float YM = theBndBox.Pmax.y;
52 const float ZM = theBndBox.Pmax.z;
53 myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm);
54 myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM);
55 myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM);
56 myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm);
57 myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm);
58 myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm);
59 myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM);
60 myVerts[7] = OpenGl_Vec3 (XM, YM, ZM);
61 myVerts[8] = OpenGl_Vec3 (XM, YM, Zm);
62 myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm);
63 myVerts[10] = OpenGl_Vec3 (XM, YM, Zm);
64 myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm);
65 myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM);
66 myVerts[13] = OpenGl_Vec3 (XM, YM, ZM);
67 myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM);
68 myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM);
69 }
70
71 //! Render presentation
72 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
73 {
74 // Apply line aspect
75 const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
76 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
77
78 glDisable (GL_LIGHTING);
79 if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0)
80 {
81 glDepthMask (GL_FALSE);
82 }
83
84 // Use highlight colors
85 glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb);
86
87 glEnableClientState (GL_VERTEX_ARRAY);
88 glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
89 glDrawArrays (GL_LINE_STRIP, 0, 16);
90 glDisableClientState (GL_VERTEX_ARRAY);
91
92 // restore aspects
93 if (!aPrevTexture.IsNull())
94 {
95 theWorkspace->EnableTexture (aPrevTexture);
96 }
97 }
98
99 //! Release graphical resources
100 virtual void Release (const Handle(OpenGl_Context)& )
101 {
102 //
103 }
104
105protected:
106
107 //! Protected destructor
108 virtual ~OpenGl_BndBoxPrs() {}
109
110private:
111
112 OpenGl_Vec3 myVerts[16]; //!< vertices array
113
114public:
115
116 DEFINE_STANDARD_ALLOC
117
118};
2166f0fa
SK
119
120/*----------------------------------------------------------------------*/
121
4269bd1b 122// =======================================================================
123// function : call_util_transpose_mat
124// purpose :
125// =======================================================================
2166f0fa
SK
126static void call_util_transpose_mat (float tmat[16], float mat[4][4])
127{
128 int i, j;
129
130 for (i=0; i<4; i++)
131 for (j=0; j<4; j++)
132 tmat[j*4+i] = mat[i][j];
133}
134
4269bd1b 135// =======================================================================
136// function : OpenGl_Structure
137// purpose :
138// =======================================================================
2166f0fa
SK
139OpenGl_Structure::OpenGl_Structure ()
140: myTransformation(NULL),
141 myTransPers(NULL),
2166f0fa
SK
142 myAspectLine(NULL),
143 myAspectFace(NULL),
144 myAspectMarker(NULL),
145 myAspectText(NULL),
146 myHighlightBox(NULL),
147 myHighlightColor(NULL),
59f45b7c 148 myNamedStatus(0),
149 myZLayer(0)
2166f0fa 150{
e276548b 151#if HAVE_OPENCL
152 myIsRaytracable = Standard_False;
153 myModificationState = 0;
154#endif
2166f0fa
SK
155}
156
4269bd1b 157// =======================================================================
158// function : ~OpenGl_Structure
159// purpose :
160// =======================================================================
5e27df78 161OpenGl_Structure::~OpenGl_Structure()
2166f0fa 162{
5e27df78 163 Release (Handle(OpenGl_Context)());
164 delete myTransformation; myTransformation = NULL;
165 delete myTransPers; myTransPers = NULL;
2166f0fa
SK
166}
167
4269bd1b 168// =======================================================================
169// function : SetTransformation
170// purpose :
171// =======================================================================
e276548b 172void OpenGl_Structure::SetTransformation (const float *theMatrix)
2166f0fa
SK
173{
174 if (!myTransformation)
e276548b 175 {
5e27df78 176 myTransformation = new OpenGl_Matrix();
e276548b 177 }
2166f0fa 178
e276548b 179 matcpy (myTransformation->mat, theMatrix);
180
181#ifdef HAVE_OPENCL
182 if (myIsRaytracable)
183 {
184 UpdateStateWithAncestorStructures();
185 }
186#endif
2166f0fa
SK
187}
188
4269bd1b 189// =======================================================================
190// function : SetTransformPersistence
191// purpose :
192// =======================================================================
2166f0fa
SK
193void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers)
194{
195 if (!myTransPers)
196 myTransPers = new TEL_TRANSFORM_PERSISTENCE;
197
198 myTransPers->mode = ATransPers.Flag;
199 myTransPers->pointX = ATransPers.Point.x;
200 myTransPers->pointY = ATransPers.Point.y;
201 myTransPers->pointZ = ATransPers.Point.z;
202}
203
4269bd1b 204// =======================================================================
205// function : SetAspectLine
206// purpose :
207// =======================================================================
fd4a6963 208void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect)
2166f0fa
SK
209{
210 if (!myAspectLine)
fd4a6963 211 {
5e27df78 212 myAspectLine = new OpenGl_AspectLine();
fd4a6963 213 }
214 myAspectLine->SetAspect (theAspect);
2166f0fa
SK
215}
216
4269bd1b 217// =======================================================================
218// function : SetAspectFace
219// purpose :
220// =======================================================================
fd4a6963 221void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect)
2166f0fa
SK
222{
223 if (!myAspectFace)
bf75be98 224 {
5e27df78 225 myAspectFace = new OpenGl_AspectFace();
bf75be98 226 }
fd4a6963 227 myAspectFace->SetAspect (theAspect);
e276548b 228
229#ifdef HAVE_OPENCL
230 if (myIsRaytracable)
231 {
232 UpdateStateWithAncestorStructures();
233 }
234#endif
2166f0fa
SK
235}
236
4269bd1b 237// =======================================================================
238// function : SetAspectMarker
239// purpose :
240// =======================================================================
fd4a6963 241void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect)
2166f0fa
SK
242{
243 if (!myAspectMarker)
a577aaab 244 {
5e27df78 245 myAspectMarker = new OpenGl_AspectMarker();
a577aaab 246 }
fd4a6963 247 myAspectMarker->SetAspect (theAspect);
2166f0fa
SK
248}
249
4269bd1b 250// =======================================================================
251// function : SetAspectText
252// purpose :
253// =======================================================================
fd4a6963 254void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect)
2166f0fa
SK
255{
256 if (!myAspectText)
fd4a6963 257 {
5e27df78 258 myAspectText = new OpenGl_AspectText();
fd4a6963 259 }
260 myAspectText->SetAspect (theAspect);
2166f0fa
SK
261}
262
4269bd1b 263// =======================================================================
264// function : SetHighlightBox
265// purpose :
266// =======================================================================
5e27df78 267void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
268 const CALL_DEF_BOUNDBOX& theBoundBox)
2166f0fa 269{
5e27df78 270 if (myHighlightBox != NULL)
271 {
272 myHighlightBox->Release (theGlCtx);
273 }
2166f0fa 274 else
5e27df78 275 {
e276548b 276#ifndef HAVE_OPENCL
5e27df78 277 myHighlightBox = new OpenGl_Group();
e276548b 278#else
279 myHighlightBox = new OpenGl_Group (this);
280#endif
5e27df78 281 }
2166f0fa 282
5e27df78 283 CALL_DEF_CONTEXTLINE aContextLine;
284 aContextLine.Color = theBoundBox.Color;
285 aContextLine.LineType = Aspect_TOL_SOLID;
286 aContextLine.Width = 1.0f;
287 myHighlightBox->SetAspectLine (aContextLine);
2166f0fa 288
27eed937 289 OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox);
290 myHighlightBox->AddElement (TelParray, aBndBoxPrs);
2166f0fa
SK
291}
292
4269bd1b 293// =======================================================================
294// function : ClearHighlightBox
295// purpose :
296// =======================================================================
5e27df78 297void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 298{
5e27df78 299 if (myHighlightBox != NULL)
2166f0fa 300 {
5e27df78 301 OpenGl_Element::Destroy (theGlCtx, myHighlightBox);
2166f0fa
SK
302 }
303}
304
4269bd1b 305// =======================================================================
306// function : SetHighlightColor
307// purpose :
308// =======================================================================
5e27df78 309void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
310 const Standard_ShortReal R,
311 const Standard_ShortReal G,
312 const Standard_ShortReal B)
2166f0fa 313{
5e27df78 314 ClearHighlightBox (theGlCtx);
315 if (myHighlightColor == NULL)
316 {
317 myHighlightColor = new TEL_COLOUR();
318 }
2166f0fa
SK
319
320 myHighlightColor->rgb[0] = R;
321 myHighlightColor->rgb[1] = G;
322 myHighlightColor->rgb[2] = B;
323 myHighlightColor->rgb[3] = 1.F;
324}
325
4269bd1b 326// =======================================================================
327// function : ClearHighlightColor
328// purpose :
329// =======================================================================
5e27df78 330void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 331{
5e27df78 332 ClearHighlightBox(theGlCtx);
333 delete myHighlightColor;
334 myHighlightColor = NULL;
2166f0fa
SK
335}
336
4269bd1b 337// =======================================================================
e276548b 338// function : SetNamedStatus
339// purpose :
340// =======================================================================
341void OpenGl_Structure::SetNamedStatus (const Standard_Integer aStatus)
342{
343 myNamedStatus = aStatus;
344
345#ifdef HAVE_OPENCL
346 if (myIsRaytracable)
347 {
348 UpdateStateWithAncestorStructures();
349 }
350#endif
351}
352
353#ifdef HAVE_OPENCL
354
355// =======================================================================
356// function : RegisterAncestorStructure
357// purpose :
358// =======================================================================
359void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const
360{
361 for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
362 {
363 if (anIt.Value() == theStructure)
364 {
365 return;
366 }
367 }
368
369 myAncestorStructures.Append (theStructure);
370}
371
372// =======================================================================
373// function : UnregisterAncestorStructure
374// purpose :
375// =======================================================================
376void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const
377{
378 for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
379 {
380 if (anIt.Value() == theStructure)
381 {
382 myAncestorStructures.Remove (anIt);
383 return;
384 }
385 }
386}
387
388// =======================================================================
d5af8626 389// function : UnregisterFromAncestorStructure
390// purpose :
391// =======================================================================
392void OpenGl_Structure::UnregisterFromAncestorStructure() const
393{
394 for (OpenGl_ListOfStructure::Iterator anIta (myAncestorStructures); anIta.More(); anIta.Next())
395 {
396 OpenGl_Structure* anAncestor = const_cast<OpenGl_Structure*> (anIta.ChangeValue());
397
398 for (OpenGl_ListOfStructure::Iterator anIts (anAncestor->myConnected); anIts.More(); anIts.Next())
399 {
400 if (anIts.Value() == this)
401 {
402 anAncestor->myConnected.Remove (anIts);
403 return;
404 }
405 }
406 }
407}
408
409// =======================================================================
e276548b 410// function : UpdateStateWithAncestorStructures
411// purpose :
412// =======================================================================
413void OpenGl_Structure::UpdateStateWithAncestorStructures() const
414{
415 myModificationState++;
416
417 for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
418 {
419 anIt.Value()->UpdateStateWithAncestorStructures();
420 }
421}
422
423// =======================================================================
424// function : UpdateRaytracableWithAncestorStructures
425// purpose :
426// =======================================================================
427void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const
428{
429 myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this);
430
431 if (!myIsRaytracable)
432 {
433 for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
434 {
435 anIt.Value()->UpdateRaytracableWithAncestorStructures();
436 }
437 }
438}
439
440// =======================================================================
441// function : SetRaytracableWithAncestorStructures
442// purpose :
443// =======================================================================
444void OpenGl_Structure::SetRaytracableWithAncestorStructures() const
445{
446 myIsRaytracable = Standard_True;
447
448 for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next())
449 {
450 if (!anIt.Value()->IsRaytracable())
451 {
452 anIt.Value()->SetRaytracableWithAncestorStructures();
453 }
454 }
455}
456
457#endif
458
459// =======================================================================
4269bd1b 460// function : Connect
461// purpose :
462// =======================================================================
e276548b 463void OpenGl_Structure::Connect (const OpenGl_Structure *theStructure)
2166f0fa 464{
e276548b 465 Disconnect (theStructure);
466 myConnected.Append (theStructure);
467
468#ifdef HAVE_OPENCL
469 if (theStructure->IsRaytracable())
470 {
471 UpdateStateWithAncestorStructures();
472 SetRaytracableWithAncestorStructures();
473 }
474
475 theStructure->RegisterAncestorStructure (this);
476#endif
2166f0fa
SK
477}
478
4269bd1b 479// =======================================================================
480// function : Disconnect
481// purpose :
482// =======================================================================
e276548b 483void OpenGl_Structure::Disconnect (const OpenGl_Structure *theStructure)
2166f0fa 484{
e276548b 485 OpenGl_ListOfStructure::Iterator its (myConnected);
2166f0fa
SK
486 while (its.More())
487 {
488 // Check for the given structure
e276548b 489 if (its.Value() == theStructure)
2166f0fa 490 {
e276548b 491 myConnected.Remove (its);
492
493#ifdef HAVE_OPENCL
494 if (theStructure->IsRaytracable())
495 {
496 UpdateStateWithAncestorStructures();
497 UpdateRaytracableWithAncestorStructures();
498 }
499
500 theStructure->UnregisterAncestorStructure (this);
501#endif
502
2166f0fa
SK
503 return;
504 }
505 its.Next();
506 }
507}
508
4269bd1b 509// =======================================================================
510// function : AddGroup
511// purpose :
512// =======================================================================
e276548b 513OpenGl_Group * OpenGl_Structure::AddGroup()
2166f0fa
SK
514{
515 // Create new group
e276548b 516#ifndef HAVE_OPENCL
517 OpenGl_Group *g = new OpenGl_Group();
518#else
519 OpenGl_Group *g = new OpenGl_Group (this);
520#endif
521
2166f0fa
SK
522 myGroups.Append(g);
523 return g;
524}
525
4269bd1b 526// =======================================================================
527// function : RemoveGroup
528// purpose :
529// =======================================================================
5e27df78 530void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
531 const OpenGl_Group* theGroup)
2166f0fa 532{
5e27df78 533 for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
2166f0fa
SK
534 {
535 // Check for the given group
5e27df78 536 if (anIter.Value() == theGroup)
2166f0fa 537 {
5e27df78 538 myGroups.Remove (anIter);
e276548b 539
540#ifdef HAVE_OPENCL
541 if (theGroup->IsRaytracable())
542 {
543 UpdateStateWithAncestorStructures();
544 UpdateRaytracableWithAncestorStructures();
545 }
546#endif
547
548 // Delete object
549 OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup));
2166f0fa
SK
550 return;
551 }
2166f0fa
SK
552 }
553}
554
4269bd1b 555// =======================================================================
556// function : Clear
557// purpose :
558// =======================================================================
5e27df78 559void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 560{
e276548b 561#ifdef HAVE_OPENCL
562 Standard_Boolean aRaytracableGroupDeleted (Standard_False);
563#endif
564
5e27df78 565 // Release groups
566 for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
2166f0fa 567 {
e276548b 568#ifdef HAVE_OPENCL
569 aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable();
570#endif
571
2166f0fa 572 // Delete objects
5e27df78 573 OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue()));
2166f0fa
SK
574 }
575 myGroups.Clear();
e276548b 576
577#ifdef HAVE_OPENCL
578 if (aRaytracableGroupDeleted)
579 {
580 UpdateStateWithAncestorStructures();
581 UpdateRaytracableWithAncestorStructures();
582 }
583#endif
2166f0fa
SK
584}
585
4269bd1b 586// =======================================================================
587// function : Render
588// purpose :
589// =======================================================================
2166f0fa
SK
590void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
591{
592 // Process the structure only if visible
593 if ( myNamedStatus & OPENGL_NS_HIDE )
594 return;
595
596 // Render named status
597 const Standard_Integer named_status = AWorkspace->NamedStatus;
598 AWorkspace->NamedStatus |= myNamedStatus;
599
600 // Is rendering in ADD or IMMEDIATE mode?
601 const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0;
602
30f0ad28 603 const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext();
604
2166f0fa
SK
605 // Apply local transformation
606 GLint matrix_mode = 0;
607 const OpenGl_Matrix *local_trsf = NULL;
608 if (myTransformation)
609 {
610 if (isImmediate)
611 {
30f0ad28 612 Tmatrix3 aModelWorld;
613 call_util_transpose_mat (*aModelWorld, myTransformation->mat);
2166f0fa 614 glGetIntegerv (GL_MATRIX_MODE, &matrix_mode);
30f0ad28 615
616 if (!aCtx->ShaderManager()->IsEmpty())
617 {
618 Tmatrix3 aWorldView;
619 glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView);
620
621 Tmatrix3 aProjection;
622 glGetFloatv (GL_PROJECTION_MATRIX, *aProjection);
623
624 aCtx->ShaderManager()->UpdateModelWorldStateTo (aModelWorld);
625 aCtx->ShaderManager()->UpdateWorldViewStateTo (aWorldView);
626 aCtx->ShaderManager()->UpdateProjectionStateTo (aProjection);
627 }
628
2166f0fa
SK
629 glMatrixMode (GL_MODELVIEW);
630 glPushMatrix ();
631 glScalef (1.F, 1.F, 1.F);
30f0ad28 632 glMultMatrixf (*aModelWorld);
2166f0fa
SK
633 }
634 else
635 {
636 glMatrixMode (GL_MODELVIEW);
637 glPushMatrix();
638
30f0ad28 639 local_trsf = AWorkspace->SetStructureMatrix (myTransformation);
2166f0fa
SK
640 }
641 }
642
643 // Apply transform persistence
644 const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL;
645 if ( myTransPers && myTransPers->mode != 0 )
646 {
30f0ad28 647 trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers);
2166f0fa
SK
648 }
649
2166f0fa
SK
650 // Apply aspects
651 const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False);
652 const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False);
653 const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False);
654 const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False);
655 if (myAspectLine)
656 AWorkspace->SetAspectLine(myAspectLine);
657 if (myAspectFace)
658 AWorkspace->SetAspectFace(myAspectFace);
659 if (myAspectMarker)
660 AWorkspace->SetAspectMarker(myAspectMarker);
661 if (myAspectText)
662 AWorkspace->SetAspectText(myAspectText);
663
664 // Apply highlight box
665 if (myHighlightBox)
666 myHighlightBox->Render( AWorkspace );
667
668 // Apply highlight color
669 const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor;
670 if (myHighlightColor)
671 AWorkspace->HighlightColor = myHighlightColor;
672
673 // Render connected structures
674 OpenGl_ListOfStructure::Iterator its(myConnected);
675 while (its.More())
676 {
677 its.Value()->Render(AWorkspace);
678 its.Next();
679 }
680
4269bd1b 681 // Set up plane equations for non-structure transformed global model-view matrix
682 const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext();
683
b859a34d 684 // List of planes to be applied to context state
685 Handle(Graphic3d_SetOfHClipPlane) aUserPlanes;
686
687 // Collect clipping planes of structure scope
688 if (!myClipPlanes.IsEmpty())
4269bd1b 689 {
b859a34d 690 Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes);
691 for (; aClippingIt.More(); aClippingIt.Next())
692 {
693 const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
694 if (!aClipPlane->IsOn())
695 {
696 continue;
697 }
698
699 if (aUserPlanes.IsNull())
700 {
701 aUserPlanes = new Graphic3d_SetOfHClipPlane();
702 }
703
704 aUserPlanes->Add (aClipPlane);
705 }
4269bd1b 706 }
707
b859a34d 708 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 709 {
b859a34d 710 // add planes at loaded view matrix state
711 aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace);
30f0ad28 712
713 // Set OCCT state uniform variables
714 if (!aContext->ShaderManager()->IsEmpty())
715 {
716 aContext->ShaderManager()->UpdateClippingState();
717 }
4269bd1b 718 }
719
2166f0fa
SK
720 // Render groups
721 OpenGl_ListOfGroup::Iterator itg(myGroups);
722 while (itg.More())
723 {
724 itg.Value()->Render(AWorkspace);
725 itg.Next();
726 }
727
b859a34d 728 // Render capping for structure groups
729 if (!aContext->Clipping().Planes().IsEmpty())
730 {
731 OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups);
732 }
4269bd1b 733
b859a34d 734 // Revert structure clippings
735 if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty())
4269bd1b 736 {
b859a34d 737 aContext->ChangeClipping().Remove (*aUserPlanes);
30f0ad28 738
739 // Set OCCT state uniform variables
740 if (!aContext->ShaderManager()->IsEmpty())
741 {
742 aContext->ShaderManager()->RevertClippingState();
743 }
4269bd1b 744 }
745
2166f0fa
SK
746 // Restore highlight color
747 AWorkspace->HighlightColor = highlight_color;
748
749 // Restore aspects
750 AWorkspace->SetAspectLine(aspect_line);
751 AWorkspace->SetAspectFace(aspect_face);
752 AWorkspace->SetAspectMarker(aspect_marker);
753 AWorkspace->SetAspectText(aspect_text);
754
755 // Restore transform persistence
756 if ( myTransPers && myTransPers->mode != 0 )
757 {
30f0ad28 758 AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers);
2166f0fa
SK
759 }
760
761 // Restore local transformation
762 if (myTransformation)
763 {
764 if (isImmediate)
765 {
766 glPopMatrix ();
767 glMatrixMode (matrix_mode);
30f0ad28 768
769 Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f },
770 { 0.f, 1.f, 0.f, 0.f },
771 { 0.f, 0.f, 1.f, 0.f },
772 { 0.f, 0.f, 0.f, 1.f } };
773
774 aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState);
2166f0fa
SK
775 }
776 else
777 {
30f0ad28 778 AWorkspace->SetStructureMatrix (local_trsf, true);
2166f0fa
SK
779
780 glMatrixMode (GL_MODELVIEW);
781 glPopMatrix();
782 }
783 }
784
785 // Restore named status
786 AWorkspace->NamedStatus = named_status;
787}
788
5e27df78 789// =======================================================================
790// function : Release
791// purpose :
792// =======================================================================
793void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
794{
795 // Release groups
796 Clear (theGlCtx);
797 OpenGl_Element::Destroy (theGlCtx, myAspectLine);
798 OpenGl_Element::Destroy (theGlCtx, myAspectFace);
799 OpenGl_Element::Destroy (theGlCtx, myAspectMarker);
800 OpenGl_Element::Destroy (theGlCtx, myAspectText);
801 ClearHighlightColor (theGlCtx);
d5af8626 802
803#ifdef HAVE_OPENCL
804 // Remove from connected list of ancestor
805 UnregisterFromAncestorStructure();
806#endif
5e27df78 807}
808
dd8a4ce9 809// =======================================================================
810// function : ReleaseGlResources
811// purpose :
812// =======================================================================
813void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
814{
815 for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
816 {
817 OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue());
818 if (aGroup != NULL)
819 {
820 aGroup->Release (theGlCtx);
821 }
822 }
823 if (myAspectLine != NULL)
824 {
825 myAspectLine->Release (theGlCtx);
826 }
827 if (myAspectFace != NULL)
828 {
829 myAspectFace->Release (theGlCtx);
830 }
831 if (myAspectMarker != NULL)
832 {
833 myAspectMarker->Release (theGlCtx);
834 }
835 if (myAspectText != NULL)
836 {
837 myAspectText->Release (theGlCtx);
838 }
839 if (myHighlightBox != NULL)
840 {
841 myHighlightBox->Release (theGlCtx);
842 }
843}
844
59f45b7c 845//=======================================================================
846//function : SetZLayer
bf75be98 847//purpose :
59f45b7c 848//=======================================================================
59f45b7c 849void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex)
850{
851 myZLayer = theLayerIndex;
852}
853
854//=======================================================================
855//function : GetZLayer
bf75be98 856//purpose :
59f45b7c 857//=======================================================================
59f45b7c 858Standard_Integer OpenGl_Structure::GetZLayer () const
859{
860 return myZLayer;
861}