Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
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 SK |
20 | #include <stdio.h> |
21 | #include <stdlib.h> | |
22 | ||
5f8b738e | 23 | #include <OpenGl_GlCore11.hxx> |
2166f0fa SK |
24 | #include <OpenGl_tgl_funcs.hxx> |
25 | #include <OpenGl_TextureBox.hxx> | |
26 | ||
3c3131a0 | 27 | #include <Image_AlienPixMap.hxx> |
2166f0fa SK |
28 | #include <Visual3d_Layer.hxx> |
29 | ||
2166f0fa SK |
30 | #include <OpenGl_AspectLine.hxx> |
31 | #include <OpenGl_Display.hxx> | |
32 | #include <OpenGl_Workspace.hxx> | |
33 | #include <OpenGl_View.hxx> | |
34 | #include <OpenGl_Trihedron.hxx> | |
35 | #include <OpenGl_GraduatedTrihedron.hxx> | |
36 | #include <OpenGl_PrinterContext.hxx> | |
59f45b7c | 37 | #include <OpenGl_Structure.hxx> |
2166f0fa | 38 | |
5f8b738e | 39 | #include <GL/glu.h> // gluBuild2DMipmaps() |
2166f0fa SK |
40 | |
41 | #define EPSI 0.0001 | |
42 | ||
2166f0fa SK |
43 | static const GLfloat default_amb[4] = { 0.F, 0.F, 0.F, 1.F }; |
44 | static const GLfloat default_sptdir[3] = { 0.F, 0.F, -1.F }; | |
45 | static const GLfloat default_sptexpo = 0.F; | |
46 | static const GLfloat default_sptcutoff = 180.F; | |
47 | ||
48 | extern void InitLayerProp (const int AListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx | |
49 | ||
50 | /*----------------------------------------------------------------------*/ | |
51 | ||
52 | struct OPENGL_CLIP_PLANE | |
53 | { | |
54 | GLboolean isEnabled; | |
55 | GLdouble Equation[4]; | |
1c35b92f | 56 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
57 | }; |
58 | ||
59 | /*----------------------------------------------------------------------*/ | |
60 | /* | |
61 | * Fonctions privees | |
62 | */ | |
63 | ||
64 | /*-----------------------------------------------------------------*/ | |
65 | /* | |
66 | * Set des lumieres | |
67 | */ | |
68 | static void bind_light(const OpenGl_Light *lptr, int *gl_lid) | |
69 | { | |
70 | // Only 8 lights in OpenGL... | |
71 | if (*gl_lid > GL_LIGHT7) return; | |
72 | ||
73 | // the light is a headlight ? | |
74 | GLint cur_matrix; | |
75 | if (lptr->HeadLight) | |
76 | { | |
77 | glGetIntegerv(GL_MATRIX_MODE, &cur_matrix); | |
78 | glMatrixMode(GL_MODELVIEW); | |
79 | glPushMatrix(); | |
80 | glLoadIdentity(); | |
81 | } | |
82 | ||
83 | GLfloat data_amb[4]; | |
84 | GLfloat data_diffu[4]; | |
85 | GLfloat data_pos[4]; | |
86 | GLfloat data_sptdir[3]; | |
87 | GLfloat data_sptexpo; | |
88 | GLfloat data_sptcutoff; | |
89 | GLfloat data_constantattenuation; | |
90 | GLfloat data_linearattenuation; | |
91 | ||
92 | /* set la light en fonction de son type */ | |
93 | switch (lptr->type) | |
94 | { | |
95 | case TLightAmbient: | |
96 | data_amb[0] = lptr->col.rgb[0]; | |
97 | data_amb[1] = lptr->col.rgb[1]; | |
98 | data_amb[2] = lptr->col.rgb[2]; | |
99 | data_amb[3] = 1.0; | |
100 | ||
101 | /*------------------------- Ambient ---------------------------*/ | |
102 | /* | |
103 | * The GL_AMBIENT parameter refers to RGBA intensity of the ambient | |
104 | * light. | |
105 | */ | |
3c3131a0 | 106 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data_amb); |
2166f0fa SK |
107 | break; |
108 | ||
109 | ||
110 | case TLightDirectional: | |
111 | data_diffu[0] = lptr->col.rgb[0]; | |
112 | data_diffu[1] = lptr->col.rgb[1]; | |
113 | data_diffu[2] = lptr->col.rgb[2]; | |
114 | data_diffu[3] = 1.0; | |
115 | ||
116 | /*------------------------- Direction ---------------------------*/ | |
117 | /* From Open GL Programming Rev 1 Guide Chapt 6 : | |
118 | Lighting The Mathematics of Lighting ( p 168 ) | |
119 | ||
120 | Directional Light Source ( Infinite ) : | |
121 | if the last parameter of GL_POSITION , w , is zero, the | |
122 | corresponding light source is a Directional one. | |
123 | ||
124 | GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot. | |
3c3131a0 | 125 | To create a realistic effect, set the GL_SPECULAR parameter |
2166f0fa SK |
126 | to the same value as the GL_DIFFUSE. |
127 | */ | |
128 | ||
129 | data_pos[0] = -lptr->dir[0]; | |
130 | data_pos[1] = -lptr->dir[1]; | |
131 | data_pos[2] = -lptr->dir[2]; | |
132 | data_pos[3] = 0.0; | |
133 | ||
134 | glLightfv(*gl_lid, GL_AMBIENT, default_amb); | |
135 | glLightfv(*gl_lid, GL_DIFFUSE, data_diffu); | |
136 | glLightfv(*gl_lid, GL_SPECULAR, data_diffu); | |
137 | ||
138 | glLightfv(*gl_lid, GL_POSITION, data_pos); | |
139 | glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir); | |
140 | glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo); | |
141 | glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff); | |
142 | break; | |
143 | ||
144 | ||
145 | case TLightPositional: | |
146 | data_diffu[0] = lptr->col.rgb[0]; | |
147 | data_diffu[1] = lptr->col.rgb[1]; | |
148 | data_diffu[2] = lptr->col.rgb[2]; | |
149 | data_diffu[3] = 1.0; | |
150 | ||
151 | /*------------------------- Position -----------------------------*/ | |
152 | /* From Open GL Programming Rev 1 Guide Chapt 6 : | |
153 | Lighting The Mathematics of Lighting ( p 168 ) | |
154 | Positional Light Source : | |
155 | if the last parameter of GL_POSITION , w , is nonzero, | |
156 | the corresponding light source is a Positional one. | |
157 | ||
158 | GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot. | |
159 | ||
3c3131a0 | 160 | To create a realistic effect, set the GL_SPECULAR parameter |
2166f0fa SK |
161 | to the same value as the GL_DIFFUSE. |
162 | */ | |
163 | ||
164 | data_pos[0] = lptr->pos[0]; | |
165 | data_pos[1] = lptr->pos[1]; | |
166 | data_pos[2] = lptr->pos[2]; | |
167 | data_pos[3] = 1.0; | |
168 | ||
169 | data_constantattenuation = lptr->atten[0]; | |
170 | data_linearattenuation = lptr->atten[1]; | |
171 | ||
172 | glLightfv(*gl_lid, GL_AMBIENT, default_amb); | |
173 | glLightfv(*gl_lid, GL_DIFFUSE, data_diffu); | |
174 | glLightfv(*gl_lid, GL_SPECULAR, data_diffu); | |
175 | ||
176 | glLightfv(*gl_lid, GL_POSITION, data_pos); | |
177 | glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir); | |
178 | glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo); | |
179 | glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff); | |
180 | glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation); | |
181 | glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation); | |
3c3131a0 | 182 | glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0); |
2166f0fa SK |
183 | break; |
184 | ||
185 | ||
186 | case TLightSpot: | |
187 | data_diffu[0] = lptr->col.rgb[0]; | |
188 | data_diffu[1] = lptr->col.rgb[1]; | |
189 | data_diffu[2] = lptr->col.rgb[2]; | |
190 | data_diffu[3] = 1.0; | |
191 | ||
192 | data_pos[0] = lptr->pos[0]; | |
193 | data_pos[1] = lptr->pos[1]; | |
194 | data_pos[2] = lptr->pos[2]; | |
195 | data_pos[3] = 1.0; | |
196 | ||
197 | data_sptdir[0] = lptr->dir[0]; | |
198 | data_sptdir[1] = lptr->dir[1]; | |
199 | data_sptdir[2] = lptr->dir[2]; | |
200 | ||
201 | data_sptexpo = ( float )lptr->shine * 128.0F; | |
202 | data_sptcutoff = ( float )(lptr->angle * 180.0F)/( float )M_PI; | |
203 | ||
204 | data_constantattenuation = lptr->atten[0]; | |
205 | data_linearattenuation = lptr->atten[1]; | |
206 | ||
207 | glLightfv(*gl_lid, GL_AMBIENT, default_amb); | |
208 | glLightfv(*gl_lid, GL_DIFFUSE, data_diffu); | |
3c3131a0 | 209 | glLightfv(*gl_lid, GL_SPECULAR, data_diffu); |
2166f0fa | 210 | |
3c3131a0 | 211 | glLightfv(*gl_lid, GL_POSITION, data_pos); |
2166f0fa SK |
212 | glLightfv(*gl_lid, GL_SPOT_DIRECTION, data_sptdir); |
213 | glLightf(*gl_lid, GL_SPOT_EXPONENT, data_sptexpo); | |
214 | glLightf(*gl_lid, GL_SPOT_CUTOFF, data_sptcutoff); | |
215 | glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation); | |
216 | glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation); | |
3c3131a0 | 217 | glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0); |
2166f0fa SK |
218 | break; |
219 | } | |
220 | ||
3c3131a0 | 221 | if (lptr->type != TLightAmbient) |
222 | { | |
2166f0fa SK |
223 | glEnable(*gl_lid); |
224 | (*gl_lid)++; | |
225 | } | |
226 | ||
227 | /* si la light etait une headlight alors restaure la matrice precedente */ | |
228 | if (lptr->HeadLight) | |
229 | { | |
230 | glPopMatrix(); | |
231 | glMatrixMode(cur_matrix); | |
232 | } | |
233 | } | |
234 | ||
235 | /*----------------------------------------------------------------------*/ | |
236 | /* | |
237 | * Prototypes | |
238 | */ | |
239 | ||
240 | static void call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat, | |
241 | float *ox, float *oy, float *oz ); | |
242 | static void call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c); | |
243 | ||
244 | /*----------------------------------------------------------------------*/ | |
245 | /* | |
246 | * Fonctions externes | |
247 | */ | |
248 | ||
249 | /* | |
250 | * Evaluates orientation matrix. | |
251 | */ | |
252 | /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */ | |
253 | void call_func_eval_ori_matrix3 (const point3* vrp, // view reference point | |
254 | const vec3* vpn, // view plane normal | |
255 | const vec3* vup, // view up vector | |
3c3131a0 | 256 | int* err_ind, |
2166f0fa SK |
257 | float mout[4][4]) // OUT view orientation matrix |
258 | { | |
259 | ||
260 | /* Translate to VRP then change the basis. | |
261 | * The old basis is: e1 = < 1, 0, 0>, e2 = < 0, 1, 0>, e3 = < 0, 0, 1>. | |
262 | * The new basis is: ("x" means cross product) | |
263 | * e3' = VPN / |VPN| | |
264 | * e1' = VUP x VPN / |VUP x VPN| | |
265 | * e2' = e3' x e1' | |
266 | * Therefore the transform from old to new is x' = TAx, where: | |
267 | * | |
268 | * | e1'x e2'x e3'x 0 | | 1 0 0 0 | | |
269 | * A = | e1'y e2'y e3'y 0 |, T = | 0 1 0 0 | | |
270 | * | e1'z e2'z e3'z 0 | | 0 0 1 0 | | |
271 | * | 0 0 0 1 | | -vrp.x -vrp.y -vrp.z 1 | | |
272 | * | |
273 | */ | |
274 | ||
275 | /* | |
276 | * These ei's are really ei primes. | |
277 | */ | |
278 | register float (*m)[4][4]; | |
279 | point3 e1, e2, e3, e4; | |
280 | double s, v; | |
281 | ||
282 | /* | |
283 | * e1' = VUP x VPN / |VUP x VPN|, but do the division later. | |
284 | */ | |
285 | e1.x = vup->delta_y * vpn->delta_z - vup->delta_z * vpn->delta_y; | |
286 | e1.y = vup->delta_z * vpn->delta_x - vup->delta_x * vpn->delta_z; | |
287 | e1.z = vup->delta_x * vpn->delta_y - vup->delta_y * vpn->delta_x; | |
288 | s = sqrt( e1.x * e1.x + e1.y * e1.y + e1.z * e1.z); | |
289 | e3.x = vpn->delta_x; | |
290 | e3.y = vpn->delta_y; | |
291 | e3.z = vpn->delta_z; | |
292 | v = sqrt( e3.x * e3.x + e3.y * e3.y + e3.z * e3.z); | |
293 | /* | |
294 | * Check for vup and vpn colinear (zero dot product). | |
295 | */ | |
296 | if ((s > -EPSI) && (s < EPSI)) | |
297 | *err_ind = 2; | |
298 | else | |
299 | /* | |
300 | * Check for a normal vector not null. | |
301 | */ | |
302 | if ((v > -EPSI) && (v < EPSI)) | |
303 | *err_ind = 3; | |
304 | else { | |
305 | /* | |
306 | * Normalize e1 | |
307 | */ | |
308 | e1.x /= ( float )s; | |
309 | e1.y /= ( float )s; | |
310 | e1.z /= ( float )s; | |
311 | /* | |
312 | * e3 = VPN / |VPN| | |
313 | */ | |
314 | e3.x /= ( float )v; | |
315 | e3.y /= ( float )v; | |
316 | e3.z /= ( float )v; | |
317 | /* | |
318 | * e2 = e3 x e1 | |
319 | */ | |
320 | e2.x = e3.y * e1.z - e3.z * e1.y; | |
321 | e2.y = e3.z * e1.x - e3.x * e1.z; | |
322 | e2.z = e3.x * e1.y - e3.y * e1.x; | |
323 | /* | |
324 | * Add the translation | |
325 | */ | |
326 | e4.x = -( e1.x * vrp->x + e1.y * vrp->y + e1.z * vrp->z); | |
327 | e4.y = -( e2.x * vrp->x + e2.y * vrp->y + e2.z * vrp->z); | |
328 | e4.z = -( e3.x * vrp->x + e3.y * vrp->y + e3.z * vrp->z); | |
329 | /* | |
330 | * Homogeneous entries | |
331 | * | |
332 | * | e1.x e2.x e3.x 0.0 | | 1 0 0 0 | | |
333 | * | e1.y e2.y e3.y 0.0 | * | 0 1 0 0 | | |
334 | * | e1.z e2.z e3.z 0.0 | | a b 1 c | | |
335 | * | e4.x e4.y e4.z 1.0 | | 0 0 0 1 | | |
336 | */ | |
337 | ||
338 | m = (float (*)[4][4])mout; | |
339 | ||
340 | (*m)[0][0] = e1.x; | |
341 | (*m)[0][1] = e2.x; | |
342 | (*m)[0][2] = e3.x; | |
343 | (*m)[0][3] = ( float )0.0; | |
344 | ||
345 | (*m)[1][0] = e1.y; | |
346 | (*m)[1][1] = e2.y; | |
347 | (*m)[1][2] = e3.y; | |
348 | (*m)[1][3] = ( float )0.0; | |
349 | ||
350 | (*m)[2][0] = e1.z; | |
351 | (*m)[2][1] = e2.z; | |
352 | (*m)[2][2] = e3.z; | |
353 | (*m)[2][3] = ( float )0.0; | |
354 | ||
355 | (*m)[3][0] = e4.x; | |
356 | (*m)[3][1] = e4.y; | |
357 | (*m)[3][2] = e4.z; | |
358 | (*m)[3][3] = ( float )1.0; | |
359 | ||
360 | *err_ind = 0; | |
361 | } | |
362 | } | |
363 | ||
364 | /*----------------------------------------------------------------------*/ | |
365 | /* | |
366 | * Evaluates mapping matrix. | |
367 | */ | |
368 | /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */ | |
369 | void call_func_eval_map_matrix3( | |
3c3131a0 | 370 | view_map3 *Map, |
371 | int *err_ind, | |
2166f0fa SK |
372 | matrix3 mat) |
373 | { | |
374 | int i, j; | |
375 | matrix3 Tpar, Spar; | |
376 | matrix3 Tper, Sper; | |
377 | matrix3 Shear; | |
378 | matrix3 Scale; | |
379 | matrix3 Tprp; | |
380 | matrix3 aux_mat1, aux_mat2, aux_mat3; | |
381 | point3 Prp; | |
382 | ||
383 | *err_ind = 0; | |
384 | for (i=0; i<4; i++) | |
385 | for (j=0; j<4; j++) | |
386 | Spar[i][j] = Sper[i][j] = aux_mat1[i][j] = aux_mat2[i][j] = | |
387 | aux_mat3[i][j] = Tper[i][j] = Tpar[i][j] = Tprp[i][j] = | |
388 | Shear[i][j] = Scale[i][j] = ( float )(i == j); | |
389 | ||
390 | Prp.x = Map->proj_ref_point.x; | |
391 | Prp.y = Map->proj_ref_point.y; | |
392 | Prp.z = Map->proj_ref_point.z; | |
393 | ||
394 | /* | |
395 | * Type Parallele | |
3c3131a0 | 396 | */ |
2166f0fa SK |
397 | if (Map->proj_type == TYPE_PARAL) |
398 | { | |
399 | float umid, vmid; | |
400 | point3 temp; | |
401 | ||
402 | #ifdef FMN | |
403 | float cx, cy, gx, gy, xsf, ysf, zsf; | |
404 | float fpd, bpd; | |
405 | float dopx, dopy, dopz; | |
406 | matrix3 tmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 }, | |
407 | { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 }, | |
408 | { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 }, | |
409 | { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } }; | |
410 | matrix3 smat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 }, | |
411 | { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 }, | |
412 | { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 }, | |
413 | { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } }; | |
414 | matrix3 shmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 }, | |
415 | { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 }, | |
416 | { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 }, | |
417 | { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } }; | |
418 | matrix3 tshmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 }, | |
419 | { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 }, | |
420 | { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 }, | |
421 | { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } }; | |
422 | ||
423 | /* centers */ | |
424 | cx = Map->win.x_min + Map->win.x_max, cx /= ( float )2.0; | |
425 | cy = Map->win.y_min + Map->win.y_max, cy /= ( float )2.0; | |
426 | ||
427 | gx = 2.0/ (Map->win.x_max - Map->win.x_min); | |
428 | gy = 2.0/ (Map->win.y_max - Map->win.y_min); | |
429 | ||
430 | tmat[0][3] = -cx; | |
431 | tmat[1][3] = -cy; | |
432 | tmat[2][3] = (Map->front_plane + Map->back_plane)/(Map->front_plane - Map->back_plane); | |
433 | ||
434 | smat[0][0] = gx; | |
435 | smat[1][1] = gy; | |
436 | smat[2][2] = -2./(Map->front_plane - Map->back_plane); | |
437 | ||
438 | /* scale factors */ | |
439 | dopx = cx - Prp.x; | |
440 | dopy = cy - Prp.y; | |
441 | dopz = - Prp.z; | |
442 | ||
443 | /* map matrix */ | |
444 | shmat[0][2] = -(dopx/dopz); | |
445 | shmat[1][2] = -(dopy/dopz); | |
446 | ||
447 | /* multiply to obtain mapping matrix */ | |
448 | call_util_mat_mul( tmat, shmat, tshmat ); | |
449 | call_util_mat_mul( smat, tshmat, mat ); | |
450 | ||
3c3131a0 | 451 | return; |
2166f0fa SK |
452 | #endif |
453 | ||
454 | /* CAL */ | |
455 | Map->proj_vp.z_min = ( float )0.0; | |
456 | Map->proj_vp.z_max = ( float )1.0; | |
457 | /* CAL */ | |
458 | ||
459 | /* Shear matrix calculation */ | |
460 | umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0; | |
461 | vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0; | |
462 | if(Prp.z == Map->view_plane){ | |
463 | /* Projection reference point is on the view plane */ | |
464 | *err_ind = 1; | |
465 | return; | |
466 | } | |
467 | Shear[2][0] = ( float )(-1.0) * ((Prp.x-umid)/(Prp.z-Map->view_plane)); | |
468 | Shear[2][1] = ( float )(-1.0) * ((Prp.y-vmid)/(Prp.z-Map->view_plane)); | |
469 | ||
470 | /* | |
471 | * Calculate the lower left coordinate of the view plane | |
472 | * after the Shearing Transformation. | |
473 | */ | |
474 | call_util_apply_trans2(Map->win.x_min, Map->win.y_min, | |
475 | Map->view_plane, Shear, &(temp.x), &(temp.y), &(temp.z)); | |
476 | ||
477 | /* Translate the back plane to the origin */ | |
478 | Tpar[3][0] = ( float )(-1.0) * temp.x; | |
479 | Tpar[3][1] = ( float )(-1.0) * temp.y; | |
480 | Tpar[3][2] = ( float )(-1.0) * Map->back_plane; | |
481 | ||
482 | call_util_mat_mul(Shear, Tpar, aux_mat1); | |
483 | ||
484 | /* Calculation of Scaling transformation */ | |
485 | Spar[0][0] = ( float )1.0 / (Map->win.x_max - Map->win.x_min); | |
486 | Spar[1][1] = ( float )1.0 / (Map->win.y_max - Map->win.y_min); | |
487 | Spar[2][2] = ( float )1.0 / (Map->front_plane - Map->back_plane ); | |
488 | call_util_mat_mul (aux_mat1, Spar, aux_mat2); | |
489 | /* Atlast we transformed view volume to NPC */ | |
490 | ||
491 | /* Translate and scale the view plane to projection view port */ | |
492 | if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 || | |
493 | Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 || | |
494 | Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 || | |
495 | Map->proj_vp.x_min > Map->proj_vp.x_max || | |
496 | Map->proj_vp.y_min > Map->proj_vp.y_max || | |
497 | Map->proj_vp.z_min > Map->proj_vp.z_max){ | |
498 | *err_ind = 1; | |
499 | return; | |
500 | } | |
501 | for(i=0; i<4; i++) | |
502 | for(j=0; j<4; j++) | |
503 | aux_mat1[i][j] = (float)(i==j); | |
504 | aux_mat1[0][0] = Map->proj_vp.x_max-Map->proj_vp.x_min; | |
505 | aux_mat1[1][1] = Map->proj_vp.y_max-Map->proj_vp.y_min; | |
506 | aux_mat1[2][2] = Map->proj_vp.z_max-Map->proj_vp.z_min; | |
507 | aux_mat1[3][0] = Map->proj_vp.x_min; | |
508 | aux_mat1[3][1] = Map->proj_vp.y_min; | |
509 | aux_mat1[3][2] = Map->proj_vp.z_min; | |
510 | call_util_mat_mul (aux_mat2, aux_mat1, mat); | |
511 | ||
3c3131a0 | 512 | return; |
513 | } | |
2166f0fa SK |
514 | |
515 | /* | |
516 | * Type Perspective | |
3c3131a0 | 517 | */ |
2166f0fa SK |
518 | else if (Map->proj_type == TYPE_PERSPECT) |
519 | { | |
520 | float umid, vmid; | |
521 | float B, F, V; | |
522 | float Zvmin; | |
523 | ||
524 | /* CAL */ | |
525 | Map->proj_vp.z_min = ( float )0.0; | |
526 | Map->proj_vp.z_max = ( float )1.0; | |
527 | /* CAL */ | |
528 | ||
529 | B = Map->back_plane; | |
530 | F = Map->front_plane; | |
531 | V = Map->view_plane; | |
532 | ||
533 | if(Prp.z == Map->view_plane){ | |
534 | /* Centre of Projection is on the view plane */ | |
535 | *err_ind = 1; | |
536 | return; | |
537 | } | |
538 | if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 || | |
539 | Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 || | |
540 | Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 || | |
541 | Map->proj_vp.x_min > Map->proj_vp.x_max || | |
542 | Map->proj_vp.y_min > Map->proj_vp.y_max || | |
543 | Map->proj_vp.z_min > Map->proj_vp.z_max || | |
544 | F < B){ | |
545 | *err_ind = 1; | |
546 | return; | |
547 | } | |
548 | ||
549 | /* This is the transformation to move VRC to Center Of Projection */ | |
550 | Tprp[3][0] = ( float )(-1.0)*Prp.x; | |
551 | Tprp[3][1] = ( float )(-1.0)*Prp.y; | |
552 | Tprp[3][2] = ( float )(-1.0)*Prp.z; | |
553 | ||
554 | /* Calculation of Shear matrix */ | |
555 | umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0-Prp.x; | |
556 | vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0-Prp.y; | |
557 | Shear[2][0] = ( float )(-1.0)*umid/(Map->view_plane-Prp.z); | |
558 | Shear[2][1] = ( float )(-1.0)*vmid/(Map->view_plane-Prp.z); | |
559 | call_util_mat_mul(Tprp, Shear, aux_mat3); | |
560 | ||
561 | /* Scale the view volume to canonical view volume | |
562 | * Centre of projection at origin. | |
563 | * 0 <= N <= -1, -0.5 <= U <= 0.5, -0.5 <= V <= 0.5 | |
564 | */ | |
565 | Scale[0][0] = (( float )(-1.0)*Prp.z+V)/ | |
566 | ((Map->win.x_max-Map->win.x_min)*(( float )(-1.0)*Prp.z+B)); | |
567 | Scale[1][1] = (( float )(-1.0)*Prp.z+V)/ | |
568 | ((Map->win.y_max-Map->win.y_min)*(( float )(-1.0)*Prp.z+B)); | |
569 | Scale[2][2] = ( float )(-1.0) / (( float )(-1.0)*Prp.z+B); | |
570 | ||
571 | call_util_mat_mul(aux_mat3, Scale, aux_mat1); | |
572 | ||
573 | /* | |
574 | * Transform the Perspective view volume into | |
575 | * Parallel view volume. | |
576 | * Lower left coordinate: (-0.5,-0.5, -1) | |
577 | * Upper right coordinate: (0.5, 0.5, 1.0) | |
578 | */ | |
579 | Zvmin = ( float )(-1.0*(-1.0*Prp.z+F)/(-1.0*Prp.z+B)); | |
580 | aux_mat2[2][2] = ( float )1.0/(( float )1.0+Zvmin); | |
581 | aux_mat2[2][3] = ( float )(-1.0); | |
582 | aux_mat2[3][2] = ( float )(-1.0)*Zvmin*aux_mat2[2][2]; | |
583 | aux_mat2[3][3] = ( float )0.0; | |
584 | call_util_mat_mul(aux_mat1, aux_mat2, Shear); | |
585 | ||
586 | for(i=0; i<4; i++) | |
587 | for(j=0; j<4; j++) | |
588 | aux_mat1[i][j] = aux_mat2[i][j] = (float)(i==j); | |
589 | ||
590 | /* Translate and scale the view plane to projection view port */ | |
591 | aux_mat2[0][0] = (Map->proj_vp.x_max-Map->proj_vp.x_min); | |
592 | aux_mat2[1][1] = (Map->proj_vp.y_max-Map->proj_vp.y_min); | |
593 | aux_mat2[2][2] = (Map->proj_vp.z_max-Map->proj_vp.z_min); | |
594 | aux_mat2[3][0] = aux_mat2[0][0]/( float )2.0+Map->proj_vp.x_min; | |
595 | aux_mat2[3][1] = aux_mat2[1][1]/( float )2.0+Map->proj_vp.y_min; | |
596 | aux_mat2[3][2] = aux_mat2[2][2]+Map->proj_vp.z_min; | |
597 | call_util_mat_mul (Shear, aux_mat2, mat); | |
598 | ||
599 | return; | |
600 | } | |
601 | else | |
602 | *err_ind = 1; | |
603 | } | |
604 | ||
605 | /*----------------------------------------------------------------------*/ | |
606 | ||
607 | static void | |
608 | call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat, | |
609 | float *ox, float *oy, float *oz ) | |
610 | { | |
611 | float temp; | |
612 | *ox = ix*mat[0][0]+iy*mat[1][0]+iz*mat[2][0]+mat[3][0]; | |
613 | *oy = ix*mat[0][1]+iy*mat[1][1]+iz*mat[2][1]+mat[3][1]; | |
614 | *oz = ix*mat[0][2]+iy*mat[1][2]+iz*mat[2][2]+mat[3][2]; | |
615 | temp = ix * mat[0][3]+iy * mat[1][3]+iz * mat[2][3]+mat[3][3]; | |
616 | *ox /= temp; | |
617 | *oy /= temp; | |
618 | *oz /= temp; | |
619 | } | |
620 | ||
621 | /*----------------------------------------------------------------------*/ | |
622 | ||
623 | static void | |
624 | call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c) | |
625 | { | |
626 | int i, j, k; | |
627 | ||
628 | for (i=0; i<4; i++) | |
629 | for (j=0; j<4; j++) | |
630 | for (mat_c[i][j] = ( float )0.0,k=0; k<4; k++) | |
631 | mat_c[i][j] += mat_a[i][k] * mat_b[k][j]; | |
632 | } | |
633 | ||
634 | /*----------------------------------------------------------------------*/ | |
635 | ||
636 | //call_func_redraw_all_structs_proc | |
637 | void OpenGl_View::Render (const Handle(OpenGl_Workspace) &AWorkspace, | |
638 | const Graphic3d_CView& ACView, | |
639 | const Aspect_CLayer2d& ACUnderLayer, | |
640 | const Aspect_CLayer2d& ACOverLayer) | |
641 | { | |
642 | // Reset FLIST status after modification of myBackfacing | |
643 | if (myResetFLIST) | |
644 | { | |
645 | AWorkspace->NamedStatus &= ~OPENGL_NS_FLIST; | |
646 | myResetFLIST = Standard_False; | |
647 | } | |
648 | ||
649 | // Store and disable current clipping planes | |
650 | GLint maxplanes; | |
651 | glGetIntegerv(GL_MAX_CLIP_PLANES, &maxplanes); | |
652 | const GLenum lastid = GL_CLIP_PLANE0 + maxplanes; | |
653 | OPENGL_CLIP_PLANE *oldPlanes = new OPENGL_CLIP_PLANE[maxplanes]; | |
654 | OPENGL_CLIP_PLANE *ptrPlane = oldPlanes; | |
655 | GLenum planeid = GL_CLIP_PLANE0; | |
656 | for ( ; planeid < lastid; planeid++, ptrPlane++ ) | |
657 | { | |
658 | glGetClipPlane( planeid, ptrPlane->Equation ); | |
659 | if ( ptrPlane->isEnabled ) | |
660 | { | |
661 | glDisable( planeid ); | |
662 | ptrPlane->isEnabled = GL_TRUE; | |
663 | } | |
664 | else | |
665 | ptrPlane->isEnabled = GL_FALSE; | |
666 | } | |
667 | ||
668 | ///////////////////////////////////////////////////////////////////////////// | |
669 | // Step 1: Prepare for redraw | |
670 | ||
671 | // Render background | |
672 | if ( (AWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) == 0 && | |
673 | ( myBgTexture.TexId != 0 || myBgGradient.type != Aspect_GFM_NONE ) ) | |
674 | { | |
675 | const Standard_Integer aViewWidth = AWorkspace->Width(); | |
676 | const Standard_Integer aViewHeight = AWorkspace->Height(); | |
677 | ||
678 | glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT ); | |
679 | ||
680 | glMatrixMode( GL_PROJECTION ); | |
681 | glPushMatrix(); | |
682 | glLoadIdentity(); | |
683 | glMatrixMode( GL_MODELVIEW ); | |
684 | glPushMatrix(); | |
685 | glLoadIdentity(); | |
686 | ||
687 | if ( glIsEnabled( GL_DEPTH_TEST ) ) | |
688 | glDisable( GL_DEPTH_TEST ); //push GL_ENABLE_BIT | |
689 | ||
f8b2ed36 | 690 | // drawing bg gradient if: |
691 | // - gradient fill type is not Aspect_GFM_NONE and | |
692 | // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode | |
693 | if ( ( myBgGradient.type != Aspect_GFM_NONE ) && | |
694 | ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED || | |
695 | myBgTexture.Style == Aspect_FM_NONE ) ) | |
2166f0fa SK |
696 | { |
697 | Tfloat* corner1 = 0;/* -1,-1*/ | |
698 | Tfloat* corner2 = 0;/* 1,-1*/ | |
699 | Tfloat* corner3 = 0;/* 1, 1*/ | |
700 | Tfloat* corner4 = 0;/* -1, 1*/ | |
701 | Tfloat dcorner1[3]; | |
702 | Tfloat dcorner2[3]; | |
703 | ||
704 | switch( myBgGradient.type ) | |
705 | { | |
706 | case Aspect_GFM_HOR: | |
f8b2ed36 | 707 | corner1 = myBgGradient.color1.rgb; |
2166f0fa | 708 | corner2 = myBgGradient.color2.rgb; |
f8b2ed36 | 709 | corner3 = myBgGradient.color2.rgb; |
2166f0fa SK |
710 | corner4 = myBgGradient.color1.rgb; |
711 | break; | |
712 | case Aspect_GFM_VER: | |
713 | corner1 = myBgGradient.color2.rgb; | |
f8b2ed36 | 714 | corner2 = myBgGradient.color2.rgb; |
2166f0fa | 715 | corner3 = myBgGradient.color1.rgb; |
f8b2ed36 | 716 | corner4 = myBgGradient.color1.rgb; |
2166f0fa SK |
717 | break; |
718 | case Aspect_GFM_DIAG1: | |
719 | corner2 = myBgGradient.color2.rgb; | |
3c3131a0 | 720 | corner4 = myBgGradient.color1.rgb; |
2166f0fa SK |
721 | dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]); |
722 | dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]); | |
723 | dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]); | |
724 | corner1 = dcorner1; | |
3c3131a0 | 725 | corner3 = dcorner2; |
2166f0fa SK |
726 | break; |
727 | case Aspect_GFM_DIAG2: | |
3c3131a0 | 728 | corner1 = myBgGradient.color2.rgb; |
729 | corner3 = myBgGradient.color1.rgb; | |
2166f0fa SK |
730 | dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]); |
731 | dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]); | |
732 | dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]); | |
733 | corner2 = dcorner1; | |
3c3131a0 | 734 | corner4 = dcorner2; |
2166f0fa SK |
735 | break; |
736 | case Aspect_GFM_CORNER1: | |
f8b2ed36 | 737 | corner1 = myBgGradient.color2.rgb; |
2166f0fa SK |
738 | corner2 = myBgGradient.color2.rgb; |
739 | corner3 = myBgGradient.color2.rgb; | |
f8b2ed36 | 740 | corner4 = myBgGradient.color1.rgb; |
2166f0fa SK |
741 | break; |
742 | case Aspect_GFM_CORNER2: | |
743 | corner1 = myBgGradient.color2.rgb; | |
f8b2ed36 | 744 | corner2 = myBgGradient.color2.rgb; |
745 | corner3 = myBgGradient.color1.rgb; | |
2166f0fa SK |
746 | corner4 = myBgGradient.color2.rgb; |
747 | break; | |
748 | case Aspect_GFM_CORNER3: | |
749 | corner1 = myBgGradient.color2.rgb; | |
f8b2ed36 | 750 | corner2 = myBgGradient.color1.rgb; |
751 | corner3 = myBgGradient.color2.rgb; | |
2166f0fa SK |
752 | corner4 = myBgGradient.color2.rgb; |
753 | break; | |
754 | case Aspect_GFM_CORNER4: | |
f8b2ed36 | 755 | corner1 = myBgGradient.color1.rgb; |
2166f0fa SK |
756 | corner2 = myBgGradient.color2.rgb; |
757 | corner3 = myBgGradient.color2.rgb; | |
f8b2ed36 | 758 | corner4 = myBgGradient.color2.rgb; |
2166f0fa SK |
759 | break; |
760 | default: | |
761 | //printf("gradient background type not right\n"); | |
762 | break; | |
763 | } | |
764 | ||
765 | // Save GL parameters | |
766 | glDisable( GL_LIGHTING ); //push GL_ENABLE_BIT | |
767 | ||
768 | GLint curSM; | |
769 | glGetIntegerv( GL_SHADE_MODEL, &curSM ); | |
770 | if ( curSM != GL_SMOOTH ) | |
771 | glShadeModel( GL_SMOOTH ); //push GL_LIGHTING_BIT | |
772 | ||
773 | glBegin(GL_TRIANGLE_FAN); | |
f8b2ed36 | 774 | if( myBgGradient.type != Aspect_GFM_CORNER1 && myBgGradient.type != Aspect_GFM_CORNER3 ) |
2166f0fa SK |
775 | { |
776 | glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.); | |
777 | glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.); | |
778 | glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.); | |
779 | glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.); | |
3c3131a0 | 780 | } |
f8b2ed36 | 781 | else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 ) |
2166f0fa SK |
782 | { |
783 | glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.); | |
784 | glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.); | |
785 | glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.); | |
786 | glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.); | |
787 | } | |
788 | glEnd(); | |
789 | ||
790 | // Restore GL parameters | |
791 | if ( curSM != GL_SMOOTH ) | |
792 | glShadeModel( curSM ); | |
793 | } | |
f8b2ed36 | 794 | // drawing bg image if: |
795 | // - it is defined and | |
796 | // - fill type is not Aspect_FM_NONE | |
797 | if ( myBgTexture.TexId != 0 && myBgTexture.Style != Aspect_FM_NONE ) | |
798 | { | |
799 | GLfloat texX_range = 1.F; // texture <s> coordinate | |
800 | GLfloat texY_range = 1.F; // texture <t> coordinate | |
801 | ||
802 | // Set up for stretching or tiling | |
803 | GLfloat x_offset, y_offset; | |
804 | if ( myBgTexture.Style == Aspect_FM_CENTERED ) | |
805 | { | |
806 | x_offset = (GLfloat)myBgTexture.Width / (GLfloat)aViewWidth; | |
807 | y_offset = (GLfloat)myBgTexture.Height / (GLfloat)aViewHeight; | |
808 | } | |
809 | else | |
810 | { | |
811 | x_offset = 1.F; | |
812 | y_offset = 1.F; | |
813 | if ( myBgTexture.Style == Aspect_FM_TILED ) | |
814 | { | |
815 | texX_range = (GLfloat)aViewWidth / (GLfloat)myBgTexture.Width; | |
816 | texY_range = (GLfloat)aViewHeight / (GLfloat)myBgTexture.Height; | |
817 | } | |
818 | } | |
819 | ||
1e743e91 | 820 | // OCCT issue 0023000: Improve the way the gradient and textured |
821 | // background is managed in 3d viewer (note 0020339) | |
822 | // Setting this coefficient to -1.F allows to tile textures relatively | |
823 | // to the top-left corner of the view (value 1.F corresponds to the | |
824 | // initial behaviour - tiling from the bottom-left corner) | |
825 | GLfloat aCoef = -1.F; | |
826 | ||
f8b2ed36 | 827 | glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT |
828 | glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT | |
829 | ||
830 | glDisable( GL_BLEND ); //push GL_ENABLE_BIT | |
831 | ||
832 | glColor3fv( AWorkspace->BackgroundColor().rgb ); | |
833 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT | |
834 | ||
1e743e91 | 835 | // Note that texture is mapped using GL_REPEAT wrapping mode so integer part |
836 | // is simply ignored, and negative multiplier is here for convenience only | |
837 | // and does not result e.g. in texture mirroring | |
f8b2ed36 | 838 | glBegin( GL_QUADS ); |
1e743e91 | 839 | glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -aCoef * y_offset ); |
840 | glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -aCoef * y_offset ); | |
841 | glTexCoord2f(texX_range, aCoef * texY_range); glVertex2f( x_offset, aCoef * y_offset ); | |
842 | glTexCoord2f(0.F, aCoef * texY_range); glVertex2f( -x_offset, aCoef * y_offset ); | |
f8b2ed36 | 843 | glEnd(); |
844 | } | |
2166f0fa SK |
845 | |
846 | glPopMatrix(); | |
847 | glMatrixMode( GL_PROJECTION ); | |
848 | glPopMatrix(); | |
849 | glMatrixMode( GL_MODELVIEW ); | |
850 | ||
851 | glPopAttrib(); //GL_ENABLE_BIT | GL_TEXTURE_BIT | |
852 | ||
853 | if ( AWorkspace->UseZBuffer() ) | |
854 | glEnable( GL_DEPTH_TEST ); | |
855 | ||
856 | /* GL_DITHER on/off pour le trace */ | |
857 | if (AWorkspace->Dither()) | |
858 | glEnable (GL_DITHER); | |
859 | else | |
860 | glDisable (GL_DITHER); | |
861 | } | |
862 | ||
863 | // Switch off lighting by default | |
864 | glDisable(GL_LIGHTING); | |
865 | ||
866 | ///////////////////////////////////////////////////////////////////////////// | |
867 | // Step 2: Draw underlayer | |
868 | RedrawLayer2d(AWorkspace, ACView, ACUnderLayer); | |
869 | ||
870 | ///////////////////////////////////////////////////////////////////////////// | |
871 | // Step 3: Redraw main plane | |
872 | ||
873 | // Setup face culling | |
874 | GLboolean isCullFace = GL_FALSE; | |
875 | if ( myBackfacing ) | |
876 | { | |
877 | isCullFace = glIsEnabled( GL_CULL_FACE ); | |
878 | if ( myBackfacing < 0 ) | |
879 | { | |
880 | glEnable( GL_CULL_FACE ); | |
881 | glCullFace( GL_BACK ); | |
882 | } | |
883 | else | |
884 | glDisable( GL_CULL_FACE ); | |
885 | } | |
886 | ||
887 | //TsmPushAttri(); /* save previous graphics context */ | |
888 | ||
889 | // if the view is scaled normal vectors are scaled to unit length for correct displaying of shaded objects | |
3c3131a0 | 890 | if(myExtra.scaleFactors[0] != 1.F || |
2166f0fa SK |
891 | myExtra.scaleFactors[1] != 1.F || |
892 | myExtra.scaleFactors[2] != 1.F) | |
893 | glEnable(GL_NORMALIZE); | |
3c3131a0 | 894 | else if(glIsEnabled(GL_NORMALIZE)) |
2166f0fa SK |
895 | glDisable(GL_NORMALIZE); |
896 | ||
897 | // Apply View Projection | |
898 | // This routine activates the Projection matrix for a view. | |
899 | ||
900 | glMatrixMode( GL_PROJECTION ); | |
901 | ||
902 | #ifdef WNT | |
903 | // add printing scale/tiling transformation | |
904 | OpenGl_PrinterContext* aPrinterContext = OpenGl_PrinterContext::GetPrinterContext(AWorkspace->GetGContext()); | |
905 | ||
906 | if (aPrinterContext) | |
907 | { | |
908 | GLfloat aProjMatrix[16]; | |
909 | aPrinterContext->GetProjTransformation(aProjMatrix); | |
910 | glLoadMatrixf((GLfloat*) aProjMatrix); | |
911 | } | |
912 | else | |
913 | #endif | |
914 | glLoadIdentity(); | |
915 | ||
916 | glMultMatrixf( (const GLfloat *) myMappingMatrix ); | |
917 | ||
918 | // Add translation necessary for the environnement mapping | |
919 | if (mySurfaceDetail != Visual3d_TOD_NONE) | |
920 | { | |
921 | // OCC280: FitAll work incorrect for perspective view if the SurfaceDetail mode is V3d_TEX_ENVIRONMENT or V3d_TEX_ALL | |
922 | // const GLfloat dep = vptr->vrep.extra.map.fpd * 0.5F; | |
923 | const GLfloat dep = (myExtra.map.fpd + myExtra.map.bpd) * 0.5F; | |
924 | glTranslatef(-dep*myExtra.vpn[0],-dep*myExtra.vpn[1],-dep*myExtra.vpn[2]); | |
925 | } | |
926 | ||
927 | // Apply matrix | |
928 | AWorkspace->SetViewMatrix((const OpenGl_Matrix *)myOrientationMatrix); | |
929 | ||
930 | /* | |
931 | While drawing after a clipplane has been defined and enabled, each vertex | |
932 | is transformed to eye-coordinates, where it is dotted with the transformed | |
933 | clipping plane equation. Eye-coordinate vertexes whose dot product with | |
934 | the transformed clipping plane equation is positive or zero are in, and | |
935 | require no clipping. Those eye-coordinate vertexes whose dot product is | |
936 | negative are clipped. Because clipplane clipping is done in eye- | |
937 | coordinates, changes to the projection matrix have no effect on its | |
938 | operation. | |
939 | ||
940 | A point and a normal are converted to a plane equation in the following manner: | |
941 | ||
942 | point = [Px,Py,Pz] | |
943 | ||
944 | normal = |Nx| | |
945 | |Ny| | |
946 | |Nz| | |
947 | ||
948 | plane equation = |A| | |
949 | |B| | |
950 | |C| | |
951 | |D| | |
952 | A = Nx | |
953 | B = Ny | |
954 | C = Nz | |
955 | D = -[Px,Py,Pz] dot |Nx| | |
956 | |Ny| | |
957 | |Nz| | |
958 | ||
959 | */ | |
960 | ||
2166f0fa SK |
961 | // Apply Fog |
962 | if ( myFog.IsOn ) | |
963 | { | |
964 | const GLfloat ramp = myExtra.map.fpd - myExtra.map.bpd; | |
965 | const GLfloat fog_start = myFog.Front * ramp - myExtra.map.fpd; | |
966 | const GLfloat fog_end = myFog.Back * ramp - myExtra.map.fpd; | |
967 | ||
968 | glFogi(GL_FOG_MODE, GL_LINEAR); | |
969 | glFogf(GL_FOG_START, fog_start); | |
970 | glFogf(GL_FOG_END, fog_end); | |
971 | glFogfv(GL_FOG_COLOR, myFog.Color.rgb); | |
972 | glEnable(GL_FOG); | |
973 | } | |
974 | else | |
975 | glDisable(GL_FOG); | |
976 | ||
977 | // Apply Lights | |
978 | { | |
979 | int i; | |
980 | ||
981 | // Switch off all lights | |
982 | for (i = GL_LIGHT0; i <= GL_LIGHT7; i++) | |
983 | glDisable(i); | |
984 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, default_amb); | |
985 | ||
986 | /* set les lights */ | |
987 | int gl_lid = GL_LIGHT0; | |
988 | OpenGl_ListOfLight::Iterator itl(myLights); | |
989 | for (; itl.More(); itl.Next()) | |
990 | { | |
991 | const OpenGl_Light &alight = itl.Value(); | |
992 | bind_light(&alight, &gl_lid); | |
993 | } | |
994 | ||
995 | if (gl_lid != GL_LIGHT0) glEnable(GL_LIGHTING); | |
996 | } | |
997 | ||
998 | // Apply InteriorShadingMethod | |
999 | glShadeModel( myIntShadingMethod == TEL_SM_FLAT ? GL_FLAT : GL_SMOOTH ); | |
1000 | ||
1001 | // Apply clipping planes | |
1002 | { | |
1003 | // Define starting plane id | |
1004 | planeid = GL_CLIP_PLANE0; | |
1005 | ||
1006 | GLdouble equation[4]; | |
1007 | ||
1008 | if ( myZClip.Back.IsOn || myZClip.Front.IsOn ) | |
1009 | { | |
1010 | // Apply front and back clipping planes | |
1011 | GLfloat mat[4][4]; | |
1012 | glMatrixMode( GL_MODELVIEW ); | |
1013 | glGetFloatv( GL_MODELVIEW_MATRIX,(GLfloat *) mat ); | |
1014 | glLoadIdentity(); | |
1015 | ||
1016 | const GLdouble ramp = myExtra.map.fpd - myExtra.map.bpd; | |
1017 | ||
1018 | if ( myZClip.Back.IsOn ) | |
1019 | { | |
1020 | const GLdouble back = ramp * myZClip.Back.Limit + myExtra.map.bpd; | |
1021 | equation[0] = 0.0; /* Nx */ | |
1022 | equation[1] = 0.0; /* Ny */ | |
1023 | equation[2] = 1.0; /* Nz */ | |
1024 | equation[3] = -back; /* P dot N */ | |
1025 | glClipPlane( planeid, equation ); | |
1026 | glEnable( planeid ); | |
1027 | planeid++; | |
1028 | } | |
1029 | ||
1030 | if ( myZClip.Front.IsOn ) | |
1031 | { | |
1032 | const GLdouble front = ramp * myZClip.Front.Limit + myExtra.map.bpd; | |
1033 | equation[0] = 0.0; /* Nx */ | |
1034 | equation[1] = 0.0; /* Ny */ | |
1035 | equation[2] = -1.0; /* Nz */ | |
1036 | equation[3] = front; /* P dot N */ | |
1037 | glClipPlane( planeid, equation ); | |
1038 | glEnable( planeid ); | |
1039 | planeid++; | |
1040 | } | |
1041 | ||
1042 | glLoadMatrixf( (GLfloat *) mat ); | |
1043 | } | |
1044 | ||
1045 | // Apply user clipping planes | |
1046 | NCollection_List<OPENGL_CLIP_REP>::Iterator planeIter(myClippingPlanes); | |
1047 | for ( ; planeIter.More(); planeIter.Next() ) | |
1048 | { | |
1049 | glClipPlane( planeid, planeIter.Value().equation ); | |
1050 | glEnable( planeid ); | |
1051 | planeid++; | |
1052 | } | |
1053 | } | |
1054 | ||
1055 | // Apply AntiAliasing | |
1056 | { | |
1057 | if (myAntiAliasing) | |
1058 | AWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING; | |
1059 | else | |
1060 | AWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING; | |
1061 | } | |
1062 | ||
1063 | Standard_Boolean isAnimationListOpen = Standard_False; | |
1064 | ||
1065 | // Request for update of animation mode? | |
1066 | if ( (AWorkspace->NamedStatus & OPENGL_NS_UPDATEAM) != 0 ) | |
1067 | { | |
1068 | // Request to rebuild display list | |
1069 | myAnimationListReady = Standard_False; | |
1070 | // Reset request for update of animation mode | |
1071 | AWorkspace->NamedStatus &= ~OPENGL_NS_UPDATEAM; | |
1072 | } | |
1073 | ||
1074 | // Is in animation mode? | |
1075 | if ( AWorkspace->NamedStatus & OPENGL_NS_ANIMATION ) | |
1076 | { | |
1077 | // Is the animation list ready? | |
1078 | if (myAnimationListReady) | |
1079 | { | |
1080 | // Execute the animation list | |
1081 | glCallList(myAnimationListIndex); | |
1082 | } | |
1083 | else | |
1084 | { | |
1085 | // Update the animation list | |
1086 | if ( AWorkspace->NamedStatus & OPENGL_NS_FLIST ) | |
1087 | { | |
1088 | if (myAnimationListIndex == 0) | |
1089 | myAnimationListIndex = glGenLists(1); | |
1090 | ||
1091 | if (myAnimationListIndex != 0) | |
1092 | { | |
1093 | glNewList(myAnimationListIndex, GL_COMPILE_AND_EXECUTE); | |
1094 | isAnimationListOpen = Standard_True; | |
1095 | } | |
1096 | } | |
1097 | else | |
1098 | AWorkspace->NamedStatus |= OPENGL_NS_FLIST; | |
1099 | } | |
1100 | } | |
1101 | else | |
1102 | myAnimationListReady = Standard_False; | |
1103 | ||
1104 | if (!myAnimationListReady) | |
1105 | { | |
1106 | // Clear status bitfields | |
1107 | AWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO); | |
1108 | ||
1109 | // Added PCT for handling of textures | |
1110 | switch (mySurfaceDetail) | |
1111 | { | |
1112 | case Visual3d_TOD_NONE: | |
1113 | AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; | |
1114 | DisableTexture(); | |
1115 | // Render the view | |
1116 | RenderStructs(AWorkspace); | |
1117 | break; | |
1118 | ||
1119 | case Visual3d_TOD_ENVIRONMENT: | |
1120 | AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; | |
1121 | SetCurrentTexture(myTextureEnv); | |
1122 | EnableTexture(); | |
1123 | // Render the view | |
1124 | RenderStructs(AWorkspace); | |
1125 | DisableTexture(); | |
1126 | break; | |
1127 | ||
1128 | case Visual3d_TOD_ALL: | |
1129 | // First pass | |
1130 | AWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX; | |
1131 | // Render the view | |
1132 | RenderStructs(AWorkspace); | |
1133 | DisableTexture(); | |
1134 | ||
1135 | // Second pass | |
1136 | if (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) | |
1137 | { | |
1138 | AWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO; | |
1139 | SetCurrentTexture(myTextureEnv); | |
1140 | EnableTexture(); | |
1141 | ||
1142 | /* sauvegarde de quelques parametres OpenGL */ | |
1143 | GLint blend_dst, blend_src; | |
1144 | GLint zbuff_f; | |
1145 | GLboolean zbuff_w; | |
1146 | glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w); | |
1147 | glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f); | |
3c3131a0 | 1148 | glGetIntegerv(GL_BLEND_DST, &blend_dst); |
1149 | glGetIntegerv(GL_BLEND_SRC, &blend_src); | |
2166f0fa SK |
1150 | GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST); |
1151 | GLboolean blend_state = glIsEnabled(GL_BLEND); | |
1152 | ||
3c3131a0 | 1153 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2166f0fa SK |
1154 | glEnable(GL_BLEND); |
1155 | ||
1156 | glDepthFunc(GL_EQUAL); | |
1157 | glDepthMask(GL_FALSE); | |
1158 | glEnable(GL_DEPTH_TEST); | |
1159 | ||
1160 | AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; | |
1161 | ||
1162 | // Render the view | |
1163 | RenderStructs(AWorkspace); | |
1164 | DisableTexture(); | |
1165 | ||
1166 | /* restauration des parametres OpenGL */ | |
1167 | glBlendFunc(blend_src, blend_dst); | |
1168 | if (!blend_state) glDisable(GL_BLEND); | |
1169 | ||
1170 | glDepthFunc(zbuff_f); | |
1171 | glDepthMask(zbuff_w); | |
1172 | if (!zbuff_state) glDisable(GL_DEPTH_FUNC); | |
1173 | } | |
1174 | break; | |
1175 | } | |
1176 | ||
1177 | if (isAnimationListOpen) | |
1178 | { | |
1179 | glEndList(); | |
1180 | myAnimationListReady = Standard_True; | |
1181 | } | |
1182 | } | |
1183 | ||
26395493 | 1184 | // Resetting GL parameters according to the default aspects |
1185 | // in order to synchronize GL state with the graphic driver state | |
1186 | // before drawing auxiliary stuff (trihedrons, overlayer) | |
1187 | // and invoking optional callbacks | |
1188 | AWorkspace->ResetAppliedAspect(); | |
2166f0fa SK |
1189 | |
1190 | // Disable current clipping planes | |
1191 | for ( planeid = GL_CLIP_PLANE0; planeid < lastid; planeid++ ) | |
1192 | glDisable( planeid ); | |
1193 | ||
1194 | /* affichage de Triedre Non Zoomable de la vue s'il existe */ | |
1195 | if (!myTrihedron.IsNull()) | |
1196 | myTrihedron->Render(AWorkspace); | |
1197 | if (!myGraduatedTrihedron.IsNull()) | |
1198 | myGraduatedTrihedron->Render(AWorkspace); | |
1199 | ||
2166f0fa SK |
1200 | // Restore face culling |
1201 | if ( myBackfacing ) | |
1202 | { | |
1203 | if ( isCullFace ) | |
1204 | { | |
1205 | glEnable ( GL_CULL_FACE ); | |
1206 | glCullFace ( GL_BACK ); | |
1207 | } | |
529afc1a | 1208 | else |
2166f0fa SK |
1209 | glDisable ( GL_CULL_FACE ); |
1210 | } | |
1211 | ||
1212 | ///////////////////////////////////////////////////////////////////////////// | |
1213 | // Step 6: Draw overlayer | |
529afc1a K |
1214 | const int aMode = 0; |
1215 | AWorkspace->DisplayCallback (ACView, (aMode | OCC_PRE_OVERLAY)); | |
2166f0fa SK |
1216 | |
1217 | RedrawLayer2d(AWorkspace, ACView, ACOverLayer); | |
1218 | ||
529afc1a | 1219 | AWorkspace->DisplayCallback (ACView, aMode); |
2166f0fa SK |
1220 | |
1221 | // Restore clipping planes | |
1222 | for ( ptrPlane = oldPlanes, planeid = GL_CLIP_PLANE0; planeid < lastid; planeid++, ptrPlane++ ) | |
1223 | { | |
1224 | glClipPlane( planeid, ptrPlane->Equation ); | |
1225 | if ( ptrPlane->isEnabled ) | |
1226 | glEnable( planeid ); | |
529afc1a | 1227 | else |
2166f0fa SK |
1228 | glDisable( planeid ); |
1229 | } | |
1230 | delete[] oldPlanes; | |
1231 | } | |
1232 | ||
1233 | /*----------------------------------------------------------------------*/ | |
1234 | ||
1235 | //ExecuteViewDisplay | |
1236 | void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace) | |
1237 | { | |
59f45b7c | 1238 | if ( myZLayers.NbStructures() <= 0 ) |
1239 | return; | |
2166f0fa SK |
1240 | |
1241 | glPushAttrib ( GL_DEPTH_BUFFER_BIT ); | |
1242 | ||
1243 | const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine( Standard_True ); | |
1244 | ||
1245 | //TsmPushAttri(); /* save previous graphics context */ | |
1246 | ||
1247 | if ( (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 ) | |
1248 | { | |
1249 | const int antiAliasingMode = AWorkspace->GetDisplay()->AntiAliasingMode(); | |
1250 | ||
1251 | if ( !myAntiAliasing ) | |
1252 | { | |
1253 | glDisable(GL_POINT_SMOOTH); | |
1254 | glDisable(GL_LINE_SMOOTH); | |
1255 | if( antiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH); | |
1256 | glBlendFunc (GL_ONE, GL_ZERO); | |
1257 | glDisable (GL_BLEND); | |
1258 | } | |
1259 | else | |
1260 | { | |
1261 | glEnable(GL_POINT_SMOOTH); | |
1262 | glEnable(GL_LINE_SMOOTH); | |
1263 | if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH); | |
3c3131a0 | 1264 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2166f0fa SK |
1265 | glEnable (GL_BLEND); |
1266 | } | |
1267 | } | |
1268 | ||
59f45b7c | 1269 | myZLayers.Render (AWorkspace); |
2166f0fa SK |
1270 | |
1271 | //TsmPopAttri(); /* restore previous graphics context; before update lights */ | |
1272 | ||
1273 | if ( AWorkspace->DegenerateModel > 1 ) | |
1274 | { | |
1275 | glLineWidth ( aspect_line->Width() ); | |
1276 | if ( aspect_line->Type() != Aspect_TOL_SOLID ) glEnable ( GL_LINE_STIPPLE ); | |
1277 | } | |
1278 | ||
1279 | glPopAttrib (); | |
1280 | } | |
1281 | ||
1282 | /*----------------------------------------------------------------------*/ | |
1283 | ||
1284 | //call_togl_redraw_layer2d | |
1285 | void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_Workspace) &AWorkspace, const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACLayer) | |
1286 | { | |
1287 | if (&ACLayer == NULL | |
1288 | || ACLayer.ptrLayer == NULL | |
1289 | || ACLayer.ptrLayer->listIndex == 0) return; | |
1290 | ||
529afc1a K |
1291 | GLsizei dispWidth = (GLsizei )ACLayer.viewport[0]; |
1292 | GLsizei dispHeight = (GLsizei )ACLayer.viewport[1]; | |
2166f0fa | 1293 | |
2166f0fa SK |
1294 | glMatrixMode( GL_MODELVIEW ); |
1295 | glPushMatrix (); | |
1296 | glLoadIdentity (); | |
1297 | ||
1298 | glMatrixMode (GL_PROJECTION); | |
1299 | glPushMatrix (); | |
1300 | glLoadIdentity (); | |
1301 | ||
1302 | if (!ACLayer.sizeDependent) | |
1303 | glViewport (0, 0, dispWidth, dispHeight); | |
1304 | ||
1305 | float left = ACLayer.ortho[0]; | |
1306 | float right = ACLayer.ortho[1]; | |
1307 | float bottom = ACLayer.ortho[2]; | |
1308 | float top = ACLayer.ortho[3]; | |
1309 | ||
1310 | int attach = ACLayer.attach; | |
1311 | ||
1312 | float ratio; | |
1313 | if (!ACLayer.sizeDependent) | |
1314 | ratio = (float) dispWidth/dispHeight; | |
1315 | else | |
1316 | ratio = ACView.DefWindow.dx/ACView.DefWindow.dy; | |
1317 | ||
1318 | float delta; | |
c9d4eb9d | 1319 | if (ratio >= 1.0) { |
2166f0fa SK |
1320 | delta = (float )((top - bottom)/2.0); |
1321 | switch (attach) { | |
1322 | case 0: /* Aspect_TOC_BOTTOM_LEFT */ | |
1323 | top = bottom + 2*delta/ratio; | |
1324 | break; | |
1325 | case 1: /* Aspect_TOC_BOTTOM_RIGHT */ | |
1326 | top = bottom + 2*delta/ratio; | |
1327 | break; | |
1328 | case 2: /* Aspect_TOC_TOP_LEFT */ | |
1329 | bottom = top - 2*delta/ratio; | |
1330 | break; | |
1331 | case 3: /* Aspect_TOC_TOP_RIGHT */ | |
1332 | bottom = top - 2*delta/ratio; | |
1333 | break; | |
1334 | } | |
1335 | } | |
c9d4eb9d | 1336 | else { |
2166f0fa SK |
1337 | delta = (float )((right - left)/2.0); |
1338 | switch (attach) { | |
1339 | case 0: /* Aspect_TOC_BOTTOM_LEFT */ | |
1340 | right = left + 2*delta*ratio; | |
1341 | break; | |
1342 | case 1: /* Aspect_TOC_BOTTOM_RIGHT */ | |
1343 | left = right - 2*delta*ratio; | |
1344 | break; | |
1345 | case 2: /* Aspect_TOC_TOP_LEFT */ | |
1346 | right = left + 2*delta*ratio; | |
1347 | break; | |
1348 | case 3: /* Aspect_TOC_TOP_RIGHT */ | |
1349 | left = right - 2*delta*ratio; | |
1350 | break; | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | #ifdef WNT | |
1355 | // Check printer context that exists only for print operation | |
1356 | OpenGl_PrinterContext* aPrinterContext = OpenGl_PrinterContext::GetPrinterContext (AWorkspace->GetGContext()); | |
1357 | ||
1358 | if (aPrinterContext) | |
1359 | { | |
1360 | // additional transformation matrix could be applied to | |
1361 | // render only those parts of viewport that will be | |
1362 | // passed to a printer as a current "frame" to provide | |
1363 | // tiling; scaling of graphics by matrix helps render a | |
1364 | // part of a view (frame) in same viewport, but with higher | |
1365 | // resolution | |
1366 | GLfloat aProjMatrix[16]; | |
1367 | aPrinterContext->GetProjTransformation (aProjMatrix); | |
1368 | glLoadMatrixf ((GLfloat*) aProjMatrix); | |
1369 | ||
1370 | // printing operation also assumes other viewport dimension | |
1371 | // to comply with transformation matrix or graphics scaling | |
1372 | // factors for tiling for layer redraw | |
1373 | GLsizei anViewportX = 0; | |
1374 | GLsizei anViewportY = 0; | |
1375 | aPrinterContext->GetLayerViewport (anViewportX, anViewportY); | |
1376 | if (anViewportX != 0 && anViewportY != 0) | |
1377 | glViewport (0, 0, anViewportX, anViewportY); | |
1378 | } | |
3c3131a0 | 1379 | #endif |
2166f0fa SK |
1380 | |
1381 | glOrtho (left, right, bottom, top, -1.0, 1.0); | |
1382 | ||
2166f0fa SK |
1383 | glPushAttrib ( |
1384 | GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT | | |
1385 | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT ); | |
c9d4eb9d | 1386 | |
2166f0fa | 1387 | glDisable (GL_DEPTH_TEST); |
c9d4eb9d | 1388 | glDisable (GL_TEXTURE_1D); |
1389 | glDisable (GL_TEXTURE_2D); | |
1390 | glDisable (GL_LIGHTING); | |
1391 | ||
1392 | // TODO: Obsolete code, the display list is always empty now, to be removed | |
2166f0fa SK |
1393 | glCallList (ACLayer.ptrLayer->listIndex); |
1394 | ||
1395 | //calling dynamic render of LayerItems | |
1396 | if ( ACLayer.ptrLayer->layerData ) | |
1397 | { | |
1398 | InitLayerProp(ACLayer.ptrLayer->listIndex); | |
1399 | ((Visual3d_Layer*)ACLayer.ptrLayer->layerData)->RenderLayerItems(); | |
1400 | InitLayerProp(0); | |
1401 | } | |
1402 | ||
1403 | glPopAttrib (); | |
1404 | ||
2166f0fa SK |
1405 | glMatrixMode (GL_PROJECTION); |
1406 | glPopMatrix (); | |
1407 | ||
1408 | glMatrixMode( GL_MODELVIEW ); | |
1409 | glPopMatrix (); | |
1410 | ||
2166f0fa SK |
1411 | if (!ACLayer.sizeDependent) |
1412 | glViewport (0, 0, (GLsizei) ACView.DefWindow.dx, (GLsizei) ACView.DefWindow.dy); | |
1413 | ||
1414 | glFlush (); | |
2166f0fa SK |
1415 | } |
1416 | ||
1417 | /*----------------------------------------------------------------------*/ | |
1418 | ||
1419 | //call_togl_create_bg_texture | |
3c3131a0 | 1420 | void OpenGl_View::CreateBackgroundTexture (const Standard_CString theFilePath, |
1421 | const Aspect_FillMethod theFillStyle) | |
2166f0fa | 1422 | { |
3c3131a0 | 1423 | if (myBgTexture.TexId != 0) |
2166f0fa | 1424 | { |
3c3131a0 | 1425 | // delete existing texture |
1426 | glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId)); | |
2166f0fa SK |
1427 | myBgTexture.TexId = 0; |
1428 | } | |
1429 | ||
3c3131a0 | 1430 | // load image from file |
1431 | Image_AlienPixMap anImageLoaded; | |
1432 | if (!anImageLoaded.Load (theFilePath)) | |
1433 | { | |
1434 | return; | |
1435 | } | |
1436 | ||
1437 | Image_PixMap anImage; | |
1438 | if (anImageLoaded.RowExtraBytes() == 0 && | |
1439 | (anImageLoaded.Format() == Image_PixMap::ImgRGB | |
1440 | || anImageLoaded.Format() == Image_PixMap::ImgRGB32 | |
1441 | || anImageLoaded.Format() == Image_PixMap::ImgRGBA)) | |
2166f0fa | 1442 | { |
3c3131a0 | 1443 | anImage.InitWrapper (anImageLoaded.Format(), anImageLoaded.ChangeData(), |
1444 | anImageLoaded.SizeX(), anImageLoaded.SizeY(), anImageLoaded.SizeRowBytes()); | |
1445 | } | |
1446 | else | |
1447 | { | |
1448 | // convert image to RGB format | |
1449 | if (!anImage.InitTrash (Image_PixMap::ImgRGB, anImageLoaded.SizeX(), anImageLoaded.SizeY())) | |
1450 | { | |
1451 | return; | |
1452 | } | |
1453 | ||
1454 | anImage.SetTopDown (false); | |
1455 | Image_PixMapData<Image_ColorRGB>& aDataNew = anImage.EditData<Image_ColorRGB>(); | |
1456 | Quantity_Color aSrcColor; | |
1457 | for (Standard_Size aRow = 0; aRow < anImage.SizeY(); ++aRow) | |
1458 | { | |
1459 | for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol) | |
2166f0fa | 1460 | { |
3c3131a0 | 1461 | aSrcColor = anImageLoaded.PixelColor (aCol, aRow); |
1462 | Image_ColorRGB& aColor = aDataNew.ChangeValue (aRow, aCol); | |
1463 | aColor.r() = int(255.0 * aSrcColor.Red()); | |
1464 | aColor.g() = int(255.0 * aSrcColor.Green()); | |
1465 | aColor.b() = int(255.0 * aSrcColor.Blue()); | |
2166f0fa | 1466 | } |
3c3131a0 | 1467 | } |
1468 | anImageLoaded.Clear(); | |
1469 | } | |
2166f0fa | 1470 | |
3c3131a0 | 1471 | // create MipMapped texture |
1472 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); | |
2166f0fa | 1473 | |
3c3131a0 | 1474 | GLuint aTextureId = 0; |
1475 | glGenTextures (1, &aTextureId); | |
1476 | glBindTexture (GL_TEXTURE_2D, aTextureId); | |
2166f0fa | 1477 | |
3c3131a0 | 1478 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
1479 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | |
1480 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
1481 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); | |
2166f0fa | 1482 | |
3c3131a0 | 1483 | const GLenum aDataFormat = (anImage.Format() == Image_PixMap::ImgRGB) ? GL_RGB : GL_RGBA; |
1484 | gluBuild2DMipmaps (GL_TEXTURE_2D, 3/*4*/, | |
1485 | GLint(anImage.SizeX()), GLint(anImage.SizeY()), | |
1486 | aDataFormat, GL_UNSIGNED_BYTE, anImage.Data()); | |
2166f0fa | 1487 | |
3c3131a0 | 1488 | myBgTexture.TexId = aTextureId; |
1489 | myBgTexture.Width = (Standard_Integer )anImage.SizeX(); | |
1490 | myBgTexture.Height = (Standard_Integer )anImage.SizeY(); | |
1491 | myBgTexture.Style = theFillStyle; | |
2166f0fa SK |
1492 | } |
1493 | ||
1494 | /*----------------------------------------------------------------------*/ | |
1495 | ||
1496 | //call_togl_set_bg_texture_style | |
1497 | void OpenGl_View::SetBackgroundTextureStyle (const Aspect_FillMethod AFillStyle) | |
1498 | { | |
f8b2ed36 | 1499 | myBgTexture.Style = AFillStyle; |
2166f0fa SK |
1500 | } |
1501 | ||
1502 | /*----------------------------------------------------------------------*/ | |
1503 | ||
1504 | //call_togl_gradient_background | |
1505 | void OpenGl_View::SetBackgroundGradient (const Quantity_Color& AColor1, | |
1506 | const Quantity_Color& AColor2, | |
1507 | const Aspect_GradientFillMethod AType) | |
1508 | { | |
1509 | Standard_Real R,G,B; | |
1510 | AColor1.Values( R, G, B, Quantity_TOC_RGB ); | |
1511 | myBgGradient.color1.rgb[0] = ( Tfloat )R; | |
1512 | myBgGradient.color1.rgb[1] = ( Tfloat )G; | |
1513 | myBgGradient.color1.rgb[2] = ( Tfloat )B; | |
1514 | myBgGradient.color1.rgb[3] = 0.F; | |
1515 | ||
1516 | AColor2.Values( R, G, B, Quantity_TOC_RGB ); | |
1517 | myBgGradient.color2.rgb[0] = ( Tfloat )R; | |
1518 | myBgGradient.color2.rgb[1] = ( Tfloat )G; | |
1519 | myBgGradient.color2.rgb[2] = ( Tfloat )B; | |
1520 | myBgGradient.color2.rgb[3] = 0.F; | |
1521 | ||
1522 | myBgGradient.type = AType; | |
1523 | } | |
1524 | ||
1525 | /*----------------------------------------------------------------------*/ | |
1526 | ||
1527 | //call_togl_set_gradient_type | |
1528 | void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod AType) | |
1529 | { | |
f8b2ed36 | 1530 | myBgGradient.type = AType; |
2166f0fa SK |
1531 | } |
1532 | ||
59f45b7c | 1533 | //======================================================================= |
1534 | //function : AddZLayer | |
3c3131a0 | 1535 | //purpose : |
59f45b7c | 1536 | //======================================================================= |
1537 | ||
1538 | void OpenGl_View::AddZLayer (const Standard_Integer theLayerId) | |
1539 | { | |
1540 | myZLayers.AddLayer (theLayerId); | |
1541 | } | |
1542 | ||
1543 | //======================================================================= | |
1544 | //function : RemoveZLayer | |
3c3131a0 | 1545 | //purpose : |
59f45b7c | 1546 | //======================================================================= |
1547 | ||
1548 | void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId) | |
1549 | { | |
1550 | myZLayers.RemoveLayer (theLayerId); | |
1551 | } | |
1552 | ||
1553 | //======================================================================= | |
1554 | //function : DisplayStructure | |
3c3131a0 | 1555 | //purpose : |
59f45b7c | 1556 | //======================================================================= |
1557 | ||
1558 | void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure, | |
1559 | const Standard_Integer thePriority) | |
1560 | { | |
1561 | Standard_Integer aZLayer = theStructure->GetZLayer (); | |
1562 | myZLayers.AddStructure (theStructure, aZLayer, thePriority); | |
1563 | } | |
1564 | ||
1565 | //======================================================================= | |
1566 | //function : EraseStructure | |
3c3131a0 | 1567 | //purpose : |
59f45b7c | 1568 | //======================================================================= |
1569 | ||
1570 | void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure) | |
1571 | { | |
1572 | Standard_Integer aZLayer = theStructure->GetZLayer (); | |
1573 | myZLayers.RemoveStructure (theStructure, aZLayer); | |
1574 | } | |
1575 | ||
1576 | //======================================================================= | |
1577 | //function : ChangeZLayer | |
1578 | //purpose : | |
1579 | //======================================================================= | |
1580 | ||
1581 | void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure, | |
1582 | const Standard_Integer theNewLayerId) | |
1583 | { | |
1584 | Standard_Integer anOldLayer = theStructure->GetZLayer (); | |
1585 | myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId); | |
1586 | } |