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 | ||
2166f0fa | 20 | |
4269bd1b | 21 | #include <OpenGl_CappingAlgo.hxx> |
22 | #include <OpenGl_Context.hxx> | |
30f0ad28 | 23 | #include <OpenGl_GlCore11.hxx> |
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 | |
b859a34d | 32 | #include <Graphic3d_SetOfHClipPlane_Handle.hxx> |
33 | ||
27eed937 | 34 | //! Auxiliary class for bounding box presentation |
35 | class OpenGl_BndBoxPrs : public OpenGl_Element | |
36 | { | |
37 | ||
38 | public: | |
39 | ||
40 | //! Main constructor | |
41 | OpenGl_BndBoxPrs (const CALL_DEF_BOUNDBOX& theBndBox) | |
42 | { | |
43 | const float Xm = theBndBox.Pmin.x; | |
44 | const float Ym = theBndBox.Pmin.y; | |
45 | const float Zm = theBndBox.Pmin.z; | |
46 | const float XM = theBndBox.Pmax.x; | |
47 | const float YM = theBndBox.Pmax.y; | |
48 | const float ZM = theBndBox.Pmax.z; | |
49 | myVerts[0] = OpenGl_Vec3 (Xm, Ym, Zm); | |
50 | myVerts[1] = OpenGl_Vec3 (Xm, Ym, ZM); | |
51 | myVerts[2] = OpenGl_Vec3 (Xm, YM, ZM); | |
52 | myVerts[3] = OpenGl_Vec3 (Xm, YM, Zm); | |
53 | myVerts[4] = OpenGl_Vec3 (Xm, Ym, Zm); | |
54 | myVerts[5] = OpenGl_Vec3 (XM, Ym, Zm); | |
55 | myVerts[6] = OpenGl_Vec3 (XM, Ym, ZM); | |
56 | myVerts[7] = OpenGl_Vec3 (XM, YM, ZM); | |
57 | myVerts[8] = OpenGl_Vec3 (XM, YM, Zm); | |
58 | myVerts[9] = OpenGl_Vec3 (XM, Ym, Zm); | |
59 | myVerts[10] = OpenGl_Vec3 (XM, YM, Zm); | |
60 | myVerts[11] = OpenGl_Vec3 (Xm, YM, Zm); | |
61 | myVerts[12] = OpenGl_Vec3 (Xm, YM, ZM); | |
62 | myVerts[13] = OpenGl_Vec3 (XM, YM, ZM); | |
63 | myVerts[14] = OpenGl_Vec3 (XM, Ym, ZM); | |
64 | myVerts[15] = OpenGl_Vec3 (Xm, Ym, ZM); | |
65 | } | |
66 | ||
67 | //! Render presentation | |
68 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const | |
69 | { | |
70 | // Apply line aspect | |
71 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); | |
72 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); | |
73 | ||
74 | glDisable (GL_LIGHTING); | |
75 | if ((theWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0) | |
76 | { | |
77 | glDepthMask (GL_FALSE); | |
78 | } | |
79 | ||
80 | // Use highlight colors | |
81 | glColor3fv ((theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) ? theWorkspace->HighlightColor->rgb : anAspectLine->Color().rgb); | |
82 | ||
83 | glEnableClientState (GL_VERTEX_ARRAY); | |
84 | glVertexPointer (3, GL_FLOAT, 0, (GLfloat* )&myVerts); | |
85 | glDrawArrays (GL_LINE_STRIP, 0, 16); | |
86 | glDisableClientState (GL_VERTEX_ARRAY); | |
87 | ||
88 | // restore aspects | |
89 | if (!aPrevTexture.IsNull()) | |
90 | { | |
91 | theWorkspace->EnableTexture (aPrevTexture); | |
92 | } | |
93 | } | |
94 | ||
95 | //! Release graphical resources | |
96 | virtual void Release (const Handle(OpenGl_Context)& ) | |
97 | { | |
98 | // | |
99 | } | |
100 | ||
101 | protected: | |
102 | ||
103 | //! Protected destructor | |
104 | virtual ~OpenGl_BndBoxPrs() {} | |
105 | ||
106 | private: | |
107 | ||
108 | OpenGl_Vec3 myVerts[16]; //!< vertices array | |
109 | ||
110 | public: | |
111 | ||
112 | DEFINE_STANDARD_ALLOC | |
113 | ||
114 | }; | |
2166f0fa SK |
115 | |
116 | /*----------------------------------------------------------------------*/ | |
117 | ||
4269bd1b | 118 | // ======================================================================= |
119 | // function : call_util_transpose_mat | |
120 | // purpose : | |
121 | // ======================================================================= | |
2166f0fa SK |
122 | static void call_util_transpose_mat (float tmat[16], float mat[4][4]) |
123 | { | |
124 | int i, j; | |
125 | ||
126 | for (i=0; i<4; i++) | |
127 | for (j=0; j<4; j++) | |
128 | tmat[j*4+i] = mat[i][j]; | |
129 | } | |
130 | ||
4269bd1b | 131 | // ======================================================================= |
132 | // function : OpenGl_Structure | |
133 | // purpose : | |
134 | // ======================================================================= | |
2166f0fa SK |
135 | OpenGl_Structure::OpenGl_Structure () |
136 | : myTransformation(NULL), | |
137 | myTransPers(NULL), | |
2166f0fa SK |
138 | myAspectLine(NULL), |
139 | myAspectFace(NULL), | |
140 | myAspectMarker(NULL), | |
141 | myAspectText(NULL), | |
142 | myHighlightBox(NULL), | |
143 | myHighlightColor(NULL), | |
59f45b7c | 144 | myNamedStatus(0), |
145 | myZLayer(0) | |
2166f0fa SK |
146 | { |
147 | } | |
148 | ||
4269bd1b | 149 | // ======================================================================= |
150 | // function : ~OpenGl_Structure | |
151 | // purpose : | |
152 | // ======================================================================= | |
5e27df78 | 153 | OpenGl_Structure::~OpenGl_Structure() |
2166f0fa | 154 | { |
5e27df78 | 155 | Release (Handle(OpenGl_Context)()); |
156 | delete myTransformation; myTransformation = NULL; | |
157 | delete myTransPers; myTransPers = NULL; | |
2166f0fa SK |
158 | } |
159 | ||
4269bd1b | 160 | // ======================================================================= |
161 | // function : SetTransformation | |
162 | // purpose : | |
163 | // ======================================================================= | |
2166f0fa SK |
164 | void OpenGl_Structure::SetTransformation(const float *AMatrix) |
165 | { | |
166 | if (!myTransformation) | |
5e27df78 | 167 | myTransformation = new OpenGl_Matrix(); |
2166f0fa SK |
168 | |
169 | matcpy( myTransformation->mat, AMatrix ); | |
170 | } | |
171 | ||
4269bd1b | 172 | // ======================================================================= |
173 | // function : SetTransformPersistence | |
174 | // purpose : | |
175 | // ======================================================================= | |
2166f0fa SK |
176 | void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers) |
177 | { | |
178 | if (!myTransPers) | |
179 | myTransPers = new TEL_TRANSFORM_PERSISTENCE; | |
180 | ||
181 | myTransPers->mode = ATransPers.Flag; | |
182 | myTransPers->pointX = ATransPers.Point.x; | |
183 | myTransPers->pointY = ATransPers.Point.y; | |
184 | myTransPers->pointZ = ATransPers.Point.z; | |
185 | } | |
186 | ||
4269bd1b | 187 | // ======================================================================= |
188 | // function : SetAspectLine | |
189 | // purpose : | |
190 | // ======================================================================= | |
fd4a6963 | 191 | void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) |
2166f0fa SK |
192 | { |
193 | if (!myAspectLine) | |
fd4a6963 | 194 | { |
5e27df78 | 195 | myAspectLine = new OpenGl_AspectLine(); |
fd4a6963 | 196 | } |
197 | myAspectLine->SetAspect (theAspect); | |
2166f0fa SK |
198 | } |
199 | ||
4269bd1b | 200 | // ======================================================================= |
201 | // function : SetAspectFace | |
202 | // purpose : | |
203 | // ======================================================================= | |
fd4a6963 | 204 | void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) |
2166f0fa SK |
205 | { |
206 | if (!myAspectFace) | |
bf75be98 | 207 | { |
5e27df78 | 208 | myAspectFace = new OpenGl_AspectFace(); |
bf75be98 | 209 | } |
fd4a6963 | 210 | myAspectFace->SetAspect (theAspect); |
2166f0fa SK |
211 | } |
212 | ||
4269bd1b | 213 | // ======================================================================= |
214 | // function : SetAspectMarker | |
215 | // purpose : | |
216 | // ======================================================================= | |
fd4a6963 | 217 | void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) |
2166f0fa SK |
218 | { |
219 | if (!myAspectMarker) | |
a577aaab | 220 | { |
5e27df78 | 221 | myAspectMarker = new OpenGl_AspectMarker(); |
a577aaab | 222 | } |
fd4a6963 | 223 | myAspectMarker->SetAspect (theAspect); |
2166f0fa SK |
224 | } |
225 | ||
4269bd1b | 226 | // ======================================================================= |
227 | // function : SetAspectText | |
228 | // purpose : | |
229 | // ======================================================================= | |
fd4a6963 | 230 | void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) |
2166f0fa SK |
231 | { |
232 | if (!myAspectText) | |
fd4a6963 | 233 | { |
5e27df78 | 234 | myAspectText = new OpenGl_AspectText(); |
fd4a6963 | 235 | } |
236 | myAspectText->SetAspect (theAspect); | |
2166f0fa SK |
237 | } |
238 | ||
4269bd1b | 239 | // ======================================================================= |
240 | // function : SetHighlightBox | |
241 | // purpose : | |
242 | // ======================================================================= | |
5e27df78 | 243 | void OpenGl_Structure::SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx, |
244 | const CALL_DEF_BOUNDBOX& theBoundBox) | |
2166f0fa | 245 | { |
5e27df78 | 246 | if (myHighlightBox != NULL) |
247 | { | |
248 | myHighlightBox->Release (theGlCtx); | |
249 | } | |
2166f0fa | 250 | else |
5e27df78 | 251 | { |
252 | myHighlightBox = new OpenGl_Group(); | |
253 | } | |
2166f0fa | 254 | |
5e27df78 | 255 | CALL_DEF_CONTEXTLINE aContextLine; |
256 | aContextLine.Color = theBoundBox.Color; | |
257 | aContextLine.LineType = Aspect_TOL_SOLID; | |
258 | aContextLine.Width = 1.0f; | |
259 | myHighlightBox->SetAspectLine (aContextLine); | |
2166f0fa | 260 | |
27eed937 | 261 | OpenGl_BndBoxPrs* aBndBoxPrs = new OpenGl_BndBoxPrs (theBoundBox); |
262 | myHighlightBox->AddElement (TelParray, aBndBoxPrs); | |
2166f0fa SK |
263 | } |
264 | ||
4269bd1b | 265 | // ======================================================================= |
266 | // function : ClearHighlightBox | |
267 | // purpose : | |
268 | // ======================================================================= | |
5e27df78 | 269 | void OpenGl_Structure::ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 270 | { |
5e27df78 | 271 | if (myHighlightBox != NULL) |
2166f0fa | 272 | { |
5e27df78 | 273 | OpenGl_Element::Destroy (theGlCtx, myHighlightBox); |
2166f0fa SK |
274 | } |
275 | } | |
276 | ||
4269bd1b | 277 | // ======================================================================= |
278 | // function : SetHighlightColor | |
279 | // purpose : | |
280 | // ======================================================================= | |
5e27df78 | 281 | void OpenGl_Structure::SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx, |
282 | const Standard_ShortReal R, | |
283 | const Standard_ShortReal G, | |
284 | const Standard_ShortReal B) | |
2166f0fa | 285 | { |
5e27df78 | 286 | ClearHighlightBox (theGlCtx); |
287 | if (myHighlightColor == NULL) | |
288 | { | |
289 | myHighlightColor = new TEL_COLOUR(); | |
290 | } | |
2166f0fa SK |
291 | |
292 | myHighlightColor->rgb[0] = R; | |
293 | myHighlightColor->rgb[1] = G; | |
294 | myHighlightColor->rgb[2] = B; | |
295 | myHighlightColor->rgb[3] = 1.F; | |
296 | } | |
297 | ||
4269bd1b | 298 | // ======================================================================= |
299 | // function : ClearHighlightColor | |
300 | // purpose : | |
301 | // ======================================================================= | |
5e27df78 | 302 | void OpenGl_Structure::ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 303 | { |
5e27df78 | 304 | ClearHighlightBox(theGlCtx); |
305 | delete myHighlightColor; | |
306 | myHighlightColor = NULL; | |
2166f0fa SK |
307 | } |
308 | ||
4269bd1b | 309 | // ======================================================================= |
310 | // function : Connect | |
311 | // purpose : | |
312 | // ======================================================================= | |
2166f0fa SK |
313 | void OpenGl_Structure::Connect (const OpenGl_Structure *AStructure) |
314 | { | |
315 | Disconnect (AStructure); | |
316 | myConnected.Append(AStructure); | |
317 | } | |
318 | ||
4269bd1b | 319 | // ======================================================================= |
320 | // function : Disconnect | |
321 | // purpose : | |
322 | // ======================================================================= | |
2166f0fa SK |
323 | void OpenGl_Structure::Disconnect (const OpenGl_Structure *AStructure) |
324 | { | |
325 | OpenGl_ListOfStructure::Iterator its(myConnected); | |
326 | while (its.More()) | |
327 | { | |
328 | // Check for the given structure | |
329 | if (its.Value() == AStructure) | |
330 | { | |
331 | myConnected.Remove(its); | |
332 | return; | |
333 | } | |
334 | its.Next(); | |
335 | } | |
336 | } | |
337 | ||
4269bd1b | 338 | // ======================================================================= |
339 | // function : AddGroup | |
340 | // purpose : | |
341 | // ======================================================================= | |
2166f0fa SK |
342 | OpenGl_Group * OpenGl_Structure::AddGroup () |
343 | { | |
344 | // Create new group | |
345 | OpenGl_Group *g = new OpenGl_Group; | |
346 | myGroups.Append(g); | |
347 | return g; | |
348 | } | |
349 | ||
4269bd1b | 350 | // ======================================================================= |
351 | // function : RemoveGroup | |
352 | // purpose : | |
353 | // ======================================================================= | |
5e27df78 | 354 | void OpenGl_Structure::RemoveGroup (const Handle(OpenGl_Context)& theGlCtx, |
355 | const OpenGl_Group* theGroup) | |
2166f0fa | 356 | { |
5e27df78 | 357 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) |
2166f0fa SK |
358 | { |
359 | // Check for the given group | |
5e27df78 | 360 | if (anIter.Value() == theGroup) |
2166f0fa SK |
361 | { |
362 | // Delete object | |
5e27df78 | 363 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
364 | myGroups.Remove (anIter); | |
2166f0fa SK |
365 | return; |
366 | } | |
2166f0fa SK |
367 | } |
368 | } | |
369 | ||
4269bd1b | 370 | // ======================================================================= |
371 | // function : Clear | |
372 | // purpose : | |
373 | // ======================================================================= | |
5e27df78 | 374 | void OpenGl_Structure::Clear (const Handle(OpenGl_Context)& theGlCtx) |
2166f0fa | 375 | { |
5e27df78 | 376 | // Release groups |
377 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
2166f0fa SK |
378 | { |
379 | // Delete objects | |
5e27df78 | 380 | OpenGl_Element::Destroy (theGlCtx, const_cast<OpenGl_Group*& > (anIter.ChangeValue())); |
2166f0fa SK |
381 | } |
382 | myGroups.Clear(); | |
383 | } | |
384 | ||
4269bd1b | 385 | // ======================================================================= |
386 | // function : Render | |
387 | // purpose : | |
388 | // ======================================================================= | |
2166f0fa SK |
389 | void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const |
390 | { | |
391 | // Process the structure only if visible | |
392 | if ( myNamedStatus & OPENGL_NS_HIDE ) | |
393 | return; | |
394 | ||
395 | // Render named status | |
396 | const Standard_Integer named_status = AWorkspace->NamedStatus; | |
397 | AWorkspace->NamedStatus |= myNamedStatus; | |
398 | ||
399 | // Is rendering in ADD or IMMEDIATE mode? | |
400 | const Standard_Boolean isImmediate = (AWorkspace->NamedStatus & (OPENGL_NS_ADD | OPENGL_NS_IMMEDIATE)) != 0; | |
401 | ||
30f0ad28 | 402 | const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext(); |
403 | ||
2166f0fa SK |
404 | // Apply local transformation |
405 | GLint matrix_mode = 0; | |
406 | const OpenGl_Matrix *local_trsf = NULL; | |
407 | if (myTransformation) | |
408 | { | |
409 | if (isImmediate) | |
410 | { | |
30f0ad28 | 411 | Tmatrix3 aModelWorld; |
412 | call_util_transpose_mat (*aModelWorld, myTransformation->mat); | |
2166f0fa | 413 | glGetIntegerv (GL_MATRIX_MODE, &matrix_mode); |
30f0ad28 | 414 | |
415 | if (!aCtx->ShaderManager()->IsEmpty()) | |
416 | { | |
417 | Tmatrix3 aWorldView; | |
418 | glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView); | |
419 | ||
420 | Tmatrix3 aProjection; | |
421 | glGetFloatv (GL_PROJECTION_MATRIX, *aProjection); | |
422 | ||
423 | aCtx->ShaderManager()->UpdateModelWorldStateTo (aModelWorld); | |
424 | aCtx->ShaderManager()->UpdateWorldViewStateTo (aWorldView); | |
425 | aCtx->ShaderManager()->UpdateProjectionStateTo (aProjection); | |
426 | } | |
427 | ||
2166f0fa SK |
428 | glMatrixMode (GL_MODELVIEW); |
429 | glPushMatrix (); | |
430 | glScalef (1.F, 1.F, 1.F); | |
30f0ad28 | 431 | glMultMatrixf (*aModelWorld); |
2166f0fa SK |
432 | } |
433 | else | |
434 | { | |
435 | glMatrixMode (GL_MODELVIEW); | |
436 | glPushMatrix(); | |
437 | ||
30f0ad28 | 438 | local_trsf = AWorkspace->SetStructureMatrix (myTransformation); |
2166f0fa SK |
439 | } |
440 | } | |
441 | ||
442 | // Apply transform persistence | |
443 | const TEL_TRANSFORM_PERSISTENCE *trans_pers = NULL; | |
444 | if ( myTransPers && myTransPers->mode != 0 ) | |
445 | { | |
30f0ad28 | 446 | trans_pers = AWorkspace->ActiveView()->BeginTransformPersistence (aCtx, myTransPers); |
2166f0fa SK |
447 | } |
448 | ||
2166f0fa SK |
449 | // Apply aspects |
450 | const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine(Standard_False); | |
451 | const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace(Standard_False); | |
452 | const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker(Standard_False); | |
453 | const OpenGl_AspectText *aspect_text = AWorkspace->AspectText(Standard_False); | |
454 | if (myAspectLine) | |
455 | AWorkspace->SetAspectLine(myAspectLine); | |
456 | if (myAspectFace) | |
457 | AWorkspace->SetAspectFace(myAspectFace); | |
458 | if (myAspectMarker) | |
459 | AWorkspace->SetAspectMarker(myAspectMarker); | |
460 | if (myAspectText) | |
461 | AWorkspace->SetAspectText(myAspectText); | |
462 | ||
463 | // Apply highlight box | |
464 | if (myHighlightBox) | |
465 | myHighlightBox->Render( AWorkspace ); | |
466 | ||
467 | // Apply highlight color | |
468 | const TEL_COLOUR *highlight_color = AWorkspace->HighlightColor; | |
469 | if (myHighlightColor) | |
470 | AWorkspace->HighlightColor = myHighlightColor; | |
471 | ||
472 | // Render connected structures | |
473 | OpenGl_ListOfStructure::Iterator its(myConnected); | |
474 | while (its.More()) | |
475 | { | |
476 | its.Value()->Render(AWorkspace); | |
477 | its.Next(); | |
478 | } | |
479 | ||
4269bd1b | 480 | // Set up plane equations for non-structure transformed global model-view matrix |
481 | const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext(); | |
482 | ||
b859a34d | 483 | // List of planes to be applied to context state |
484 | Handle(Graphic3d_SetOfHClipPlane) aUserPlanes; | |
485 | ||
486 | // Collect clipping planes of structure scope | |
487 | if (!myClipPlanes.IsEmpty()) | |
4269bd1b | 488 | { |
b859a34d | 489 | Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes); |
490 | for (; aClippingIt.More(); aClippingIt.Next()) | |
491 | { | |
492 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); | |
493 | if (!aClipPlane->IsOn()) | |
494 | { | |
495 | continue; | |
496 | } | |
497 | ||
498 | if (aUserPlanes.IsNull()) | |
499 | { | |
500 | aUserPlanes = new Graphic3d_SetOfHClipPlane(); | |
501 | } | |
502 | ||
503 | aUserPlanes->Add (aClipPlane); | |
504 | } | |
4269bd1b | 505 | } |
506 | ||
b859a34d | 507 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) |
4269bd1b | 508 | { |
b859a34d | 509 | // add planes at loaded view matrix state |
510 | aContext->ChangeClipping().AddWorld (*aUserPlanes, AWorkspace); | |
30f0ad28 | 511 | |
512 | // Set OCCT state uniform variables | |
513 | if (!aContext->ShaderManager()->IsEmpty()) | |
514 | { | |
515 | aContext->ShaderManager()->UpdateClippingState(); | |
516 | } | |
4269bd1b | 517 | } |
518 | ||
2166f0fa SK |
519 | // Render groups |
520 | OpenGl_ListOfGroup::Iterator itg(myGroups); | |
521 | while (itg.More()) | |
522 | { | |
523 | itg.Value()->Render(AWorkspace); | |
524 | itg.Next(); | |
525 | } | |
526 | ||
b859a34d | 527 | // Render capping for structure groups |
528 | if (!aContext->Clipping().Planes().IsEmpty()) | |
529 | { | |
530 | OpenGl_CappingAlgo::RenderCapping (AWorkspace, myGroups); | |
531 | } | |
4269bd1b | 532 | |
b859a34d | 533 | // Revert structure clippings |
534 | if (!aUserPlanes.IsNull() && !aUserPlanes->IsEmpty()) | |
4269bd1b | 535 | { |
b859a34d | 536 | aContext->ChangeClipping().Remove (*aUserPlanes); |
30f0ad28 | 537 | |
538 | // Set OCCT state uniform variables | |
539 | if (!aContext->ShaderManager()->IsEmpty()) | |
540 | { | |
541 | aContext->ShaderManager()->RevertClippingState(); | |
542 | } | |
4269bd1b | 543 | } |
544 | ||
2166f0fa SK |
545 | // Restore highlight color |
546 | AWorkspace->HighlightColor = highlight_color; | |
547 | ||
548 | // Restore aspects | |
549 | AWorkspace->SetAspectLine(aspect_line); | |
550 | AWorkspace->SetAspectFace(aspect_face); | |
551 | AWorkspace->SetAspectMarker(aspect_marker); | |
552 | AWorkspace->SetAspectText(aspect_text); | |
553 | ||
554 | // Restore transform persistence | |
555 | if ( myTransPers && myTransPers->mode != 0 ) | |
556 | { | |
30f0ad28 | 557 | AWorkspace->ActiveView()->BeginTransformPersistence (aContext, trans_pers); |
2166f0fa SK |
558 | } |
559 | ||
560 | // Restore local transformation | |
561 | if (myTransformation) | |
562 | { | |
563 | if (isImmediate) | |
564 | { | |
565 | glPopMatrix (); | |
566 | glMatrixMode (matrix_mode); | |
30f0ad28 | 567 | |
568 | Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f }, | |
569 | { 0.f, 1.f, 0.f, 0.f }, | |
570 | { 0.f, 0.f, 1.f, 0.f }, | |
571 | { 0.f, 0.f, 0.f, 1.f } }; | |
572 | ||
573 | aContext->ShaderManager()->RevertModelWorldStateTo (aModelWorldState); | |
2166f0fa SK |
574 | } |
575 | else | |
576 | { | |
30f0ad28 | 577 | AWorkspace->SetStructureMatrix (local_trsf, true); |
2166f0fa SK |
578 | |
579 | glMatrixMode (GL_MODELVIEW); | |
580 | glPopMatrix(); | |
581 | } | |
582 | } | |
583 | ||
584 | // Restore named status | |
585 | AWorkspace->NamedStatus = named_status; | |
586 | } | |
587 | ||
5e27df78 | 588 | // ======================================================================= |
589 | // function : Release | |
590 | // purpose : | |
591 | // ======================================================================= | |
592 | void OpenGl_Structure::Release (const Handle(OpenGl_Context)& theGlCtx) | |
593 | { | |
594 | // Release groups | |
595 | Clear (theGlCtx); | |
596 | OpenGl_Element::Destroy (theGlCtx, myAspectLine); | |
597 | OpenGl_Element::Destroy (theGlCtx, myAspectFace); | |
598 | OpenGl_Element::Destroy (theGlCtx, myAspectMarker); | |
599 | OpenGl_Element::Destroy (theGlCtx, myAspectText); | |
600 | ClearHighlightColor (theGlCtx); | |
601 | } | |
602 | ||
dd8a4ce9 | 603 | // ======================================================================= |
604 | // function : ReleaseGlResources | |
605 | // purpose : | |
606 | // ======================================================================= | |
607 | void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx) | |
608 | { | |
609 | for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next()) | |
610 | { | |
611 | OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue()); | |
612 | if (aGroup != NULL) | |
613 | { | |
614 | aGroup->Release (theGlCtx); | |
615 | } | |
616 | } | |
617 | if (myAspectLine != NULL) | |
618 | { | |
619 | myAspectLine->Release (theGlCtx); | |
620 | } | |
621 | if (myAspectFace != NULL) | |
622 | { | |
623 | myAspectFace->Release (theGlCtx); | |
624 | } | |
625 | if (myAspectMarker != NULL) | |
626 | { | |
627 | myAspectMarker->Release (theGlCtx); | |
628 | } | |
629 | if (myAspectText != NULL) | |
630 | { | |
631 | myAspectText->Release (theGlCtx); | |
632 | } | |
633 | if (myHighlightBox != NULL) | |
634 | { | |
635 | myHighlightBox->Release (theGlCtx); | |
636 | } | |
637 | } | |
638 | ||
59f45b7c | 639 | //======================================================================= |
640 | //function : SetZLayer | |
bf75be98 | 641 | //purpose : |
59f45b7c | 642 | //======================================================================= |
59f45b7c | 643 | void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex) |
644 | { | |
645 | myZLayer = theLayerIndex; | |
646 | } | |
647 | ||
648 | //======================================================================= | |
649 | //function : GetZLayer | |
bf75be98 | 650 | //purpose : |
59f45b7c | 651 | //======================================================================= |
59f45b7c | 652 | Standard_Integer OpenGl_Structure::GetZLayer () const |
653 | { | |
654 | return myZLayer; | |
655 | } |