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 | |
e276548b | 16 | #ifdef HAVE_CONFIG_H |
17 | #include <config.h> | |
18 | #endif | |
19 | ||
4269bd1b | 20 | #include <OpenGl_CappingAlgo.hxx> |
21 | #include <OpenGl_Context.hxx> | |
30f0ad28 | 22 | #include <OpenGl_GlCore11.hxx> |
63bcc448 | 23 | #include <OpenGl_GraphicDriver.hxx> |
30f0ad28 | 24 | #include <OpenGl_ShaderManager.hxx> |
25 | #include <OpenGl_ShaderProgram.hxx> | |
26 | #include <OpenGl_Structure.hxx> | |
2166f0fa | 27 | #include <OpenGl_telem_util.hxx> |
30f0ad28 | 28 | #include <OpenGl_Vec.hxx> |
29 | #include <OpenGl_View.hxx> | |
30 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 31 | |
51b10cd4 | 32 | #include <Graphic3d_SequenceOfHClipPlane_Handle.hxx> |
b859a34d | 33 | |
63bcc448 | 34 | IMPLEMENT_STANDARD_HANDLE (OpenGl_Structure, Graphic3d_CStructure) |
35 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure) | |
36 | ||
27eed937 | 37 | //! Auxiliary class for bounding box presentation |
38 | class OpenGl_BndBoxPrs : public OpenGl_Element | |
39 | { | |
40 | ||
41 | public: | |
42 | ||
43 | //! Main constructor | |
44 | OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox) | |
45 | { | |
46 | const float Xm = theBndBox.Pmin.x; | |
47 | const float Ym = theBndBox.Pmin.y; | |
48 | const float Zm = theBndBox.Pmin.z; | |
49 | const float XM = theBndBox.Pmax.x; | |
50 | const float YM = theBndBox.Pmax.y; | |
51 | const float ZM = theBndBox.Pmax.z; | |
52 | myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm); | |
53 | myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM); | |
54 | myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM); | |
55 | myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm); | |
56 | myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm); | |
57 | myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm); | |
58 | myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM); | |
59 | myVerts[7] = OpenGl_Vec3 (XM, YM, ZM); | |
60 | myVerts[8] = OpenGl_Vec3 (XM, YM, Zm); | |
61 | myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm); | |
62 | myVerts[10] = OpenGl_Vec3 (XM, YM, Zm); | |
63 | myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm); | |
64 | myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM); | |
65 | myVerts[13] = OpenGl_Vec3 (XM, YM, ZM); | |
66 | myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM); | |
67 | myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM); | |
68 | } | |
69 | ||
70 | //! Render presentation | |
71 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const | |
72 | { | |
73 | // Apply line aspect | |
74 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); | |
75 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); | |
76 | ||
77 | glDisable (GL_LIGHTING); | |
679ecdee | 78 | if ((theWorkspace->NamedStatus & OPENGL_NS_IMMEDIATE) != 0) |
27eed937 | 79 | { |
80 | glDepthMask (GL_FALSE); | |
81 | } | |
82 | ||
83 | // Use highlight colors | |
84 | glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb); | |
85 | ||
86 | glEnableClientState (GL_VERTEX_ARRAY); | |
87 | glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts); | |
88 | glDrawArrays (GL_LINE_STRIP, 0, 16); | |
89 | glDisableClientState (GL_VERTEX_ARRAY); | |
90 | ||
91 | // restore aspects | |
92 | if (!aPrevTexture.IsNull()) | |
93 | { | |
94 | theWorkspace->EnableTexture (aPrevTexture); | |
95 | } | |
96 | } | |
97 | ||
98 | //! Release graphical resources | |
99 | virtual void Release (const Handle(OpenGl_Context)& ) | |
100 | { | |
101 | // | |
102 | } | |
103 | ||
104 | protected: | |
105 | ||
106 | //! Protected destructor | |
107 | virtual ~OpenGl_BndBoxPrs() {} | |
108 | ||
109 | private: | |
110 | ||
111 | OpenGl_Vec3 myVerts[16]; //!< vertices array | |
112 | ||
113 | public: | |
114 | ||
115 | DEFINE_STANDARD_ALLOC | |
116 | ||
117 | }; | |
2166f0fa SK |
118 | |
119 | /*----------------------------------------------------------------------*/ | |
120 | ||
4269bd1b | 121 | // ======================================================================= |
122 | // function : call_util_transpose_mat | |
123 | // purpose : | |
124 | // ======================================================================= | |
2166f0fa SK |
125 | static void call_util_transpose_mat (float tmat[16], float mat[4][4]) |
126 | { | |
127 | int i, j; | |
128 | ||
129 | for (i=0; i<4; i++) | |
130 | for (j=0; j<4; j++) | |
131 | tmat[j*4+i] = mat[i][j]; | |
132 | } | |
133 | ||
4269bd1b | 134 | // ======================================================================= |
135 | // function : OpenGl_Structure | |
136 | // purpose : | |
137 | // ======================================================================= | |
63bcc448 | 138 | OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager) |
139 | : Graphic3d_CStructure (theManager), | |
140 | myTransformation(NULL), | |
2166f0fa | 141 | myTransPers(NULL), |
2166f0fa SK |
142 | myAspectLine(NULL), |
143 | myAspectFace(NULL), | |
144 | myAspectMarker(NULL), | |
145 | myAspectText(NULL), | |
146 | myHighlightBox(NULL), | |
147 | myHighlightColor(NULL), | |
59f45b7c | 148 | myNamedStatus(0), |
149 | myZLayer(0) | |
2166f0fa | 150 | { |
63bcc448 | 151 | UpdateNamedStatus(); |
e276548b | 152 | #if HAVE_OPENCL |
153 | myIsRaytracable = Standard_False; | |
154 | myModificationState = 0; | |
155 | #endif | |
2166f0fa SK |
156 | } |
157 | ||
4269bd1b | 158 | // ======================================================================= |
159 | // function : ~OpenGl_Structure | |
160 | // purpose : | |
161 | // ======================================================================= | |
5e27df78 | 162 | OpenGl_Structure::~OpenGl_Structure() |
2166f0fa | 163 | { |
5e27df78 | 164 | Release (Handle(OpenGl_Context)()); |
165 | delete myTransformation; myTransformation = NULL; | |
166 | delete myTransPers; myTransPers = NULL; | |
2166f0fa SK |
167 | } |
168 | ||
4269bd1b | 169 | // ======================================================================= |
63bcc448 | 170 | // function : UpdateAspects |
4269bd1b | 171 | // purpose : |
172 | // ======================================================================= | |
63bcc448 | 173 | void OpenGl_Structure::UpdateAspects() |
2166f0fa | 174 | { |
63bcc448 | 175 | SetTransformPersistence (TransformPersistence); |
176 | ||
177 | if (ContextLine.IsDef) | |
178 | SetAspectLine (ContextLine); | |
179 | ||
180 | if (ContextFillArea.IsDef) | |
181 | SetAspectFace (ContextFillArea); | |
182 | ||
183 | if (ContextMarker.IsDef) | |
184 | SetAspectMarker (ContextMarker); | |
185 | ||
186 | if (ContextText.IsDef) | |
187 | SetAspectText (ContextText); | |
188 | } | |
189 | ||
190 | // ======================================================================= | |
191 | // function : UpdateTransformation | |
192 | // purpose : | |
193 | // ======================================================================= | |
194 | void OpenGl_Structure::UpdateTransformation() | |
195 | { | |
196 | if (myTransformation == NULL) | |
e276548b | 197 | { |
5e27df78 | 198 | myTransformation = new OpenGl_Matrix(); |
e276548b | 199 | } |
2166f0fa | 200 | |
63bcc448 | 201 | matcpy (myTransformation->mat, &Graphic3d_CStructure::Transformation[0][0]); |
e276548b | 202 | |
203 | #ifdef HAVE_OPENCL | |
204 | if (myIsRaytracable) | |
205 | { | |
206 | UpdateStateWithAncestorStructures(); | |
207 | } | |
208 | #endif | |
2166f0fa SK |
209 | } |
210 | ||
4269bd1b | 211 | // ======================================================================= |
212 | // function : SetTransformPersistence | |
213 | // purpose : | |
214 | // ======================================================================= | |
2166f0fa SK |
215 | void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers) |
216 | { | |
217 | if (!myTransPers) | |
218 | myTransPers = new TEL_TRANSFORM_PERSISTENCE; | |
219 | ||
220 | myTransPers->mode = ATransPers.Flag; | |
221 | myTransPers->pointX = ATransPers.Point.x; | |
222 | myTransPers->pointY = ATransPers.Point.y; | |
223 | myTransPers->pointZ = ATransPers.Point.z; | |
224 | } | |
225 | ||
4269bd1b | 226 | // ======================================================================= |
227 | // function : SetAspectLine | |
228 | // purpose : | |
229 | // ======================================================================= | |
fd4a6963 | 230 | void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) |
2166f0fa SK |
231 | { |
232 | if (!myAspectLine) | |
fd4a6963 | 233 | { |
5e27df78 | 234 | myAspectLine = new OpenGl_AspectLine(); |
fd4a6963 | 235 | } |
236 | myAspectLine->SetAspect (theAspect); | |
2166f0fa SK |
237 | } |
238 | ||
4269bd1b | 239 | // ======================================================================= |
240 | // function : SetAspectFace | |
241 | // purpose : | |
242 | // ======================================================================= | |
fd4a6963 | 243 | void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
2166f0fa SK |
244 | { |
245 | if (!myAspectFace) | |
bf75be98 | 246 | { |
5e27df78 | 247 | myAspectFace = new OpenGl_AspectFace(); |
bf75be98 | 248 | } |
fd4a6963 | 249 | myAspectFace->SetAspect (theAspect); |
e276548b | 250 | |
251 | #ifdef HAVE_OPENCL | |
252 | if (myIsRaytracable) | |
253 | { | |
254 | UpdateStateWithAncestorStructures(); | |
255 | } | |
256 | #endif | |
2166f0fa SK |
257 | } |
258 | ||
4269bd1b | 259 | // ======================================================================= |
260 | // function : SetAspectMarker | |
261 | // purpose : | |
262 | // ======================================================================= | |
fd4a6963 | 263 | void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) |
2166f0fa SK |
264 | { |
265 | if (!myAspectMarker) | |
a577aaab | 266 | { |
5e27df78 | 267 | myAspectMarker = new OpenGl_AspectMarker(); |
a577aaab | 268 | } |
fd4a6963 | 269 | myAspectMarker->SetAspect (theAspect); |
2166f0fa SK |
270 | } |
271 | ||
4269bd1b | 272 | // ======================================================================= |
273 | // function : SetAspectText | |
274 | // purpose : | |
275 | // ======================================================================= | |
fd4a6963 | 276 | void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) |
2166f0fa SK |
277 | { |
278 | if (!myAspectText) | |
fd4a6963 | 279 | { |
5e27df78 | 280 | myAspectText = new OpenGl_AspectText(); |
fd4a6963 | 281 | } |
282 | myAspectText->SetAspect (theAspect); | |
2166f0fa SK |
283 | } |
284 | ||
4269bd1b | 285 | // ======================================================================= |
286 | // function : SetHighlightBox | |
287 | // purpose : | |
288 | // ======================================================================= | |
5e27df78 | 289 | void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx, |
290 | const CALL_DEF_BOUNDBOX& theBoundBox) | |
2166f0fa | 291 | { |
5e27df78 | 292 | if (myHighlightBox != NULL) |
293 | { | |
294 | myHighlightBox->Release (theGlCtx); | |
295 | } | |
2166f0fa | 296 | else |
5e27df78 | 297 | { |
e276548b | 298 | #ifndef HAVE_OPENCL |
5e27df78 | 299 | myHighlightBox = new OpenGl_Group(); |
e276548b | 300 | #else |
301 | myHighlightBox = new OpenGl_Group (this); | |
302 | #endif | |
5e27df78 | 303 | } |
2166f0fa | 304 | |
5e27df78 | 305 | CALL_DEF_CONTEXTLINE aContextLine; |
306 | aContextLine.Color = theBoundBox.Color; | |
307 | aContextLine.LineType = Aspect_TOL_SOLID; | |
308 | aContextLine.Width = 1.0f; | |
309 | myHighlightBox->SetAspectLine (aContextLine); | |
2166f0fa | 310 | |
27eed937 | 311 | OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox); |
5322131b | 312 | myHighlightBox->AddElement (aBndBoxPrs); |
2166f0fa SK |
313 | } |
314 | ||
4269bd1b | 315 | // ======================================================================= |
316 | // function : ClearHighlightBox | |
317 | // purpose : | |
318 | // ======================================================================= | |
5e27df78 | 319 | void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 320 | { |
5e27df78 | 321 | if (myHighlightBox != NULL) |
2166f0fa | 322 | { |
5e27df78 | 323 | OpenGl_Element::Destroy (theGlCtx, myHighlightBox); |
2166f0fa SK |
324 | } |
325 | } | |
326 | ||
63bcc448 | 327 | // ======================================================================= |
328 | // function : HighlightWithColor | |
329 | // purpose : | |
330 | // ======================================================================= | |
331 | void OpenGl_Structure::HighlightWithColor (const Graphic3d_Vec3& theColor, | |
332 | const Standard_Boolean theToCreate) | |
333 | { | |
334 | const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext(); | |
335 | if (theToCreate) | |
336 | SetHighlightColor (aCtx, theColor); | |
337 | else | |
338 | ClearHighlightColor (aCtx); | |
339 | } | |
340 | ||
341 | // ======================================================================= | |
342 | // function : HighlightWithBndBox | |
343 | // purpose : | |
344 | // ======================================================================= | |
345 | void OpenGl_Structure::HighlightWithBndBox (const Standard_Boolean theToCreate) | |
346 | { | |
347 | const Handle(OpenGl_Context)& aCtx = GlDriver()->GetSharedContext(); | |
348 | if (theToCreate) | |
349 | SetHighlightBox (aCtx, BoundBox); | |
350 | else | |
351 | ClearHighlightBox (aCtx); | |
352 | } | |
353 | ||
4269bd1b | 354 | // ======================================================================= |
355 | // function : SetHighlightColor | |
356 | // purpose : | |
357 | // ======================================================================= | |
5e27df78 | 358 | void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx, |
63bcc448 | 359 | const Graphic3d_Vec3& theColor) |
2166f0fa | 360 | { |
5e27df78 | 361 | ClearHighlightBox (theGlCtx); |
362 | if (myHighlightColor == NULL) | |
363 | { | |
364 | myHighlightColor = new TEL_COLOUR(); | |
365 | } | |
2166f0fa | 366 | |
63bcc448 | 367 | myHighlightColor->rgb[0] = theColor.r(); |
368 | myHighlightColor->rgb[1] = theColor.g(); | |
369 | myHighlightColor->rgb[2] = theColor.b(); | |
2166f0fa SK |
370 | myHighlightColor->rgb[3] = 1.F; |
371 | } | |
372 | ||
4269bd1b | 373 | // ======================================================================= |
374 | // function : ClearHighlightColor | |
375 | // purpose : | |
376 | // ======================================================================= | |
5e27df78 | 377 | void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 378 | { |
5e27df78 | 379 | ClearHighlightBox(theGlCtx); |
380 | delete myHighlightColor; | |
381 | myHighlightColor = NULL; | |
2166f0fa SK |
382 | } |
383 | ||
e276548b | 384 | // ======================================================================= |
63bcc448 | 385 | // function : UpdateNamedStatus |
e276548b | 386 | // purpose : |
387 | // ======================================================================= | |
63bcc448 | 388 | void OpenGl_Structure::UpdateNamedStatus() |
e276548b | 389 | { |
63bcc448 | 390 | myNamedStatus = 0; |
391 | if (highlight) myNamedStatus |= OPENGL_NS_HIGHLIGHT; | |
392 | if (!visible) myNamedStatus |= OPENGL_NS_HIDE; | |
e276548b | 393 | |
394 | #ifdef HAVE_OPENCL | |
395 | if (myIsRaytracable) | |
396 | { | |
397 | UpdateStateWithAncestorStructures(); | |
398 | } | |
399 | #endif | |
400 | } | |
401 | ||
402 | #ifdef HAVE_OPENCL | |
403 | ||
404 | // ======================================================================= | |
405 | // function : RegisterAncestorStructure | |
406 | // purpose : | |
407 | // ======================================================================= | |
408 | void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const | |
409 | { | |
410 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
411 | { | |
412 | if (anIt.Value() == theStructure) | |
413 | { | |
414 | return; | |
5322131b | 415 | } |
e276548b | 416 | } |
417 | ||
418 | myAncestorStructures.Append (theStructure); | |
419 | } | |
420 | ||
421 | // ======================================================================= | |
422 | // function : UnregisterAncestorStructure | |
423 | // purpose : | |
424 | // ======================================================================= | |
425 | void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const | |
426 | { | |
427 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
428 | { | |
429 | if (anIt.Value() == theStructure) | |
430 | { | |
431 | myAncestorStructures.Remove (anIt); | |
432 | return; | |
5322131b | 433 | } |
e276548b | 434 | } |
435 | } | |
436 | ||
d5af8626 | 437 | // ======================================================================= |
438 | // function : UnregisterFromAncestorStructure | |
439 | // purpose : | |
440 | // ======================================================================= | |
441 | void OpenGl_Structure::UnregisterFromAncestorStructure() const | |
442 | { | |
443 | for (OpenGl_ListOfStructure::Iterator anIta (myAncestorStructures); anIta.More(); anIta.Next()) | |
444 | { | |
445 | OpenGl_Structure* anAncestor = const_cast<OpenGl_Structure*> (anIta.ChangeValue()); | |
446 | ||
447 | for (OpenGl_ListOfStructure::Iterator anIts (anAncestor->myConnected); anIts.More(); anIts.Next()) | |
448 | { | |
449 | if (anIts.Value() == this) | |
450 | { | |
451 | anAncestor->myConnected.Remove (anIts); | |
452 | return; | |
5322131b | 453 | } |
d5af8626 | 454 | } |
455 | } | |
456 | } | |
457 | ||
e276548b | 458 | // ======================================================================= |
459 | // function : UpdateStateWithAncestorStructures | |
460 | // purpose : | |
461 | // ======================================================================= | |
462 | void OpenGl_Structure::UpdateStateWithAncestorStructures() const | |
463 | { | |
464 | myModificationState++; | |
465 | ||
466 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
467 | { | |
468 | anIt.Value()->UpdateStateWithAncestorStructures(); | |
469 | } | |
470 | } | |
471 | ||
472 | // ======================================================================= | |
473 | // function : UpdateRaytracableWithAncestorStructures | |
474 | // purpose : | |
475 | // ======================================================================= | |
476 | void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const | |
477 | { | |
478 | myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this); | |
479 | ||
480 | if (!myIsRaytracable) | |
481 | { | |
482 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
483 | { | |
484 | anIt.Value()->UpdateRaytracableWithAncestorStructures(); | |
485 | } | |
486 | } | |
487 | } | |
488 | ||
489 | // ======================================================================= | |
490 | // function : SetRaytracableWithAncestorStructures | |
491 | // purpose : | |
492 | // ======================================================================= | |
493 | void OpenGl_Structure::SetRaytracableWithAncestorStructures() const | |
494 | { | |
495 | myIsRaytracable = Standard_True; | |
496 | ||
497 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
498 | { | |
499 | if (!anIt.Value()->IsRaytracable()) | |
500 | { | |
501 | anIt.Value()->SetRaytracableWithAncestorStructures(); | |
502 | } | |
503 | } | |
504 | } | |
505 | ||
506 | #endif | |
507 | ||
4269bd1b | 508 | // ======================================================================= |
509 | // function : Connect | |
510 | // purpose : | |
511 | // ======================================================================= | |
63bcc448 | 512 | void OpenGl_Structure::Connect (Graphic3d_CStructure& theStructure) |
2166f0fa | 513 | { |
63bcc448 | 514 | OpenGl_Structure* aStruct = (OpenGl_Structure* )&theStructure; |
e276548b | 515 | Disconnect (theStructure); |
63bcc448 | 516 | myConnected.Append (aStruct); |
e276548b | 517 | |
518 | #ifdef HAVE_OPENCL | |
63bcc448 | 519 | if (aStruct->IsRaytracable()) |
e276548b | 520 | { |
521 | UpdateStateWithAncestorStructures(); | |
522 | SetRaytracableWithAncestorStructures(); | |
523 | } | |
524 | ||
63bcc448 | 525 | aStruct->RegisterAncestorStructure (this); |
e276548b | 526 | #endif |
2166f0fa SK |
527 | } |
528 | ||
4269bd1b | 529 | // ======================================================================= |
530 | // function : Disconnect | |
531 | // purpose : | |
532 | // ======================================================================= | |
63bcc448 | 533 | void OpenGl_Structure::Disconnect (Graphic3d_CStructure& theStructure) |
2166f0fa | 534 | { |
63bcc448 | 535 | OpenGl_Structure* aStruct = (OpenGl_Structure* )&theStructure; |
536 | for (OpenGl_ListOfStructure::Iterator anIter (myConnected); anIter.More(); anIter.Next()) | |
2166f0fa SK |
537 | { |
538 | // Check for the given structure | |
63bcc448 | 539 | if (anIter.Value() == aStruct) |
2166f0fa | 540 | { |
63bcc448 | 541 | myConnected.Remove (anIter); |
e276548b | 542 | |
543 | #ifdef HAVE_OPENCL | |
63bcc448 | 544 | if (aStruct->IsRaytracable()) |
e276548b | 545 | { |
546 | UpdateStateWithAncestorStructures(); | |
547 | UpdateRaytracableWithAncestorStructures(); | |
548 | } | |
549 | ||
63bcc448 | 550 | aStruct->UnregisterAncestorStructure (this); |
e276548b | 551 | #endif |
2166f0fa SK |
552 | return; |
553 | } | |
2166f0fa SK |
554 | } |
555 | } | |
556 | ||
4269bd1b | 557 | // ======================================================================= |
558 | // function : AddGroup | |
559 | // purpose : | |
560 | // ======================================================================= | |
e276548b | 561 | OpenGl_Group * OpenGl_Structure::AddGroup() |
2166f0fa SK |
562 | { |
563 | // Create new group | |
e276548b | 564 | #ifndef HAVE_OPENCL |
565 | OpenGl_Group *g = new OpenGl_Group(); | |
566 | #else | |
567 | OpenGl_Group *g = new OpenGl_Group (this); | |
568 | #endif | |
569 | ||
2166f0fa SK |
570 | myGroups.Append(g); |
571 | return g; | |
572 | } | |
573 | ||
4269bd1b | 574 | // ======================================================================= |
575 | // function : RemoveGroup | |
576 | // purpose : | |
577 | // ======================================================================= | |
5e27df78 | 578 | void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx, |
579 | const OpenGl_Group* theGroup) | |
2166f0fa | 580 | { |
5e27df78 | 581 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
2166f0fa SK |
582 | { |
583 | // Check for the given group | |
5e27df78 | 584 | if (anIter.Value() == theGroup) |
2166f0fa | 585 | { |
5e27df78 | 586 | myGroups.Remove (anIter); |
e276548b | 587 | |
588 | #ifdef HAVE_OPENCL | |
589 | if (theGroup->IsRaytracable()) | |
590 | { | |
591 | UpdateStateWithAncestorStructures(); | |
592 | UpdateRaytracableWithAncestorStructures(); | |
593 | } | |
594 | #endif | |
595 | ||
596 | // Delete object | |
597 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup)); | |
2166f0fa SK |
598 | return; |
599 | } | |
2166f0fa SK |
600 | } |
601 | } | |
602 | ||
63bcc448 | 603 | // ======================================================================= |
604 | // function : Clear | |
605 | // purpose : | |
606 | // ======================================================================= | |
607 | void OpenGl_Structure::Clear() | |
608 | { | |
609 | Clear (GlDriver()->GetSharedContext()); | |
610 | } | |
611 | ||
4269bd1b | 612 | // ======================================================================= |
613 | // function : Clear | |
614 | // purpose : | |
615 | // ======================================================================= | |
5e27df78 | 616 | void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 617 | { |
e276548b | 618 | #ifdef HAVE_OPENCL |
619 | Standard_Boolean aRaytracableGroupDeleted (Standard_False); | |
620 | #endif | |
621 | ||
5e27df78 | 622 | // Release groups |
623 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
2166f0fa | 624 | { |
e276548b | 625 | #ifdef HAVE_OPENCL |
626 | aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable(); | |
627 | #endif | |
5322131b | 628 | |
2166f0fa | 629 | // Delete objects |
5e27df78 | 630 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
2166f0fa SK |
631 | } |
632 | myGroups.Clear(); | |
e276548b | 633 | |
634 | #ifdef HAVE_OPENCL | |
635 | if (aRaytracableGroupDeleted) | |
636 | { | |
637 | UpdateStateWithAncestorStructures(); | |
638 | UpdateRaytracableWithAncestorStructures(); | |
639 | } | |
640 | #endif | |
2166f0fa SK |
641 | } |
642 | ||
4269bd1b | 643 | // ======================================================================= |
644 | // function : Render | |
645 | // purpose : | |
646 | // ======================================================================= | |
2166f0fa SK |
647 | void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const |
648 | { | |
649 | // Process the structure only if visible | |
650 | if ( myNamedStatus & OPENGL_NS_HIDE ) | |
651 | return; | |
652 | ||
653 | // Render named status | |
654 | const Standard_Integer named_status = AWorkspace->NamedStatus; | |
655 | AWorkspace->NamedStatus |= myNamedStatus; | |
656 | ||
657 | // Is rendering in ADD or IMMEDIATE mode? | |
679ecdee | 658 | const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & OPENGL_NS_IMMEDIATE) != 0; |
2166f0fa | 659 | |
30f0ad28 | 660 | const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext(); |
661 | ||
2166f0fa SK |
662 | // Apply local transformation |
663 | GLint matrix_mode = 0; | |
664 | const OpenGl_Matrix *local_trsf = NULL; | |
665 | if (myTransformation) | |
666 | { | |
667 | if (isImmediate) | |
668 | { | |
30f0ad28 | 669 | Tmatrix3 aModelWorld; |
670 | call_util_transpose_mat (*aModelWorld, myTransformation->mat); | |
2166f0fa | 671 | glGetIntegerv (GL_MATRIX_MODE, &matrix_mode); |
30f0ad28 | 672 | |
673 | if (!aCtx->ShaderManager()->IsEmpty()) | |
674 | { | |
675 | Tmatrix3 aWorldView; | |
676 | glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView); | |
677 | ||
678 | Tmatrix3 aProjection; | |
679 | glGetFloatv (GL_PROJECTION_MATRIX, *aProjection); | |
680 | ||
b5ac8292 | 681 | aCtx->ShaderManager()->UpdateModelWorldStateTo (&aModelWorld); |
682 | aCtx->ShaderManager()->UpdateWorldViewStateTo (&aWorldView); | |
683 | aCtx->ShaderManager()->UpdateProjectionStateTo (&aProjection); | |
30f0ad28 | 684 | } |
685 | ||
2166f0fa SK |
686 | glMatrixMode (GL_MODELVIEW); |
687 | glPushMatrix (); | |
688 | glScalef (1.F, 1.F, 1.F); | |
30f0ad28 | 689 | glMultMatrixf (*aModelWorld); |
2166f0fa SK |
690 | } |
691 | else | |
692 | { | |
693 | glMatrixMode (GL_MODELVIEW); | |
694 | glPushMatrix(); | |
695 | ||
30f0ad28 | 696 | local_trsf = AWorkspace->SetStructureMatrix (myTransformation); |
2166f0fa SK |
697 | } |
698 | } | |
699 | ||
700 | // Apply transform persistence | |
701 | const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL; | |
702 | if ( myTransPers && myTransPers->mode != 0 ) | |
703 | { | |
30f0ad28 | 704 | trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers); |
2166f0fa SK |
705 | } |
706 | ||
2166f0fa SK |
707 | // Apply aspects |
708 | const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False); | |
709 | const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False); | |
710 | const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False); | |
711 | const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False); | |
712 | if (myAspectLine) | |
713 | AWorkspace->SetAspectLine(myAspectLine); | |
714 | if (myAspectFace) | |
715 | AWorkspace->SetAspectFace(myAspectFace); | |
716 | if (myAspectMarker) | |
717 | AWorkspace->SetAspectMarker(myAspectMarker); | |
718 | if (myAspectText) | |
719 | AWorkspace->SetAspectText(myAspectText); | |
720 | ||
721 | // Apply highlight box | |
722 | if (myHighlightBox) | |
723 | myHighlightBox->Render( AWorkspace ); | |
724 | ||
725 | // Apply highlight color | |
726 | const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor; | |
727 | if (myHighlightColor) | |
728 | AWorkspace->HighlightColor = myHighlightColor; | |
729 | ||
730 | // Render connected structures | |
731 | OpenGl_ListOfStructure::Iterator its(myConnected); | |
732 | while (its.More()) | |
733 | { | |
734 | its.Value()->Render(AWorkspace); | |
735 | its.Next(); | |
736 | } | |
737 | ||
4269bd1b | 738 | // Set up plane equations for non-structure transformed global model-view matrix |
739 | const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext(); | |
740 | ||
b859a34d | 741 | // List of planes to be applied to context state |
51b10cd4 | 742 | Handle(Graphic3d_SequenceOfHClipPlane) aUserPlanes; |
b859a34d | 743 | |
744 | // Collect clipping planes of structure scope | |
745 | if (!myClipPlanes.IsEmpty()) | |
4269bd1b | 746 | { |
51b10cd4 | 747 | Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes); |
b859a34d | 748 | for (; aClippingIt.More(); aClippingIt.Next()) |
749 | { | |
750 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); | |
751 | if (!aClipPlane->IsOn()) | |
752 | { | |
753 | continue; | |
754 | } | |
755 | ||
756 | if (aUserPlanes.IsNull()) | |
757 | { | |
51b10cd4 | 758 | aUserPlanes = new Graphic3d_SequenceOfHClipPlane(); |
b859a34d | 759 | } |
760 | ||
51b10cd4 | 761 | aUserPlanes->Append (aClipPlane); |
b859a34d | 762 | } |
4269bd1b | 763 | } |
764 | ||
b859a34d | 765 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
4269bd1b | 766 | { |
b859a34d | 767 | // add planes at loaded view matrix state |
768 | aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace); | |
30f0ad28 | 769 | |
770 | // Set OCCT state uniform variables | |
771 | if (!aContext->ShaderManager()->IsEmpty()) | |
772 | { | |
773 | aContext->ShaderManager()->UpdateClippingState(); | |
774 | } | |
4269bd1b | 775 | } |
776 | ||
2166f0fa | 777 | // Render groups |
679ecdee | 778 | const OpenGl_ListOfGroup& aGroups = Groups(); |
779 | OpenGl_ListOfGroup::Iterator itg (aGroups); | |
2166f0fa SK |
780 | while (itg.More()) |
781 | { | |
782 | itg.Value()->Render(AWorkspace); | |
783 | itg.Next(); | |
784 | } | |
785 | ||
b859a34d | 786 | // Render capping for structure groups |
787 | if (!aContext->Clipping().Planes().IsEmpty()) | |
788 | { | |
679ecdee | 789 | OpenGl_CappingAlgo::RenderCapping (AWorkspace, aGroups); |
b859a34d | 790 | } |
4269bd1b | 791 | |
b859a34d | 792 | // Revert structure clippings |
793 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) | |
4269bd1b | 794 | { |
b859a34d | 795 | aContext->ChangeClipping().Remove (*aUserPlanes); |
30f0ad28 | 796 | |
797 | // Set OCCT state uniform variables | |
798 | if (!aContext->ShaderManager()->IsEmpty()) | |
799 | { | |
800 | aContext->ShaderManager()->RevertClippingState(); | |
801 | } | |
4269bd1b | 802 | } |
803 | ||
2166f0fa SK |
804 | // Restore highlight color |
805 | AWorkspace->HighlightColor = highlight_color; | |
806 | ||
807 | // Restore aspects | |
808 | AWorkspace->SetAspectLine(aspect_line); | |
809 | AWorkspace->SetAspectFace(aspect_face); | |
810 | AWorkspace->SetAspectMarker(aspect_marker); | |
811 | AWorkspace->SetAspectText(aspect_text); | |
812 | ||
813 | // Restore transform persistence | |
814 | if ( myTransPers && myTransPers->mode != 0 ) | |
815 | { | |
30f0ad28 | 816 | AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers); |
2166f0fa SK |
817 | } |
818 | ||
819 | // Restore local transformation | |
820 | if (myTransformation) | |
821 | { | |
822 | if (isImmediate) | |
823 | { | |
824 | glPopMatrix (); | |
825 | glMatrixMode (matrix_mode); | |
30f0ad28 | 826 | |
827 | Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f }, | |
828 | { 0.f, 1.f, 0.f, 0.f }, | |
829 | { 0.f, 0.f, 1.f, 0.f }, | |
830 | { 0.f, 0.f, 0.f, 1.f } }; | |
831 | ||
b5ac8292 | 832 | aContext->ShaderManager()->RevertModelWorldStateTo (&aModelWorldState); |
2166f0fa SK |
833 | } |
834 | else | |
835 | { | |
30f0ad28 | 836 | AWorkspace->SetStructureMatrix (local_trsf, true); |
2166f0fa SK |
837 | |
838 | glMatrixMode (GL_MODELVIEW); | |
839 | glPopMatrix(); | |
840 | } | |
841 | } | |
842 | ||
843 | // Restore named status | |
844 | AWorkspace->NamedStatus = named_status; | |
845 | } | |
846 | ||
5e27df78 | 847 | // ======================================================================= |
848 | // function : Release | |
849 | // purpose : | |
850 | // ======================================================================= | |
851 | void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx) | |
852 | { | |
853 | // Release groups | |
854 | Clear (theGlCtx); | |
855 | OpenGl_Element::Destroy (theGlCtx, myAspectLine); | |
856 | OpenGl_Element::Destroy (theGlCtx, myAspectFace); | |
857 | OpenGl_Element::Destroy (theGlCtx, myAspectMarker); | |
858 | OpenGl_Element::Destroy (theGlCtx, myAspectText); | |
859 | ClearHighlightColor (theGlCtx); | |
d5af8626 | 860 | |
861 | #ifdef HAVE_OPENCL | |
862 | // Remove from connected list of ancestor | |
863 | UnregisterFromAncestorStructure(); | |
864 | #endif | |
5e27df78 | 865 | } |
866 | ||
dd8a4ce9 | 867 | // ======================================================================= |
868 | // function : ReleaseGlResources | |
869 | // purpose : | |
870 | // ======================================================================= | |
871 | void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx) | |
872 | { | |
873 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
874 | { | |
875 | OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue()); | |
876 | if (aGroup != NULL) | |
877 | { | |
878 | aGroup->Release (theGlCtx); | |
879 | } | |
880 | } | |
881 | if (myAspectLine != NULL) | |
882 | { | |
883 | myAspectLine->Release (theGlCtx); | |
884 | } | |
885 | if (myAspectFace != NULL) | |
886 | { | |
887 | myAspectFace->Release (theGlCtx); | |
888 | } | |
889 | if (myAspectMarker != NULL) | |
890 | { | |
891 | myAspectMarker->Release (theGlCtx); | |
892 | } | |
893 | if (myAspectText != NULL) | |
894 | { | |
895 | myAspectText->Release (theGlCtx); | |
896 | } | |
897 | if (myHighlightBox != NULL) | |
898 | { | |
899 | myHighlightBox->Release (theGlCtx); | |
900 | } | |
901 | } | |
902 | ||
59f45b7c | 903 | //======================================================================= |
904 | //function : SetZLayer | |
bf75be98 | 905 | //purpose : |
59f45b7c | 906 | //======================================================================= |
59f45b7c | 907 | void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex) |
908 | { | |
909 | myZLayer = theLayerIndex; | |
910 | } | |
911 | ||
912 | //======================================================================= | |
913 | //function : GetZLayer | |
bf75be98 | 914 | //purpose : |
59f45b7c | 915 | //======================================================================= |
59f45b7c | 916 | Standard_Integer OpenGl_Structure::GetZLayer () const |
917 | { | |
918 | return myZLayer; | |
919 | } | |
679ecdee | 920 | |
921 | class OpenGl_StructureShadow : public OpenGl_Structure | |
922 | { | |
923 | ||
924 | public: | |
925 | ||
926 | //! Create empty structure | |
927 | OpenGl_StructureShadow (const Handle(Graphic3d_StructureManager)& theManager, | |
928 | const Handle(OpenGl_Structure)& theStructure); | |
929 | ||
930 | virtual const OpenGl_ListOfGroup& Groups() const { return myParent->Groups(); } | |
931 | ||
932 | private: | |
933 | ||
934 | Handle(OpenGl_Structure) myParent; | |
935 | ||
936 | public: | |
937 | ||
938 | DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition | |
939 | ||
940 | }; | |
941 | ||
942 | DEFINE_STANDARD_HANDLE(OpenGl_StructureShadow, OpenGl_Structure) | |
943 | ||
944 | IMPLEMENT_STANDARD_HANDLE (OpenGl_StructureShadow, OpenGl_Structure) | |
945 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_StructureShadow, OpenGl_Structure) | |
946 | ||
947 | OpenGl_StructureShadow::OpenGl_StructureShadow (const Handle(Graphic3d_StructureManager)& theManager, | |
948 | const Handle(OpenGl_Structure)& theStructure) | |
949 | : OpenGl_Structure (theManager) | |
950 | { | |
951 | Handle(OpenGl_StructureShadow) aShadow = Handle(OpenGl_StructureShadow)::DownCast (theStructure); | |
952 | myParent = aShadow.IsNull() ? theStructure : aShadow->myParent; | |
953 | ||
954 | ||
955 | Composition = myParent->Composition; | |
956 | ContainsFacet = myParent->ContainsFacet; | |
957 | IsInfinite = myParent->IsInfinite; | |
958 | for (Standard_Integer i = 0; i <= 3; ++i) | |
959 | { | |
960 | for (Standard_Integer j = 0; j <= 3; ++j) | |
961 | { | |
962 | Graphic3d_CStructure::Transformation[i][j] = myParent->Graphic3d_CStructure::Transformation[i][j]; | |
963 | } | |
964 | } | |
965 | ||
966 | TransformPersistence.IsSet = myParent->TransformPersistence.IsSet; | |
967 | TransformPersistence.Flag = myParent->TransformPersistence.Flag; | |
968 | TransformPersistence.Point = myParent->TransformPersistence.Point; | |
969 | } | |
970 | ||
971 | //======================================================================= | |
972 | //function : ShadowLink | |
973 | //purpose : | |
974 | //======================================================================= | |
975 | Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const | |
976 | { | |
977 | return new OpenGl_StructureShadow (theManager, this); | |
978 | } |