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