Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
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 | // |
973c2be1 | 7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
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 | ||
30f0ad28 | 20 | #include <NCollection_Mat4.hxx> |
5f8b738e | 21 | |
bf75be98 | 22 | #include <OpenGl_Context.hxx> |
2166f0fa | 23 | #include <OpenGl_Display.hxx> |
30f0ad28 | 24 | #include <OpenGl_GlCore11.hxx> |
25 | #include <OpenGl_GraduatedTrihedron.hxx> | |
392ac980 | 26 | #include <OpenGl_GraphicDriver.hxx> |
30f0ad28 | 27 | #include <OpenGl_ShaderManager.hxx> |
bf75be98 | 28 | #include <OpenGl_Texture.hxx> |
2166f0fa | 29 | #include <OpenGl_Trihedron.hxx> |
2166f0fa | 30 | #include <OpenGl_transform_persistence.hxx> |
30f0ad28 | 31 | #include <OpenGl_View.hxx> |
32 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 33 | |
bf75be98 | 34 | #include <Graphic3d_TextureEnv.hxx> |
35 | ||
2166f0fa SK |
36 | IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared) |
37 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared) | |
38 | ||
39 | /*----------------------------------------------------------------------*/ | |
40 | ||
41 | static const OPENGL_BG_TEXTURE myDefaultBgTexture = { 0, 0, 0, Aspect_FM_CENTERED }; | |
42 | static const OPENGL_BG_GRADIENT myDefaultBgGradient = { {{ 0.F, 0.F, 0.F, 1.F }}, {{ 0.F, 0.F, 0.F, 1.F }}, Aspect_GFM_NONE }; | |
43 | static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } }; | |
44 | static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } }; | |
45 | static const OPENGL_EXTRA_REP myDefaultExtra = | |
46 | { | |
47 | //vrp | |
48 | { 0.F, 0.F, 0.F }, | |
49 | //vpn | |
50 | { 0.F, 0.F, 1.F }, | |
51 | //vup | |
52 | { 0.F, 1.F, 0.F }, | |
53 | //map | |
54 | { | |
55 | //window | |
56 | { 0.F, 0.F, 1.F, 1.F }, | |
57 | //viewport | |
58 | { 0.F, 0.F, 0.F, 1.F, 1.F, 1.F }, | |
59 | //proj | |
60 | TelParallel, | |
61 | //prp | |
62 | { 0.F, 0.F, 0.F }, | |
63 | //vpd | |
64 | 0.F, | |
65 | //fpd | |
66 | 0.F, | |
67 | //bpd | |
68 | -1.F | |
69 | }, | |
70 | //scaleFactors | |
71 | { 1.F, 1.F, 1.F } | |
72 | }; | |
73 | ||
74 | static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } }; | |
75 | static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F }; | |
c34dba32 | 76 | static const GLdouble THE_IDENTITY_MATRIX[4][4] = |
77 | { | |
78 | {1.0, 0.0, 0.0, 0.0}, | |
79 | {0.0, 1.0, 0.0, 0.0}, | |
80 | {0.0, 0.0, 1.0, 0.0}, | |
81 | {0.0, 0.0, 0.0, 1.0} | |
82 | }; | |
2166f0fa SK |
83 | |
84 | /*----------------------------------------------------------------------*/ | |
85 | ||
392ac980 | 86 | OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, |
87 | OpenGl_StateCounter* theCounter) | |
bf75be98 | 88 | : mySurfaceDetail(Visual3d_TOD_NONE), |
2166f0fa SK |
89 | myBackfacing(0), |
90 | myBgTexture(myDefaultBgTexture), | |
91 | myBgGradient(myDefaultBgGradient), | |
92 | //myOrientationMatrix(myDefaultMatrix), | |
93 | //myMappingMatrix(myDefaultMatrix), | |
94 | //shield_indicator = TOn, | |
95 | //shield_colour = { { 0.F, 0.F, 0.F, 1.F } }, | |
96 | //border_indicator = TOff, | |
97 | //border_colour = { { 0.F, 0.F, 0.F, 1.F } }, | |
98 | //active_status = TOn, | |
99 | myZClip(myDefaultZClip), | |
100 | myExtra(myDefaultExtra), | |
101 | myFog(myDefaultFog), | |
2f6cb3ac | 102 | myTrihedron(NULL), |
103 | myGraduatedTrihedron(NULL), | |
2166f0fa SK |
104 | myVisualization(AContext.Visualization), |
105 | myIntShadingMethod(TEL_SM_GOURAUD), | |
106 | myAntiAliasing(Standard_False), | |
2166f0fa | 107 | myTransPers(&myDefaultTransPers), |
30f0ad28 | 108 | myIsTransPers(Standard_False), |
392ac980 | 109 | myStateCounter (theCounter), |
110 | myLastOrientationState (0, 0), | |
111 | myLastViewMappingState (0, 0), | |
112 | myLastLightSourceState (0, 0) | |
2166f0fa SK |
113 | { |
114 | // Initialize matrices | |
115 | memcpy(myOrientationMatrix,myDefaultMatrix,sizeof(Tmatrix3)); | |
116 | memcpy(myMappingMatrix,myDefaultMatrix,sizeof(Tmatrix3)); | |
117 | ||
118 | // Shading method | |
119 | switch (AContext.Model) | |
120 | { | |
121 | case 1 : /* VISUAL3D_TOM_INTERP_COLOR */ | |
122 | case 3 : /* VISUAL3D_TOM_VERTEX */ | |
123 | myIntShadingMethod = TEL_SM_GOURAUD; | |
124 | break; | |
125 | default : | |
126 | myIntShadingMethod = TEL_SM_FLAT; | |
127 | break; | |
128 | } | |
e276548b | 129 | |
392ac980 | 130 | myCurrOrientationState = myStateCounter->Increment(); // <-- delete after merge with camera |
131 | myCurrViewMappingState = myStateCounter->Increment(); // <-- delete after merge with camera | |
132 | myCurrLightSourceState = myStateCounter->Increment(); | |
133 | ||
e276548b | 134 | #ifdef HAVE_OPENCL |
135 | myModificationState = 1; // initial state | |
136 | #endif | |
2166f0fa SK |
137 | } |
138 | ||
139 | /*----------------------------------------------------------------------*/ | |
140 | ||
141 | OpenGl_View::~OpenGl_View () | |
142 | { | |
bf75be98 | 143 | ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context |
144 | } | |
145 | ||
146 | void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) | |
147 | { | |
a174a3c5 | 148 | OpenGl_Element::Destroy (theCtx, myTrihedron); |
149 | OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron); | |
30f0ad28 | 150 | |
bf75be98 | 151 | if (!myTextureEnv.IsNull()) |
152 | { | |
153 | theCtx->DelayedRelease (myTextureEnv); | |
154 | myTextureEnv.Nullify(); | |
155 | } | |
156 | if (myBgTexture.TexId != 0) | |
157 | { | |
158 | glDeleteTextures (1, (GLuint*)&(myBgTexture.TexId)); | |
159 | myBgTexture.TexId = 0; | |
160 | } | |
bf75be98 | 161 | } |
2166f0fa | 162 | |
bf75be98 | 163 | void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx, |
164 | const Handle(Graphic3d_TextureEnv)& theTexture) | |
165 | { | |
166 | if (!myTextureEnv.IsNull()) | |
167 | { | |
168 | theCtx->DelayedRelease (myTextureEnv); | |
169 | myTextureEnv.Nullify(); | |
170 | } | |
171 | ||
172 | if (theTexture.IsNull()) | |
173 | { | |
174 | return; | |
175 | } | |
176 | ||
177 | myTextureEnv = new OpenGl_Texture (theTexture->GetParams()); | |
178 | Handle(Image_PixMap) anImage = theTexture->GetImage(); | |
e276548b | 179 | if (!anImage.IsNull()) |
da0e82aa | 180 | myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type()); |
e276548b | 181 | |
182 | #ifdef HAVE_OPENCL | |
183 | myModificationState++; | |
184 | #endif | |
185 | } | |
186 | ||
187 | void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode) | |
188 | { | |
189 | mySurfaceDetail = theMode; | |
190 | ||
191 | #ifdef HAVE_OPENCL | |
192 | myModificationState++; | |
193 | #endif | |
2166f0fa SK |
194 | } |
195 | ||
12381341 | 196 | // ======================================================================= |
197 | // function : SetBackfacing | |
198 | // purpose : | |
199 | // ======================================================================= | |
de75ed09 | 200 | void OpenGl_View::SetBackfacing (const Standard_Integer theMode) |
2166f0fa | 201 | { |
de75ed09 | 202 | myBackfacing = theMode; |
2166f0fa SK |
203 | } |
204 | ||
12381341 | 205 | // ======================================================================= |
206 | // function : SetLights | |
207 | // purpose : | |
208 | // ======================================================================= | |
209 | void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT& theViewCtx) | |
2166f0fa SK |
210 | { |
211 | myLights.Clear(); | |
12381341 | 212 | for (Standard_Integer aLightIt = 0; aLightIt < theViewCtx.NbActiveLight; ++aLightIt) |
2166f0fa | 213 | { |
12381341 | 214 | myLights.Append (theViewCtx.ActiveLight[aLightIt]); |
2166f0fa | 215 | } |
392ac980 | 216 | myCurrLightSourceState = myStateCounter->Increment(); |
2166f0fa SK |
217 | } |
218 | ||
219 | /*----------------------------------------------------------------------*/ | |
220 | ||
2166f0fa SK |
221 | //call_togl_setvisualisation |
222 | void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext) | |
223 | { | |
224 | myVisualization = AContext.Visualization; | |
225 | // Shading method | |
226 | switch (AContext.Model) | |
227 | { | |
228 | case 1 : /* VISUAL3D_TOM_INTERP_COLOR */ | |
229 | case 3 : /* VISUAL3D_TOM_VERTEX */ | |
230 | myIntShadingMethod = TEL_SM_GOURAUD; | |
231 | break; | |
232 | default : | |
233 | myIntShadingMethod = TEL_SM_FLAT; | |
234 | break; | |
235 | } | |
236 | } | |
237 | ||
238 | /*----------------------------------------------------------------------*/ | |
239 | ||
240 | //call_togl_cliplimit | |
bf75be98 | 241 | void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView) |
2166f0fa SK |
242 | { |
243 | myZClip.Back.Limit = | |
bf75be98 | 244 | (theCView.Context.ZClipBackPlane - theCView.Mapping.BackPlaneDistance) / |
245 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa | 246 | myZClip.Front.Limit = |
bf75be98 | 247 | (theCView.Context.ZClipFrontPlane - theCView.Mapping.BackPlaneDistance) / |
248 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
249 | if (myZClip.Back.Limit < 0.0f) | |
250 | myZClip.Back.Limit = 0.0f; | |
251 | if (myZClip.Front.Limit > 1.0f) | |
252 | myZClip.Front.Limit = 1.0f; | |
253 | if (myZClip.Back.Limit > myZClip.Front.Limit) | |
2166f0fa | 254 | { |
bf75be98 | 255 | myZClip.Back.Limit = 0.0f; |
256 | myZClip.Front.Limit = 1.0f; | |
2166f0fa SK |
257 | } |
258 | ||
bf75be98 | 259 | myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0); |
260 | myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0); | |
2166f0fa SK |
261 | } |
262 | ||
263 | /*----------------------------------------------------------------------*/ | |
264 | ||
265 | //call_togl_viewmapping | |
fd4a6963 | 266 | void OpenGl_View::SetMapping (const Handle(OpenGl_Display)& theGlDisplay, |
267 | const Graphic3d_CView& theCView) | |
2166f0fa | 268 | { |
bf75be98 | 269 | const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx; |
270 | const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy; | |
2166f0fa SK |
271 | |
272 | TEL_VIEW_MAPPING Map; | |
273 | ||
bf75be98 | 274 | Map.window.xmin = theCView.Mapping.WindowLimit.um; |
275 | Map.window.ymin = theCView.Mapping.WindowLimit.vm; | |
276 | Map.window.xmax = theCView.Mapping.WindowLimit.uM; | |
277 | Map.window.ymax = theCView.Mapping.WindowLimit.vM; | |
2166f0fa SK |
278 | |
279 | Map.viewport.xmin = 0.F; | |
280 | Map.viewport.xmax = ( 1.F < r_ratio ? 1.F : r_ratio ); | |
281 | Map.viewport.ymin = 0.F; | |
282 | Map.viewport.ymax = ( 1.F < ratio ? 1.F : ratio ); | |
283 | Map.viewport.zmin = 0.F; | |
284 | Map.viewport.zmax = 1.F; | |
285 | ||
bf75be98 | 286 | // projection type |
287 | switch (theCView.Mapping.Projection) | |
2166f0fa SK |
288 | { |
289 | case 0 : | |
290 | Map.proj = TelPerspective; | |
291 | break; | |
292 | case 1 : | |
293 | Map.proj = TelParallel; | |
294 | break; | |
295 | } | |
296 | ||
bf75be98 | 297 | // projection reference point |
298 | Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x; | |
299 | Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y; | |
300 | Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z; | |
fd4a6963 | 301 | if (!theGlDisplay.IsNull() && !theGlDisplay->Walkthrough()) |
bf75be98 | 302 | Map.prp[2] += theCView.Mapping.FrontPlaneDistance; |
2166f0fa | 303 | |
bf75be98 | 304 | // view plane distance |
305 | Map.vpd = theCView.Mapping.ViewPlaneDistance; | |
2166f0fa | 306 | |
bf75be98 | 307 | // back plane distance |
308 | Map.bpd = theCView.Mapping.BackPlaneDistance; | |
2166f0fa | 309 | |
bf75be98 | 310 | // front plane distance |
311 | Map.fpd = theCView.Mapping.FrontPlaneDistance; | |
2166f0fa SK |
312 | |
313 | Tint err_ind = 0; | |
314 | ||
bf75be98 | 315 | // use user-defined matrix |
316 | if (theCView.Mapping.IsCustomMatrix) | |
2166f0fa SK |
317 | { |
318 | int i, j; | |
319 | for( i = 0; i < 4; i++ ) | |
320 | for( j = 0; j < 4; j++ ) | |
bf75be98 | 321 | myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j]; |
2166f0fa | 322 | } |
bf75be98 | 323 | else |
fd4a6963 | 324 | TelEvalViewMappingMatrix (theGlDisplay, &Map, &err_ind, myMappingMatrix); |
2166f0fa | 325 | |
bf75be98 | 326 | if (!err_ind) |
2166f0fa | 327 | myExtra.map = Map; |
30f0ad28 | 328 | |
392ac980 | 329 | myCurrViewMappingState = myStateCounter->Increment(); |
2166f0fa SK |
330 | } |
331 | ||
332 | /*----------------------------------------------------------------------*/ | |
333 | ||
334 | //call_togl_vieworientation | |
bf75be98 | 335 | void OpenGl_View::SetOrientation (const Graphic3d_CView& theCView) |
2166f0fa SK |
336 | { |
337 | Tfloat Vrp[3]; | |
338 | Tfloat Vpn[3]; | |
339 | Tfloat Vup[3]; | |
340 | Tfloat ScaleFactors[3]; | |
341 | ||
bf75be98 | 342 | Vrp[0] = theCView.Orientation.ViewReferencePoint.x; |
343 | Vrp[1] = theCView.Orientation.ViewReferencePoint.y; | |
344 | Vrp[2] = theCView.Orientation.ViewReferencePoint.z; | |
2166f0fa | 345 | |
bf75be98 | 346 | Vpn[0] = theCView.Orientation.ViewReferencePlane.x; |
347 | Vpn[1] = theCView.Orientation.ViewReferencePlane.y; | |
348 | Vpn[2] = theCView.Orientation.ViewReferencePlane.z; | |
2166f0fa | 349 | |
bf75be98 | 350 | Vup[0] = theCView.Orientation.ViewReferenceUp.x; |
351 | Vup[1] = theCView.Orientation.ViewReferenceUp.y; | |
352 | Vup[2] = theCView.Orientation.ViewReferenceUp.z; | |
2166f0fa | 353 | |
bf75be98 | 354 | ScaleFactors[0] = theCView.Orientation.ViewScaleX; |
355 | ScaleFactors[1] = theCView.Orientation.ViewScaleY; | |
356 | ScaleFactors[2] = theCView.Orientation.ViewScaleZ; | |
2166f0fa SK |
357 | |
358 | Tint err_ind = 0; | |
359 | ||
360 | // use user-defined matrix | |
bf75be98 | 361 | if (theCView.Orientation.IsCustomMatrix) |
2166f0fa SK |
362 | { |
363 | int i, j; | |
364 | for( i = 0; i < 4; i++ ) | |
365 | for( j = 0; j < 4; j++ ) | |
bf75be98 | 366 | myOrientationMatrix[i][j] = theCView.Orientation.ModelViewMatrix[i][j]; |
2166f0fa SK |
367 | } |
368 | else | |
bf75be98 | 369 | { |
370 | TelEvalViewOrientationMatrix (Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix); | |
371 | } | |
2166f0fa | 372 | |
bf75be98 | 373 | if (!err_ind) |
2166f0fa SK |
374 | { |
375 | myExtra.vrp[0] = Vrp[0]; | |
376 | myExtra.vrp[1] = Vrp[1]; | |
377 | myExtra.vrp[2] = Vrp[2]; | |
378 | ||
379 | myExtra.vpn[0] = Vpn[0]; | |
380 | myExtra.vpn[1] = Vpn[1]; | |
381 | myExtra.vpn[2] = Vpn[2]; | |
382 | ||
383 | myExtra.vup[0] = Vup[0]; | |
384 | myExtra.vup[1] = Vup[1]; | |
385 | myExtra.vup[2] = Vup[2]; | |
386 | ||
387 | myExtra.scaleFactors[0] = ScaleFactors[0], | |
388 | myExtra.scaleFactors[1] = ScaleFactors[1], | |
389 | myExtra.scaleFactors[2] = ScaleFactors[2]; | |
390 | } | |
30f0ad28 | 391 | |
392ac980 | 392 | myCurrOrientationState = myStateCounter->Increment(); |
2166f0fa SK |
393 | } |
394 | ||
395 | /*----------------------------------------------------------------------*/ | |
396 | ||
bf75be98 | 397 | void OpenGl_View::SetFog (const Graphic3d_CView& theCView, |
398 | const Standard_Boolean theFlag) | |
2166f0fa | 399 | { |
bf75be98 | 400 | if (!theFlag) |
2166f0fa SK |
401 | { |
402 | myFog.IsOn = Standard_False; | |
403 | } | |
404 | else | |
405 | { | |
406 | myFog.IsOn = Standard_True; | |
407 | ||
408 | myFog.Front = | |
bf75be98 | 409 | (theCView.Context.DepthFrontPlane - theCView.Mapping.BackPlaneDistance) / |
410 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa SK |
411 | |
412 | myFog.Back = | |
bf75be98 | 413 | (theCView.Context.DepthBackPlane - theCView.Mapping.BackPlaneDistance) / |
414 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa SK |
415 | |
416 | if (myFog.Front < 0.F) | |
417 | myFog.Front = 0.F; | |
418 | else if (myFog.Front > 1.F) | |
419 | myFog.Front = 1.F; | |
420 | ||
421 | if (myFog.Back < 0.F) | |
422 | myFog.Back = 0.F; | |
423 | else if (myFog.Back > 1.F) | |
424 | myFog.Back = 1.F; | |
425 | ||
426 | if (myFog.Back > myFog.Front) | |
427 | { | |
428 | myFog.Front = 1.F; | |
429 | myFog.Back = 0.F; | |
430 | } | |
431 | ||
bf75be98 | 432 | myFog.Color.rgb[0] = theCView.DefWindow.Background.r; |
433 | myFog.Color.rgb[1] = theCView.DefWindow.Background.g; | |
434 | myFog.Color.rgb[2] = theCView.DefWindow.Background.b; | |
435 | myFog.Color.rgb[3] = 1.0f; | |
2166f0fa SK |
436 | } |
437 | } | |
438 | ||
439 | /*----------------------------------------------------------------------*/ | |
440 | ||
a174a3c5 | 441 | void OpenGl_View::TriedronDisplay (const Handle(OpenGl_Context)& theCtx, |
442 | const Aspect_TypeOfTriedronPosition thePosition, | |
443 | const Quantity_NameOfColor theColor, | |
444 | const Standard_Real theScale, | |
445 | const Standard_Boolean theAsWireframe) | |
2166f0fa | 446 | { |
a174a3c5 | 447 | OpenGl_Element::Destroy (theCtx, myTrihedron); |
448 | myTrihedron = new OpenGl_Trihedron (thePosition, theColor, theScale, theAsWireframe); | |
2166f0fa SK |
449 | } |
450 | ||
451 | /*----------------------------------------------------------------------*/ | |
452 | ||
a174a3c5 | 453 | void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx) |
2166f0fa | 454 | { |
a174a3c5 | 455 | OpenGl_Element::Destroy (theCtx, myTrihedron); |
2166f0fa SK |
456 | } |
457 | ||
458 | /*----------------------------------------------------------------------*/ | |
459 | ||
a174a3c5 | 460 | void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, |
461 | const Graphic3d_CGraduatedTrihedron& theData) | |
2166f0fa | 462 | { |
a174a3c5 | 463 | OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron); |
464 | myGraduatedTrihedron = new OpenGl_GraduatedTrihedron (theData); | |
2166f0fa SK |
465 | } |
466 | ||
467 | /*----------------------------------------------------------------------*/ | |
468 | ||
a174a3c5 | 469 | void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx) |
2166f0fa | 470 | { |
a174a3c5 | 471 | OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron); |
2166f0fa SK |
472 | } |
473 | ||
474 | /*----------------------------------------------------------------------*/ | |
475 | ||
476 | //transform_persistence_end | |
30f0ad28 | 477 | void OpenGl_View::EndTransformPersistence(const Handle(OpenGl_Context)& theCtx) |
2166f0fa | 478 | { |
c34dba32 | 479 | if (myIsTransPers) |
2166f0fa | 480 | { |
c34dba32 | 481 | // restore matrix |
2166f0fa | 482 | glMatrixMode (GL_PROJECTION); |
c34dba32 | 483 | glPopMatrix(); |
2166f0fa | 484 | glMatrixMode (GL_MODELVIEW); |
c34dba32 | 485 | glPopMatrix(); |
2166f0fa | 486 | myIsTransPers = Standard_False; |
30f0ad28 | 487 | |
488 | // Note: the approach of accessing OpenGl matrices is used now since the matrix | |
489 | // manipulation are made with help of OpenGl methods. This might be replaced by | |
490 | // direct computation of matrices by OCC subroutines. | |
491 | Tmatrix3 aResultWorldView; | |
492 | glGetFloatv (GL_MODELVIEW_MATRIX, *aResultWorldView); | |
493 | ||
494 | Tmatrix3 aResultProjection; | |
495 | glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection); | |
496 | ||
497 | // Set OCCT state uniform variables | |
498 | theCtx->ShaderManager()->RevertWorldViewStateTo (aResultWorldView); | |
499 | theCtx->ShaderManager()->RevertProjectionStateTo (aResultProjection); | |
2166f0fa | 500 | } |
bf75be98 | 501 | } |
2166f0fa SK |
502 | |
503 | /*----------------------------------------------------------------------*/ | |
504 | ||
505 | //transform_persistence_begin | |
30f0ad28 | 506 | const TEL_TRANSFORM_PERSISTENCE* OpenGl_View::BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx, |
507 | const TEL_TRANSFORM_PERSISTENCE* theTransPers) | |
2166f0fa | 508 | { |
c34dba32 | 509 | const TEL_TRANSFORM_PERSISTENCE* aTransPersPrev = myTransPers; |
510 | myTransPers = theTransPers; | |
511 | if (theTransPers->mode == 0) | |
2166f0fa | 512 | { |
30f0ad28 | 513 | EndTransformPersistence (theCtx); |
c34dba32 | 514 | return aTransPersPrev; |
2166f0fa SK |
515 | } |
516 | ||
c34dba32 | 517 | GLint aViewport[4]; |
518 | GLdouble aModelMatrix[4][4]; | |
519 | GLdouble aProjMatrix[4][4]; | |
520 | glGetIntegerv (GL_VIEWPORT, aViewport); | |
521 | glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix); | |
522 | glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble *)aProjMatrix); | |
523 | const GLdouble aViewportW = (GLdouble )aViewport[2]; | |
524 | const GLdouble aViewportH = (GLdouble )aViewport[3]; | |
2166f0fa | 525 | |
c34dba32 | 526 | if (myIsTransPers) |
2166f0fa | 527 | { |
c34dba32 | 528 | // pop matrix stack - it will be overridden later |
2166f0fa | 529 | glMatrixMode (GL_PROJECTION); |
c34dba32 | 530 | glPopMatrix(); |
2166f0fa | 531 | glMatrixMode (GL_MODELVIEW); |
c34dba32 | 532 | glPopMatrix(); |
2166f0fa SK |
533 | } |
534 | else | |
c34dba32 | 535 | { |
2166f0fa | 536 | myIsTransPers = Standard_True; |
c34dba32 | 537 | } |
2166f0fa | 538 | |
c34dba32 | 539 | // push matrices into stack and reset them |
540 | glMatrixMode (GL_MODELVIEW); | |
2166f0fa SK |
541 | glPushMatrix(); |
542 | glLoadIdentity(); | |
543 | ||
c34dba32 | 544 | glMatrixMode (GL_PROJECTION); |
2166f0fa SK |
545 | glPushMatrix(); |
546 | glLoadIdentity(); | |
547 | ||
c34dba32 | 548 | // get the window's (fixed) coordinates for theTransPers->point before matrixes modifications |
549 | GLdouble aWinX = 0.0, aWinY = 0.0, aWinZ = 0.0; | |
550 | if ((theTransPers->mode & TPF_PAN) != TPF_PAN) | |
2166f0fa | 551 | { |
c34dba32 | 552 | gluProject (theTransPers->pointX, theTransPers->pointY, theTransPers->pointZ, |
553 | (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport, | |
554 | &aWinX, &aWinY, &aWinZ); | |
2166f0fa SK |
555 | } |
556 | ||
c34dba32 | 557 | // prevent zooming |
558 | if ((theTransPers->mode & TPF_ZOOM) | |
559 | || (theTransPers->mode == TPF_TRIEDRON)) | |
2166f0fa | 560 | { |
c34dba32 | 561 | // compute fixed-zoom multiplier |
562 | // actually function works ugly with TelPerspective! | |
563 | const GLdouble aDet2 = 0.002 / (aViewportW > aViewportH ? aProjMatrix[1][1] : aProjMatrix[0][0]); | |
564 | aProjMatrix[0][0] *= aDet2; | |
565 | aProjMatrix[1][1] *= aDet2; | |
566 | aProjMatrix[2][2] *= aDet2; | |
2166f0fa SK |
567 | } |
568 | ||
c34dba32 | 569 | // prevent translation - annulate translate matrix |
570 | if ((theTransPers->mode & TPF_PAN) | |
571 | || (theTransPers->mode == TPF_TRIEDRON)) | |
2166f0fa | 572 | { |
c34dba32 | 573 | aModelMatrix[3][0] = 0.0; |
574 | aModelMatrix[3][1] = 0.0; | |
575 | aModelMatrix[3][2] = 0.0; | |
576 | aProjMatrix [3][0] = 0.0; | |
577 | aProjMatrix [3][1] = 0.0; | |
578 | aProjMatrix [3][2] = 0.0; | |
2166f0fa | 579 | } |
2166f0fa | 580 | |
c34dba32 | 581 | // prevent scaling-on-axis |
582 | if (theTransPers->mode & TPF_ZOOM) | |
583 | { | |
584 | const double aScaleX = myExtra.scaleFactors[0]; | |
585 | const double aScaleY = myExtra.scaleFactors[1]; | |
586 | const double aScaleZ = myExtra.scaleFactors[2]; | |
587 | for (int i = 0; i < 3; ++i) | |
588 | { | |
589 | aModelMatrix[0][i] /= aScaleX; | |
590 | aModelMatrix[1][i] /= aScaleY; | |
591 | aModelMatrix[2][i] /= aScaleZ; | |
592 | } | |
2166f0fa SK |
593 | } |
594 | ||
c34dba32 | 595 | // prevent rotating - annulate rotate matrix |
596 | if (theTransPers->mode & TPF_ROTATE) | |
2166f0fa | 597 | { |
c34dba32 | 598 | aModelMatrix[0][0] = 1.0; |
599 | aModelMatrix[1][1] = 1.0; | |
600 | aModelMatrix[2][2] = 1.0; | |
601 | ||
602 | aModelMatrix[1][0] = 0.0; | |
603 | aModelMatrix[2][0] = 0.0; | |
604 | aModelMatrix[0][1] = 0.0; | |
605 | aModelMatrix[2][1] = 0.0; | |
606 | aModelMatrix[0][2] = 0.0; | |
607 | aModelMatrix[1][2] = 0.0; | |
2166f0fa SK |
608 | } |
609 | ||
c34dba32 | 610 | // load computed matrices |
2166f0fa | 611 | glMatrixMode (GL_MODELVIEW); |
c34dba32 | 612 | glMultMatrixd ((GLdouble* )aModelMatrix); |
2166f0fa SK |
613 | |
614 | glMatrixMode (GL_PROJECTION); | |
c34dba32 | 615 | glMultMatrixd ((GLdouble* )aProjMatrix); |
2166f0fa | 616 | |
c34dba32 | 617 | if (theTransPers->mode == TPF_TRIEDRON) |
2166f0fa | 618 | { |
c34dba32 | 619 | // move to the window corner |
620 | if (theTransPers->pointX != 0.0 | |
621 | && theTransPers->pointY != 0.0) | |
2166f0fa | 622 | { |
c34dba32 | 623 | GLdouble aW1, aH1, aW2, aH2, aDummy; |
624 | glMatrixMode (GL_PROJECTION); | |
625 | gluUnProject ( 0.5 * aViewportW, 0.5 * aViewportH, 0.0, | |
626 | (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport, | |
627 | &aW1, &aH1, &aDummy); | |
628 | gluUnProject (-0.5 * aViewportW, -0.5 * aViewportH, 0.0, | |
629 | (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport, | |
630 | &aW2, &aH2, &aDummy); | |
631 | GLdouble aMoveX = 0.5 * (aW1 - aW2 - theTransPers->pointZ); | |
632 | GLdouble aMoveY = 0.5 * (aH1 - aH2 - theTransPers->pointZ); | |
633 | aMoveX = (theTransPers->pointX > 0.0) ? aMoveX : -aMoveX; | |
634 | aMoveY = (theTransPers->pointY > 0.0) ? aMoveY : -aMoveY; | |
635 | glTranslated (aMoveX, aMoveY, 0.0); | |
2166f0fa SK |
636 | } |
637 | } | |
c34dba32 | 638 | else if ((theTransPers->mode & TPF_PAN) != TPF_PAN) |
639 | { | |
640 | // move to thePoint using saved win-coordinates ('marker-behaviour') | |
641 | GLdouble aMoveX, aMoveY, aMoveZ; | |
642 | glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix); | |
643 | glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble* )aProjMatrix); | |
644 | gluUnProject (aWinX, aWinY, aWinZ, | |
645 | (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport, | |
646 | &aMoveX, &aMoveY, &aMoveZ); | |
2166f0fa | 647 | |
c34dba32 | 648 | glMatrixMode (GL_MODELVIEW); |
649 | glTranslated (aMoveX, aMoveY, aMoveZ); | |
650 | } | |
2166f0fa | 651 | |
30f0ad28 | 652 | // Note: the approach of accessing OpenGl matrices is used now since the matrix |
653 | // manipulation are made with help of OpenGl methods. This might be replaced by | |
654 | // direct computation of matrices by OCC subroutines. | |
655 | Tmatrix3 aResultWorldView; | |
656 | glGetFloatv (GL_MODELVIEW_MATRIX, *aResultWorldView); | |
657 | ||
658 | Tmatrix3 aResultProjection; | |
659 | glGetFloatv (GL_PROJECTION_MATRIX, *aResultProjection); | |
660 | ||
661 | // Set OCCT state uniform variables | |
662 | theCtx->ShaderManager()->UpdateWorldViewStateTo (aResultWorldView); | |
663 | theCtx->ShaderManager()->UpdateProjectionStateTo (aResultProjection); | |
664 | ||
c34dba32 | 665 | return aTransPersPrev; |
666 | } |