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