OCC22199 OpenGL memory leaks in TKOpenGl
[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>
161c4476 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 }
161c4476 90 OpenGl_ResourceCleaner::GetInstance()->Cleanup();
7fd59977 91 call_func_redraw_all_structs_begin (aview->WsId);
92 if (anunderlayer->ptrLayer)
93 {
94 call_togl_redraw_layer2d (aview, anunderlayer);
95 }
96 call_func_redraw_all_structs_proc (aview->WsId);
97 if (anoverlayer->ptrLayer)
98 {
99 call_togl_redraw_layer2d (aview, anoverlayer);
100 }
101 call_subr_displayCB (aview, OCC_REDRAW_WINDOW);
102 call_func_redraw_all_structs_end (aview->WsId, swap);
103 call_togl_redraw_immediat_mode (aview);
104
105 if (aFrameBuffer != NULL)
106 {
107 aFrameBuffer->UnbindBuffer();
108 // move back original viewport
109 glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]);
110 }
111 }
112
113#ifdef WNT
114 if (OpenGl_AVIWriter_AllowWriting (aview->DefWindow.XWindow))
115 {
116 GLint params[4];
117 glGetIntegerv (GL_VIEWPORT, params);
118 int nWidth = params[2] & ~0x7;
119 int nHeight = params[3] & ~0x7;
120
121 const int nBitsPerPixel = 24;
122 GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
123
124 glPixelStorei (GL_PACK_ALIGNMENT, 1);
125 glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
126 OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
127 delete[] aDumpData;
128 }
129#endif
130
131 return;
132}
133
134void EXPORT
135call_togl_redraw_area
136(
137 CALL_DEF_VIEW * aview,
138 CALL_DEF_LAYER * anunderlayer,
139 CALL_DEF_LAYER * anoverlayer,
140 int x, int y, int width, int height
141 )
142{
143 CMN_KEY_DATA data;
144
145 /*
146 When the exposure area size is > window size / 2 do a full redraw.
147 */
148 if( width*height >
149 (int)(aview->DefWindow.dx*aview->DefWindow.dy)/2 ) {
150 call_togl_redraw(aview,anunderlayer,anoverlayer);
151 return;
152 }
153 /*
154 Or redraw only the area in the front buffer
155 */
156 TsmGetWSAttri (aview->WsId, WSWindow, &data);
157 if (TxglWinset (call_thedisplay, (WINDOW) data.ldata) == TSuccess)
158 {
159 GLint buffer;
160 glGetIntegerv (GL_DRAW_BUFFER, &buffer);
161 if (buffer != GL_FRONT) glDrawBuffer (GL_FRONT);
162 glEnable (GL_SCISSOR_TEST);
163 glScissor ((GLint )x,
164 (GLint )((int )aview->DefWindow.dy - (y + height)),
165 (GLsizei )width, (GLsizei )height);
161c4476 166 OpenGl_ResourceCleaner::GetInstance()->Cleanup();
7fd59977 167 call_func_redraw_all_structs_begin (aview->WsId);
168 if (anunderlayer->ptrLayer)
169 {
170 call_togl_redraw_layer2d (aview, anunderlayer);
171 }
172 call_func_redraw_all_structs_proc (aview->WsId);
173 if (anoverlayer->ptrLayer)
174 {
175 call_togl_redraw_layer2d (aview, anoverlayer);
176 }
177 call_subr_displayCB(aview,OCC_REDRAW_WINDOWAREA);
178 call_func_redraw_all_structs_end (aview->WsId, 0);
179 call_togl_redraw_immediat_mode (aview);
180 glFlush();
181 glDisable (GL_SCISSOR_TEST);
182 if (buffer != GL_FRONT) glDrawBuffer (buffer);
183 }
184}