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> |
63bcc448 | 19 | #include <OpenGl_GraphicDriver.hxx> |
30f0ad28 | 20 | #include <OpenGl_ShaderManager.hxx> |
21 | #include <OpenGl_ShaderProgram.hxx> | |
2bd4bfac | 22 | #include <OpenGl_StructureShadow.hxx> |
2166f0fa | 23 | #include <OpenGl_telem_util.hxx> |
30f0ad28 | 24 | #include <OpenGl_Vec.hxx> |
25 | #include <OpenGl_View.hxx> | |
26 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 27 | |
494782f6 | 28 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
b859a34d | 29 | |
63bcc448 | 30 | |
27eed937 | 31 | //! Auxiliary class for bounding box presentation |
32 | class OpenGl_BndBoxPrs : public OpenGl_Element | |
33 | { | |
34 | ||
35 | public: | |
36 | ||
37 | //! Main constructor | |
b7cd4ba7 | 38 | OpenGl_BndBoxPrs (const Graphic3d_BndBox4f& theBndBox) |
39 | { | |
40 | const float Xm = theBndBox.CornerMin().x(); | |
41 | const float Ym = theBndBox.CornerMin().y(); | |
42 | const float Zm = theBndBox.CornerMin().z(); | |
43 | const float XM = theBndBox.CornerMax().x(); | |
44 | const float YM = theBndBox.CornerMax().y(); | |
45 | const float ZM = theBndBox.CornerMax().z(); | |
46 | ||
27eed937 | 47 | myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm); |
48 | myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM); | |
49 | myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM); | |
50 | myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm); | |
51 | myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm); | |
52 | myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm); | |
53 | myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM); | |
54 | myVerts[7] = OpenGl_Vec3 (XM, YM, ZM); | |
55 | myVerts[8] = OpenGl_Vec3 (XM, YM, Zm); | |
56 | myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm); | |
57 | myVerts[10] = OpenGl_Vec3 (XM, YM, Zm); | |
58 | myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm); | |
59 | myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM); | |
60 | myVerts[13] = OpenGl_Vec3 (XM, YM, ZM); | |
61 | myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM); | |
62 | myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM); | |
63 | } | |
64 | ||
65 | //! Render presentation | |
66 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const | |
67 | { | |
ca3c13d1 | 68 | #if !defined(GL_ES_VERSION_2_0) |
27eed937 | 69 | // Apply line aspect |
70 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); | |
71 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); | |
72 | ||
73 | glDisable (GL_LIGHTING); | |
27eed937 | 74 | |
75 | // Use highlight colors | |
ca3c13d1 | 76 | theWorkspace->GetGlContext()->core11->glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb); |
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 | } | |
ca3c13d1 | 88 | #endif |
27eed937 | 89 | } |
90 | ||
91 | //! Release graphical resources | |
10b9c7df | 92 | virtual void Release (OpenGl_Context*) |
27eed937 | 93 | { |
94 | // | |
95 | } | |
96 | ||
97 | protected: | |
98 | ||
99 | //! Protected destructor | |
100 | virtual ~OpenGl_BndBoxPrs() {} | |
101 | ||
102 | private: | |
103 | ||
104 | OpenGl_Vec3 myVerts[16]; //!< vertices array | |
105 | ||
106 | public: | |
107 | ||
108 | DEFINE_STANDARD_ALLOC | |
109 | ||
110 | }; | |
2166f0fa SK |
111 | |
112 | /*----------------------------------------------------------------------*/ | |
113 | ||
4269bd1b | 114 | // ======================================================================= |
115 | // function : OpenGl_Structure | |
116 | // purpose : | |
117 | // ======================================================================= | |
63bcc448 | 118 | OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager) |
119 | : Graphic3d_CStructure (theManager), | |
d4aaad5b | 120 | myTransformation (NULL), |
121 | myTransPers (NULL), | |
122 | myAspectLine (NULL), | |
123 | myAspectFace (NULL), | |
124 | myAspectMarker (NULL), | |
125 | myAspectText (NULL), | |
126 | myHighlightColor (NULL), | |
127 | myInstancedStructure (NULL), | |
128 | myIsRaytracable (Standard_False), | |
129 | myModificationState (0), | |
130 | myIsCulled (Standard_True), | |
131 | myIsMirrored (Standard_False) | |
2166f0fa | 132 | { |
a1954302 | 133 | // |
2166f0fa SK |
134 | } |
135 | ||
4269bd1b | 136 | // ======================================================================= |
137 | // function : ~OpenGl_Structure | |
138 | // purpose : | |
139 | // ======================================================================= | |
5e27df78 | 140 | OpenGl_Structure::~OpenGl_Structure() |
2166f0fa | 141 | { |
5e27df78 | 142 | Release (Handle(OpenGl_Context)()); |
143 | delete myTransformation; myTransformation = NULL; | |
144 | delete myTransPers; myTransPers = NULL; | |
2166f0fa SK |
145 | } |
146 | ||
4269bd1b | 147 | // ======================================================================= |
63bcc448 | 148 | // function : UpdateAspects |
4269bd1b | 149 | // purpose : |
150 | // ======================================================================= | |
63bcc448 | 151 | void OpenGl_Structure::UpdateAspects() |
2166f0fa | 152 | { |
63bcc448 | 153 | SetTransformPersistence (TransformPersistence); |
154 | ||
155 | if (ContextLine.IsDef) | |
156 | SetAspectLine (ContextLine); | |
157 | ||
158 | if (ContextFillArea.IsDef) | |
159 | SetAspectFace (ContextFillArea); | |
160 | ||
161 | if (ContextMarker.IsDef) | |
162 | SetAspectMarker (ContextMarker); | |
163 | ||
164 | if (ContextText.IsDef) | |
165 | SetAspectText (ContextText); | |
166 | } | |
167 | ||
168 | // ======================================================================= | |
169 | // function : UpdateTransformation | |
170 | // purpose : | |
171 | // ======================================================================= | |
172 | void OpenGl_Structure::UpdateTransformation() | |
173 | { | |
174 | if (myTransformation == NULL) | |
e276548b | 175 | { |
5e27df78 | 176 | myTransformation = new OpenGl_Matrix(); |
e276548b | 177 | } |
2166f0fa | 178 | |
7d9e854b | 179 | Standard_ShortReal (*aMat)[4] = Graphic3d_CStructure::Transformation; |
180 | ||
181 | Standard_ShortReal aDet = | |
182 | aMat[0][0] * (aMat[1][1] * aMat[2][2] - aMat[2][1] * aMat[1][2]) - | |
183 | aMat[0][1] * (aMat[1][0] * aMat[2][2] - aMat[2][0] * aMat[1][2]) + | |
184 | aMat[0][2] * (aMat[1][0] * aMat[2][1] - aMat[2][0] * aMat[1][1]); | |
185 | ||
186 | // Determinant of transform matrix less then 0 means that mirror transform applied. | |
187 | myIsMirrored = aDet < 0.0f; | |
188 | ||
63bcc448 | 189 | matcpy (myTransformation->mat, &Graphic3d_CStructure::Transformation[0][0]); |
e276548b | 190 | |
d4aaad5b | 191 | if (IsRaytracable()) |
e276548b | 192 | { |
d4aaad5b | 193 | ++myModificationState; |
e276548b | 194 | } |
2166f0fa SK |
195 | } |
196 | ||
4269bd1b | 197 | // ======================================================================= |
198 | // function : SetTransformPersistence | |
199 | // purpose : | |
200 | // ======================================================================= | |
2166f0fa SK |
201 | void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers) |
202 | { | |
203 | if (!myTransPers) | |
204 | myTransPers = new TEL_TRANSFORM_PERSISTENCE; | |
205 | ||
206 | myTransPers->mode = ATransPers.Flag; | |
207 | myTransPers->pointX = ATransPers.Point.x; | |
208 | myTransPers->pointY = ATransPers.Point.y; | |
209 | myTransPers->pointZ = ATransPers.Point.z; | |
b7cd4ba7 | 210 | MarkAsNotCulled(); |
2166f0fa SK |
211 | } |
212 | ||
4269bd1b | 213 | // ======================================================================= |
214 | // function : SetAspectLine | |
215 | // purpose : | |
216 | // ======================================================================= | |
fd4a6963 | 217 | void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) |
2166f0fa SK |
218 | { |
219 | if (!myAspectLine) | |
fd4a6963 | 220 | { |
5e27df78 | 221 | myAspectLine = new OpenGl_AspectLine(); |
fd4a6963 | 222 | } |
223 | myAspectLine->SetAspect (theAspect); | |
2166f0fa SK |
224 | } |
225 | ||
4269bd1b | 226 | // ======================================================================= |
227 | // function : SetAspectFace | |
228 | // purpose : | |
229 | // ======================================================================= | |
fd4a6963 | 230 | void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
2166f0fa SK |
231 | { |
232 | if (!myAspectFace) | |
bf75be98 | 233 | { |
5e27df78 | 234 | myAspectFace = new OpenGl_AspectFace(); |
bf75be98 | 235 | } |
fd4a6963 | 236 | myAspectFace->SetAspect (theAspect); |
e276548b | 237 | |
d4aaad5b | 238 | if (IsRaytracable()) |
e276548b | 239 | { |
d4aaad5b | 240 | ++myModificationState; |
e276548b | 241 | } |
2166f0fa SK |
242 | } |
243 | ||
4269bd1b | 244 | // ======================================================================= |
245 | // function : SetAspectMarker | |
246 | // purpose : | |
247 | // ======================================================================= | |
fd4a6963 | 248 | void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) |
2166f0fa SK |
249 | { |
250 | if (!myAspectMarker) | |
a577aaab | 251 | { |
5e27df78 | 252 | myAspectMarker = new OpenGl_AspectMarker(); |
a577aaab | 253 | } |
fd4a6963 | 254 | myAspectMarker->SetAspect (theAspect); |
2166f0fa SK |
255 | } |
256 | ||
4269bd1b | 257 | // ======================================================================= |
258 | // function : SetAspectText | |
259 | // purpose : | |
260 | // ======================================================================= | |
fd4a6963 | 261 | void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) |
2166f0fa SK |
262 | { |
263 | if (!myAspectText) | |
fd4a6963 | 264 | { |
5e27df78 | 265 | myAspectText = new OpenGl_AspectText(); |
fd4a6963 | 266 | } |
267 | myAspectText->SetAspect (theAspect); | |
2166f0fa SK |
268 | } |
269 | ||
4269bd1b | 270 | // ======================================================================= |
b64d84be | 271 | // function : clearHighlightBox |
4269bd1b | 272 | // purpose : |
273 | // ======================================================================= | |
b64d84be | 274 | void OpenGl_Structure::clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 275 | { |
b64d84be | 276 | if (!myHighlightBox.IsNull()) |
5e27df78 | 277 | { |
278 | myHighlightBox->Release (theGlCtx); | |
b64d84be | 279 | myHighlightBox.Nullify(); |
2166f0fa SK |
280 | } |
281 | } | |
282 | ||
63bcc448 | 283 | // ======================================================================= |
284 | // function : HighlightWithColor | |
285 | // purpose : | |
286 | // ======================================================================= | |
287 | void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor, | |
288 | const Standard_Boolean theToCreate) | |
289 | { | |
7d9e854b | 290 | const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext(); |
63bcc448 | 291 | if (theToCreate) |
7d9e854b | 292 | setHighlightColor (aContext, theColor); |
63bcc448 | 293 | else |
7d9e854b | 294 | clearHighlightColor (aContext); |
63bcc448 | 295 | } |
296 | ||
297 | // ======================================================================= | |
298 | // function : HighlightWithBndBox | |
299 | // purpose : | |
300 | // ======================================================================= | |
b64d84be | 301 | void OpenGl_Structure::HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct, |
302 | const Standard_Boolean theToCreate) | |
63bcc448 | 303 | { |
7d9e854b | 304 | const Handle(OpenGl_Context)& aContext = GlDriver()->GetSharedContext(); |
b64d84be | 305 | if (!theToCreate) |
306 | { | |
7d9e854b | 307 | clearHighlightBox (aContext); |
b64d84be | 308 | return; |
309 | } | |
310 | ||
311 | if (!myHighlightBox.IsNull()) | |
312 | { | |
7d9e854b | 313 | myHighlightBox->Release (aContext); |
b64d84be | 314 | } |
63bcc448 | 315 | else |
b64d84be | 316 | { |
317 | myHighlightBox = new OpenGl_Group (theStruct); | |
318 | } | |
319 | ||
320 | CALL_DEF_CONTEXTLINE& aContextLine = myHighlightBox->ChangeContextLine(); | |
321 | aContextLine.IsDef = 1; | |
b7cd4ba7 | 322 | aContextLine.Color = HighlightColor; |
b64d84be | 323 | aContextLine.LineType = Aspect_TOL_SOLID; |
324 | aContextLine.Width = 1.0f; | |
325 | myHighlightBox->UpdateAspectLine (Standard_True); | |
326 | ||
b7cd4ba7 | 327 | OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (myBndBox); |
b64d84be | 328 | myHighlightBox->AddElement (aBndBoxPrs); |
63bcc448 | 329 | } |
330 | ||
4269bd1b | 331 | // ======================================================================= |
b64d84be | 332 | // function : setHighlightColor |
4269bd1b | 333 | // purpose : |
334 | // ======================================================================= | |
b64d84be | 335 | void OpenGl_Structure::setHighlightColor (const Handle(OpenGl_Context)& theGlCtx, |
63bcc448 | 336 | const Graphic3d_Vec3& theColor) |
2166f0fa | 337 | { |
b64d84be | 338 | clearHighlightBox (theGlCtx); |
5e27df78 | 339 | if (myHighlightColor == NULL) |
340 | { | |
341 | myHighlightColor = new TEL_COLOUR(); | |
342 | } | |
2166f0fa | 343 | |
63bcc448 | 344 | myHighlightColor->rgb[0] = theColor.r(); |
345 | myHighlightColor->rgb[1] = theColor.g(); | |
346 | myHighlightColor->rgb[2] = theColor.b(); | |
2166f0fa SK |
347 | myHighlightColor->rgb[3] = 1.F; |
348 | } | |
349 | ||
4269bd1b | 350 | // ======================================================================= |
b64d84be | 351 | // function : clearHighlightColor |
4269bd1b | 352 | // purpose : |
353 | // ======================================================================= | |
b64d84be | 354 | void OpenGl_Structure::clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 355 | { |
b64d84be | 356 | clearHighlightBox(theGlCtx); |
5e27df78 | 357 | delete myHighlightColor; |
358 | myHighlightColor = NULL; | |
2166f0fa SK |
359 | } |
360 | ||
e276548b | 361 | // ======================================================================= |
a1954302 | 362 | // function : OnVisibilityChanged |
e276548b | 363 | // purpose : |
364 | // ======================================================================= | |
a1954302 | 365 | void OpenGl_Structure::OnVisibilityChanged() |
e276548b | 366 | { |
d4aaad5b | 367 | if (IsRaytracable()) |
e276548b | 368 | { |
d4aaad5b | 369 | ++myModificationState; |
e276548b | 370 | } |
e276548b | 371 | } |
372 | ||
e276548b | 373 | // ======================================================================= |
d4aaad5b | 374 | // function : IsRaytracable |
e276548b | 375 | // purpose : |
376 | // ======================================================================= | |
d4aaad5b | 377 | Standard_Boolean OpenGl_Structure::IsRaytracable() const |
e276548b | 378 | { |
d4aaad5b | 379 | if (!myGroups.IsEmpty()) |
e276548b | 380 | { |
d4aaad5b | 381 | return myIsRaytracable; // geometry structure |
e276548b | 382 | } |
d4aaad5b | 383 | else if (myInstancedStructure != NULL) |
e276548b | 384 | { |
d4aaad5b | 385 | return myInstancedStructure->IsRaytracable(); // instance structure |
e276548b | 386 | } |
d5af8626 | 387 | |
d4aaad5b | 388 | return Standard_False; // has no any groups or structures |
d5af8626 | 389 | } |
390 | ||
e276548b | 391 | // ======================================================================= |
d4aaad5b | 392 | // function : UpdateRaytracableState |
e276548b | 393 | // purpose : |
394 | // ======================================================================= | |
d4aaad5b | 395 | void OpenGl_Structure::UpdateStateIfRaytracable (const Standard_Boolean toCheck) const |
e276548b | 396 | { |
d4aaad5b | 397 | myIsRaytracable = !toCheck || OpenGl_Raytrace::IsRaytracedStructure (this); |
e276548b | 398 | |
d4aaad5b | 399 | if (IsRaytracable()) |
e276548b | 400 | { |
d4aaad5b | 401 | ++myModificationState; |
e276548b | 402 | } |
403 | } | |
404 | ||
4269bd1b | 405 | // ======================================================================= |
406 | // function : Connect | |
407 | // purpose : | |
408 | // ======================================================================= | |
63bcc448 | 409 | void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure) |
2166f0fa | 410 | { |
d4aaad5b | 411 | OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure); |
412 | ||
413 | Standard_ASSERT_RAISE (myInstancedStructure == NULL || myInstancedStructure == aStruct, | |
414 | "Error! Instanced structure is already defined"); | |
415 | ||
416 | myInstancedStructure = aStruct; | |
e276548b | 417 | |
63bcc448 | 418 | if (aStruct->IsRaytracable()) |
e276548b | 419 | { |
d4aaad5b | 420 | UpdateStateIfRaytracable (Standard_False); |
e276548b | 421 | } |
2166f0fa SK |
422 | } |
423 | ||
4269bd1b | 424 | // ======================================================================= |
425 | // function : Disconnect | |
426 | // purpose : | |
427 | // ======================================================================= | |
63bcc448 | 428 | void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure) |
2166f0fa | 429 | { |
d4aaad5b | 430 | OpenGl_Structure* aStruct = static_cast<OpenGl_Structure*> (&theStructure); |
e276548b | 431 | |
d4aaad5b | 432 | if (myInstancedStructure == aStruct) |
433 | { | |
434 | myInstancedStructure = NULL; | |
e276548b | 435 | |
d4aaad5b | 436 | if (aStruct->IsRaytracable()) |
437 | { | |
438 | UpdateStateIfRaytracable(); | |
2166f0fa | 439 | } |
2166f0fa SK |
440 | } |
441 | } | |
442 | ||
4269bd1b | 443 | // ======================================================================= |
b64d84be | 444 | // function : NewGroup |
4269bd1b | 445 | // purpose : |
446 | // ======================================================================= | |
b64d84be | 447 | Handle(Graphic3d_Group) OpenGl_Structure::NewGroup (const Handle(Graphic3d_Structure)& theStruct) |
2166f0fa | 448 | { |
b64d84be | 449 | Handle(OpenGl_Group) aGroup = new OpenGl_Group (theStruct); |
450 | myGroups.Append (aGroup); | |
451 | return aGroup; | |
2166f0fa SK |
452 | } |
453 | ||
4269bd1b | 454 | // ======================================================================= |
455 | // function : RemoveGroup | |
456 | // purpose : | |
457 | // ======================================================================= | |
b64d84be | 458 | void OpenGl_Structure::RemoveGroup (const Handle(Graphic3d_Group)& theGroup) |
2166f0fa | 459 | { |
b64d84be | 460 | if (theGroup.IsNull()) |
461 | { | |
462 | return; | |
463 | } | |
464 | ||
465 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next()) | |
2166f0fa SK |
466 | { |
467 | // Check for the given group | |
b64d84be | 468 | if (aGroupIter.Value() == theGroup) |
2166f0fa | 469 | { |
d4aaad5b | 470 | const Standard_Boolean wasRaytracable = |
471 | static_cast<const OpenGl_Group&> (*theGroup).IsRaytracable(); | |
472 | ||
b64d84be | 473 | theGroup->Clear (Standard_False); |
e276548b | 474 | |
d4aaad5b | 475 | if (wasRaytracable) |
e276548b | 476 | { |
d4aaad5b | 477 | UpdateStateIfRaytracable(); |
e276548b | 478 | } |
e276548b | 479 | |
b64d84be | 480 | myGroups.Remove (aGroupIter); |
2166f0fa SK |
481 | return; |
482 | } | |
2166f0fa SK |
483 | } |
484 | } | |
485 | ||
63bcc448 | 486 | // ======================================================================= |
487 | // function : Clear | |
488 | // purpose : | |
489 | // ======================================================================= | |
490 | void OpenGl_Structure::Clear() | |
491 | { | |
492 | Clear (GlDriver()->GetSharedContext()); | |
493 | } | |
494 | ||
4269bd1b | 495 | // ======================================================================= |
496 | // function : Clear | |
497 | // purpose : | |
498 | // ======================================================================= | |
5e27df78 | 499 | void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 500 | { |
e276548b | 501 | Standard_Boolean aRaytracableGroupDeleted (Standard_False); |
e276548b | 502 | |
5e27df78 | 503 | // Release groups |
b64d84be | 504 | for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next()) |
2166f0fa | 505 | { |
b64d84be | 506 | aRaytracableGroupDeleted |= aGroupIter.Value()->IsRaytracable(); |
5322131b | 507 | |
2166f0fa | 508 | // Delete objects |
b64d84be | 509 | aGroupIter.ChangeValue()->Release (theGlCtx); |
2166f0fa SK |
510 | } |
511 | myGroups.Clear(); | |
e276548b | 512 | |
e276548b | 513 | if (aRaytracableGroupDeleted) |
514 | { | |
d4aaad5b | 515 | myIsRaytracable = Standard_False; |
e276548b | 516 | } |
b7cd4ba7 | 517 | |
518 | Is2dText = Standard_False; | |
519 | IsForHighlight = Standard_False; | |
2166f0fa SK |
520 | } |
521 | ||
0717ddc1 | 522 | // ======================================================================= |
523 | // function : RenderGeometry | |
524 | // purpose : | |
525 | // ======================================================================= | |
7d9e854b | 526 | void OpenGl_Structure::RenderGeometry (const Handle(OpenGl_Workspace) &theWorkspace) const |
0717ddc1 | 527 | { |
528 | // Render groups | |
529 | const Graphic3d_SequenceOfGroup& aGroups = DrawGroups(); | |
530 | for (OpenGl_Structure::GroupIterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) | |
531 | { | |
7d9e854b | 532 | aGroupIter.Value()->Render (theWorkspace); |
0717ddc1 | 533 | } |
534 | } | |
535 | ||
4269bd1b | 536 | // ======================================================================= |
537 | // function : Render | |
538 | // purpose : | |
539 | // ======================================================================= | |
7d9e854b | 540 | void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) const |
2166f0fa SK |
541 | { |
542 | // Process the structure only if visible | |
a1954302 | 543 | if (!visible) |
7d9e854b | 544 | { |
2166f0fa | 545 | return; |
7d9e854b | 546 | } |
2166f0fa | 547 | |
c827ea3a | 548 | const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); |
b7cd4ba7 | 549 | |
2166f0fa | 550 | // Render named status |
7d9e854b | 551 | const Standard_Integer aNamedStatus = theWorkspace->NamedStatus; |
a1954302 | 552 | if (highlight) |
553 | { | |
554 | theWorkspace->NamedStatus |= OPENGL_NS_HIGHLIGHT; | |
555 | } | |
2166f0fa | 556 | |
7d9e854b | 557 | // Do we need to restore GL_NORMALIZE? |
c827ea3a | 558 | const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled(); |
2166f0fa SK |
559 | |
560 | // Apply local transformation | |
2166f0fa SK |
561 | if (myTransformation) |
562 | { | |
c827ea3a | 563 | OpenGl_Matrix aModelWorld; |
564 | OpenGl_Transposemat3 (&aModelWorld, myTransformation); | |
565 | aCtx->ModelWorldState.Push(); | |
566 | aCtx->ModelWorldState.SetCurrent (OpenGl_Mat4::Map ((Standard_ShortReal* )aModelWorld.mat)); | |
7d9e854b | 567 | |
568 | Standard_ShortReal aScaleX = OpenGl_Vec3 (myTransformation->mat[0][0], | |
569 | myTransformation->mat[0][1], | |
570 | myTransformation->mat[0][2]).SquareModulus(); | |
571 | // Scale transform detected. | |
572 | if (Abs (aScaleX - 1.f) > Precision::Confusion()) | |
573 | { | |
c827ea3a | 574 | aCtx->SetGlNormalizeEnabled (Standard_True); |
7d9e854b | 575 | } |
2166f0fa SK |
576 | } |
577 | ||
578 | // Apply transform persistence | |
7d9e854b | 579 | const TEL_TRANSFORM_PERSISTENCE *aTransPersistence = NULL; |
2166f0fa SK |
580 | if ( myTransPers && myTransPers->mode != 0 ) |
581 | { | |
af65fb19 | 582 | aTransPersistence = theWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers, theWorkspace->Width(), theWorkspace->Height()); |
2166f0fa SK |
583 | } |
584 | ||
c827ea3a | 585 | // Take into account transform persistence |
586 | aCtx->ApplyModelViewMatrix(); | |
587 | ||
2166f0fa | 588 | // Apply aspects |
7d9e854b | 589 | const OpenGl_AspectLine *anAspectLine = theWorkspace->AspectLine (Standard_False); |
590 | const OpenGl_AspectFace *anAspectFace = theWorkspace->AspectFace (Standard_False); | |
591 | const OpenGl_AspectMarker *anAspectMarker = theWorkspace->AspectMarker (Standard_False); | |
592 | const OpenGl_AspectText *anAspectText = theWorkspace->AspectText (Standard_False); | |
2166f0fa | 593 | if (myAspectLine) |
7d9e854b | 594 | { |
595 | theWorkspace->SetAspectLine (myAspectLine); | |
596 | } | |
2166f0fa | 597 | if (myAspectFace) |
7d9e854b | 598 | { |
599 | theWorkspace->SetAspectFace (myAspectFace); | |
600 | } | |
2166f0fa | 601 | if (myAspectMarker) |
7d9e854b | 602 | { |
603 | theWorkspace->SetAspectMarker (myAspectMarker); | |
604 | } | |
2166f0fa | 605 | if (myAspectText) |
7d9e854b | 606 | { |
607 | theWorkspace->SetAspectText (myAspectText); | |
608 | } | |
609 | ||
610 | // Apply correction for mirror transform | |
611 | if (myIsMirrored) | |
612 | { | |
c827ea3a | 613 | aCtx->core11fwd->glFrontFace (GL_CW); |
7d9e854b | 614 | } |
2166f0fa | 615 | |
2166f0fa | 616 | // Apply highlight color |
7d9e854b | 617 | const TEL_COLOUR *aHighlightColor = theWorkspace->HighlightColor; |
2166f0fa | 618 | if (myHighlightColor) |
7d9e854b | 619 | theWorkspace->HighlightColor = myHighlightColor; |
2166f0fa | 620 | |
d4aaad5b | 621 | // Render instanced structure (if exists) |
622 | if (myInstancedStructure != NULL) | |
2166f0fa | 623 | { |
d4aaad5b | 624 | myInstancedStructure->RenderGeometry (theWorkspace); |
2166f0fa SK |
625 | } |
626 | ||
4269bd1b | 627 | // Set up plane equations for non-structure transformed global model-view matrix |
b859a34d | 628 | // List of planes to be applied to context state |
494782f6 | 629 | NCollection_Handle<Graphic3d_SequenceOfHClipPlane> aUserPlanes; |
b859a34d | 630 | |
631 | // Collect clipping planes of structure scope | |
632 | if (!myClipPlanes.IsEmpty()) | |
4269bd1b | 633 | { |
7d9e854b | 634 | Graphic3d_SequenceOfHClipPlane::Iterator aClippingIter (myClipPlanes); |
635 | for (; aClippingIter.More(); aClippingIter.Next()) | |
b859a34d | 636 | { |
7d9e854b | 637 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIter.Value(); |
b859a34d | 638 | if (!aClipPlane->IsOn()) |
639 | { | |
640 | continue; | |
641 | } | |
642 | ||
643 | if (aUserPlanes.IsNull()) | |
644 | { | |
51b10cd4 | 645 | aUserPlanes = new Graphic3d_SequenceOfHClipPlane(); |
b859a34d | 646 | } |
647 | ||
51b10cd4 | 648 | aUserPlanes->Append (aClipPlane); |
b859a34d | 649 | } |
4269bd1b | 650 | } |
651 | ||
b859a34d | 652 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
4269bd1b | 653 | { |
b859a34d | 654 | // add planes at loaded view matrix state |
c827ea3a | 655 | aCtx->ChangeClipping().AddWorld (*aUserPlanes, theWorkspace); |
30f0ad28 | 656 | |
657 | // Set OCCT state uniform variables | |
c827ea3a | 658 | if (!aCtx->ShaderManager()->IsEmpty()) |
30f0ad28 | 659 | { |
c827ea3a | 660 | aCtx->ShaderManager()->UpdateClippingState(); |
30f0ad28 | 661 | } |
4269bd1b | 662 | } |
663 | ||
2166f0fa | 664 | // Render groups |
b64d84be | 665 | const Graphic3d_SequenceOfGroup& aGroups = DrawGroups(); |
666 | for (OpenGl_Structure::GroupIterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next()) | |
2166f0fa | 667 | { |
7d9e854b | 668 | aGroupIter.Value()->Render (theWorkspace); |
2166f0fa SK |
669 | } |
670 | ||
7d9e854b | 671 | // Reset correction for mirror transform |
672 | if (myIsMirrored) | |
c827ea3a | 673 | { |
674 | aCtx->core11fwd->glFrontFace (GL_CCW); | |
675 | } | |
7d9e854b | 676 | |
b859a34d | 677 | // Render capping for structure groups |
c827ea3a | 678 | if (!aCtx->Clipping().Planes().IsEmpty()) |
b859a34d | 679 | { |
7d9e854b | 680 | OpenGl_CappingAlgo::RenderCapping (theWorkspace, aGroups); |
b859a34d | 681 | } |
4269bd1b | 682 | |
b859a34d | 683 | // Revert structure clippings |
684 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) | |
4269bd1b | 685 | { |
c827ea3a | 686 | aCtx->ChangeClipping().Remove (*aUserPlanes); |
30f0ad28 | 687 | |
688 | // Set OCCT state uniform variables | |
c827ea3a | 689 | if (!aCtx->ShaderManager()->IsEmpty()) |
30f0ad28 | 690 | { |
c827ea3a | 691 | aCtx->ShaderManager()->RevertClippingState(); |
30f0ad28 | 692 | } |
4269bd1b | 693 | } |
694 | ||
c827ea3a | 695 | // Apply local transformation |
696 | if (myTransformation) | |
697 | { | |
698 | aCtx->ModelWorldState.Pop(); | |
699 | aCtx->SetGlNormalizeEnabled (anOldGlNormalize); | |
700 | } | |
701 | ||
2166f0fa | 702 | // Restore highlight color |
7d9e854b | 703 | theWorkspace->HighlightColor = aHighlightColor; |
2166f0fa SK |
704 | |
705 | // Restore aspects | |
7d9e854b | 706 | theWorkspace->SetAspectLine (anAspectLine); |
707 | theWorkspace->SetAspectFace (anAspectFace); | |
708 | theWorkspace->SetAspectMarker (anAspectMarker); | |
709 | theWorkspace->SetAspectText (anAspectText); | |
2166f0fa SK |
710 | |
711 | // Restore transform persistence | |
712 | if ( myTransPers && myTransPers->mode != 0 ) | |
713 | { | |
af65fb19 | 714 | theWorkspace->ActiveView()->BeginTransformPersistence (aCtx, aTransPersistence, theWorkspace->Width(), theWorkspace->Height()); |
2166f0fa SK |
715 | } |
716 | ||
b7cd4ba7 | 717 | // Apply highlight box |
718 | if (!myHighlightBox.IsNull()) | |
719 | { | |
7d9e854b | 720 | myHighlightBox->Render (theWorkspace); |
b7cd4ba7 | 721 | } |
722 | ||
2166f0fa | 723 | // Restore named status |
7d9e854b | 724 | theWorkspace->NamedStatus = aNamedStatus; |
2166f0fa SK |
725 | } |
726 | ||
5e27df78 | 727 | // ======================================================================= |
728 | // function : Release | |
729 | // purpose : | |
730 | // ======================================================================= | |
731 | void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx) | |
732 | { | |
733 | // Release groups | |
734 | Clear (theGlCtx); | |
10b9c7df | 735 | OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine); |
736 | OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace); | |
737 | OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectMarker); | |
738 | OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectText); | |
b64d84be | 739 | clearHighlightColor (theGlCtx); |
5e27df78 | 740 | } |
741 | ||
dd8a4ce9 | 742 | // ======================================================================= |
743 | // function : ReleaseGlResources | |
744 | // purpose : | |
745 | // ======================================================================= | |
746 | void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx) | |
747 | { | |
b64d84be | 748 | for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next()) |
dd8a4ce9 | 749 | { |
b64d84be | 750 | aGroupIter.ChangeValue()->Release (theGlCtx); |
dd8a4ce9 | 751 | } |
752 | if (myAspectLine != NULL) | |
753 | { | |
10b9c7df | 754 | myAspectLine->Release (theGlCtx.operator->()); |
dd8a4ce9 | 755 | } |
756 | if (myAspectFace != NULL) | |
757 | { | |
10b9c7df | 758 | myAspectFace->Release (theGlCtx.operator->()); |
dd8a4ce9 | 759 | } |
760 | if (myAspectMarker != NULL) | |
761 | { | |
10b9c7df | 762 | myAspectMarker->Release (theGlCtx.operator->()); |
dd8a4ce9 | 763 | } |
764 | if (myAspectText != NULL) | |
765 | { | |
10b9c7df | 766 | myAspectText->Release (theGlCtx.operator->()); |
dd8a4ce9 | 767 | } |
b64d84be | 768 | if (!myHighlightBox.IsNull()) |
dd8a4ce9 | 769 | { |
10b9c7df | 770 | myHighlightBox->Release (theGlCtx.operator->()); |
dd8a4ce9 | 771 | } |
772 | } | |
773 | ||
679ecdee | 774 | //======================================================================= |
775 | //function : ShadowLink | |
776 | //purpose : | |
777 | //======================================================================= | |
778 | Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const | |
779 | { | |
780 | return new OpenGl_StructureShadow (theManager, this); | |
781 | } |