1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
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.
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.
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.
23 #include <OpenGl_GlCore11.hxx>
24 #include <OpenGl_tgl_funcs.hxx>
26 #include <Image_AlienPixMap.hxx>
27 #include <Visual3d_Layer.hxx>
29 #include <OpenGl_AspectLine.hxx>
30 #include <OpenGl_Display.hxx>
31 #include <OpenGl_Workspace.hxx>
32 #include <OpenGl_View.hxx>
33 #include <OpenGl_Trihedron.hxx>
34 #include <OpenGl_GraduatedTrihedron.hxx>
35 #include <OpenGl_PrinterContext.hxx>
36 #include <OpenGl_Structure.hxx>
40 static const GLfloat default_amb[4] = { 0.F, 0.F, 0.F, 1.F };
41 static const GLfloat default_sptdir[3] = { 0.F, 0.F, -1.F };
42 static const GLfloat default_sptexpo = 0.F;
43 static const GLfloat default_sptcutoff = 180.F;
45 extern void InitLayerProp (const int AListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx
47 /*----------------------------------------------------------------------*/
49 struct OPENGL_CLIP_PLANE
56 /*----------------------------------------------------------------------*/
61 /*-----------------------------------------------------------------*/
65 static void bind_light(const OpenGl_Light *lptr, int *gl_lid)
67 // Only 8 lights in OpenGL...
68 if (*gl_lid > GL_LIGHT7) return;
70 // the light is a headlight ?
74 glGetIntegerv(GL_MATRIX_MODE, &cur_matrix);
75 glMatrixMode(GL_MODELVIEW);
81 GLfloat data_diffu[4];
83 GLfloat data_sptdir[3];
85 GLfloat data_sptcutoff;
86 GLfloat data_constantattenuation;
87 GLfloat data_linearattenuation;
89 /* set la light en fonction de son type */
93 data_amb[0] = lptr->col.rgb[0];
94 data_amb[1] = lptr->col.rgb[1];
95 data_amb[2] = lptr->col.rgb[2];
98 /*------------------------- Ambient ---------------------------*/
100 * The GL_AMBIENT parameter refers to RGBA intensity of the ambient
103 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data_amb);
107 case TLightDirectional:
108 data_diffu[0] = lptr->col.rgb[0];
109 data_diffu[1] = lptr->col.rgb[1];
110 data_diffu[2] = lptr->col.rgb[2];
113 /*------------------------- Direction ---------------------------*/
114 /* From Open GL Programming Rev 1 Guide Chapt 6 :
115 Lighting The Mathematics of Lighting ( p 168 )
117 Directional Light Source ( Infinite ) :
118 if the last parameter of GL_POSITION , w , is zero, the
119 corresponding light source is a Directional one.
121 GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
122 To create a realistic effect, set the GL_SPECULAR parameter
123 to the same value as the GL_DIFFUSE.
126 data_pos[0] = -lptr->dir[0];
127 data_pos[1] = -lptr->dir[1];
128 data_pos[2] = -lptr->dir[2];
131 glLightfv(*gl_lid, GL_AMBIENT, default_amb);
132 glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
133 glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
135 glLightfv(*gl_lid, GL_POSITION, data_pos);
136 glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir);
137 glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo);
138 glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff);
142 case TLightPositional:
143 data_diffu[0] = lptr->col.rgb[0];
144 data_diffu[1] = lptr->col.rgb[1];
145 data_diffu[2] = lptr->col.rgb[2];
148 /*------------------------- Position -----------------------------*/
149 /* From Open GL Programming Rev 1 Guide Chapt 6 :
150 Lighting The Mathematics of Lighting ( p 168 )
151 Positional Light Source :
152 if the last parameter of GL_POSITION , w , is nonzero,
153 the corresponding light source is a Positional one.
155 GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
157 To create a realistic effect, set the GL_SPECULAR parameter
158 to the same value as the GL_DIFFUSE.
161 data_pos[0] = lptr->pos[0];
162 data_pos[1] = lptr->pos[1];
163 data_pos[2] = lptr->pos[2];
166 data_constantattenuation = lptr->atten[0];
167 data_linearattenuation = lptr->atten[1];
169 glLightfv(*gl_lid, GL_AMBIENT, default_amb);
170 glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
171 glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
173 glLightfv(*gl_lid, GL_POSITION, data_pos);
174 glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir);
175 glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo);
176 glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff);
177 glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
178 glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
179 glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
184 data_diffu[0] = lptr->col.rgb[0];
185 data_diffu[1] = lptr->col.rgb[1];
186 data_diffu[2] = lptr->col.rgb[2];
189 data_pos[0] = lptr->pos[0];
190 data_pos[1] = lptr->pos[1];
191 data_pos[2] = lptr->pos[2];
194 data_sptdir[0] = lptr->dir[0];
195 data_sptdir[1] = lptr->dir[1];
196 data_sptdir[2] = lptr->dir[2];
198 data_sptexpo = ( float )lptr->shine * 128.0F;
199 data_sptcutoff = ( float )(lptr->angle * 180.0F)/( float )M_PI;
201 data_constantattenuation = lptr->atten[0];
202 data_linearattenuation = lptr->atten[1];
204 glLightfv(*gl_lid, GL_AMBIENT, default_amb);
205 glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
206 glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
208 glLightfv(*gl_lid, GL_POSITION, data_pos);
209 glLightfv(*gl_lid, GL_SPOT_DIRECTION, data_sptdir);
210 glLightf(*gl_lid, GL_SPOT_EXPONENT, data_sptexpo);
211 glLightf(*gl_lid, GL_SPOT_CUTOFF, data_sptcutoff);
212 glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
213 glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
214 glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
218 if (lptr->type != TLightAmbient)
224 /* si la light etait une headlight alors restaure la matrice precedente */
228 glMatrixMode(cur_matrix);
232 /*----------------------------------------------------------------------*/
237 static void call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat,
238 float *ox, float *oy, float *oz );
239 static void call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c);
241 /*----------------------------------------------------------------------*/
247 * Evaluates orientation matrix.
249 /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
250 void call_func_eval_ori_matrix3 (const point3* vrp, // view reference point
251 const vec3* vpn, // view plane normal
252 const vec3* vup, // view up vector
254 float mout[4][4]) // OUT view orientation matrix
257 /* Translate to VRP then change the basis.
258 * The old basis is: e1 = < 1, 0, 0>, e2 = < 0, 1, 0>, e3 = < 0, 0, 1>.
259 * The new basis is: ("x" means cross product)
261 * e1' = VUP x VPN / |VUP x VPN|
263 * Therefore the transform from old to new is x' = TAx, where:
265 * | e1'x e2'x e3'x 0 | | 1 0 0 0 |
266 * A = | e1'y e2'y e3'y 0 |, T = | 0 1 0 0 |
267 * | e1'z e2'z e3'z 0 | | 0 0 1 0 |
268 * | 0 0 0 1 | | -vrp.x -vrp.y -vrp.z 1 |
273 * These ei's are really ei primes.
275 register float (*m)[4][4];
276 point3 e1, e2, e3, e4;
280 * e1' = VUP x VPN / |VUP x VPN|, but do the division later.
282 e1.x = vup->delta_y * vpn->delta_z - vup->delta_z * vpn->delta_y;
283 e1.y = vup->delta_z * vpn->delta_x - vup->delta_x * vpn->delta_z;
284 e1.z = vup->delta_x * vpn->delta_y - vup->delta_y * vpn->delta_x;
285 s = sqrt( e1.x * e1.x + e1.y * e1.y + e1.z * e1.z);
289 v = sqrt( e3.x * e3.x + e3.y * e3.y + e3.z * e3.z);
291 * Check for vup and vpn colinear (zero dot product).
293 if ((s > -EPSI) && (s < EPSI))
297 * Check for a normal vector not null.
299 if ((v > -EPSI) && (v < EPSI))
317 e2.x = e3.y * e1.z - e3.z * e1.y;
318 e2.y = e3.z * e1.x - e3.x * e1.z;
319 e2.z = e3.x * e1.y - e3.y * e1.x;
321 * Add the translation
323 e4.x = -( e1.x * vrp->x + e1.y * vrp->y + e1.z * vrp->z);
324 e4.y = -( e2.x * vrp->x + e2.y * vrp->y + e2.z * vrp->z);
325 e4.z = -( e3.x * vrp->x + e3.y * vrp->y + e3.z * vrp->z);
327 * Homogeneous entries
329 * | e1.x e2.x e3.x 0.0 | | 1 0 0 0 |
330 * | e1.y e2.y e3.y 0.0 | * | 0 1 0 0 |
331 * | e1.z e2.z e3.z 0.0 | | a b 1 c |
332 * | e4.x e4.y e4.z 1.0 | | 0 0 0 1 |
335 m = (float (*)[4][4])mout;
340 (*m)[0][3] = ( float )0.0;
345 (*m)[1][3] = ( float )0.0;
350 (*m)[2][3] = ( float )0.0;
355 (*m)[3][3] = ( float )1.0;
361 /*----------------------------------------------------------------------*/
363 * Evaluates mapping matrix.
365 /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
366 void call_func_eval_map_matrix3(
377 matrix3 aux_mat1, aux_mat2, aux_mat3;
383 Spar[i][j] = Sper[i][j] = aux_mat1[i][j] = aux_mat2[i][j] =
384 aux_mat3[i][j] = Tper[i][j] = Tpar[i][j] = Tprp[i][j] =
385 Shear[i][j] = Scale[i][j] = ( float )(i == j);
387 Prp.x = Map->proj_ref_point.x;
388 Prp.y = Map->proj_ref_point.y;
389 Prp.z = Map->proj_ref_point.z;
394 if (Map->proj_type == TYPE_PARAL)
400 float cx, cy, gx, gy, xsf, ysf, zsf;
402 float dopx, dopy, dopz;
403 matrix3 tmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
404 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
405 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
406 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
407 matrix3 smat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
408 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
409 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
410 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
411 matrix3 shmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
412 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
413 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
414 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
415 matrix3 tshmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
416 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
417 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
418 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
421 cx = Map->win.x_min + Map->win.x_max, cx /= ( float )2.0;
422 cy = Map->win.y_min + Map->win.y_max, cy /= ( float )2.0;
424 gx = 2.0/ (Map->win.x_max - Map->win.x_min);
425 gy = 2.0/ (Map->win.y_max - Map->win.y_min);
429 tmat[2][3] = (Map->front_plane + Map->back_plane)/(Map->front_plane - Map->back_plane);
433 smat[2][2] = -2./(Map->front_plane - Map->back_plane);
441 shmat[0][2] = -(dopx/dopz);
442 shmat[1][2] = -(dopy/dopz);
444 /* multiply to obtain mapping matrix */
445 call_util_mat_mul( tmat, shmat, tshmat );
446 call_util_mat_mul( smat, tshmat, mat );
452 Map->proj_vp.z_min = ( float )0.0;
453 Map->proj_vp.z_max = ( float )1.0;
456 /* Shear matrix calculation */
457 umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0;
458 vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0;
459 if(Prp.z == Map->view_plane){
460 /* Projection reference point is on the view plane */
464 Shear[2][0] = ( float )(-1.0) * ((Prp.x-umid)/(Prp.z-Map->view_plane));
465 Shear[2][1] = ( float )(-1.0) * ((Prp.y-vmid)/(Prp.z-Map->view_plane));
468 * Calculate the lower left coordinate of the view plane
469 * after the Shearing Transformation.
471 call_util_apply_trans2(Map->win.x_min, Map->win.y_min,
472 Map->view_plane, Shear, &(temp.x), &(temp.y), &(temp.z));
474 /* Translate the back plane to the origin */
475 Tpar[3][0] = ( float )(-1.0) * temp.x;
476 Tpar[3][1] = ( float )(-1.0) * temp.y;
477 Tpar[3][2] = ( float )(-1.0) * Map->back_plane;
479 call_util_mat_mul(Shear, Tpar, aux_mat1);
481 /* Calculation of Scaling transformation */
482 Spar[0][0] = ( float )1.0 / (Map->win.x_max - Map->win.x_min);
483 Spar[1][1] = ( float )1.0 / (Map->win.y_max - Map->win.y_min);
484 Spar[2][2] = ( float )1.0 / (Map->front_plane - Map->back_plane );
485 call_util_mat_mul (aux_mat1, Spar, aux_mat2);
486 /* Atlast we transformed view volume to NPC */
488 /* Translate and scale the view plane to projection view port */
489 if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 ||
490 Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 ||
491 Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 ||
492 Map->proj_vp.x_min > Map->proj_vp.x_max ||
493 Map->proj_vp.y_min > Map->proj_vp.y_max ||
494 Map->proj_vp.z_min > Map->proj_vp.z_max){
500 aux_mat1[i][j] = (float)(i==j);
501 aux_mat1[0][0] = Map->proj_vp.x_max-Map->proj_vp.x_min;
502 aux_mat1[1][1] = Map->proj_vp.y_max-Map->proj_vp.y_min;
503 aux_mat1[2][2] = Map->proj_vp.z_max-Map->proj_vp.z_min;
504 aux_mat1[3][0] = Map->proj_vp.x_min;
505 aux_mat1[3][1] = Map->proj_vp.y_min;
506 aux_mat1[3][2] = Map->proj_vp.z_min;
507 call_util_mat_mul (aux_mat2, aux_mat1, mat);
515 else if (Map->proj_type == TYPE_PERSPECT)
522 Map->proj_vp.z_min = ( float )0.0;
523 Map->proj_vp.z_max = ( float )1.0;
527 F = Map->front_plane;
530 if(Prp.z == Map->view_plane){
531 /* Centre of Projection is on the view plane */
535 if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 ||
536 Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 ||
537 Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 ||
538 Map->proj_vp.x_min > Map->proj_vp.x_max ||
539 Map->proj_vp.y_min > Map->proj_vp.y_max ||
540 Map->proj_vp.z_min > Map->proj_vp.z_max ||
546 /* This is the transformation to move VRC to Center Of Projection */
547 Tprp[3][0] = ( float )(-1.0)*Prp.x;
548 Tprp[3][1] = ( float )(-1.0)*Prp.y;
549 Tprp[3][2] = ( float )(-1.0)*Prp.z;
551 /* Calculation of Shear matrix */
552 umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0-Prp.x;
553 vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0-Prp.y;
554 Shear[2][0] = ( float )(-1.0)*umid/(Map->view_plane-Prp.z);
555 Shear[2][1] = ( float )(-1.0)*vmid/(Map->view_plane-Prp.z);
556 call_util_mat_mul(Tprp, Shear, aux_mat3);
558 /* Scale the view volume to canonical view volume
559 * Centre of projection at origin.
560 * 0 <= N <= -1, -0.5 <= U <= 0.5, -0.5 <= V <= 0.5
562 Scale[0][0] = (( float )(-1.0)*Prp.z+V)/
563 ((Map->win.x_max-Map->win.x_min)*(( float )(-1.0)*Prp.z+B));
564 Scale[1][1] = (( float )(-1.0)*Prp.z+V)/
565 ((Map->win.y_max-Map->win.y_min)*(( float )(-1.0)*Prp.z+B));
566 Scale[2][2] = ( float )(-1.0) / (( float )(-1.0)*Prp.z+B);
568 call_util_mat_mul(aux_mat3, Scale, aux_mat1);
571 * Transform the Perspective view volume into
572 * Parallel view volume.
573 * Lower left coordinate: (-0.5,-0.5, -1)
574 * Upper right coordinate: (0.5, 0.5, 1.0)
576 Zvmin = ( float )(-1.0*(-1.0*Prp.z+F)/(-1.0*Prp.z+B));
577 aux_mat2[2][2] = ( float )1.0/(( float )1.0+Zvmin);
578 aux_mat2[2][3] = ( float )(-1.0);
579 aux_mat2[3][2] = ( float )(-1.0)*Zvmin*aux_mat2[2][2];
580 aux_mat2[3][3] = ( float )0.0;
581 call_util_mat_mul(aux_mat1, aux_mat2, Shear);
585 aux_mat1[i][j] = aux_mat2[i][j] = (float)(i==j);
587 /* Translate and scale the view plane to projection view port */
588 aux_mat2[0][0] = (Map->proj_vp.x_max-Map->proj_vp.x_min);
589 aux_mat2[1][1] = (Map->proj_vp.y_max-Map->proj_vp.y_min);
590 aux_mat2[2][2] = (Map->proj_vp.z_max-Map->proj_vp.z_min);
591 aux_mat2[3][0] = aux_mat2[0][0]/( float )2.0+Map->proj_vp.x_min;
592 aux_mat2[3][1] = aux_mat2[1][1]/( float )2.0+Map->proj_vp.y_min;
593 aux_mat2[3][2] = aux_mat2[2][2]+Map->proj_vp.z_min;
594 call_util_mat_mul (Shear, aux_mat2, mat);
602 /*----------------------------------------------------------------------*/
605 call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat,
606 float *ox, float *oy, float *oz )
609 *ox = ix*mat[0][0]+iy*mat[1][0]+iz*mat[2][0]+mat[3][0];
610 *oy = ix*mat[0][1]+iy*mat[1][1]+iz*mat[2][1]+mat[3][1];
611 *oz = ix*mat[0][2]+iy*mat[1][2]+iz*mat[2][2]+mat[3][2];
612 temp = ix * mat[0][3]+iy * mat[1][3]+iz * mat[2][3]+mat[3][3];
618 /*----------------------------------------------------------------------*/
621 call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c)
627 for (mat_c[i][j] = ( float )0.0,k=0; k<4; k++)
628 mat_c[i][j] += mat_a[i][k] * mat_b[k][j];
631 /*----------------------------------------------------------------------*/
633 //call_func_redraw_all_structs_proc
634 void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
635 const Handle(OpenGl_Workspace) &AWorkspace,
636 const Graphic3d_CView& ACView,
637 const Aspect_CLayer2d& ACUnderLayer,
638 const Aspect_CLayer2d& ACOverLayer)
640 // Reset FLIST status after modification of myBackfacing
643 AWorkspace->NamedStatus &= ~OPENGL_NS_FLIST;
644 myResetFLIST = Standard_False;
647 // Store and disable current clipping planes
649 glGetIntegerv(GL_MAX_CLIP_PLANES, &maxplanes);
650 const GLenum lastid = GL_CLIP_PLANE0 + maxplanes;
651 OPENGL_CLIP_PLANE *oldPlanes = new OPENGL_CLIP_PLANE[maxplanes];
652 OPENGL_CLIP_PLANE *ptrPlane = oldPlanes;
653 GLenum planeid = GL_CLIP_PLANE0;
654 for ( ; planeid < lastid; planeid++, ptrPlane++ )
656 glGetClipPlane( planeid, ptrPlane->Equation );
657 if ( ptrPlane->isEnabled )
659 glDisable( planeid );
660 ptrPlane->isEnabled = GL_TRUE;
663 ptrPlane->isEnabled = GL_FALSE;
666 /////////////////////////////////////////////////////////////////////////////
667 // Step 1: Prepare for redraw
670 if ( (AWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) == 0 &&
671 ( myBgTexture.TexId != 0 || myBgGradient.type != Aspect_GFM_NONE ) )
673 const Standard_Integer aViewWidth = AWorkspace->Width();
674 const Standard_Integer aViewHeight = AWorkspace->Height();
676 glPushAttrib( GL_ENABLE_BIT | GL_TEXTURE_BIT );
678 glMatrixMode( GL_PROJECTION );
681 glMatrixMode( GL_MODELVIEW );
685 if ( glIsEnabled( GL_DEPTH_TEST ) )
686 glDisable( GL_DEPTH_TEST ); //push GL_ENABLE_BIT
688 // drawing bg gradient if:
689 // - gradient fill type is not Aspect_GFM_NONE and
690 // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
691 if ( ( myBgGradient.type != Aspect_GFM_NONE ) &&
692 ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED ||
693 myBgTexture.Style == Aspect_FM_NONE ) )
695 Tfloat* corner1 = 0;/* -1,-1*/
696 Tfloat* corner2 = 0;/* 1,-1*/
697 Tfloat* corner3 = 0;/* 1, 1*/
698 Tfloat* corner4 = 0;/* -1, 1*/
702 switch( myBgGradient.type )
705 corner1 = myBgGradient.color1.rgb;
706 corner2 = myBgGradient.color2.rgb;
707 corner3 = myBgGradient.color2.rgb;
708 corner4 = myBgGradient.color1.rgb;
711 corner1 = myBgGradient.color2.rgb;
712 corner2 = myBgGradient.color2.rgb;
713 corner3 = myBgGradient.color1.rgb;
714 corner4 = myBgGradient.color1.rgb;
716 case Aspect_GFM_DIAG1:
717 corner2 = myBgGradient.color2.rgb;
718 corner4 = myBgGradient.color1.rgb;
719 dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]);
720 dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]);
721 dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]);
725 case Aspect_GFM_DIAG2:
726 corner1 = myBgGradient.color2.rgb;
727 corner3 = myBgGradient.color1.rgb;
728 dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]);
729 dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]);
730 dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]);
734 case Aspect_GFM_CORNER1:
735 corner1 = myBgGradient.color2.rgb;
736 corner2 = myBgGradient.color2.rgb;
737 corner3 = myBgGradient.color2.rgb;
738 corner4 = myBgGradient.color1.rgb;
740 case Aspect_GFM_CORNER2:
741 corner1 = myBgGradient.color2.rgb;
742 corner2 = myBgGradient.color2.rgb;
743 corner3 = myBgGradient.color1.rgb;
744 corner4 = myBgGradient.color2.rgb;
746 case Aspect_GFM_CORNER3:
747 corner1 = myBgGradient.color2.rgb;
748 corner2 = myBgGradient.color1.rgb;
749 corner3 = myBgGradient.color2.rgb;
750 corner4 = myBgGradient.color2.rgb;
752 case Aspect_GFM_CORNER4:
753 corner1 = myBgGradient.color1.rgb;
754 corner2 = myBgGradient.color2.rgb;
755 corner3 = myBgGradient.color2.rgb;
756 corner4 = myBgGradient.color2.rgb;
759 //printf("gradient background type not right\n");
763 // Save GL parameters
764 glDisable( GL_LIGHTING ); //push GL_ENABLE_BIT
767 glGetIntegerv( GL_SHADE_MODEL, &curSM );
768 if ( curSM != GL_SMOOTH )
769 glShadeModel( GL_SMOOTH ); //push GL_LIGHTING_BIT
771 glBegin(GL_TRIANGLE_FAN);
772 if( myBgGradient.type != Aspect_GFM_CORNER1 && myBgGradient.type != Aspect_GFM_CORNER3 )
774 glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.);
775 glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
776 glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
777 glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
779 else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 )
781 glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
782 glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
783 glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
784 glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.);
788 // Restore GL parameters
789 if ( curSM != GL_SMOOTH )
790 glShadeModel( curSM );
792 // drawing bg image if:
793 // - it is defined and
794 // - fill type is not Aspect_FM_NONE
795 if ( myBgTexture.TexId != 0 && myBgTexture.Style != Aspect_FM_NONE )
797 GLfloat texX_range = 1.F; // texture <s> coordinate
798 GLfloat texY_range = 1.F; // texture <t> coordinate
800 // Set up for stretching or tiling
801 GLfloat x_offset, y_offset;
802 if ( myBgTexture.Style == Aspect_FM_CENTERED )
804 x_offset = (GLfloat)myBgTexture.Width / (GLfloat)aViewWidth;
805 y_offset = (GLfloat)myBgTexture.Height / (GLfloat)aViewHeight;
811 if ( myBgTexture.Style == Aspect_FM_TILED )
813 texX_range = (GLfloat)aViewWidth / (GLfloat)myBgTexture.Width;
814 texY_range = (GLfloat)aViewHeight / (GLfloat)myBgTexture.Height;
818 // OCCT issue 0023000: Improve the way the gradient and textured
819 // background is managed in 3d viewer (note 0020339)
820 // Setting this coefficient to -1.F allows to tile textures relatively
821 // to the top-left corner of the view (value 1.F corresponds to the
822 // initial behaviour - tiling from the bottom-left corner)
823 GLfloat aCoef = -1.F;
825 glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT
826 glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT
828 glDisable( GL_BLEND ); //push GL_ENABLE_BIT
830 glColor3fv( AWorkspace->BackgroundColor().rgb );
831 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT
833 // Note that texture is mapped using GL_REPEAT wrapping mode so integer part
834 // is simply ignored, and negative multiplier is here for convenience only
835 // and does not result e.g. in texture mirroring
837 glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -aCoef * y_offset );
838 glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -aCoef * y_offset );
839 glTexCoord2f(texX_range, aCoef * texY_range); glVertex2f( x_offset, aCoef * y_offset );
840 glTexCoord2f(0.F, aCoef * texY_range); glVertex2f( -x_offset, aCoef * y_offset );
845 glMatrixMode( GL_PROJECTION );
847 glMatrixMode( GL_MODELVIEW );
849 glPopAttrib(); //GL_ENABLE_BIT | GL_TEXTURE_BIT
851 if ( AWorkspace->UseZBuffer() )
852 glEnable( GL_DEPTH_TEST );
854 /* GL_DITHER on/off pour le trace */
855 if (AWorkspace->Dither())
856 glEnable (GL_DITHER);
858 glDisable (GL_DITHER);
861 // Switch off lighting by default
862 glDisable(GL_LIGHTING);
864 /////////////////////////////////////////////////////////////////////////////
865 // Step 2: Draw underlayer
866 RedrawLayer2d (thePrintContext, AWorkspace, ACView, ACUnderLayer);
868 /////////////////////////////////////////////////////////////////////////////
869 // Step 3: Redraw main plane
871 // Setup face culling
872 GLboolean isCullFace = GL_FALSE;
875 isCullFace = glIsEnabled( GL_CULL_FACE );
876 if ( myBackfacing < 0 )
878 glEnable( GL_CULL_FACE );
879 glCullFace( GL_BACK );
882 glDisable( GL_CULL_FACE );
885 //TsmPushAttri(); /* save previous graphics context */
887 // if the view is scaled normal vectors are scaled to unit length for correct displaying of shaded objects
888 if(myExtra.scaleFactors[0] != 1.F ||
889 myExtra.scaleFactors[1] != 1.F ||
890 myExtra.scaleFactors[2] != 1.F)
891 glEnable(GL_NORMALIZE);
892 else if(glIsEnabled(GL_NORMALIZE))
893 glDisable(GL_NORMALIZE);
895 // Apply View Projection
896 // This routine activates the Projection matrix for a view.
898 glMatrixMode( GL_PROJECTION );
901 // add printing scale/tiling transformation
902 if (!thePrintContext.IsNull())
904 thePrintContext->LoadProjTransformation();
910 glMultMatrixf( (const GLfloat *) myMappingMatrix );
912 // Add translation necessary for the environnement mapping
913 if (mySurfaceDetail != Visual3d_TOD_NONE)
915 // OCC280: FitAll work incorrect for perspective view if the SurfaceDetail mode is V3d_TEX_ENVIRONMENT or V3d_TEX_ALL
916 // const GLfloat dep = vptr->vrep.extra.map.fpd * 0.5F;
917 const GLfloat dep = (myExtra.map.fpd + myExtra.map.bpd) * 0.5F;
918 glTranslatef(-dep*myExtra.vpn[0],-dep*myExtra.vpn[1],-dep*myExtra.vpn[2]);
922 AWorkspace->SetViewMatrix((const OpenGl_Matrix *)myOrientationMatrix);
925 While drawing after a clipplane has been defined and enabled, each vertex
926 is transformed to eye-coordinates, where it is dotted with the transformed
927 clipping plane equation. Eye-coordinate vertexes whose dot product with
928 the transformed clipping plane equation is positive or zero are in, and
929 require no clipping. Those eye-coordinate vertexes whose dot product is
930 negative are clipped. Because clipplane clipping is done in eye-
931 coordinates, changes to the projection matrix have no effect on its
934 A point and a normal are converted to a plane equation in the following manner:
949 D = -[Px,Py,Pz] dot |Nx|
958 const GLfloat ramp = myExtra.map.fpd - myExtra.map.bpd;
959 const GLfloat fog_start = myFog.Front * ramp - myExtra.map.fpd;
960 const GLfloat fog_end = myFog.Back * ramp - myExtra.map.fpd;
962 glFogi(GL_FOG_MODE, GL_LINEAR);
963 glFogf(GL_FOG_START, fog_start);
964 glFogf(GL_FOG_END, fog_end);
965 glFogfv(GL_FOG_COLOR, myFog.Color.rgb);
975 // Switch off all lights
976 for (i = GL_LIGHT0; i <= GL_LIGHT7; i++)
978 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, default_amb);
981 int gl_lid = GL_LIGHT0;
982 OpenGl_ListOfLight::Iterator itl(myLights);
983 for (; itl.More(); itl.Next())
985 const OpenGl_Light &alight = itl.Value();
986 bind_light(&alight, &gl_lid);
989 if (gl_lid != GL_LIGHT0) glEnable(GL_LIGHTING);
992 // Apply InteriorShadingMethod
993 glShadeModel( myIntShadingMethod == TEL_SM_FLAT ? GL_FLAT : GL_SMOOTH );
995 // Apply clipping planes
997 // Define starting plane id
998 planeid = GL_CLIP_PLANE0;
1000 GLdouble equation[4];
1002 if ( myZClip.Back.IsOn || myZClip.Front.IsOn )
1004 // Apply front and back clipping planes
1006 glMatrixMode( GL_MODELVIEW );
1007 glGetFloatv( GL_MODELVIEW_MATRIX,(GLfloat *) mat );
1010 const GLdouble ramp = myExtra.map.fpd - myExtra.map.bpd;
1012 if ( myZClip.Back.IsOn )
1014 const GLdouble back = ramp * myZClip.Back.Limit + myExtra.map.bpd;
1015 equation[0] = 0.0; /* Nx */
1016 equation[1] = 0.0; /* Ny */
1017 equation[2] = 1.0; /* Nz */
1018 equation[3] = -back; /* P dot N */
1019 glClipPlane( planeid, equation );
1020 glEnable( planeid );
1024 if ( myZClip.Front.IsOn )
1026 const GLdouble front = ramp * myZClip.Front.Limit + myExtra.map.bpd;
1027 equation[0] = 0.0; /* Nx */
1028 equation[1] = 0.0; /* Ny */
1029 equation[2] = -1.0; /* Nz */
1030 equation[3] = front; /* P dot N */
1031 glClipPlane( planeid, equation );
1032 glEnable( planeid );
1036 glLoadMatrixf( (GLfloat *) mat );
1039 // Apply user clipping planes
1040 NCollection_List<OPENGL_CLIP_REP>::Iterator planeIter(myClippingPlanes);
1041 for ( ; planeIter.More(); planeIter.Next() )
1043 glClipPlane( planeid, planeIter.Value().equation );
1044 glEnable( planeid );
1049 // Apply AntiAliasing
1052 AWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING;
1054 AWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING;
1057 Standard_Boolean isAnimationListOpen = Standard_False;
1059 // Request for update of animation mode?
1060 if ( (AWorkspace->NamedStatus & OPENGL_NS_UPDATEAM) != 0 )
1062 // Request to rebuild display list
1063 myAnimationListReady = Standard_False;
1064 // Reset request for update of animation mode
1065 AWorkspace->NamedStatus &= ~OPENGL_NS_UPDATEAM;
1068 // Is in animation mode?
1069 if ( AWorkspace->NamedStatus & OPENGL_NS_ANIMATION )
1071 // Is the animation list ready?
1072 if (myAnimationListReady)
1074 // Execute the animation list
1075 glCallList(myAnimationListIndex);
1079 // Update the animation list
1080 if ( AWorkspace->NamedStatus & OPENGL_NS_FLIST )
1082 if (myAnimationListIndex == 0)
1083 myAnimationListIndex = glGenLists(1);
1085 if (myAnimationListIndex != 0)
1087 glNewList(myAnimationListIndex, GL_COMPILE_AND_EXECUTE);
1088 isAnimationListOpen = Standard_True;
1092 AWorkspace->NamedStatus |= OPENGL_NS_FLIST;
1096 myAnimationListReady = Standard_False;
1098 if (!myAnimationListReady)
1100 // Clear status bitfields
1101 AWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO);
1103 // Added PCT for handling of textures
1104 switch (mySurfaceDetail)
1106 case Visual3d_TOD_NONE:
1107 AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1108 AWorkspace->DisableTexture();
1110 RenderStructs(AWorkspace);
1113 case Visual3d_TOD_ENVIRONMENT:
1114 AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1115 AWorkspace->EnableTexture (myTextureEnv);
1117 RenderStructs(AWorkspace);
1118 AWorkspace->DisableTexture();
1121 case Visual3d_TOD_ALL:
1123 AWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
1125 RenderStructs(AWorkspace);
1126 AWorkspace->DisableTexture();
1129 if (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED)
1131 AWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO;
1132 AWorkspace->EnableTexture (myTextureEnv);
1134 /* sauvegarde de quelques parametres OpenGL */
1135 GLint blend_dst, blend_src;
1138 glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w);
1139 glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f);
1140 glGetIntegerv(GL_BLEND_DST, &blend_dst);
1141 glGetIntegerv(GL_BLEND_SRC, &blend_src);
1142 GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
1143 GLboolean blend_state = glIsEnabled(GL_BLEND);
1145 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1148 glDepthFunc(GL_EQUAL);
1149 glDepthMask(GL_FALSE);
1150 glEnable(GL_DEPTH_TEST);
1152 AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
1155 RenderStructs(AWorkspace);
1156 AWorkspace->DisableTexture();
1158 /* restauration des parametres OpenGL */
1159 glBlendFunc(blend_src, blend_dst);
1160 if (!blend_state) glDisable(GL_BLEND);
1162 glDepthFunc(zbuff_f);
1163 glDepthMask(zbuff_w);
1164 if (!zbuff_state) glDisable(GL_DEPTH_FUNC);
1169 if (isAnimationListOpen)
1172 myAnimationListReady = Standard_True;
1176 // Resetting GL parameters according to the default aspects
1177 // in order to synchronize GL state with the graphic driver state
1178 // before drawing auxiliary stuff (trihedrons, overlayer)
1179 // and invoking optional callbacks
1180 AWorkspace->ResetAppliedAspect();
1182 // Disable current clipping planes
1183 for ( planeid = GL_CLIP_PLANE0; planeid < lastid; planeid++ )
1184 glDisable( planeid );
1186 // display global trihedron
1187 if (myTrihedron != NULL)
1189 myTrihedron->Render (AWorkspace);
1191 if (myGraduatedTrihedron != NULL)
1193 myGraduatedTrihedron->Render (AWorkspace);
1196 // Restore face culling
1201 glEnable ( GL_CULL_FACE );
1202 glCullFace ( GL_BACK );
1205 glDisable ( GL_CULL_FACE );
1208 /////////////////////////////////////////////////////////////////////////////
1209 // Step 6: Draw overlayer
1210 const int aMode = 0;
1211 AWorkspace->DisplayCallback (ACView, (aMode | OCC_PRE_OVERLAY));
1213 RedrawLayer2d (thePrintContext, AWorkspace, ACView, ACOverLayer);
1215 AWorkspace->DisplayCallback (ACView, aMode);
1217 // Restore clipping planes
1218 for ( ptrPlane = oldPlanes, planeid = GL_CLIP_PLANE0; planeid < lastid; planeid++, ptrPlane++ )
1220 glClipPlane( planeid, ptrPlane->Equation );
1221 if ( ptrPlane->isEnabled )
1222 glEnable( planeid );
1224 glDisable( planeid );
1229 /*----------------------------------------------------------------------*/
1231 //ExecuteViewDisplay
1232 void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace)
1234 if ( myZLayers.NbStructures() <= 0 )
1237 glPushAttrib ( GL_DEPTH_BUFFER_BIT );
1239 const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine( Standard_True );
1241 //TsmPushAttri(); /* save previous graphics context */
1243 if ( (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
1245 const int antiAliasingMode = AWorkspace->GetDisplay()->AntiAliasingMode();
1247 if ( !myAntiAliasing )
1249 glDisable(GL_POINT_SMOOTH);
1250 glDisable(GL_LINE_SMOOTH);
1251 if( antiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH);
1252 glBlendFunc (GL_ONE, GL_ZERO);
1253 glDisable (GL_BLEND);
1257 glEnable(GL_POINT_SMOOTH);
1258 glEnable(GL_LINE_SMOOTH);
1259 if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
1260 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1261 glEnable (GL_BLEND);
1265 myZLayers.Render (AWorkspace);
1267 //TsmPopAttri(); /* restore previous graphics context; before update lights */
1269 if ( AWorkspace->DegenerateModel > 1 )
1271 glLineWidth ( aspect_line->Width() );
1272 if ( aspect_line->Type() != Aspect_TOL_SOLID ) glEnable ( GL_LINE_STIPPLE );
1278 /*----------------------------------------------------------------------*/
1280 //call_togl_redraw_layer2d
1281 void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
1282 const Handle(OpenGl_Workspace)& AWorkspace,
1283 const Graphic3d_CView& ACView,
1284 const Aspect_CLayer2d& ACLayer)
1286 if (&ACLayer == NULL
1287 || ACLayer.ptrLayer == NULL
1288 || ACLayer.ptrLayer->listIndex == 0) return;
1290 GLsizei dispWidth = (GLsizei )ACLayer.viewport[0];
1291 GLsizei dispHeight = (GLsizei )ACLayer.viewport[1];
1293 glMatrixMode( GL_MODELVIEW );
1297 glMatrixMode (GL_PROJECTION);
1301 if (!ACLayer.sizeDependent)
1302 glViewport (0, 0, dispWidth, dispHeight);
1304 float left = ACLayer.ortho[0];
1305 float right = ACLayer.ortho[1];
1306 float bottom = ACLayer.ortho[2];
1307 float top = ACLayer.ortho[3];
1309 int attach = ACLayer.attach;
1312 if (!ACLayer.sizeDependent)
1313 ratio = (float) dispWidth/dispHeight;
1315 ratio = ACView.DefWindow.dx/ACView.DefWindow.dy;
1319 delta = (float )((top - bottom)/2.0);
1321 case 0: /* Aspect_TOC_BOTTOM_LEFT */
1322 top = bottom + 2*delta/ratio;
1324 case 1: /* Aspect_TOC_BOTTOM_RIGHT */
1325 top = bottom + 2*delta/ratio;
1327 case 2: /* Aspect_TOC_TOP_LEFT */
1328 bottom = top - 2*delta/ratio;
1330 case 3: /* Aspect_TOC_TOP_RIGHT */
1331 bottom = top - 2*delta/ratio;
1336 delta = (float )((right - left)/2.0);
1338 case 0: /* Aspect_TOC_BOTTOM_LEFT */
1339 right = left + 2*delta*ratio;
1341 case 1: /* Aspect_TOC_BOTTOM_RIGHT */
1342 left = right - 2*delta*ratio;
1344 case 2: /* Aspect_TOC_TOP_LEFT */
1345 right = left + 2*delta*ratio;
1347 case 3: /* Aspect_TOC_TOP_RIGHT */
1348 left = right - 2*delta*ratio;
1354 // Check printer context that exists only for print operation
1355 if (!thePrintContext.IsNull())
1357 // additional transformation matrix could be applied to
1358 // render only those parts of viewport that will be
1359 // passed to a printer as a current "frame" to provide
1360 // tiling; scaling of graphics by matrix helps render a
1361 // part of a view (frame) in same viewport, but with higher
1363 thePrintContext->LoadProjTransformation();
1365 // printing operation also assumes other viewport dimension
1366 // to comply with transformation matrix or graphics scaling
1367 // factors for tiling for layer redraw
1368 GLsizei anViewportX = 0;
1369 GLsizei anViewportY = 0;
1370 thePrintContext->GetLayerViewport (anViewportX, anViewportY);
1371 if (anViewportX != 0 && anViewportY != 0)
1372 glViewport (0, 0, anViewportX, anViewportY);
1376 glOrtho (left, right, bottom, top, -1.0, 1.0);
1379 GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
1380 GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT );
1382 glDisable (GL_DEPTH_TEST);
1383 glDisable (GL_TEXTURE_1D);
1384 glDisable (GL_TEXTURE_2D);
1385 glDisable (GL_LIGHTING);
1387 // TODO: Obsolete code, the display list is always empty now, to be removed
1388 glCallList (ACLayer.ptrLayer->listIndex);
1390 //calling dynamic render of LayerItems
1391 if ( ACLayer.ptrLayer->layerData )
1393 InitLayerProp(ACLayer.ptrLayer->listIndex);
1394 ((Visual3d_Layer*)ACLayer.ptrLayer->layerData)->RenderLayerItems();
1400 glMatrixMode (GL_PROJECTION);
1403 glMatrixMode( GL_MODELVIEW );
1406 if (!ACLayer.sizeDependent)
1407 glViewport (0, 0, (GLsizei) ACView.DefWindow.dx, (GLsizei) ACView.DefWindow.dy);
1412 /*----------------------------------------------------------------------*/
1414 //call_togl_create_bg_texture
1415 void OpenGl_View::CreateBackgroundTexture (const Standard_CString theFilePath,
1416 const Aspect_FillMethod theFillStyle)
1418 if (myBgTexture.TexId != 0)
1420 // delete existing texture
1421 glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId));
1422 myBgTexture.TexId = 0;
1425 // load image from file
1426 Image_AlienPixMap anImageLoaded;
1427 if (!anImageLoaded.Load (theFilePath))
1432 Image_PixMap anImage;
1433 if (anImageLoaded.RowExtraBytes() == 0 &&
1434 (anImageLoaded.Format() == Image_PixMap::ImgRGB
1435 || anImageLoaded.Format() == Image_PixMap::ImgRGB32
1436 || anImageLoaded.Format() == Image_PixMap::ImgRGBA))
1438 anImage.InitWrapper (anImageLoaded.Format(), anImageLoaded.ChangeData(),
1439 anImageLoaded.SizeX(), anImageLoaded.SizeY(), anImageLoaded.SizeRowBytes());
1443 // convert image to RGB format
1444 if (!anImage.InitTrash (Image_PixMap::ImgRGB, anImageLoaded.SizeX(), anImageLoaded.SizeY()))
1449 anImage.SetTopDown (false);
1450 Image_PixMapData<Image_ColorRGB>& aDataNew = anImage.EditData<Image_ColorRGB>();
1451 Quantity_Color aSrcColor;
1452 for (Standard_Size aRow = 0; aRow < anImage.SizeY(); ++aRow)
1454 for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
1456 aSrcColor = anImageLoaded.PixelColor (aCol, aRow);
1457 Image_ColorRGB& aColor = aDataNew.ChangeValue (aRow, aCol);
1458 aColor.r() = int(255.0 * aSrcColor.Red());
1459 aColor.g() = int(255.0 * aSrcColor.Green());
1460 aColor.b() = int(255.0 * aSrcColor.Blue());
1463 anImageLoaded.Clear();
1466 // create MipMapped texture
1467 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
1469 GLuint aTextureId = 0;
1470 glGenTextures (1, &aTextureId);
1471 glBindTexture (GL_TEXTURE_2D, aTextureId);
1473 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1474 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1475 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1476 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1478 const GLenum aDataFormat = (anImage.Format() == Image_PixMap::ImgRGB) ? GL_RGB : GL_RGBA;
1479 gluBuild2DMipmaps (GL_TEXTURE_2D, 3/*4*/,
1480 GLint(anImage.SizeX()), GLint(anImage.SizeY()),
1481 aDataFormat, GL_UNSIGNED_BYTE, anImage.Data());
1483 myBgTexture.TexId = aTextureId;
1484 myBgTexture.Width = (Standard_Integer )anImage.SizeX();
1485 myBgTexture.Height = (Standard_Integer )anImage.SizeY();
1486 myBgTexture.Style = theFillStyle;
1489 /*----------------------------------------------------------------------*/
1491 //call_togl_set_bg_texture_style
1492 void OpenGl_View::SetBackgroundTextureStyle (const Aspect_FillMethod AFillStyle)
1494 myBgTexture.Style = AFillStyle;
1497 /*----------------------------------------------------------------------*/
1499 //call_togl_gradient_background
1500 void OpenGl_View::SetBackgroundGradient (const Quantity_Color& AColor1,
1501 const Quantity_Color& AColor2,
1502 const Aspect_GradientFillMethod AType)
1504 Standard_Real R,G,B;
1505 AColor1.Values( R, G, B, Quantity_TOC_RGB );
1506 myBgGradient.color1.rgb[0] = ( Tfloat )R;
1507 myBgGradient.color1.rgb[1] = ( Tfloat )G;
1508 myBgGradient.color1.rgb[2] = ( Tfloat )B;
1509 myBgGradient.color1.rgb[3] = 0.F;
1511 AColor2.Values( R, G, B, Quantity_TOC_RGB );
1512 myBgGradient.color2.rgb[0] = ( Tfloat )R;
1513 myBgGradient.color2.rgb[1] = ( Tfloat )G;
1514 myBgGradient.color2.rgb[2] = ( Tfloat )B;
1515 myBgGradient.color2.rgb[3] = 0.F;
1517 myBgGradient.type = AType;
1520 /*----------------------------------------------------------------------*/
1522 //call_togl_set_gradient_type
1523 void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod AType)
1525 myBgGradient.type = AType;
1528 //=======================================================================
1529 //function : AddZLayer
1531 //=======================================================================
1533 void OpenGl_View::AddZLayer (const Standard_Integer theLayerId)
1535 myZLayers.AddLayer (theLayerId);
1538 //=======================================================================
1539 //function : RemoveZLayer
1541 //=======================================================================
1543 void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId)
1545 myZLayers.RemoveLayer (theLayerId);
1548 //=======================================================================
1549 //function : DisplayStructure
1551 //=======================================================================
1553 void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure,
1554 const Standard_Integer thePriority)
1556 Standard_Integer aZLayer = theStructure->GetZLayer ();
1557 myZLayers.AddStructure (theStructure, aZLayer, thePriority);
1560 //=======================================================================
1561 //function : EraseStructure
1563 //=======================================================================
1565 void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure)
1567 Standard_Integer aZLayer = theStructure->GetZLayer ();
1568 myZLayers.RemoveStructure (theStructure, aZLayer);
1571 //=======================================================================
1572 //function : ChangeZLayer
1574 //=======================================================================
1576 void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure,
1577 const Standard_Integer theNewLayerId)
1579 Standard_Integer anOldLayer = theStructure->GetZLayer ();
1580 myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId);