0025180: Visualization - Homogeneous transformation API in TKV3d
[occt.git] / src / OpenGl / OpenGl_Structure.cxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
4269bd1b 16#include <OpenGl_CappingAlgo.hxx>
17#include <OpenGl_Context.hxx>
30f0ad28 18#include <OpenGl_GlCore11.hxx>
63bcc448 19#include <OpenGl_GraphicDriver.hxx>
30f0ad28 20#include <OpenGl_ShaderManager.hxx>
21#include <OpenGl_ShaderProgram.hxx>
2bd4bfac 22#include <OpenGl_StructureShadow.hxx>
30f0ad28 23#include <OpenGl_Vec.hxx>
24#include <OpenGl_View.hxx>
25#include <OpenGl_Workspace.hxx>
2166f0fa 26
494782f6 27#include <Graphic3d_SequenceOfHClipPlane.hxx>
b859a34d 28
63bcc448 29
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure)
31
27eed937 32//! Auxiliary class for bounding box presentation
33class OpenGl_BndBoxPrs : public OpenGl_Element
34{
35
36public:
37
38 //! Main constructor
b7cd4ba7 39 OpenGl_BndBoxPrs (const Graphic3d_BndBox4f& theBndBox)
40 {
41 const float Xm = theBndBox.CornerMin().x();
42 const float Ym = theBndBox.CornerMin().y();
43 const float Zm = theBndBox.CornerMin().z();
44 const float XM = theBndBox.CornerMax().x();
45 const float YM = theBndBox.CornerMax().y();
46 const float ZM = theBndBox.CornerMax().z();
47
27eed937 48 myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm);
49 myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM);
50 myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM);
51 myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm);
52 myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm);
53 myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm);
54 myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM);
55 myVerts[7] = OpenGl_Vec3 (XM, YM, ZM);
56 myVerts[8] = OpenGl_Vec3 (XM, YM, Zm);
57 myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm);
58 myVerts[10] = OpenGl_Vec3 (XM, YM, Zm);
59 myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm);
60 myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM);
61 myVerts[13] = OpenGl_Vec3 (XM, YM, ZM);
62 myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM);
63 myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM);
64 }
65
66 //! Render presentation
67 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
68 {
ca3c13d1 69 #if !defined(GL_ES_VERSION_2_0)
27eed937 70 // Apply line aspect
27eed937 71 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
72
73 glDisable (GL_LIGHTING);
27eed937 74
75 // Use highlight colors
b6472664 76 theWorkspace->GetGlContext()->core11->glColor3fv (theWorkspace->LineColor().GetData());
27eed937 77
78 glEnableClientState (GL_VERTEX_ARRAY);
79 glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts);
80 glDrawArrays (GL_LINE_STRIP, 0, 16);
81 glDisableClientState (GL_VERTEX_ARRAY);
82
83 // restore aspects
84 if (!aPrevTexture.IsNull())
85 {
86 theWorkspace->EnableTexture (aPrevTexture);
87 }
20aeeb7b 88 #else
89 (void )theWorkspace;
ca3c13d1 90 #endif
27eed937 91 }
92
93 //! Release graphical resources
10b9c7df 94 virtual void Release (OpenGl_Context*)
27eed937 95 {
96 //
97 }
98
99protected:
100
101 //! Protected destructor
102 virtual ~OpenGl_BndBoxPrs() {}
103
104private:
105
106 OpenGl_Vec3 myVerts[16]; //!< vertices array
107
108public:
109
110 DEFINE_STANDARD_ALLOC
111
112};
2166f0fa
SK
113
114/*----------------------------------------------------------------------*/
115
4269bd1b 116// =======================================================================
4269bd1b 117// function : OpenGl_Structure
118// purpose :
119// =======================================================================
63bcc448 120OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
121: Graphic3d_CStructure (theManager),
d4aaad5b 122 myHighlightColor (NULL),
123 myInstancedStructure (NULL),
124 myIsRaytracable (Standard_False),
125 myModificationState (0),
126 myIsCulled (Standard_True),
127 myIsMirrored (Standard_False)
2166f0fa 128{
a1954302 129 //
2166f0fa
SK
130}
131
4269bd1b 132// =======================================================================
133// function : ~OpenGl_Structure
134// purpose :
135// =======================================================================
5e27df78 136OpenGl_Structure::~OpenGl_Structure()
2166f0fa 137{
5e27df78 138 Release (Handle(OpenGl_Context)());
2166f0fa
SK
139}
140
4269bd1b 141// =======================================================================
1f7f5a90 142// function : SetTransformation
63bcc448 143// purpose :
144// =======================================================================
1f7f5a90 145void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
63bcc448 146{
1f7f5a90 147 myTrsf = theTrsf;
148 myIsMirrored = Standard_False;
149 if (!myTrsf.IsNull())
150 {
151 // Determinant of transform matrix less then 0 means that mirror transform applied.
152 const Standard_Real aDet = myTrsf->Value(1, 1) * (myTrsf->Value (2, 2) * myTrsf->Value (3, 3) - myTrsf->Value (3, 2) * myTrsf->Value (2, 3))
153 - myTrsf->Value(1, 2) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 3) - myTrsf->Value (3, 1) * myTrsf->Value (2, 3))
154 + myTrsf->Value(1, 3) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 2) - myTrsf->Value (3, 1) * myTrsf->Value (2, 2));
155 myIsMirrored = aDet < 0.0;
156 }
7d9e854b 157
d4aaad5b 158 if (IsRaytracable())
e276548b 159 {
d4aaad5b 160 ++myModificationState;
e276548b 161 }
2166f0fa
SK
162}
163
4269bd1b 164// =======================================================================
b64d84be 165// function : clearHighlightBox
4269bd1b 166// purpose :
167// =======================================================================
b64d84be 168void OpenGl_Structure::clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 169{
b64d84be 170 if (!myHighlightBox.IsNull())
5e27df78 171 {
172 myHighlightBox->Release (theGlCtx);
b64d84be 173 myHighlightBox.Nullify();
2166f0fa
SK
174 }
175}
176
4269bd1b 177// =======================================================================
63bcc448 178// function : HighlightWithColor
179// purpose :
180// =======================================================================
181void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor,
182 const Standard_Boolean theToCreate)
183{
7d9e854b 184 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
63bcc448 185 if (theToCreate)
7d9e854b 186 setHighlightColor (aContext, theColor);
63bcc448 187 else
7d9e854b 188 clearHighlightColor (aContext);
63bcc448 189}
190
191// =======================================================================
192// function : HighlightWithBndBox
193// purpose :
194// =======================================================================
b64d84be 195void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
196 const Standard_Boolean theToCreate)
63bcc448 197{
7d9e854b 198 const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext();
b64d84be 199 if (!theToCreate)
200 {
7d9e854b 201 clearHighlightBox (aContext);
b64d84be 202 return;
203 }
204
205 if (!myHighlightBox.IsNull())
206 {
7d9e854b 207 myHighlightBox->Release (aContext);
b64d84be 208 }
63bcc448 209 else
b64d84be 210 {
211 myHighlightBox = new OpenGl_Group (theStruct);
212 }
213
b6472664 214 myHighlightBox->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (HighlightColor, Aspect_TOL_SOLID, 1.0));
b64d84be 215
b7cd4ba7 216 OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox);
b64d84be 217 myHighlightBox->AddElement (aBndBoxPrs);
63bcc448 218}
219
220// =======================================================================
b64d84be 221// function : setHighlightColor
4269bd1b 222// purpose :
223// =======================================================================
b64d84be 224void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 225 const Graphic3d_Vec3& theColor)
2166f0fa 226{
b64d84be 227 clearHighlightBox (theGlCtx);
5e27df78 228 if (myHighlightColor == NULL)
229 {
b6472664 230 myHighlightColor = new OpenGl_Vec4 (theColor, 1.0f);
231 }
232 else
233 {
234 myHighlightColor->xyz() = theColor;
5e27df78 235 }
2166f0fa
SK
236}
237
4269bd1b 238// =======================================================================
b64d84be 239// function : clearHighlightColor
4269bd1b 240// purpose :
241// =======================================================================
b64d84be 242void OpenGl_Structure::clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 243{
b64d84be 244 clearHighlightBox(theGlCtx);
5e27df78 245 delete myHighlightColor;
246 myHighlightColor = NULL;
2166f0fa
SK
247}
248
4269bd1b 249// =======================================================================
a1954302 250// function : OnVisibilityChanged
e276548b 251// purpose :
252// =======================================================================
a1954302 253void OpenGl_Structure::OnVisibilityChanged()
e276548b 254{
d4aaad5b 255 if (IsRaytracable())
e276548b 256 {
d4aaad5b 257 ++myModificationState;
e276548b 258 }
e276548b 259}
260
e276548b 261// =======================================================================
d4aaad5b 262// function : IsRaytracable
e276548b 263// purpose :
264// =======================================================================
d4aaad5b 265Standard_Boolean OpenGl_Structure::IsRaytracable() const
e276548b 266{
3e05329c 267 if (!myGroups.IsEmpty()
268 && myIsRaytracable)
e276548b 269 {
3e05329c 270 return Standard_True;
e276548b 271 }
d5af8626 272
3e05329c 273 return myInstancedStructure != NULL
274 && myInstancedStructure->IsRaytracable();
d5af8626 275}
276
277// =======================================================================
d4aaad5b 278// function : UpdateRaytracableState
e276548b 279// purpose :
280// =======================================================================
d4aaad5b 281void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
e276548b 282{
3e05329c 283 myIsRaytracable = !toCheck;
284 if (!myIsRaytracable)
285 {
286 for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
287 {
288 if (anIter.Value()->IsRaytracable())
289 {
290 myIsRaytracable = Standard_True;
291 break;
292 }
293 }
294 }
e276548b 295
d4aaad5b 296 if (IsRaytracable())
e276548b 297 {
d4aaad5b 298 ++myModificationState;
e276548b 299 }
300}
301
e276548b 302// =======================================================================
4269bd1b 303// function : Connect
304// purpose :
305// =======================================================================
63bcc448 306void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
2166f0fa 307{
d4aaad5b 308 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
309
310 Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
311 "Error! Instanced structure is already defined");
312
313 myInstancedStructure = aStruct;
e276548b 314
63bcc448 315 if (aStruct->IsRaytracable())
e276548b 316 {
d4aaad5b 317 UpdateStateIfRaytracable (Standard_False);
e276548b 318 }
2166f0fa
SK
319}
320
4269bd1b 321// =======================================================================
322// function : Disconnect
323// purpose :
324// =======================================================================
63bcc448 325void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
2166f0fa 326{
d4aaad5b 327 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
e276548b 328
d4aaad5b 329 if (myInstancedStructure == aStruct)
330 {
331 myInstancedStructure = NULL;
e276548b 332
d4aaad5b 333 if (aStruct->IsRaytracable())
334 {
335 UpdateStateIfRaytracable();
2166f0fa 336 }
2166f0fa
SK
337 }
338}
339
4269bd1b 340// =======================================================================
b64d84be 341// function : NewGroup
4269bd1b 342// purpose :
343// =======================================================================
b64d84be 344Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
2166f0fa 345{
b64d84be 346 Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
347 myGroups.Append (aGroup);
348 return aGroup;
2166f0fa
SK
349}
350
4269bd1b 351// =======================================================================
352// function : RemoveGroup
353// purpose :
354// =======================================================================
b64d84be 355void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
2166f0fa 356{
b64d84be 357 if (theGroup.IsNull())
358 {
359 return;
360 }
361
362 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa
SK
363 {
364 // Check for the given group
b64d84be 365 if (aGroupIter.Value() == theGroup)
2166f0fa 366 {
d4aaad5b 367 const Standard_Boolean wasRaytracable =
368 static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
369
b64d84be 370 theGroup->Clear (Standard_False);
e276548b 371
d4aaad5b 372 if (wasRaytracable)
e276548b 373 {
d4aaad5b 374 UpdateStateIfRaytracable();
e276548b 375 }
e276548b 376
b64d84be 377 myGroups.Remove (aGroupIter);
2166f0fa
SK
378 return;
379 }
2166f0fa
SK
380 }
381}
382
4269bd1b 383// =======================================================================
384// function : Clear
385// purpose :
386// =======================================================================
63bcc448 387void OpenGl_Structure::Clear()
388{
389 Clear (GlDriver()->GetSharedContext());
390}
391
392// =======================================================================
393// function : Clear
394// purpose :
395// =======================================================================
5e27df78 396void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 397{
e276548b 398 Standard_Boolean aRaytracableGroupDeleted (Standard_False);
e276548b 399
5e27df78 400 // Release groups
b64d84be 401 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa 402 {
b64d84be 403 aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
5322131b 404
2166f0fa 405 // Delete objects
b64d84be 406 aGroupIter.ChangeValue()->Release (theGlCtx);
2166f0fa
SK
407 }
408 myGroups.Clear();
e276548b 409
e276548b 410 if (aRaytracableGroupDeleted)
411 {
d4aaad5b 412 myIsRaytracable = Standard_False;
e276548b 413 }
b7cd4ba7 414
415 Is2dText = Standard_False;
416 IsForHighlight = Standard_False;
2166f0fa
SK
417}
418
4269bd1b 419// =======================================================================
cc6852f3 420// function : renderGeometry
0717ddc1 421// purpose :
422// =======================================================================
cc6852f3 423void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
424 bool& theHasClosed) const
0717ddc1 425{
cc6852f3 426 if (myInstancedStructure != NULL)
0717ddc1 427 {
cc6852f3 428 myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
429 }
430
431 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
432 {
433 theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
7d9e854b 434 aGroupIter.Value()->Render (theWorkspace);
0717ddc1 435 }
436}
cc6852f3 437
438// =======================================================================
4269bd1b 439// function : Render
440// purpose :
441// =======================================================================
7d9e854b 442void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
2166f0fa
SK
443{
444 // Process the structure only if visible
a1954302 445 if (!visible)
7d9e854b 446 {
2166f0fa 447 return;
7d9e854b 448 }
2166f0fa 449
c827ea3a 450 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
b7cd4ba7 451
2166f0fa 452 // Render named status
a1954302 453 if (highlight)
454 {
f9ba5c4d 455 theWorkspace->SetHighlight (true);
a1954302 456 }
2166f0fa 457
2166f0fa 458 // Apply local transformation
6bd94e0d 459 aCtx->ModelWorldState.Push();
1f7f5a90 460 OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent();
461 if (!myTrsf.IsNull())
462 {
463 myTrsf->Trsf().GetMat4 (aModelWorld);
464 }
465 else
466 {
467 aModelWorld.InitIdentity();
468 }
6bd94e0d 469
1d92133e 470 const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
471
472#if !defined(GL_ES_VERSION_2_0)
473 // detect scale transform
1f7f5a90 474 if (aCtx->core11 != NULL
475 && !myTrsf.IsNull())
1d92133e 476 {
1f7f5a90 477 const Standard_Real aScale = myTrsf->ScaleFactor();
478 if (Abs (aScale - 1.0) > Precision::Confusion())
1d92133e 479 {
480 aCtx->SetGlNormalizeEnabled (Standard_True);
481 }
482 }
483#endif
484
778cd667 485 if (!myTrsfPers.IsNull())
825aa485 486 {
778cd667 487 OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current();
488 myTrsfPers->Apply (theWorkspace->View()->Camera(), aCtx->ProjectionState.Current(), aWorldView,
489 aCtx->Viewport()[2], aCtx->Viewport()[3]);
2166f0fa 490
825aa485 491 aCtx->WorldViewState.Push();
825aa485 492 aCtx->WorldViewState.SetCurrent (aWorldView);
2166f0fa 493
1d92133e 494 #if !defined(GL_ES_VERSION_2_0)
495 if (!aCtx->IsGlNormalizeEnabled()
496 && aCtx->core11 != NULL)
497 {
498 const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor<Standard_ShortReal> (aWorldView);
499 if (Abs (aScale - 1.0f) > Precision::Confusion())
500 {
501 aCtx->SetGlNormalizeEnabled (Standard_True);
502 }
503 }
504 #endif
04be5003 505 }
506
d437b80d 507 // Take into account transform persistence
508 aCtx->ApplyModelViewMatrix();
c827ea3a 509
f9ba5c4d 510 // remember aspects
511 const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->AspectLine();
512 const OpenGl_AspectFace* aPrevAspectFace = theWorkspace->AspectFace();
513 const OpenGl_AspectMarker* aPrevAspectMarker = theWorkspace->AspectMarker();
514 const OpenGl_AspectText* aPrevAspectText = theWorkspace->AspectText();
7d9e854b 515
516 // Apply correction for mirror transform
517 if (myIsMirrored)
518 {
c827ea3a 519 aCtx->core11fwd->glFrontFace (GL_CW);
7d9e854b 520 }
2166f0fa 521
2166f0fa 522 // Apply highlight color
b6472664 523 const OpenGl_Vec4* aHighlightColor = theWorkspace->HighlightColor;
2166f0fa 524 if (myHighlightColor)
7d9e854b 525 theWorkspace->HighlightColor = myHighlightColor;
2166f0fa 526
b859a34d 527 // Collect clipping planes of structure scope
3202bf1e 528 aCtx->ChangeClipping().SetLocalPlanes (aCtx, myClipPlanes);
4269bd1b 529
1a7ece8f 530 // True if structure is fully clipped
531 bool isClipped = false;
3202bf1e 532 bool hasDisabled = false;
533 if (aCtx->Clipping().IsClippingOrCappingOn())
1a7ece8f 534 {
3202bf1e 535 const Graphic3d_BndBox4f& aBBox = BoundingBox();
778cd667 536 if ((!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d())
3202bf1e 537 || (!myClipPlanes.IsNull() && myClipPlanes->ToOverrideGlobal()))
1a7ece8f 538 {
3202bf1e 539 aCtx->ChangeClipping().DisableGlobal (aCtx);
540 hasDisabled = aCtx->Clipping().HasDisabled();
541 }
1a7ece8f 542
3202bf1e 543 // Set of clipping planes that do not intersect the structure,
544 // and thus can be disabled to improve rendering performance
545 if (aBBox.IsValid()
778cd667 546 && myTrsfPers.IsNull())
3202bf1e 547 {
548 for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next())
1a7ece8f 549 {
3202bf1e 550 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
551 if (!aPlane->IsOn())
552 {
553 continue;
554 }
1a7ece8f 555
3202bf1e 556 // check for clipping
557 const Graphic3d_Vec4d& aPlaneEquation = aPlane->GetEquation();
558 const Graphic3d_Vec4d aMaxPnt (aPlaneEquation.x() > 0.0 ? aBBox.CornerMax().x() : aBBox.CornerMin().x(),
559 aPlaneEquation.y() > 0.0 ? aBBox.CornerMax().y() : aBBox.CornerMin().y(),
560 aPlaneEquation.z() > 0.0 ? aBBox.CornerMax().z() : aBBox.CornerMin().z(),
561 1.0);
562 if (aPlaneEquation.Dot (aMaxPnt) < 0.0) // max vertex is outside the half-space
563 {
564 isClipped = true;
565 break;
566 }
567
568 // check for no intersection (e.g. object is "entirely not clipped")
569 const Graphic3d_Vec4d aMinPnt (aPlaneEquation.x() > 0.0 ? aBBox.CornerMin().x() : aBBox.CornerMax().x(),
570 aPlaneEquation.y() > 0.0 ? aBBox.CornerMin().y() : aBBox.CornerMax().y(),
571 aPlaneEquation.z() > 0.0 ? aBBox.CornerMin().z() : aBBox.CornerMax().z(),
572 1.0);
573 if (aPlaneEquation.Dot (aMinPnt) > 0.0) // min vertex is inside the half-space
1a7ece8f 574 {
3202bf1e 575 aCtx->ChangeClipping().SetEnabled (aCtx, aPlaneIt, Standard_False);
576 hasDisabled = true;
1a7ece8f 577 }
1a7ece8f 578 }
579 }
3202bf1e 580
581 if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
582 || hasDisabled)
583 {
584 // Set OCCT state uniform variables
585 aCtx->ShaderManager()->UpdateClippingState();
586 }
1a7ece8f 587 }
588
2166f0fa 589 // Render groups
cc6852f3 590 bool hasClosedPrims = false;
1a7ece8f 591 if (!isClipped)
592 {
593 renderGeometry (theWorkspace, hasClosedPrims);
594 }
2166f0fa 595
7d9e854b 596 // Reset correction for mirror transform
597 if (myIsMirrored)
c827ea3a 598 {
599 aCtx->core11fwd->glFrontFace (GL_CCW);
600 }
7d9e854b 601
b859a34d 602 // Render capping for structure groups
cc6852f3 603 if (hasClosedPrims
1a7ece8f 604 && aCtx->Clipping().IsCappingOn())
b859a34d 605 {
cc6852f3 606 OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
b859a34d 607 }
4269bd1b 608
b859a34d 609 // Revert structure clippings
3202bf1e 610 if (hasDisabled)
1a7ece8f 611 {
612 // enable planes that were previously disabled
3202bf1e 613 aCtx->ChangeClipping().RestoreDisabled (aCtx);
1a7ece8f 614 }
3202bf1e 615 aCtx->ChangeClipping().SetLocalPlanes (aCtx, Handle(Graphic3d_SequenceOfHClipPlane)());
616 if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
617 || hasDisabled)
4269bd1b 618 {
30f0ad28 619 // Set OCCT state uniform variables
deb02f86 620 aCtx->ShaderManager()->RevertClippingState();
4269bd1b 621 }
622
825aa485 623 // Restore local transformation
6bd94e0d 624 aCtx->ModelWorldState.Pop();
625 aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
778cd667 626 if (!myTrsfPers.IsNull())
825aa485 627 {
825aa485 628 aCtx->WorldViewState.Pop();
825aa485 629 }
c827ea3a 630
2166f0fa 631 // Restore highlight color
7d9e854b 632 theWorkspace->HighlightColor = aHighlightColor;
2166f0fa
SK
633
634 // Restore aspects
f9ba5c4d 635 theWorkspace->SetAspectLine (aPrevAspectLine);
636 theWorkspace->SetAspectFace (aPrevAspectFace);
637 theWorkspace->SetAspectMarker (aPrevAspectMarker);
638 theWorkspace->SetAspectText (aPrevAspectText);
2166f0fa 639
b7cd4ba7 640 // Apply highlight box
641 if (!myHighlightBox.IsNull())
642 {
7d9e854b 643 myHighlightBox->Render (theWorkspace);
b7cd4ba7 644 }
645
2166f0fa 646 // Restore named status
f9ba5c4d 647 theWorkspace->SetHighlight (false);
2166f0fa
SK
648}
649
5e27df78 650// =======================================================================
651// function : Release
652// purpose :
653// =======================================================================
654void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
655{
656 // Release groups
657 Clear (theGlCtx);
b64d84be 658 clearHighlightColor (theGlCtx);
5e27df78 659}
660
dd8a4ce9 661// =======================================================================
662// function : ReleaseGlResources
663// purpose :
664// =======================================================================
665void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
666{
b64d84be 667 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
dd8a4ce9 668 {
b64d84be 669 aGroupIter.ChangeValue()->Release (theGlCtx);
dd8a4ce9 670 }
b64d84be 671 if (!myHighlightBox.IsNull())
dd8a4ce9 672 {
10b9c7df 673 myHighlightBox->Release (theGlCtx.operator->());
dd8a4ce9 674 }
675}
676
59f45b7c 677//=======================================================================
679ecdee 678//function : ShadowLink
679//purpose :
680//=======================================================================
681Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
682{
683 return new OpenGl_StructureShadow (theManager, this);
684}