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