Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-08-01 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
e276548b | 20 | #ifdef HAVE_CONFIG_H |
21 | #include <config.h> | |
22 | #endif | |
23 | ||
2166f0fa | 24 | |
4269bd1b | 25 | #include <OpenGl_CappingAlgo.hxx> |
26 | #include <OpenGl_Context.hxx> | |
30f0ad28 | 27 | #include <OpenGl_GlCore11.hxx> |
28 | #include <OpenGl_ShaderManager.hxx> | |
29 | #include <OpenGl_ShaderProgram.hxx> | |
30 | #include <OpenGl_Structure.hxx> | |
2166f0fa | 31 | #include <OpenGl_telem_util.hxx> |
30f0ad28 | 32 | #include <OpenGl_Vec.hxx> |
33 | #include <OpenGl_View.hxx> | |
34 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 35 | |
b859a34d | 36 | #include <Graphic3d_SetOfHClipPlane_Handle.hxx> |
37 | ||
27eed937 | 38 | //! Auxiliary class for bounding box presentation |
39 | class OpenGl_BndBoxPrs : public OpenGl_Element | |
40 | { | |
41 | ||
42 | public: | |
43 | ||
44 | //! Main constructor | |
45 | OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox) | |
46 | { | |
47 | const float Xm = theBndBox.Pmin.x; | |
48 | const float Ym = theBndBox.Pmin.y; | |
49 | const float Zm = theBndBox.Pmin.z; | |
50 | const float XM = theBndBox.Pmax.x; | |
51 | const float YM = theBndBox.Pmax.y; | |
52 | const float ZM = theBndBox.Pmax.z; | |
53 | myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm); | |
54 | myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM); | |
55 | myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM); | |
56 | myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm); | |
57 | myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm); | |
58 | myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm); | |
59 | myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM); | |
60 | myVerts[7] = OpenGl_Vec3 (XM, YM, ZM); | |
61 | myVerts[8] = OpenGl_Vec3 (XM, YM, Zm); | |
62 | myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm); | |
63 | myVerts[10] = OpenGl_Vec3 (XM, YM, Zm); | |
64 | myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm); | |
65 | myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM); | |
66 | myVerts[13] = OpenGl_Vec3 (XM, YM, ZM); | |
67 | myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM); | |
68 | myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM); | |
69 | } | |
70 | ||
71 | //! Render presentation | |
72 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const | |
73 | { | |
74 | // Apply line aspect | |
75 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); | |
76 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); | |
77 | ||
78 | glDisable (GL_LIGHTING); | |
79 | if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0) | |
80 | { | |
81 | glDepthMask (GL_FALSE); | |
82 | } | |
83 | ||
84 | // Use highlight colors | |
85 | glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb); | |
86 | ||
87 | glEnableClientState (GL_VERTEX_ARRAY); | |
88 | glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts); | |
89 | glDrawArrays (GL_LINE_STRIP, 0, 16); | |
90 | glDisableClientState (GL_VERTEX_ARRAY); | |
91 | ||
92 | // restore aspects | |
93 | if (!aPrevTexture.IsNull()) | |
94 | { | |
95 | theWorkspace->EnableTexture (aPrevTexture); | |
96 | } | |
97 | } | |
98 | ||
99 | //! Release graphical resources | |
100 | virtual void Release (const Handle(OpenGl_Context)& ) | |
101 | { | |
102 | // | |
103 | } | |
104 | ||
105 | protected: | |
106 | ||
107 | //! Protected destructor | |
108 | virtual ~OpenGl_BndBoxPrs() {} | |
109 | ||
110 | private: | |
111 | ||
112 | OpenGl_Vec3 myVerts[16]; //!< vertices array | |
113 | ||
114 | public: | |
115 | ||
116 | DEFINE_STANDARD_ALLOC | |
117 | ||
118 | }; | |
2166f0fa SK |
119 | |
120 | /*----------------------------------------------------------------------*/ | |
121 | ||
4269bd1b | 122 | // ======================================================================= |
123 | // function : call_util_transpose_mat | |
124 | // purpose : | |
125 | // ======================================================================= | |
2166f0fa SK |
126 | static void call_util_transpose_mat (float tmat[16], float mat[4][4]) |
127 | { | |
128 | int i, j; | |
129 | ||
130 | for (i=0; i<4; i++) | |
131 | for (j=0; j<4; j++) | |
132 | tmat[j*4+i] = mat[i][j]; | |
133 | } | |
134 | ||
4269bd1b | 135 | // ======================================================================= |
136 | // function : OpenGl_Structure | |
137 | // purpose : | |
138 | // ======================================================================= | |
2166f0fa SK |
139 | OpenGl_Structure::OpenGl_Structure () |
140 | : myTransformation(NULL), | |
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 | { |
e276548b | 151 | #if HAVE_OPENCL |
152 | myIsRaytracable = Standard_False; | |
153 | myModificationState = 0; | |
154 | #endif | |
2166f0fa SK |
155 | } |
156 | ||
4269bd1b | 157 | // ======================================================================= |
158 | // function : ~OpenGl_Structure | |
159 | // purpose : | |
160 | // ======================================================================= | |
5e27df78 | 161 | OpenGl_Structure::~OpenGl_Structure() |
2166f0fa | 162 | { |
5e27df78 | 163 | Release (Handle(OpenGl_Context)()); |
164 | delete myTransformation; myTransformation = NULL; | |
165 | delete myTransPers; myTransPers = NULL; | |
2166f0fa SK |
166 | } |
167 | ||
4269bd1b | 168 | // ======================================================================= |
169 | // function : SetTransformation | |
170 | // purpose : | |
171 | // ======================================================================= | |
e276548b | 172 | void OpenGl_Structure::SetTransformation (const float *theMatrix) |
2166f0fa SK |
173 | { |
174 | if (!myTransformation) | |
e276548b | 175 | { |
5e27df78 | 176 | myTransformation = new OpenGl_Matrix(); |
e276548b | 177 | } |
2166f0fa | 178 | |
e276548b | 179 | matcpy (myTransformation->mat, theMatrix); |
180 | ||
181 | #ifdef HAVE_OPENCL | |
182 | if (myIsRaytracable) | |
183 | { | |
184 | UpdateStateWithAncestorStructures(); | |
185 | } | |
186 | #endif | |
2166f0fa SK |
187 | } |
188 | ||
4269bd1b | 189 | // ======================================================================= |
190 | // function : SetTransformPersistence | |
191 | // purpose : | |
192 | // ======================================================================= | |
2166f0fa SK |
193 | void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers) |
194 | { | |
195 | if (!myTransPers) | |
196 | myTransPers = new TEL_TRANSFORM_PERSISTENCE; | |
197 | ||
198 | myTransPers->mode = ATransPers.Flag; | |
199 | myTransPers->pointX = ATransPers.Point.x; | |
200 | myTransPers->pointY = ATransPers.Point.y; | |
201 | myTransPers->pointZ = ATransPers.Point.z; | |
202 | } | |
203 | ||
4269bd1b | 204 | // ======================================================================= |
205 | // function : SetAspectLine | |
206 | // purpose : | |
207 | // ======================================================================= | |
fd4a6963 | 208 | void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) |
2166f0fa SK |
209 | { |
210 | if (!myAspectLine) | |
fd4a6963 | 211 | { |
5e27df78 | 212 | myAspectLine = new OpenGl_AspectLine(); |
fd4a6963 | 213 | } |
214 | myAspectLine->SetAspect (theAspect); | |
2166f0fa SK |
215 | } |
216 | ||
4269bd1b | 217 | // ======================================================================= |
218 | // function : SetAspectFace | |
219 | // purpose : | |
220 | // ======================================================================= | |
fd4a6963 | 221 | void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
2166f0fa SK |
222 | { |
223 | if (!myAspectFace) | |
bf75be98 | 224 | { |
5e27df78 | 225 | myAspectFace = new OpenGl_AspectFace(); |
bf75be98 | 226 | } |
fd4a6963 | 227 | myAspectFace->SetAspect (theAspect); |
e276548b | 228 | |
229 | #ifdef HAVE_OPENCL | |
230 | if (myIsRaytracable) | |
231 | { | |
232 | UpdateStateWithAncestorStructures(); | |
233 | } | |
234 | #endif | |
2166f0fa SK |
235 | } |
236 | ||
4269bd1b | 237 | // ======================================================================= |
238 | // function : SetAspectMarker | |
239 | // purpose : | |
240 | // ======================================================================= | |
fd4a6963 | 241 | void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) |
2166f0fa SK |
242 | { |
243 | if (!myAspectMarker) | |
a577aaab | 244 | { |
5e27df78 | 245 | myAspectMarker = new OpenGl_AspectMarker(); |
a577aaab | 246 | } |
fd4a6963 | 247 | myAspectMarker->SetAspect (theAspect); |
2166f0fa SK |
248 | } |
249 | ||
4269bd1b | 250 | // ======================================================================= |
251 | // function : SetAspectText | |
252 | // purpose : | |
253 | // ======================================================================= | |
fd4a6963 | 254 | void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) |
2166f0fa SK |
255 | { |
256 | if (!myAspectText) | |
fd4a6963 | 257 | { |
5e27df78 | 258 | myAspectText = new OpenGl_AspectText(); |
fd4a6963 | 259 | } |
260 | myAspectText->SetAspect (theAspect); | |
2166f0fa SK |
261 | } |
262 | ||
4269bd1b | 263 | // ======================================================================= |
264 | // function : SetHighlightBox | |
265 | // purpose : | |
266 | // ======================================================================= | |
5e27df78 | 267 | void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx, |
268 | const CALL_DEF_BOUNDBOX& theBoundBox) | |
2166f0fa | 269 | { |
5e27df78 | 270 | if (myHighlightBox != NULL) |
271 | { | |
272 | myHighlightBox->Release (theGlCtx); | |
273 | } | |
2166f0fa | 274 | else |
5e27df78 | 275 | { |
e276548b | 276 | #ifndef HAVE_OPENCL |
5e27df78 | 277 | myHighlightBox = new OpenGl_Group(); |
e276548b | 278 | #else |
279 | myHighlightBox = new OpenGl_Group (this); | |
280 | #endif | |
5e27df78 | 281 | } |
2166f0fa | 282 | |
5e27df78 | 283 | CALL_DEF_CONTEXTLINE aContextLine; |
284 | aContextLine.Color = theBoundBox.Color; | |
285 | aContextLine.LineType = Aspect_TOL_SOLID; | |
286 | aContextLine.Width = 1.0f; | |
287 | myHighlightBox->SetAspectLine (aContextLine); | |
2166f0fa | 288 | |
27eed937 | 289 | OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox); |
290 | myHighlightBox->AddElement (TelParray, aBndBoxPrs); | |
2166f0fa SK |
291 | } |
292 | ||
4269bd1b | 293 | // ======================================================================= |
294 | // function : ClearHighlightBox | |
295 | // purpose : | |
296 | // ======================================================================= | |
5e27df78 | 297 | void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 298 | { |
5e27df78 | 299 | if (myHighlightBox != NULL) |
2166f0fa | 300 | { |
5e27df78 | 301 | OpenGl_Element::Destroy (theGlCtx, myHighlightBox); |
2166f0fa SK |
302 | } |
303 | } | |
304 | ||
4269bd1b | 305 | // ======================================================================= |
306 | // function : SetHighlightColor | |
307 | // purpose : | |
308 | // ======================================================================= | |
5e27df78 | 309 | void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx, |
310 | const Standard_ShortReal R, | |
311 | const Standard_ShortReal G, | |
312 | const Standard_ShortReal B) | |
2166f0fa | 313 | { |
5e27df78 | 314 | ClearHighlightBox (theGlCtx); |
315 | if (myHighlightColor == NULL) | |
316 | { | |
317 | myHighlightColor = new TEL_COLOUR(); | |
318 | } | |
2166f0fa SK |
319 | |
320 | myHighlightColor->rgb[0] = R; | |
321 | myHighlightColor->rgb[1] = G; | |
322 | myHighlightColor->rgb[2] = B; | |
323 | myHighlightColor->rgb[3] = 1.F; | |
324 | } | |
325 | ||
4269bd1b | 326 | // ======================================================================= |
327 | // function : ClearHighlightColor | |
328 | // purpose : | |
329 | // ======================================================================= | |
5e27df78 | 330 | void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 331 | { |
5e27df78 | 332 | ClearHighlightBox(theGlCtx); |
333 | delete myHighlightColor; | |
334 | myHighlightColor = NULL; | |
2166f0fa SK |
335 | } |
336 | ||
e276548b | 337 | // ======================================================================= |
338 | // function : SetNamedStatus | |
339 | // purpose : | |
340 | // ======================================================================= | |
341 | void OpenGl_Structure::SetNamedStatus (const Standard_Integer aStatus) | |
342 | { | |
343 | myNamedStatus = aStatus; | |
344 | ||
345 | #ifdef HAVE_OPENCL | |
346 | if (myIsRaytracable) | |
347 | { | |
348 | UpdateStateWithAncestorStructures(); | |
349 | } | |
350 | #endif | |
351 | } | |
352 | ||
353 | #ifdef HAVE_OPENCL | |
354 | ||
355 | // ======================================================================= | |
356 | // function : RegisterAncestorStructure | |
357 | // purpose : | |
358 | // ======================================================================= | |
359 | void OpenGl_Structure::RegisterAncestorStructure (const OpenGl_Structure* theStructure) const | |
360 | { | |
361 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
362 | { | |
363 | if (anIt.Value() == theStructure) | |
364 | { | |
365 | return; | |
366 | } | |
367 | } | |
368 | ||
369 | myAncestorStructures.Append (theStructure); | |
370 | } | |
371 | ||
372 | // ======================================================================= | |
373 | // function : UnregisterAncestorStructure | |
374 | // purpose : | |
375 | // ======================================================================= | |
376 | void OpenGl_Structure::UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const | |
377 | { | |
378 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
379 | { | |
380 | if (anIt.Value() == theStructure) | |
381 | { | |
382 | myAncestorStructures.Remove (anIt); | |
383 | return; | |
384 | } | |
385 | } | |
386 | } | |
387 | ||
388 | // ======================================================================= | |
389 | // function : UpdateStateWithAncestorStructures | |
390 | // purpose : | |
391 | // ======================================================================= | |
392 | void OpenGl_Structure::UpdateStateWithAncestorStructures() const | |
393 | { | |
394 | myModificationState++; | |
395 | ||
396 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
397 | { | |
398 | anIt.Value()->UpdateStateWithAncestorStructures(); | |
399 | } | |
400 | } | |
401 | ||
402 | // ======================================================================= | |
403 | // function : UpdateRaytracableWithAncestorStructures | |
404 | // purpose : | |
405 | // ======================================================================= | |
406 | void OpenGl_Structure::UpdateRaytracableWithAncestorStructures() const | |
407 | { | |
408 | myIsRaytracable = OpenGl_Raytrace::IsRaytracedStructure (this); | |
409 | ||
410 | if (!myIsRaytracable) | |
411 | { | |
412 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
413 | { | |
414 | anIt.Value()->UpdateRaytracableWithAncestorStructures(); | |
415 | } | |
416 | } | |
417 | } | |
418 | ||
419 | // ======================================================================= | |
420 | // function : SetRaytracableWithAncestorStructures | |
421 | // purpose : | |
422 | // ======================================================================= | |
423 | void OpenGl_Structure::SetRaytracableWithAncestorStructures() const | |
424 | { | |
425 | myIsRaytracable = Standard_True; | |
426 | ||
427 | for (OpenGl_ListOfStructure::Iterator anIt (myAncestorStructures); anIt.More(); anIt.Next()) | |
428 | { | |
429 | if (!anIt.Value()->IsRaytracable()) | |
430 | { | |
431 | anIt.Value()->SetRaytracableWithAncestorStructures(); | |
432 | } | |
433 | } | |
434 | } | |
435 | ||
436 | #endif | |
437 | ||
4269bd1b | 438 | // ======================================================================= |
439 | // function : Connect | |
440 | // purpose : | |
441 | // ======================================================================= | |
e276548b | 442 | void OpenGl_Structure::Connect (const OpenGl_Structure *theStructure) |
2166f0fa | 443 | { |
e276548b | 444 | Disconnect (theStructure); |
445 | myConnected.Append (theStructure); | |
446 | ||
447 | #ifdef HAVE_OPENCL | |
448 | if (theStructure->IsRaytracable()) | |
449 | { | |
450 | UpdateStateWithAncestorStructures(); | |
451 | SetRaytracableWithAncestorStructures(); | |
452 | } | |
453 | ||
454 | theStructure->RegisterAncestorStructure (this); | |
455 | #endif | |
2166f0fa SK |
456 | } |
457 | ||
4269bd1b | 458 | // ======================================================================= |
459 | // function : Disconnect | |
460 | // purpose : | |
461 | // ======================================================================= | |
e276548b | 462 | void OpenGl_Structure::Disconnect (const OpenGl_Structure *theStructure) |
2166f0fa | 463 | { |
e276548b | 464 | OpenGl_ListOfStructure::Iterator its (myConnected); |
2166f0fa SK |
465 | while (its.More()) |
466 | { | |
467 | // Check for the given structure | |
e276548b | 468 | if (its.Value() == theStructure) |
2166f0fa | 469 | { |
e276548b | 470 | myConnected.Remove (its); |
471 | ||
472 | #ifdef HAVE_OPENCL | |
473 | if (theStructure->IsRaytracable()) | |
474 | { | |
475 | UpdateStateWithAncestorStructures(); | |
476 | UpdateRaytracableWithAncestorStructures(); | |
477 | } | |
478 | ||
479 | theStructure->UnregisterAncestorStructure (this); | |
480 | #endif | |
481 | ||
2166f0fa SK |
482 | return; |
483 | } | |
484 | its.Next(); | |
485 | } | |
486 | } | |
487 | ||
4269bd1b | 488 | // ======================================================================= |
489 | // function : AddGroup | |
490 | // purpose : | |
491 | // ======================================================================= | |
e276548b | 492 | OpenGl_Group * OpenGl_Structure::AddGroup() |
2166f0fa SK |
493 | { |
494 | // Create new group | |
e276548b | 495 | #ifndef HAVE_OPENCL |
496 | OpenGl_Group *g = new OpenGl_Group(); | |
497 | #else | |
498 | OpenGl_Group *g = new OpenGl_Group (this); | |
499 | #endif | |
500 | ||
2166f0fa SK |
501 | myGroups.Append(g); |
502 | return g; | |
503 | } | |
504 | ||
4269bd1b | 505 | // ======================================================================= |
506 | // function : RemoveGroup | |
507 | // purpose : | |
508 | // ======================================================================= | |
5e27df78 | 509 | void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx, |
510 | const OpenGl_Group* theGroup) | |
2166f0fa | 511 | { |
5e27df78 | 512 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
2166f0fa SK |
513 | { |
514 | // Check for the given group | |
5e27df78 | 515 | if (anIter.Value() == theGroup) |
2166f0fa | 516 | { |
5e27df78 | 517 | myGroups.Remove (anIter); |
e276548b | 518 | |
519 | #ifdef HAVE_OPENCL | |
520 | if (theGroup->IsRaytracable()) | |
521 | { | |
522 | UpdateStateWithAncestorStructures(); | |
523 | UpdateRaytracableWithAncestorStructures(); | |
524 | } | |
525 | #endif | |
526 | ||
527 | // Delete object | |
528 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (theGroup)); | |
2166f0fa SK |
529 | return; |
530 | } | |
2166f0fa SK |
531 | } |
532 | } | |
533 | ||
4269bd1b | 534 | // ======================================================================= |
535 | // function : Clear | |
536 | // purpose : | |
537 | // ======================================================================= | |
5e27df78 | 538 | void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 539 | { |
e276548b | 540 | #ifdef HAVE_OPENCL |
541 | Standard_Boolean aRaytracableGroupDeleted (Standard_False); | |
542 | #endif | |
543 | ||
5e27df78 | 544 | // Release groups |
545 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
2166f0fa | 546 | { |
e276548b | 547 | #ifdef HAVE_OPENCL |
548 | aRaytracableGroupDeleted |= anIter.Value()->IsRaytracable(); | |
549 | #endif | |
550 | ||
2166f0fa | 551 | // Delete objects |
5e27df78 | 552 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
2166f0fa SK |
553 | } |
554 | myGroups.Clear(); | |
e276548b | 555 | |
556 | #ifdef HAVE_OPENCL | |
557 | if (aRaytracableGroupDeleted) | |
558 | { | |
559 | UpdateStateWithAncestorStructures(); | |
560 | UpdateRaytracableWithAncestorStructures(); | |
561 | } | |
562 | #endif | |
2166f0fa SK |
563 | } |
564 | ||
4269bd1b | 565 | // ======================================================================= |
566 | // function : Render | |
567 | // purpose : | |
568 | // ======================================================================= | |
2166f0fa SK |
569 | void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const |
570 | { | |
571 | // Process the structure only if visible | |
572 | if ( myNamedStatus & OPENGL_NS_HIDE ) | |
573 | return; | |
574 | ||
575 | // Render named status | |
576 | const Standard_Integer named_status = AWorkspace->NamedStatus; | |
577 | AWorkspace->NamedStatus |= myNamedStatus; | |
578 | ||
579 | // Is rendering in ADD or IMMEDIATE mode? | |
580 | const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0; | |
581 | ||
30f0ad28 | 582 | const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext(); |
583 | ||
2166f0fa SK |
584 | // Apply local transformation |
585 | GLint matrix_mode = 0; | |
586 | const OpenGl_Matrix *local_trsf = NULL; | |
587 | if (myTransformation) | |
588 | { | |
589 | if (isImmediate) | |
590 | { | |
30f0ad28 | 591 | Tmatrix3 aModelWorld; |
592 | call_util_transpose_mat (*aModelWorld, myTransformation->mat); | |
2166f0fa | 593 | glGetIntegerv (GL_MATRIX_MODE, &matrix_mode); |
30f0ad28 | 594 | |
595 | if (!aCtx->ShaderManager()->IsEmpty()) | |
596 | { | |
597 | Tmatrix3 aWorldView; | |
598 | glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView); | |
599 | ||
600 | Tmatrix3 aProjection; | |
601 | glGetFloatv (GL_PROJECTION_MATRIX, *aProjection); | |
602 | ||
603 | aCtx->ShaderManager()->UpdateModelWorldStateTo (aModelWorld); | |
604 | aCtx->ShaderManager()->UpdateWorldViewStateTo (aWorldView); | |
605 | aCtx->ShaderManager()->UpdateProjectionStateTo (aProjection); | |
606 | } | |
607 | ||
2166f0fa SK |
608 | glMatrixMode (GL_MODELVIEW); |
609 | glPushMatrix (); | |
610 | glScalef (1.F, 1.F, 1.F); | |
30f0ad28 | 611 | glMultMatrixf (*aModelWorld); |
2166f0fa SK |
612 | } |
613 | else | |
614 | { | |
615 | glMatrixMode (GL_MODELVIEW); | |
616 | glPushMatrix(); | |
617 | ||
30f0ad28 | 618 | local_trsf = AWorkspace->SetStructureMatrix (myTransformation); |
2166f0fa SK |
619 | } |
620 | } | |
621 | ||
622 | // Apply transform persistence | |
623 | const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL; | |
624 | if ( myTransPers && myTransPers->mode != 0 ) | |
625 | { | |
30f0ad28 | 626 | trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers); |
2166f0fa SK |
627 | } |
628 | ||
2166f0fa SK |
629 | // Apply aspects |
630 | const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False); | |
631 | const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False); | |
632 | const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False); | |
633 | const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False); | |
634 | if (myAspectLine) | |
635 | AWorkspace->SetAspectLine(myAspectLine); | |
636 | if (myAspectFace) | |
637 | AWorkspace->SetAspectFace(myAspectFace); | |
638 | if (myAspectMarker) | |
639 | AWorkspace->SetAspectMarker(myAspectMarker); | |
640 | if (myAspectText) | |
641 | AWorkspace->SetAspectText(myAspectText); | |
642 | ||
643 | // Apply highlight box | |
644 | if (myHighlightBox) | |
645 | myHighlightBox->Render( AWorkspace ); | |
646 | ||
647 | // Apply highlight color | |
648 | const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor; | |
649 | if (myHighlightColor) | |
650 | AWorkspace->HighlightColor = myHighlightColor; | |
651 | ||
652 | // Render connected structures | |
653 | OpenGl_ListOfStructure::Iterator its(myConnected); | |
654 | while (its.More()) | |
655 | { | |
656 | its.Value()->Render(AWorkspace); | |
657 | its.Next(); | |
658 | } | |
659 | ||
4269bd1b | 660 | // Set up plane equations for non-structure transformed global model-view matrix |
661 | const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext(); | |
662 | ||
b859a34d | 663 | // List of planes to be applied to context state |
664 | Handle(Graphic3d_SetOfHClipPlane) aUserPlanes; | |
665 | ||
666 | // Collect clipping planes of structure scope | |
667 | if (!myClipPlanes.IsEmpty()) | |
4269bd1b | 668 | { |
b859a34d | 669 | Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes); |
670 | for (; aClippingIt.More(); aClippingIt.Next()) | |
671 | { | |
672 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); | |
673 | if (!aClipPlane->IsOn()) | |
674 | { | |
675 | continue; | |
676 | } | |
677 | ||
678 | if (aUserPlanes.IsNull()) | |
679 | { | |
680 | aUserPlanes = new Graphic3d_SetOfHClipPlane(); | |
681 | } | |
682 | ||
683 | aUserPlanes->Add (aClipPlane); | |
684 | } | |
4269bd1b | 685 | } |
686 | ||
b859a34d | 687 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
4269bd1b | 688 | { |
b859a34d | 689 | // add planes at loaded view matrix state |
690 | aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace); | |
30f0ad28 | 691 | |
692 | // Set OCCT state uniform variables | |
693 | if (!aContext->ShaderManager()->IsEmpty()) | |
694 | { | |
695 | aContext->ShaderManager()->UpdateClippingState(); | |
696 | } | |
4269bd1b | 697 | } |
698 | ||
2166f0fa SK |
699 | // Render groups |
700 | OpenGl_ListOfGroup::Iterator itg(myGroups); | |
701 | while (itg.More()) | |
702 | { | |
703 | itg.Value()->Render(AWorkspace); | |
704 | itg.Next(); | |
705 | } | |
706 | ||
b859a34d | 707 | // Render capping for structure groups |
708 | if (!aContext->Clipping().Planes().IsEmpty()) | |
709 | { | |
710 | OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups); | |
711 | } | |
4269bd1b | 712 | |
b859a34d | 713 | // Revert structure clippings |
714 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) | |
4269bd1b | 715 | { |
b859a34d | 716 | aContext->ChangeClipping().Remove (*aUserPlanes); |
30f0ad28 | 717 | |
718 | // Set OCCT state uniform variables | |
719 | if (!aContext->ShaderManager()->IsEmpty()) | |
720 | { | |
721 | aContext->ShaderManager()->RevertClippingState(); | |
722 | } | |
4269bd1b | 723 | } |
724 | ||
2166f0fa SK |
725 | // Restore highlight color |
726 | AWorkspace->HighlightColor = highlight_color; | |
727 | ||
728 | // Restore aspects | |
729 | AWorkspace->SetAspectLine(aspect_line); | |
730 | AWorkspace->SetAspectFace(aspect_face); | |
731 | AWorkspace->SetAspectMarker(aspect_marker); | |
732 | AWorkspace->SetAspectText(aspect_text); | |
733 | ||
734 | // Restore transform persistence | |
735 | if ( myTransPers && myTransPers->mode != 0 ) | |
736 | { | |
30f0ad28 | 737 | AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers); |
2166f0fa SK |
738 | } |
739 | ||
740 | // Restore local transformation | |
741 | if (myTransformation) | |
742 | { | |
743 | if (isImmediate) | |
744 | { | |
745 | glPopMatrix (); | |
746 | glMatrixMode (matrix_mode); | |
30f0ad28 | 747 | |
748 | Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f }, | |
749 | { 0.f, 1.f, 0.f, 0.f }, | |
750 | { 0.f, 0.f, 1.f, 0.f }, | |
751 | { 0.f, 0.f, 0.f, 1.f } }; | |
752 | ||
753 | aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState); | |
2166f0fa SK |
754 | } |
755 | else | |
756 | { | |
30f0ad28 | 757 | AWorkspace->SetStructureMatrix (local_trsf, true); |
2166f0fa SK |
758 | |
759 | glMatrixMode (GL_MODELVIEW); | |
760 | glPopMatrix(); | |
761 | } | |
762 | } | |
763 | ||
764 | // Restore named status | |
765 | AWorkspace->NamedStatus = named_status; | |
766 | } | |
767 | ||
5e27df78 | 768 | // ======================================================================= |
769 | // function : Release | |
770 | // purpose : | |
771 | // ======================================================================= | |
772 | void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx) | |
773 | { | |
774 | // Release groups | |
775 | Clear (theGlCtx); | |
776 | OpenGl_Element::Destroy (theGlCtx, myAspectLine); | |
777 | OpenGl_Element::Destroy (theGlCtx, myAspectFace); | |
778 | OpenGl_Element::Destroy (theGlCtx, myAspectMarker); | |
779 | OpenGl_Element::Destroy (theGlCtx, myAspectText); | |
780 | ClearHighlightColor (theGlCtx); | |
781 | } | |
782 | ||
dd8a4ce9 | 783 | // ======================================================================= |
784 | // function : ReleaseGlResources | |
785 | // purpose : | |
786 | // ======================================================================= | |
787 | void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx) | |
788 | { | |
789 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
790 | { | |
791 | OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue()); | |
792 | if (aGroup != NULL) | |
793 | { | |
794 | aGroup->Release (theGlCtx); | |
795 | } | |
796 | } | |
797 | if (myAspectLine != NULL) | |
798 | { | |
799 | myAspectLine->Release (theGlCtx); | |
800 | } | |
801 | if (myAspectFace != NULL) | |
802 | { | |
803 | myAspectFace->Release (theGlCtx); | |
804 | } | |
805 | if (myAspectMarker != NULL) | |
806 | { | |
807 | myAspectMarker->Release (theGlCtx); | |
808 | } | |
809 | if (myAspectText != NULL) | |
810 | { | |
811 | myAspectText->Release (theGlCtx); | |
812 | } | |
813 | if (myHighlightBox != NULL) | |
814 | { | |
815 | myHighlightBox->Release (theGlCtx); | |
816 | } | |
817 | } | |
818 | ||
59f45b7c | 819 | //======================================================================= |
820 | //function : SetZLayer | |
bf75be98 | 821 | //purpose : |
59f45b7c | 822 | //======================================================================= |
59f45b7c | 823 | void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex) |
824 | { | |
825 | myZLayer = theLayerIndex; | |
826 | } | |
827 | ||
828 | //======================================================================= | |
829 | //function : GetZLayer | |
bf75be98 | 830 | //purpose : |
59f45b7c | 831 | //======================================================================= |
59f45b7c | 832 | Standard_Integer OpenGl_Structure::GetZLayer () const |
833 | { | |
834 | return myZLayer; | |
835 | } |