Merging OCC22105, OCC22354, OCC22150 , OCC22199 , OCC22391 and OCC22108
[occt.git] / src / OpenGl / OpenGl_togl_redraw.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3FONCTION :
4----------
5file OpenGl_togl_redraw.c :
6
7
8REMARQUES:
9----------
10
11
12HISTORIQUE DES MODIFICATIONS :
13--------------------------------
14xx-xx-xx : CAL ; Creation.
1523-01-97 : CAL : Ajout pour mettre des traces facilement
16apres lancement de Designer
1705-02-97 : FMN ; Suppression de OpenGl_tgl_vis.h
1803-03-97 : FMN ; (PRO4063) Ajout displaylist pour le mode transient
1907-10-97 : FMN ; Simplification WNT
2008-08-98 : FMN ; ajout PRINT debug
2118-11-98 : CAL ; S4062. Ajout des layers.
2215-11-99 : GG ; Add call_togl_redraw_area()
2315-11-99 : VKH ; G004 redrawing view to a large pixmap
2402.01.100 : JR : = 0 for Integer and = NULL for pointers
2502.02.100 " #include <GL/glu.h> for declaration of gluErrorString
2607-03-00 : GG : G004 use the already created pixmap.
27Enable two side lighting before redrawing in pixmap.
28
29************************************************************************/
30
31#define G004 /* VKH 15-11-99 redrawing view to a large pixmap
32*/
33
34#define RIC120302 /* GG Enable to use the application display
35callback at end of traversal
36Modified P. Dolbey 09/06/07 to call back
37before redrawing the overlayer
38*/
39
40/*----------------------------------------------------------------------*/
41/*
42* Includes
43*/
44
45#ifdef G004
46#ifndef WNT
47#define CALL_DEF_STRING_LENGTH 132
48#else
49#include <OpenGl_AVIWriter.hxx>
50#endif
51# include <OpenGl_tgl_all.hxx>
52GLboolean g_fBitmap;
53#endif /*G004*/
54
55#include <OpenGl_tgl.hxx>
56#include <OpenGl_tsm_ws.hxx>
57#include <OpenGl_tgl_tox.hxx>
58#include <OpenGl_txgl.hxx>
59#include <OpenGl_tgl_funcs.hxx>
60#include <OpenGl_tgl_subrvis.hxx>
61#include <OpenGl_FrameBuffer.hxx>
d4c2114a 62#include <OpenGl_ResourceCleaner.hxx>
7fd59977 63#include <InterfaceGraphic_Graphic3d.hxx>
64#include <InterfaceGraphic_Visual3d.hxx>
65
66void EXPORT
67call_togl_redraw
68(
69 CALL_DEF_VIEW * aview,
70 CALL_DEF_LAYER * anunderlayer,
71 CALL_DEF_LAYER * anoverlayer
72 )
73{
74 CMN_KEY_DATA data;
75 Tint swap = 1; /* swap buffers ? yes */
76
77 if ( TsmGetWSAttri (aview->WsId, WSWindow, &data) != TSuccess ) return;
78
79 WINDOW aWin = (WINDOW )data.ldata;
80 if (TxglWinset (call_thedisplay, aWin) == TSuccess)
81 {
82 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )aview->ptrFBO;
83 GLint aViewPortBack[4]; glGetIntegerv (GL_VIEWPORT, aViewPortBack);
84 if (aFrameBuffer != NULL)
85 {
86 aFrameBuffer->SetupViewport();
87 aFrameBuffer->BindBuffer();
88 swap = 0; // no need to swap buffers
89 }
d4c2114a 90 OpenGl_ResourceCleaner::GetInstance()->Cleanup();
7fd59977 91 call_func_redraw_all_structs_begin (aview->WsId);
d4c2114a 92 call_togl_setplane( aview );
7fd59977 93 if (anunderlayer->ptrLayer)
94 {
95 call_togl_redraw_layer2d (aview, anunderlayer);
96 }
97 call_func_redraw_all_structs_proc (aview->WsId);
98 if (anoverlayer->ptrLayer)
99 {
100 call_togl_redraw_layer2d (aview, anoverlayer);
101 }
102 call_subr_displayCB (aview, OCC_REDRAW_WINDOW);
103 call_func_redraw_all_structs_end (aview->WsId, swap);
104 call_togl_redraw_immediat_mode (aview);
105
106 if (aFrameBuffer != NULL)
107 {
108 aFrameBuffer->UnbindBuffer();
109 // move back original viewport
110 glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]);
111 }
112 }
113
114#ifdef WNT
115 if (OpenGl_AVIWriter_AllowWriting (aview->DefWindow.XWindow))
116 {
117 GLint params[4];
118 glGetIntegerv (GL_VIEWPORT, params);
119 int nWidth = params[2] & ~0x7;
120 int nHeight = params[3] & ~0x7;
121
122 const int nBitsPerPixel = 24;
123 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
124
125 glPixelStorei (GL_PACK_ALIGNMENT, 1);
126 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
127 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
128 delete[] aDumpData;
129 }
130#endif
131
132 return;
133}
134
135void EXPORT
136call_togl_redraw_area
137(
138 CALL_DEF_VIEW * aview,
139 CALL_DEF_LAYER * anunderlayer,
140 CALL_DEF_LAYER * anoverlayer,
141 int x, int y, int width, int height
142 )
143{
144 CMN_KEY_DATA data;
145
146 /*
147 When the exposure area size is > window size / 2 do a full redraw.
148 */
149 if( width*height >
150 (int)(aview->DefWindow.dx*aview->DefWindow.dy)/2 ) {
151 call_togl_redraw(aview,anunderlayer,anoverlayer);
152 return;
153 }
154 /*
155 Or redraw only the area in the front buffer
156 */
157 TsmGetWSAttri (aview->WsId, WSWindow, &data);
158 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
159 {
160 GLint buffer;
161 glGetIntegerv (GL_DRAW_BUFFER, &buffer);
162 if (buffer != GL_FRONT) glDrawBuffer (GL_FRONT);
163 glEnable (GL_SCISSOR_TEST);
164 glScissor ((GLint )x,
165 (GLint )((int )aview->DefWindow.dy - (y + height)),
166 (GLsizei )width, (GLsizei )height);
d4c2114a 167 OpenGl_ResourceCleaner::GetInstance()->Cleanup();
7fd59977 168 call_func_redraw_all_structs_begin (aview->WsId);
d4c2114a 169 call_togl_setplane( aview );
7fd59977 170 if (anunderlayer->ptrLayer)
171 {
172 call_togl_redraw_layer2d (aview, anunderlayer);
173 }
174 call_func_redraw_all_structs_proc (aview->WsId);
175 if (anoverlayer->ptrLayer)
176 {
177 call_togl_redraw_layer2d (aview, anoverlayer);
178 }
179 call_subr_displayCB(aview,OCC_REDRAW_WINDOWAREA);
180 call_func_redraw_all_structs_end (aview->WsId, 0);
181 call_togl_redraw_immediat_mode (aview);
182 glFlush();
183 glDisable (GL_SCISSOR_TEST);
184 if (buffer != GL_FRONT) glDrawBuffer (buffer);
185 }
186}