1 /***********************************************************************
5 file OpenGl_togl_begin_immediat_mode.c :
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 xx-xx-xx : CAL ; Creation.
15 08-03-96 : FMN ; - Ajout include manquant
16 01-04-96 : CAL ; Integration MINSK portage WNT
17 15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
18 07-05-96 : CAL ; Gestion du minmax calcule en C++
19 voir call_togl_set_minmax
20 Debug temporaire pour ROB, TelRobSetRGB ()
21 12-06-96 : CAL ; Recuperation des attributs lors d'un draw_structure
22 22-07-96 : GG ; Faire fonctionner correctement le highlight
23 des polygones en mode immediat
24 11-09-96 : FMN ; Ajout appel a TxglWinset dans call_togl_begin_immediat_mode
25 04-11-96 : CAL : Retrait du mode simule, ajout du higlight
26 dans togl_draw_structure
27 06-11-96 : CAL : Retrait du test sur doublebuffer PRO5949
28 16-12-96 : CAL : Ajout d'un glFinish () dans end_immediat_mode
29 21-01-97 : CAL : Gestion du flag <partial> differente pour
30 eviter les comparaisons avec shortrealfirst ou last
31 22-04-97 : FMN ; Correction faute i a la place de j dans util_transform_pt
32 22-04-97 : FMN ; Correction appel util_transform_pt dans togl_set_minmax
33 24-04-97 : FMN ; (PRO4063) Ajout displaylist pour le mode transient
34 25-07-97 : CAL ; Portage WNT (Bool, False, True)
35 30-07-97 : FMN ; Meilleure gestion de la desactivation des lights
36 10-09-97 : FMN ; Meilleure gestion de la desactivation des lights
37 07-10-97 : FMN ; Simplification WNT
38 Ajout glFlush dans call_togl_clear_immediat_mode()
39 26-11-97 : FMN ; Ajout mode Ajout et xor
40 Meilleure gestion display list pour le RetainMode
41 19-12-97 : FMN ; Oublie return dans le call_togl_begin_ajout_mode()
42 22-12-97 : FMN ; Suppression DEBUG_TEMPO_FOR_ROB
44 Ajout affichage cadre TelCopyBuffer
45 Ajout LightOff sur le redraw.
46 02-02-98 : CAL ; Correction du bug sur les transformations de structure
47 tracees en mode transient. (PRO10217) (PRO12283)
48 05-02-98 : CAL ; Perfs : mise en place d'un flag identity pour savoir
49 si la matrice de transformation est l'identite.
50 08-04-98 : FMN ; Mailleur traitement du reaffichage d'une vue. Remplacement
51 de TsmDisplayStructure() par call_func_redraw_all_structs().
52 08-07-98 : FMN ; PRO14399: Desactivation animationFlag quand on debute
53 le mode immediat (Transient et Ajout).
54 30-09-98 : CAL ; Optimisation pour eviter de charger inutilement
55 les matrices de la vue.
56 27-11-98 : CAL ; S4062. Ajout des layers.
57 02.14.100 : JR : Warnings on WNT truncations from double to float
60 // -> Preserve current attributes because
61 // attributes can be changed between
62 // begin_immediate_mode() end end_immediate_mode()
63 // -> Optimize transformations computation.
64 // -> Optimize REDRAW in immediat mode.
65 // 19/09/00 -> Avoid to raise in set_linetype() & set_linewith()
66 // due to a bad call to TsmPutAttri() function.
68 BUC60726 GG_040900 Clear the last temporary detected in any case
70 BUC60900 GG_180501 Unhilight entity more earlier
71 when clear() is call instead at the next begin().
73 ************************************************************************/
76 #define BUC60863 /*GG_100401 After any view update, made identical
77 // the front and back buffer to avoid ghost drawing.
81 #define IMP150501 /*GG_150501 CADPAK_V2 Enable/Disable Zbuffer
82 NOTE that the previous and unused "double-buffer"
83 arg is changed to "zbuffer" and enable/disable
84 to use the OpenGl zbuffer capabilities during immediat
88 #define IMP260601 /*GG Enable correct backing store between 2 different views.
91 #define IMP051001 /*GG Activates the polygon offset for polygon
92 // selection fill mode.
95 /*----------------------------------------------------------------------*/
97 #define RIC120302 /* GG Enable to use the application display
98 // callback at end of traversal
105 #include <OpenGl_tgl_all.hxx>
107 #include <OpenGl_Extension.hxx>
113 #include <InterfaceGraphic_Labels.hxx>
114 #include <InterfaceGraphic_Graphic3d.hxx>
115 #include <InterfaceGraphic_Visual3d.hxx>
117 #include <OpenGl_tsm_ws.hxx>
118 #include <OpenGl_txgl.hxx>
119 #include <OpenGl_tgl_tox.hxx>
120 #include <OpenGl_tgl_funcs.hxx>
121 #include <OpenGl_telem_filters.hxx>
122 #include <OpenGl_telem.hxx>
123 #include <OpenGl_telem_util.hxx>
124 #include <OpenGl_telem_view.hxx>
125 #include <OpenGl_LightBox.hxx>
126 #include <OpenGl_animation.hxx>
127 #include <OpenGl_telem_attri.hxx>
128 #include <OpenGl_tgl.hxx>
129 #include <OpenGl_tgl_subrvis.hxx>
131 int call_util_osd_getenv( char * , char * , int ) ;
133 /*----------------------------------------------------------------------*/
142 #include <OpenGl_traces.h>
146 /*----------------------------------------------------------------------*/
151 /*----------------------------------------------------------------------*/
153 * Prototypes fonctions
156 /*----------------------------------------------------------------------*/
158 * Prototypes Private functions
161 static void call_util_transform_pt (float *x, float *y, float *z);
162 static int call_util_is_identity ();
163 static void call_util_transpose_mat (float tmat[16], float mat[4][4]);
165 /*----------------------------------------------------------------------*/
167 * Variables statiques
170 static int openglNumberOfPoints = 0;
171 static GLint openglViewId = 0;
172 static GLint openglWsId = 0;
174 static int identity = 1;
176 static int partial = -1; /* -1 init, 0 complete, 1 partielle */
178 static float xm, ym, zm, XM, YM, ZM;
180 static float openglMat[4][4] = {
187 static GLboolean transientOpen = GL_FALSE;
189 /*----------------------------------------------------------------------*/
191 /*----------------------------------------------------------------------*/
193 int EXPORT call_togl_begin_ajout_mode (
199 TsmGetWSAttri (aview->WsId, WSWindow, &data);
201 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return (0);
203 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
206 if (aview->ViewId == -1) return (0);
208 openglWsId = aview->WsId;
209 openglViewId = aview->ViewId;
211 /* mise en place des matrices de projection et de mapping */
212 /* TelSetViewIndex (aview->WsId, aview->ViewId); */
215 printf ("call_togl_begin_ajout_mode %d %d\n", openglViewId, openglWsId);
218 TelMakeFrontAndBackBufCurrent (aview->WsId);
225 /*----------------------------------------------------------------------*/
226 void EXPORT call_togl_end_ajout_mode ()
230 printf ("call_togl_end_ajout_mode %d %d\n", openglViewId, openglWsId);
233 if (openglViewId != 0) {
234 TelMakeBackBufCurrent (openglWsId);
242 /* FMN necessaire pour l'affichage sur WNT */
250 /*----------------------------------------------------------------------*/
252 /*----------------------------------------------------------------------*/
254 void EXPORT call_togl_clear_immediat_mode (
255 CALL_DEF_VIEW *aview, Tint aFlush
259 GLuint listIndex = 0;
260 GLuint retainmode = 0;
262 if( transientOpen ) {
263 call_togl_end_immediat_mode(0);
267 TsmGetWSAttri (aview->WsId, WSWindow, &data);
268 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return;
270 TsmGetWSAttri( aview->WsId, WSRetainMode, &data );
271 retainmode = data.ldata;
274 printf("call_togl_clear_immediat_mode. xm %f, ym %f, zm %f, XM %f, YM %f, ZM %f, partial %d retainmode %d\n",xm, ym, zm, XM, YM, ZM, partial, retainmode);
277 if ( TelBackBufferRestored () == TOff ) {
278 call_togl_erase_animation_mode();
279 call_func_redraw_all_structs_begin (aview->WsId);
280 if( aview->ptrUnderLayer)
281 call_togl_redraw_layer2d (aview, (CALL_DEF_LAYER *)aview->ptrUnderLayer);
282 call_func_redraw_all_structs_proc (aview->WsId);
283 if( aview->ptrOverLayer)
284 call_togl_redraw_layer2d (aview, (CALL_DEF_LAYER *)aview->ptrOverLayer);
286 call_subr_displayCB(aview,OCC_REDRAW_WINDOW);
288 call_func_redraw_all_structs_end (aview->WsId, aFlush);
291 Made the back identical to the front buffer
293 if( retainmode && (partial >= 0) )
294 TelCopyBuffers (aview->WsId, GL_FRONT, GL_BACK,
295 xm, ym, zm, XM, YM, ZM, partial);
297 printf(" $$$ REDRAW\n");
299 TelSetBackBufferRestored (TOn);
300 } else if( partial >= 0 ) {
302 Restore pixels from the back buffer.
304 TelCopyBuffers (aview->WsId, GL_BACK, GL_FRONT,
305 xm, ym, zm, XM, YM, ZM, partial);
308 TsmGetWSAttri (aview->WsId, WSTransient, &data);
309 listIndex = (GLuint) data.ldata;
310 if( listIndex != 0 ) { /* Clear current list contents */
311 glNewList( listIndex, GL_COMPILE_AND_EXECUTE);
315 XM = YM = ZM = (float ) shortrealfirst ();
316 xm = ym = zm = (float ) shortreallast ();
319 /*----------------------------------------------------------------------*/
321 void call_togl_redraw_immediat_mode(
322 CALL_DEF_VIEW * aview
326 GLuint listIndex = 0;
329 GLboolean flag_zbuffer = GL_FALSE;
332 TsmGetWSAttri( aview->WsId, WSRetainMode, &data );
333 retainmode = data.ldata;
335 TsmGetWSAttri (aview->WsId, WSTransient, &data);
336 listIndex = (GLuint) data.ldata;
338 if (retainmode != 0) {
339 if (listIndex != 0) {
340 TelMakeFrontBufCurrent (aview->WsId);
343 /* mise en place des matrices de projection et de mapping */
344 /* TelSetViewIndex (aview->WsId, aview->ViewId); */
347 printf("call_togl_redraw_immediat_mode::call displaylist(%d) \n",
351 glCallList(listIndex);
353 flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
354 if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
355 glCallList(listIndex);
356 if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
358 /* FMN necessaire pour l'affichage sur WNT */
361 TelMakeBackBufCurrent (aview->WsId);
367 /*----------------------------------------------------------------------*/
370 call_togl_begin_immediat_mode
372 CALL_DEF_VIEW * aview,
373 CALL_DEF_LAYER * anunderlayer,
374 CALL_DEF_LAYER * anoverlayer,
384 GLuint listIndex = 0;
386 if (aview->ViewId == -1) return (0);
388 TsmGetWSAttri (aview->WsId, WSWindow, &data);
390 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return (0);
392 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
395 openglWsId = aview->WsId;
396 openglViewId = aview->ViewId;
398 data.ldata = retainmode;
399 TsmSetWSAttri( aview->WsId, WSRetainMode, &data );
402 printf ("call_togl_begin_immediat_mode %d %d RetainMode %d zbuffer %d partial %d\n", openglViewId, openglWsId, retainmode, zbuffer, partial);
405 call_togl_clear_immediat_mode(aview,1);
407 TelMakeFrontBufCurrent (aview->WsId);
413 glColor3f (1., 0., 0.);
414 glBegin(GL_LINE_LOOP);
415 glVertex3f (xm, ym, zm);
416 glVertex3f (XM, ym, zm);
417 glVertex3f (XM, YM, zm);
418 glVertex3f (xm, YM, zm);
427 TsmGetWSAttri (aview->WsId, WSTransient, &data);
428 listIndex = (GLuint) data.ldata;
430 if (listIndex == 0) {
431 listIndex = glGenLists(1);
433 printf("call_togl_begin_immediat_mode::init displaylist() %d \n", listIndex);
435 data.ldata = listIndex;
436 TsmSetWSAttri( aview->WsId, WSTransient, &data );
438 if (listIndex == 0) return(0);
440 printf("call_togl_begin_immediat_mode::glNewList() %d \n", listIndex);
442 glNewList(listIndex, GL_COMPILE_AND_EXECUTE);
443 transientOpen = GL_TRUE;
448 glEnable(GL_DEPTH_TEST);
449 } else glDisable(GL_DEPTH_TEST);
456 /*----------------------------------------------------------------------*/
458 call_togl_end_immediat_mode (synchronize)
459 GLboolean synchronize
461 End of immediate graphic primitives in the view.
465 call_togl_end_immediat_mode
472 printf ("call_togl_end_immediat_mode %d %d %d\n",
473 synchronize, openglViewId, openglWsId);
476 #ifndef BUC60863 /* Don't modify the current minmax !!*/
477 /* Mise ajout MinMax */
478 if ((xm > shortreallast ()) ||
479 (ym > shortreallast ()) ||
480 (zm > shortreallast ()) ||
481 (XM > shortreallast ()) ||
482 (YM > shortreallast ()) ||
483 (ZM > shortreallast ()) ||
484 (xm < shortrealfirst ()) ||
485 (ym < shortrealfirst ()) ||
486 (zm < shortrealfirst ()) ||
487 (XM < shortrealfirst ()) ||
488 (YM < shortrealfirst ()) ||
489 (ZM < shortrealfirst ())) {
490 XM = YM = ZM = (float ) shortreallast ();
491 xm = ym = zm = (float ) shortrealfirst ();
495 if (partial != 0) partial = 1;
499 if (openglViewId != 0) {
502 glColor3f (0., 1., 0.);
503 glBegin(GL_LINE_LOOP);
504 glVertex3f (xm, ym, zm);
505 glVertex3f (XM, ym, zm);
506 glVertex3f (XM, YM, zm);
507 glVertex3f (xm, YM, zm);
515 printf("--->glEndList() \n");
517 transientOpen = GL_FALSE;
520 TelMakeBackBufCurrent (openglWsId);
524 * Ajout CAL : pour voir quelque chose
525 * avant le prochain begin_immediat_mode
538 /*----------------------------------------------------------------------*/
540 call_togl_transform (amatrix, mode)
544 Set the local transformation for All primitives
545 REPLACE the existante if mode is True or POSTCONCATENATE if GL_FALSE
548 call_togl_transform ( float amatrix[4][4], int mode )
551 if (mode || identity) {
554 openglMat[i][j] = amatrix[i][j];
556 TelMultiplymat3 (openglMat, openglMat, amatrix);
558 identity = call_util_is_identity ();
563 call_togl_begin_polyline ()
565 Sets the graphic library ready to receive a polyline.
569 call_togl_begin_polyline ()
571 openglNumberOfPoints = 0;
573 glBegin (GL_LINE_STRIP);
577 /*----------------------------------------------------------------------*/
579 call_togl_end_polyline ()
585 call_togl_end_polyline ()
589 printf ("call_togl_end_polyline %d %d\n", openglViewId, openglWsId);
592 if (openglViewId != 0) glEnd ();
596 /*----------------------------------------------------------------------*/
598 call_togl_draw (x, y, z)
603 Defines a new point in the current primitive.
616 printf ("call_togl_draw %d %d\n", openglViewId, openglWsId);
619 if (openglViewId != 0) {
620 openglNumberOfPoints ++;
621 call_util_transform_pt (&x, &y, &z);
628 glVertex3f (x, y, z);
634 /*----------------------------------------------------------------------*/
636 call_togl_move (x, y, z)
641 Defines a new point in the current primitive.
654 printf ("call_togl_move %d %d\n", openglViewId, openglWsId);
657 if (openglViewId != 0) {
658 if (openglNumberOfPoints != 0) {
659 call_togl_end_polyline ();
660 call_togl_begin_polyline ();
663 openglNumberOfPoints ++;
664 call_util_transform_pt (&x, &y, &z);
671 glVertex3f (x, y, z);
677 /*----------------------------------------------------------------------*/
679 call_togl_set_linecolor (r, g, b)
684 Sets a new color in the current primitive.
688 call_togl_set_linecolor
697 printf ("call_togl_set_linecolor %d %d\n", openglViewId, openglWsId);
700 if (openglViewId != 0) {
703 key.id = TelPolylineColour;
704 color.rgb[0] = r; color.rgb[1] = g; color.rgb[2] = b;
705 key.data.pdata = &color;
706 TsmSetAttri( 1, &key );
711 /*----------------------------------------------------------------------*/
713 call_togl_set_linetype (type)
716 Sets a new line type in the current primitive.
720 call_togl_set_linetype
726 printf ("call_togl_set_linetype %d %d\n", openglViewId, openglWsId);
729 if (openglViewId != 0) {
731 key.id = TelPolylineType;
732 key.data.ldata = type;
733 TsmSetAttri( 1, &key);
738 /*----------------------------------------------------------------------*/
740 call_togl_set_linewidth (width)
743 Sets a new line width in the current primitive.
747 call_togl_set_linewidth
754 printf ("call_togl_set_linewidth %d %d\n", openglViewId, openglWsId);
757 if (openglViewId != 0) {
759 key.id = TelPolylineWidth;
760 key.data.fdata = width;
761 TsmSetAttri( 1, &key);
766 /*----------------------------------------------------------------------*/
768 call_togl_draw_structure (aStructureId)
771 Draw a structure in the transient view space
775 call_togl_draw_structure
782 register Tint istrsfed = 0;
783 register Tint display = 1;
784 register Tint highl = TOff;
785 register TelType telem;
793 printf ("call_togl_draw_structure %d %d %d\n", openglViewId, openglWsId);
796 if (openglViewId == 0) return;
798 if (TsmGetStructure (aStructureId, &num, &node) == TFailure || !num) return;
800 /*transform_persistence_end();*/
802 TsmPushAttriLight ();
806 /* mise en place de la matrice de transformation du trace transient */
808 call_util_transpose_mat (mat16, openglMat);
809 glGetIntegerv (GL_MATRIX_MODE, &mode1);
810 glMatrixMode (GL_MODELVIEW);
812 glScalef (1., 1., 1.);
813 glMultMatrixf (mat16);
816 for (i = 0; i < num; i++, node = node->next) {
817 telem = node->elem.el;
819 TelTrace(telem,node->elem.data.ldata);
823 case TelRemoveNameset: {
824 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0);
826 if( TglFilterNameset( openglWsId, InvisFilter ) == TSuccess )
829 if( TglFilterNameset( openglWsId, HighlFilter ) == TSuccess )
840 /* do not send Display message to */
841 /* primitives if they are invisible */
846 glDepthMask(GL_FALSE);
849 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
856 case TelPolygonHoles:
857 case TelPolygonIndices:
860 case TelTriangleMesh: {
861 /* do not send Display message to */
862 /* primitives if they are invisible */
867 glDepthMask(GL_FALSE);
871 call_subr_disable_polygon_offset();
875 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
878 call_subr_enable_polygon_offset();
885 case TelLocalTran3: {
886 tel_matrix3_data d = ((tel_matrix3_data)(node->elem.data.pdata));
888 call_util_transpose_mat (mat16, d->mat);
889 glGetIntegerv (GL_MATRIX_MODE, &mode2);
890 glMatrixMode (GL_MODELVIEW);
892 glScalef (1., 1., 1.);
893 glMultMatrixf (mat16);
896 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
897 case TelTransformPersistence:
900 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
903 /*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
906 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0, &key);
917 glMatrixMode (mode2);
921 glMatrixMode (mode1);
927 /*----------------------------------------------------------------------*/
929 call_togl_set_minmax (x1, y1, z1, x2, y2, z2)
937 Give the boundary box of the transient graphic
941 call_togl_set_minmax (
951 printf("call_togl_set_minmax. x1 %f, y1 %f, z1 %f, x2 %f, y2 %f, z2 %f\n",x1, y1, z1, x2, y2, z2);
953 if ((x1 > shortreallast ()) ||
954 (y1 > shortreallast ()) ||
955 (z1 > shortreallast ()) ||
956 (x2 > shortreallast ()) ||
957 (y2 > shortreallast ()) ||
958 (z2 > shortreallast ()) ||
959 (x1 < shortrealfirst ()) ||
960 (y1 < shortrealfirst ()) ||
961 (z1 < shortrealfirst ()) ||
962 (x2 < shortrealfirst ()) ||
963 (y2 < shortrealfirst ()) ||
964 (z2 < shortrealfirst ())) {
965 XM = YM = ZM = (float ) shortreallast ();
966 xm = ym = zm = (float ) shortrealfirst ();
970 call_util_transform_pt (&x1, &y1, &z1);
971 call_util_transform_pt (&x2, &y2, &z2);
972 if (x1 > XM) XM = x1;
973 if (x1 < xm) xm = x1;
974 if (y1 > YM) YM = y1;
975 if (y1 < ym) ym = y1;
976 if (z1 > ZM) ZM = z1;
977 if (z1 < zm) zm = z1;
979 if (x2 > XM) XM = x2;
980 if (x2 < xm) xm = x2;
981 if (y2 > YM) YM = y2;
982 if (y2 < ym) ym = y2;
983 if (z2 > ZM) ZM = z2;
984 if (z2 < zm) zm = z2;
985 if (partial != 0) partial = 1;
989 /*----------------------------------------------------------------------*/
994 /*----------------------------------------------------------------------*/
996 call_util_transform_pt (x, y, z)
1001 Transform the point pt
1004 static void call_util_transform_pt
1013 float tpt[4], pt[4];
1016 pt[0] = *x, pt[1] = *y, pt[2] = *z, pt[3] = 1.0;
1018 for (i = 0; i < 4; i++) {
1019 for (j = 0, sum = 0.0; j < 4; j++)
1020 sum += openglMat[i][j] * pt[j];
1024 *x = tpt[0], *y = tpt[1], *z = tpt[2];
1029 /*----------------------------------------------------------------------*/
1031 int call_util_is_identity ()
1033 Returns 1 if openglMat is the identity
1036 static int call_util_is_identity
1043 for (i = 0; res && i < 4; i++)
1044 for (j = 0; res && j < 4; j++)
1045 if (i == j) res = (openglMat[i][j] == 1.);
1046 else res = (openglMat[i][j] == 0.);
1049 printf ("La matrice suivante :\n");
1050 for (i = 0; i < 4; i++) {
1052 for (j = 0; j < 4; j++)
1053 printf ("%f ", openglMat[i][j]);
1057 printf ("est la matrice identite\n");
1059 printf ("n'est pas la matrice identite\n");
1066 /*----------------------------------------------------------------------*/
1068 void call_util_transpose_mat (tmat, mat)
1072 Transpose mat and returns tmat.
1075 static void call_util_transpose_mat (float tmat[16], float mat[4][4]) {
1080 tmat[j*4+i] = mat[i][j];
1083 printf ("Transposee :\n");
1084 for (i = 0; i < 4; i++) {
1086 for (j = 0; j < 4; j++)
1087 printf ("%f ", tmat[i*4+j]);