0030679: Attached model hangs most of OCCT common functionality
[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>
25c35042 19#include <OpenGl_ClippingIterator.hxx>
63bcc448 20#include <OpenGl_GraphicDriver.hxx>
30f0ad28 21#include <OpenGl_ShaderManager.hxx>
22#include <OpenGl_ShaderProgram.hxx>
2bd4bfac 23#include <OpenGl_StructureShadow.hxx>
30f0ad28 24#include <OpenGl_Vec.hxx>
25#include <OpenGl_View.hxx>
26#include <OpenGl_Workspace.hxx>
2166f0fa 27
92efcf78 28IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure)
29
98b15dbf 30// =======================================================================
31// function : renderBoundingBox
32// purpose :
33// =======================================================================
34void OpenGl_Structure::renderBoundingBox (const Handle(OpenGl_Workspace)& theWorkspace) const
27eed937 35{
98b15dbf 36 if (!myBndBox.IsValid())
27eed937 37 {
98b15dbf 38 return;
27eed937 39 }
40
98b15dbf 41 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
42 const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
43 const Graphic3d_ZLayerSettings& aLayer = myGraphicDriver->ZLayerSettings (myZLayer);
44 const Graphic3d_Vec3d aMoveVec = myTrsfPers.IsNull()
45 && !aLayer.OriginTransformation().IsNull()
46 ? -Graphic3d_Vec3d (aLayer.Origin().X(), aLayer.Origin().Y(), aLayer.Origin().Z())
47 : Graphic3d_Vec3d (0.0, 0.0, 0.0);
48 if (aCtx->core20fwd != NULL
49 && aCtx->ShaderManager()->BindBoundBoxProgram())
50 {
51 const Graphic3d_Vec3d aCenter = myBndBox.Center() + aMoveVec;
52 const Graphic3d_Vec3d aSize = myBndBox.Size();
53 aCtx->ActiveProgram()->SetUniform (aCtx, "occBBoxCenter", Graphic3d_Vec3 ((float )aCenter.x(), (float )aCenter.y(), (float )aCenter.z()));
54 aCtx->ActiveProgram()->SetUniform (aCtx, "occBBoxSize", Graphic3d_Vec3 ((float )aSize.x(), (float )aSize.y(), (float )aSize.z()));
bf5f0ca2 55 aCtx->SetColor4fv (theWorkspace->InteriorColor());
98b15dbf 56
57 const Handle(OpenGl_VertexBuffer)& aBoundBoxVertBuffer = aCtx->ShaderManager()->BoundBoxVertBuffer();
58 aBoundBoxVertBuffer->BindAttribute (aCtx, Graphic3d_TOA_POS);
59 aCtx->core20fwd->glDrawArrays (GL_LINES, 0, aBoundBoxVertBuffer->GetElemsNb());
60 aBoundBoxVertBuffer->UnbindAttribute(aCtx, Graphic3d_TOA_POS);
61 }
62#if !defined(GL_ES_VERSION_2_0)
63 else if (aCtx->core11 != NULL)
27eed937 64 {
98b15dbf 65 const Graphic3d_Vec3d aMind = myBndBox.CornerMin() + aMoveVec;
66 const Graphic3d_Vec3d aMaxd = myBndBox.CornerMax() + aMoveVec;
67 const Graphic3d_Vec3 aMin ((float )aMind.x(), (float )aMind.y(), (float )aMind.z());
68 const Graphic3d_Vec3 aMax ((float )aMaxd.x(), (float )aMaxd.y(), (float )aMaxd.z());
69 const OpenGl_Vec3 aVerts[16] =
70 {
71 OpenGl_Vec3 (aMin.x(), aMin.y(), aMin.z()),
72 OpenGl_Vec3 (aMin.x(), aMin.y(), aMax.z()),
73 OpenGl_Vec3 (aMin.x(), aMax.y(), aMax.z()),
74 OpenGl_Vec3 (aMin.x(), aMax.y(), aMin.z()),
75 OpenGl_Vec3 (aMin.x(), aMin.y(), aMin.z()),
76 OpenGl_Vec3 (aMax.x(), aMin.y(), aMin.z()),
77 OpenGl_Vec3 (aMax.x(), aMin.y(), aMax.z()),
78 OpenGl_Vec3 (aMax.x(), aMax.y(), aMax.z()),
79 OpenGl_Vec3 (aMax.x(), aMax.y(), aMin.z()),
80 OpenGl_Vec3 (aMax.x(), aMin.y(), aMin.z()),
81 OpenGl_Vec3 (aMax.x(), aMax.y(), aMin.z()),
82 OpenGl_Vec3 (aMin.x(), aMax.y(), aMin.z()),
83 OpenGl_Vec3 (aMin.x(), aMax.y(), aMax.z()),
84 OpenGl_Vec3 (aMax.x(), aMax.y(), aMax.z()),
85 OpenGl_Vec3 (aMax.x(), aMin.y(), aMax.z()),
86 OpenGl_Vec3 (aMin.x(), aMin.y(), aMax.z())
87 };
88
89 aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID, Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, false, Handle(OpenGl_ShaderProgram)());
bf5f0ca2 90 aCtx->SetColor4fv (theWorkspace->InteriorColor());
98b15dbf 91 aCtx->core11fwd->glDisable (GL_LIGHTING);
92 aCtx->core11->glEnableClientState (GL_VERTEX_ARRAY);
93 aCtx->core11->glVertexPointer (3, GL_FLOAT, 0, aVerts[0].GetData());
94 aCtx->core11fwd->glDrawArrays (GL_LINE_STRIP, 0, 16);
95 aCtx->core11->glDisableClientState (GL_VERTEX_ARRAY);
27eed937 96 }
98b15dbf 97#endif
98 aCtx->BindTextures (aPrevTexture);
99}
2166f0fa 100
4269bd1b 101// =======================================================================
4269bd1b 102// function : OpenGl_Structure
103// purpose :
104// =======================================================================
63bcc448 105OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
106: Graphic3d_CStructure (theManager),
d4aaad5b 107 myInstancedStructure (NULL),
108 myIsRaytracable (Standard_False),
109 myModificationState (0),
d4aaad5b 110 myIsMirrored (Standard_False)
2166f0fa 111{
7c3ef2f7 112 updateLayerTransformation();
2166f0fa
SK
113}
114
4269bd1b 115// =======================================================================
116// function : ~OpenGl_Structure
117// purpose :
118// =======================================================================
5e27df78 119OpenGl_Structure::~OpenGl_Structure()
2166f0fa 120{
5e27df78 121 Release (Handle(OpenGl_Context)());
2166f0fa
SK
122}
123
4269bd1b 124// =======================================================================
7c3ef2f7 125// function : SetZLayer
126// purpose :
127// =======================================================================
128void OpenGl_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerIndex)
129{
130 Graphic3d_CStructure::SetZLayer (theLayerIndex);
131 updateLayerTransformation();
132}
133
134// =======================================================================
1f7f5a90 135// function : SetTransformation
63bcc448 136// purpose :
137// =======================================================================
1f7f5a90 138void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf)
63bcc448 139{
1f7f5a90 140 myTrsf = theTrsf;
141 myIsMirrored = Standard_False;
142 if (!myTrsf.IsNull())
143 {
144 // Determinant of transform matrix less then 0 means that mirror transform applied.
145 const Standard_Real aDet = myTrsf->Value(1, 1) * (myTrsf->Value (2, 2) * myTrsf->Value (3, 3) - myTrsf->Value (3, 2) * myTrsf->Value (2, 3))
146 - myTrsf->Value(1, 2) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 3) - myTrsf->Value (3, 1) * myTrsf->Value (2, 3))
147 + myTrsf->Value(1, 3) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 2) - myTrsf->Value (3, 1) * myTrsf->Value (2, 2));
148 myIsMirrored = aDet < 0.0;
149 }
7d9e854b 150
7c3ef2f7 151 updateLayerTransformation();
d4aaad5b 152 if (IsRaytracable())
e276548b 153 {
d4aaad5b 154 ++myModificationState;
e276548b 155 }
2166f0fa
SK
156}
157
4269bd1b 158// =======================================================================
7c3ef2f7 159// function : SetTransformPersistence
160// purpose :
161// =======================================================================
162void OpenGl_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
163{
164 myTrsfPers = theTrsfPers;
165 updateLayerTransformation();
166}
167
168// =======================================================================
169// function : updateLayerTransformation
170// purpose :
171// =======================================================================
172void OpenGl_Structure::updateLayerTransformation()
173{
174 gp_Trsf aRenderTrsf;
175 if (!myTrsf.IsNull())
176 {
177 aRenderTrsf = myTrsf->Trsf();
178 }
179
180 const Graphic3d_ZLayerSettings& aLayer = myGraphicDriver->ZLayerSettings (myZLayer);
181 if (!aLayer.OriginTransformation().IsNull()
182 && myTrsfPers.IsNull())
183 {
184 aRenderTrsf.SetTranslationPart (aRenderTrsf.TranslationPart() - aLayer.Origin());
185 }
186 aRenderTrsf.GetMat4 (myRenderTrsf);
187}
188
189// =======================================================================
8e5fb5ea 190// function : GraphicHighlight
4269bd1b 191// purpose :
192// =======================================================================
98b15dbf 193void OpenGl_Structure::GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle)
2166f0fa 194{
8e5fb5ea 195 myHighlightStyle = theStyle;
8e5fb5ea 196 highlight = 1;
2166f0fa
SK
197}
198
4269bd1b 199// =======================================================================
8e5fb5ea 200// function : GraphicUnhighlight
4269bd1b 201// purpose :
202// =======================================================================
8e5fb5ea 203void OpenGl_Structure::GraphicUnhighlight()
2166f0fa 204{
8e5fb5ea 205 highlight = 0;
8e5fb5ea 206 myHighlightStyle.Nullify();
2166f0fa
SK
207}
208
4269bd1b 209// =======================================================================
a1954302 210// function : OnVisibilityChanged
e276548b 211// purpose :
212// =======================================================================
a1954302 213void OpenGl_Structure::OnVisibilityChanged()
e276548b 214{
d4aaad5b 215 if (IsRaytracable())
e276548b 216 {
d4aaad5b 217 ++myModificationState;
e276548b 218 }
e276548b 219}
220
e276548b 221// =======================================================================
d4aaad5b 222// function : IsRaytracable
e276548b 223// purpose :
224// =======================================================================
d4aaad5b 225Standard_Boolean OpenGl_Structure::IsRaytracable() const
e276548b 226{
3e05329c 227 if (!myGroups.IsEmpty()
228 && myIsRaytracable)
e276548b 229 {
3e05329c 230 return Standard_True;
e276548b 231 }
d5af8626 232
3e05329c 233 return myInstancedStructure != NULL
234 && myInstancedStructure->IsRaytracable();
d5af8626 235}
236
237// =======================================================================
d4aaad5b 238// function : UpdateRaytracableState
e276548b 239// purpose :
240// =======================================================================
d4aaad5b 241void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const
e276548b 242{
3e05329c 243 myIsRaytracable = !toCheck;
244 if (!myIsRaytracable)
245 {
246 for (OpenGl_Structure::GroupIterator anIter (myGroups); anIter.More(); anIter.Next())
247 {
248 if (anIter.Value()->IsRaytracable())
249 {
250 myIsRaytracable = Standard_True;
251 break;
252 }
253 }
254 }
e276548b 255
d4aaad5b 256 if (IsRaytracable())
e276548b 257 {
d4aaad5b 258 ++myModificationState;
e276548b 259 }
260}
261
e276548b 262// =======================================================================
4269bd1b 263// function : Connect
264// purpose :
265// =======================================================================
63bcc448 266void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure)
2166f0fa 267{
d4aaad5b 268 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
269
270 Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct,
271 "Error! Instanced structure is already defined");
272
273 myInstancedStructure = aStruct;
e276548b 274
63bcc448 275 if (aStruct->IsRaytracable())
e276548b 276 {
d4aaad5b 277 UpdateStateIfRaytracable (Standard_False);
e276548b 278 }
2166f0fa
SK
279}
280
4269bd1b 281// =======================================================================
282// function : Disconnect
283// purpose :
284// =======================================================================
63bcc448 285void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure)
2166f0fa 286{
d4aaad5b 287 OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure);
e276548b 288
d4aaad5b 289 if (myInstancedStructure == aStruct)
290 {
291 myInstancedStructure = NULL;
e276548b 292
d4aaad5b 293 if (aStruct->IsRaytracable())
294 {
295 UpdateStateIfRaytracable();
2166f0fa 296 }
2166f0fa
SK
297 }
298}
299
4269bd1b 300// =======================================================================
b64d84be 301// function : NewGroup
4269bd1b 302// purpose :
303// =======================================================================
b64d84be 304Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct)
2166f0fa 305{
b64d84be 306 Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct);
307 myGroups.Append (aGroup);
308 return aGroup;
2166f0fa
SK
309}
310
4269bd1b 311// =======================================================================
312// function : RemoveGroup
313// purpose :
314// =======================================================================
b64d84be 315void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup)
2166f0fa 316{
b64d84be 317 if (theGroup.IsNull())
318 {
319 return;
320 }
321
322 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa
SK
323 {
324 // Check for the given group
b64d84be 325 if (aGroupIter.Value() == theGroup)
2166f0fa 326 {
d4aaad5b 327 const Standard_Boolean wasRaytracable =
328 static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable();
329
b64d84be 330 theGroup->Clear (Standard_False);
e276548b 331
d4aaad5b 332 if (wasRaytracable)
e276548b 333 {
d4aaad5b 334 UpdateStateIfRaytracable();
e276548b 335 }
e276548b 336
b64d84be 337 myGroups.Remove (aGroupIter);
2166f0fa
SK
338 return;
339 }
2166f0fa
SK
340 }
341}
342
4269bd1b 343// =======================================================================
344// function : Clear
345// purpose :
346// =======================================================================
63bcc448 347void OpenGl_Structure::Clear()
348{
349 Clear (GlDriver()->GetSharedContext());
350}
351
352// =======================================================================
353// function : Clear
354// purpose :
355// =======================================================================
5e27df78 356void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx)
2166f0fa 357{
e276548b 358 Standard_Boolean aRaytracableGroupDeleted (Standard_False);
e276548b 359
5e27df78 360 // Release groups
b64d84be 361 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
2166f0fa 362 {
b64d84be 363 aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable();
5322131b 364
2166f0fa 365 // Delete objects
b64d84be 366 aGroupIter.ChangeValue()->Release (theGlCtx);
2166f0fa
SK
367 }
368 myGroups.Clear();
e276548b 369
e276548b 370 if (aRaytracableGroupDeleted)
371 {
d4aaad5b 372 myIsRaytracable = Standard_False;
e276548b 373 }
b7cd4ba7 374
375 Is2dText = Standard_False;
376 IsForHighlight = Standard_False;
2166f0fa
SK
377}
378
4269bd1b 379// =======================================================================
cc6852f3 380// function : renderGeometry
0717ddc1 381// purpose :
382// =======================================================================
cc6852f3 383void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
384 bool& theHasClosed) const
0717ddc1 385{
cc6852f3 386 if (myInstancedStructure != NULL)
0717ddc1 387 {
cc6852f3 388 myInstancedStructure->renderGeometry (theWorkspace, theHasClosed);
389 }
390
391 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
392 {
393 theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed();
7d9e854b 394 aGroupIter.Value()->Render (theWorkspace);
0717ddc1 395 }
396}
cc6852f3 397
398// =======================================================================
4269bd1b 399// function : Render
400// purpose :
401// =======================================================================
7d9e854b 402void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
2166f0fa
SK
403{
404 // Process the structure only if visible
a1954302 405 if (!visible)
7d9e854b 406 {
2166f0fa 407 return;
7d9e854b 408 }
2166f0fa 409
c827ea3a 410 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
b7cd4ba7 411
2166f0fa 412 // Render named status
98b15dbf 413 if (highlight && !myHighlightStyle.IsNull() && myHighlightStyle->Method() != Aspect_TOHM_BOUNDBOX)
a1954302 414 {
f838dac4 415 theWorkspace->SetHighlightStyle (myHighlightStyle);
a1954302 416 }
2166f0fa 417
2166f0fa 418 // Apply local transformation
6bd94e0d 419 aCtx->ModelWorldState.Push();
1f7f5a90 420 OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent();
7c3ef2f7 421 aModelWorld = myRenderTrsf;
6bd94e0d 422
1d92133e 423 const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
1d92133e 424#if !defined(GL_ES_VERSION_2_0)
425 // detect scale transform
1f7f5a90 426 if (aCtx->core11 != NULL
427 && !myTrsf.IsNull())
1d92133e 428 {
1f7f5a90 429 const Standard_Real aScale = myTrsf->ScaleFactor();
430 if (Abs (aScale - 1.0) > Precision::Confusion())
1d92133e 431 {
432 aCtx->SetGlNormalizeEnabled (Standard_True);
433 }
434 }
435#endif
436
778cd667 437 if (!myTrsfPers.IsNull())
825aa485 438 {
825aa485 439 aCtx->WorldViewState.Push();
7c3ef2f7 440 OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent();
441 myTrsfPers->Apply (theWorkspace->View()->Camera(),
442 aCtx->ProjectionState.Current(), aWorldView,
56689b27 443 aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
2166f0fa 444
1d92133e 445 #if !defined(GL_ES_VERSION_2_0)
446 if (!aCtx->IsGlNormalizeEnabled()
447 && aCtx->core11 != NULL)
448 {
449 const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor<Standard_ShortReal> (aWorldView);
7c3ef2f7 450 if (Abs (aScale - 1.0) > Precision::Confusion())
1d92133e 451 {
452 aCtx->SetGlNormalizeEnabled (Standard_True);
453 }
454 }
455 #endif
04be5003 456 }
457
d437b80d 458 // Take into account transform persistence
459 aCtx->ApplyModelViewMatrix();
c827ea3a 460
f9ba5c4d 461 // remember aspects
bf5f0ca2 462 const OpenGl_Aspects* aPrevAspectFace = theWorkspace->Aspects();
7d9e854b 463
464 // Apply correction for mirror transform
465 if (myIsMirrored)
466 {
c827ea3a 467 aCtx->core11fwd->glFrontFace (GL_CW);
7d9e854b 468 }
2166f0fa 469
b859a34d 470 // Collect clipping planes of structure scope
25c35042 471 aCtx->ChangeClipping().SetLocalPlanes (myClipPlanes);
4269bd1b 472
1a7ece8f 473 // True if structure is fully clipped
474 bool isClipped = false;
3202bf1e 475 bool hasDisabled = false;
476 if (aCtx->Clipping().IsClippingOrCappingOn())
1a7ece8f 477 {
7c3ef2f7 478 const Graphic3d_BndBox3d& aBBox = BoundingBox();
8b1441e3 479 if (!myClipPlanes.IsNull()
480 && myClipPlanes->ToOverrideGlobal())
1a7ece8f 481 {
25c35042 482 aCtx->ChangeClipping().DisableGlobal();
3202bf1e 483 hasDisabled = aCtx->Clipping().HasDisabled();
484 }
8b1441e3 485 else if (!myTrsfPers.IsNull())
486 {
487 if (myTrsfPers->IsZoomOrRotate())
488 {
489 // Zoom/rotate persistence object lives in two worlds at the same time.
490 // Global clipping planes can not be trivially applied without being converted
491 // into local space of transformation persistence object.
492 // As more simple alternative - just clip entire object by its anchor point defined in the world space.
493 const gp_Pnt anAnchor = myTrsfPers->AnchorPoint();
494 for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More() && aPlaneIt.IsGlobal(); aPlaneIt.Next())
495 {
496 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
497 if (!aPlane->IsOn())
498 {
499 continue;
500 }
501
502 // check for clipping
8b1441e3 503 const Graphic3d_Vec4d aCheckPnt (anAnchor.X(), anAnchor.Y(), anAnchor.Z(), 1.0);
25c35042 504 if (aPlane->ProbePoint (aCheckPnt) == Graphic3d_ClipState_Out)
8b1441e3 505 {
506 isClipped = true;
507 break;
508 }
509 }
510 }
511
25c35042 512 aCtx->ChangeClipping().DisableGlobal();
8b1441e3 513 hasDisabled = aCtx->Clipping().HasDisabled();
514 }
1a7ece8f 515
3202bf1e 516 // Set of clipping planes that do not intersect the structure,
517 // and thus can be disabled to improve rendering performance
518 if (aBBox.IsValid()
778cd667 519 && myTrsfPers.IsNull())
3202bf1e 520 {
521 for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next())
1a7ece8f 522 {
3202bf1e 523 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
32ca7711 524 if (aPlaneIt.IsDisabled())
3202bf1e 525 {
526 continue;
527 }
1a7ece8f 528
25c35042 529 const Graphic3d_ClipState aBoxState = aPlane->ProbeBox (aBBox);
530 if (aBoxState == Graphic3d_ClipState_Out)
3202bf1e 531 {
532 isClipped = true;
533 break;
534 }
25c35042 535 else if (aBoxState == Graphic3d_ClipState_In)
1a7ece8f 536 {
25c35042 537 aCtx->ChangeClipping().SetEnabled (aPlaneIt, false);
3202bf1e 538 hasDisabled = true;
1a7ece8f 539 }
1a7ece8f 540 }
541 }
3202bf1e 542
543 if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
544 || hasDisabled)
545 {
546 // Set OCCT state uniform variables
547 aCtx->ShaderManager()->UpdateClippingState();
548 }
1a7ece8f 549 }
550
2166f0fa 551 // Render groups
cc6852f3 552 bool hasClosedPrims = false;
1a7ece8f 553 if (!isClipped)
554 {
555 renderGeometry (theWorkspace, hasClosedPrims);
556 }
2166f0fa 557
7d9e854b 558 // Reset correction for mirror transform
559 if (myIsMirrored)
c827ea3a 560 {
561 aCtx->core11fwd->glFrontFace (GL_CCW);
562 }
7d9e854b 563
b859a34d 564 // Render capping for structure groups
cc6852f3 565 if (hasClosedPrims
1a7ece8f 566 && aCtx->Clipping().IsCappingOn())
b859a34d 567 {
cc6852f3 568 OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
b859a34d 569 }
4269bd1b 570
b859a34d 571 // Revert structure clippings
3202bf1e 572 if (hasDisabled)
1a7ece8f 573 {
574 // enable planes that were previously disabled
25c35042 575 aCtx->ChangeClipping().RestoreDisabled();
1a7ece8f 576 }
25c35042 577 aCtx->ChangeClipping().SetLocalPlanes (Handle(Graphic3d_SequenceOfHClipPlane)());
3202bf1e 578 if ((!myClipPlanes.IsNull() && !myClipPlanes->IsEmpty())
579 || hasDisabled)
4269bd1b 580 {
30f0ad28 581 // Set OCCT state uniform variables
deb02f86 582 aCtx->ShaderManager()->RevertClippingState();
4269bd1b 583 }
584
825aa485 585 // Restore local transformation
6bd94e0d 586 aCtx->ModelWorldState.Pop();
587 aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
c827ea3a 588
2166f0fa 589 // Restore aspects
bf5f0ca2 590 theWorkspace->SetAspects (aPrevAspectFace);
2166f0fa 591
b7cd4ba7 592 // Apply highlight box
98b15dbf 593 if (!isClipped
594 && !myHighlightStyle.IsNull()
595 && myHighlightStyle->Method() == Aspect_TOHM_BOUNDBOX)
b7cd4ba7 596 {
98b15dbf 597 aCtx->ApplyModelViewMatrix();
f838dac4 598 theWorkspace->SetHighlightStyle (myHighlightStyle);
98b15dbf 599 renderBoundingBox (theWorkspace);
600 }
601
602 if (!myTrsfPers.IsNull())
603 {
604 aCtx->WorldViewState.Pop();
b7cd4ba7 605 }
606
2166f0fa 607 // Restore named status
f838dac4 608 theWorkspace->SetHighlightStyle (Handle(Graphic3d_PresentationAttributes)());
2166f0fa
SK
609}
610
5e27df78 611// =======================================================================
612// function : Release
613// purpose :
614// =======================================================================
615void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx)
616{
617 // Release groups
618 Clear (theGlCtx);
8e5fb5ea 619 myHighlightStyle.Nullify();
5e27df78 620}
621
dd8a4ce9 622// =======================================================================
623// function : ReleaseGlResources
624// purpose :
625// =======================================================================
626void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
627{
b64d84be 628 for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
dd8a4ce9 629 {
b64d84be 630 aGroupIter.ChangeValue()->Release (theGlCtx);
dd8a4ce9 631 }
dd8a4ce9 632}
633
59f45b7c 634//=======================================================================
679ecdee 635//function : ShadowLink
636//purpose :
637//=======================================================================
638Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const
639{
640 return new OpenGl_StructureShadow (theManager, this);
641}