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);
290 // Made the back identical to the front buffer.
291 // Always perform full copy (partial update optimization is useless on mordern hardware)!
293 TelCopyBuffers (aview->WsId, GL_FRONT, GL_BACK, xm, ym, zm, XM, YM, ZM, 0);
295 printf(" $$$ REDRAW\n");
297 TelSetBackBufferRestored (TOn);
298 } else if( partial >= 0 ) {
299 // Restore pixels from the back buffer.
300 // Always perform full copy (partial update optimization is useless on mordern hardware)!
301 TelCopyBuffers (aview->WsId, GL_BACK, GL_FRONT, xm, ym, zm, XM, YM, ZM, 0);
304 TsmGetWSAttri (aview->WsId, WSTransient, &data);
305 listIndex = (GLuint) data.ldata;
306 if( listIndex != 0 ) { /* Clear current list contents */
307 glNewList( listIndex, GL_COMPILE_AND_EXECUTE);
311 XM = YM = ZM = (float ) shortrealfirst ();
312 xm = ym = zm = (float ) shortreallast ();
315 /*----------------------------------------------------------------------*/
317 void call_togl_redraw_immediat_mode(
318 CALL_DEF_VIEW * aview
322 GLuint listIndex = 0;
325 GLboolean flag_zbuffer = GL_FALSE;
328 TsmGetWSAttri( aview->WsId, WSRetainMode, &data );
329 retainmode = data.ldata;
331 TsmGetWSAttri (aview->WsId, WSTransient, &data);
332 listIndex = (GLuint) data.ldata;
334 if (retainmode != 0) {
335 if (listIndex != 0) {
336 TelMakeFrontBufCurrent (aview->WsId);
339 /* mise en place des matrices de projection et de mapping */
340 /* TelSetViewIndex (aview->WsId, aview->ViewId); */
343 printf("call_togl_redraw_immediat_mode::call displaylist(%d) \n",
347 glCallList(listIndex);
349 flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
350 if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
351 glCallList(listIndex);
352 if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
354 /* FMN necessaire pour l'affichage sur WNT */
357 TelMakeBackBufCurrent (aview->WsId);
363 /*----------------------------------------------------------------------*/
366 call_togl_begin_immediat_mode
368 CALL_DEF_VIEW * aview,
369 CALL_DEF_LAYER * anunderlayer,
370 CALL_DEF_LAYER * anoverlayer,
380 GLuint listIndex = 0;
382 if (aview->ViewId == -1) return (0);
384 TsmGetWSAttri (aview->WsId, WSWindow, &data);
386 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) != TSuccess) return (0);
388 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
391 openglWsId = aview->WsId;
392 openglViewId = aview->ViewId;
394 data.ldata = retainmode;
395 TsmSetWSAttri( aview->WsId, WSRetainMode, &data );
398 printf ("call_togl_begin_immediat_mode %d %d RetainMode %d zbuffer %d partial %d\n", openglViewId, openglWsId, retainmode, zbuffer, partial);
401 call_togl_clear_immediat_mode(aview,1);
403 TelMakeFrontBufCurrent (aview->WsId);
409 glColor3f (1., 0., 0.);
410 glBegin(GL_LINE_LOOP);
411 glVertex3f (xm, ym, zm);
412 glVertex3f (XM, ym, zm);
413 glVertex3f (XM, YM, zm);
414 glVertex3f (xm, YM, zm);
423 TsmGetWSAttri (aview->WsId, WSTransient, &data);
424 listIndex = (GLuint) data.ldata;
426 if (listIndex == 0) {
427 listIndex = glGenLists(1);
429 printf("call_togl_begin_immediat_mode::init displaylist() %d \n", listIndex);
431 data.ldata = listIndex;
432 TsmSetWSAttri( aview->WsId, WSTransient, &data );
434 if (listIndex == 0) return(0);
436 printf("call_togl_begin_immediat_mode::glNewList() %d \n", listIndex);
438 glNewList(listIndex, GL_COMPILE_AND_EXECUTE);
439 transientOpen = GL_TRUE;
444 glEnable(GL_DEPTH_TEST);
445 } else glDisable(GL_DEPTH_TEST);
452 /*----------------------------------------------------------------------*/
454 call_togl_end_immediat_mode (synchronize)
455 GLboolean synchronize
457 End of immediate graphic primitives in the view.
461 call_togl_end_immediat_mode
468 printf ("call_togl_end_immediat_mode %d %d %d\n",
469 synchronize, openglViewId, openglWsId);
472 #ifndef BUC60863 /* Don't modify the current minmax !!*/
473 /* Mise ajout MinMax */
474 if ((xm > shortreallast ()) ||
475 (ym > shortreallast ()) ||
476 (zm > shortreallast ()) ||
477 (XM > shortreallast ()) ||
478 (YM > shortreallast ()) ||
479 (ZM > shortreallast ()) ||
480 (xm < shortrealfirst ()) ||
481 (ym < shortrealfirst ()) ||
482 (zm < shortrealfirst ()) ||
483 (XM < shortrealfirst ()) ||
484 (YM < shortrealfirst ()) ||
485 (ZM < shortrealfirst ())) {
486 XM = YM = ZM = (float ) shortreallast ();
487 xm = ym = zm = (float ) shortrealfirst ();
491 if (partial != 0) partial = 1;
495 if (openglViewId != 0) {
498 glColor3f (0., 1., 0.);
499 glBegin(GL_LINE_LOOP);
500 glVertex3f (xm, ym, zm);
501 glVertex3f (XM, ym, zm);
502 glVertex3f (XM, YM, zm);
503 glVertex3f (xm, YM, zm);
511 printf("--->glEndList() \n");
513 transientOpen = GL_FALSE;
516 TelMakeBackBufCurrent (openglWsId);
520 * Ajout CAL : pour voir quelque chose
521 * avant le prochain begin_immediat_mode
534 /*----------------------------------------------------------------------*/
536 call_togl_transform (amatrix, mode)
540 Set the local transformation for All primitives
541 REPLACE the existante if mode is True or POSTCONCATENATE if GL_FALSE
544 call_togl_transform ( float amatrix[4][4], int mode )
547 if (mode || identity) {
550 openglMat[i][j] = amatrix[i][j];
552 TelMultiplymat3 (openglMat, openglMat, amatrix);
554 identity = call_util_is_identity ();
559 call_togl_begin_polyline ()
561 Sets the graphic library ready to receive a polyline.
565 call_togl_begin_polyline ()
567 openglNumberOfPoints = 0;
569 glBegin (GL_LINE_STRIP);
573 /*----------------------------------------------------------------------*/
575 call_togl_end_polyline ()
581 call_togl_end_polyline ()
585 printf ("call_togl_end_polyline %d %d\n", openglViewId, openglWsId);
588 if (openglViewId != 0) glEnd ();
592 /*----------------------------------------------------------------------*/
594 call_togl_draw (x, y, z)
599 Defines a new point in the current primitive.
612 printf ("call_togl_draw %d %d\n", openglViewId, openglWsId);
615 if (openglViewId != 0) {
616 openglNumberOfPoints ++;
617 call_util_transform_pt (&x, &y, &z);
624 glVertex3f (x, y, z);
630 /*----------------------------------------------------------------------*/
632 call_togl_move (x, y, z)
637 Defines a new point in the current primitive.
650 printf ("call_togl_move %d %d\n", openglViewId, openglWsId);
653 if (openglViewId != 0) {
654 if (openglNumberOfPoints != 0) {
655 call_togl_end_polyline ();
656 call_togl_begin_polyline ();
659 openglNumberOfPoints ++;
660 call_util_transform_pt (&x, &y, &z);
667 glVertex3f (x, y, z);
673 /*----------------------------------------------------------------------*/
675 call_togl_set_linecolor (r, g, b)
680 Sets a new color in the current primitive.
684 call_togl_set_linecolor
693 printf ("call_togl_set_linecolor %d %d\n", openglViewId, openglWsId);
696 if (openglViewId != 0) {
699 key.id = TelPolylineColour;
700 color.rgb[0] = r; color.rgb[1] = g; color.rgb[2] = b;
701 key.data.pdata = &color;
702 TsmSetAttri( 1, &key );
707 /*----------------------------------------------------------------------*/
709 call_togl_set_linetype (type)
712 Sets a new line type in the current primitive.
716 call_togl_set_linetype
722 printf ("call_togl_set_linetype %d %d\n", openglViewId, openglWsId);
725 if (openglViewId != 0) {
727 key.id = TelPolylineType;
728 key.data.ldata = type;
729 TsmSetAttri( 1, &key);
734 /*----------------------------------------------------------------------*/
736 call_togl_set_linewidth (width)
739 Sets a new line width in the current primitive.
743 call_togl_set_linewidth
750 printf ("call_togl_set_linewidth %d %d\n", openglViewId, openglWsId);
753 if (openglViewId != 0) {
755 key.id = TelPolylineWidth;
756 key.data.fdata = width;
757 TsmSetAttri( 1, &key);
762 /*----------------------------------------------------------------------*/
764 call_togl_draw_structure (aStructureId)
767 Draw a structure in the transient view space
771 call_togl_draw_structure
778 register Tint istrsfed = 0;
779 register Tint display = 1;
780 register Tint highl = TOff;
781 register TelType telem;
789 printf ("call_togl_draw_structure %d %d %d\n", openglViewId, openglWsId);
792 if (openglViewId == 0) return;
794 if (TsmGetStructure (aStructureId, &num, &node) == TFailure || !num) return;
796 /*transform_persistence_end();*/
798 TsmPushAttriLight ();
802 /* mise en place de la matrice de transformation du trace transient */
804 call_util_transpose_mat (mat16, openglMat);
805 glGetIntegerv (GL_MATRIX_MODE, &mode1);
806 glMatrixMode (GL_MODELVIEW);
808 glScalef (1., 1., 1.);
809 glMultMatrixf (mat16);
812 for (i = 0; i < num; i++, node = node->next) {
813 telem = node->elem.el;
815 TelTrace(telem,node->elem.data.ldata);
819 case TelRemoveNameset: {
820 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0);
822 if( TglFilterNameset( openglWsId, InvisFilter ) == TSuccess )
825 if( TglFilterNameset( openglWsId, HighlFilter ) == TSuccess )
836 /* do not send Display message to */
837 /* primitives if they are invisible */
842 glDepthMask(GL_FALSE);
845 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
852 case TelPolygonHoles:
853 case TelPolygonIndices:
856 case TelTriangleMesh: {
857 /* do not send Display message to */
858 /* primitives if they are invisible */
863 glDepthMask(GL_FALSE);
867 call_subr_disable_polygon_offset();
871 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
874 call_subr_enable_polygon_offset();
881 case TelLocalTran3: {
882 tel_matrix3_data d = ((tel_matrix3_data)(node->elem.data.pdata));
884 call_util_transpose_mat (mat16, d->mat);
885 glGetIntegerv (GL_MATRIX_MODE, &mode2);
886 glMatrixMode (GL_MODELVIEW);
888 glScalef (1., 1., 1.);
889 glMultMatrixf (mat16);
892 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
893 case TelTransformPersistence:
896 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
899 /*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
902 TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0, &key);
913 glMatrixMode (mode2);
917 glMatrixMode (mode1);
923 /*----------------------------------------------------------------------*/
925 call_togl_set_minmax (x1, y1, z1, x2, y2, z2)
933 Give the boundary box of the transient graphic
937 call_togl_set_minmax (
947 printf("call_togl_set_minmax. x1 %f, y1 %f, z1 %f, x2 %f, y2 %f, z2 %f\n",x1, y1, z1, x2, y2, z2);
949 if ((x1 > shortreallast ()) ||
950 (y1 > shortreallast ()) ||
951 (z1 > shortreallast ()) ||
952 (x2 > shortreallast ()) ||
953 (y2 > shortreallast ()) ||
954 (z2 > shortreallast ()) ||
955 (x1 < shortrealfirst ()) ||
956 (y1 < shortrealfirst ()) ||
957 (z1 < shortrealfirst ()) ||
958 (x2 < shortrealfirst ()) ||
959 (y2 < shortrealfirst ()) ||
960 (z2 < shortrealfirst ())) {
961 XM = YM = ZM = (float ) shortreallast ();
962 xm = ym = zm = (float ) shortrealfirst ();
966 call_util_transform_pt (&x1, &y1, &z1);
967 call_util_transform_pt (&x2, &y2, &z2);
968 if (x1 > XM) XM = x1;
969 if (x1 < xm) xm = x1;
970 if (y1 > YM) YM = y1;
971 if (y1 < ym) ym = y1;
972 if (z1 > ZM) ZM = z1;
973 if (z1 < zm) zm = z1;
975 if (x2 > XM) XM = x2;
976 if (x2 < xm) xm = x2;
977 if (y2 > YM) YM = y2;
978 if (y2 < ym) ym = y2;
979 if (z2 > ZM) ZM = z2;
980 if (z2 < zm) zm = z2;
981 if (partial != 0) partial = 1;
985 /*----------------------------------------------------------------------*/
990 /*----------------------------------------------------------------------*/
992 call_util_transform_pt (x, y, z)
997 Transform the point pt
1000 static void call_util_transform_pt
1009 float tpt[4], pt[4];
1012 pt[0] = *x, pt[1] = *y, pt[2] = *z, pt[3] = 1.0;
1014 for (i = 0; i < 4; i++) {
1015 for (j = 0, sum = 0.0; j < 4; j++)
1016 sum += openglMat[i][j] * pt[j];
1020 *x = tpt[0], *y = tpt[1], *z = tpt[2];
1025 /*----------------------------------------------------------------------*/
1027 int call_util_is_identity ()
1029 Returns 1 if openglMat is the identity
1032 static int call_util_is_identity
1039 for (i = 0; res && i < 4; i++)
1040 for (j = 0; res && j < 4; j++)
1041 if (i == j) res = (openglMat[i][j] == 1.);
1042 else res = (openglMat[i][j] == 0.);
1045 printf ("La matrice suivante :\n");
1046 for (i = 0; i < 4; i++) {
1048 for (j = 0; j < 4; j++)
1049 printf ("%f ", openglMat[i][j]);
1053 printf ("est la matrice identite\n");
1055 printf ("n'est pas la matrice identite\n");
1062 /*----------------------------------------------------------------------*/
1064 void call_util_transpose_mat (tmat, mat)
1068 Transpose mat and returns tmat.
1071 static void call_util_transpose_mat (float tmat[16], float mat[4][4]) {
1076 tmat[j*4+i] = mat[i][j];
1079 printf ("Transposee :\n");
1080 for (i = 0; i < 4; i++) {
1082 for (j = 0; j < 4; j++)
1083 printf ("%f ", tmat[i*4+j]);