0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / OpenGl / OpenGl_ws.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3FONCTION :
4----------
5File OpenGl_ws :
6
7
8REMARQUES:
9----------
10
11HISTORIQUE DES MODIFICATIONS :
12--------------------------------
13xx-xx-xx : xxx ; Creation.
1402-07-96 : FMN ; Suppression WSWSHeight, WSWSWidth et WSType
1517-07-96 : FMN ; Ajout WSZbuffer
1624-04-97 : FMN ; (PRO4063) Ajout displaylist pour le mode transient
1727-07-97 : CAL ; Portage NT (GLuint)
1828-08-97 : PCT ; ajout texture mapping
1913-03-98 : FMN ; Suppression variable WSNeedsClear
2008-07-98 : FMN ; Changement du nom de la primitive call_togl_erase_immediat_mode()
21-> call_togl_erase_animation_mode.
22
23************************************************************************/
24
25#define G003 /* EUG 11-01-00 backfacing management
26*/
27
28#define OCC1188 /* SAV 23/12/02 background texture management */
29
30/*----------------------------------------------------------------------*/
31/*
32* Includes
33*/
34
35#include <OpenGl_tgl_all.hxx>
36
37#include <OpenGl_tsm.hxx>
38
39#include <OpenGl_tsm_ws.hxx>
40#include <OpenGl_animation.hxx>
41#include <OpenGl_Memory.hxx>
42
43/*----------------------------------------------------------------------*/
44/*
45* Constantes
46*/
47
48#define WS_HTBL_SIZE 23
49#define BUC61044 /* 25/10/01 SAV ; added functionality to control gl depth testing
50from higher API */
51#define BUC61045 /* 25/10/01 SAV ; added functionality to control gl lighting
52from higher API */
53
54/*----------------------------------------------------------------------*/
55/*
56* Types definitions
57*/
58
59#ifdef OCC1188
60/* background texture properties */
61struct WS_BG_TEXTURE
62{
63 Tuint texId;
64 Tint width;
65 Tint height;
66 Tint style; /* 0 - centered, 1 - tiled, 2 - stretch */
67 IMPLEMENT_MEMORY_OPERATORS
68};
69typedef WS_BG_TEXTURE *ws_bg_texture;
70#endif
71
72typedef TSM_BG_GRADIENT WS_BG_GRADIENT;
73typedef WS_BG_GRADIENT *ws_bg_gradient;
74
75struct WS_REC
76{
77 Tint texture_env;
78 Tint surface_detail;
79 void *filters;
80 Tint window;
81 Tint width;
82 Tint height;
83 Tint d_buff;
84 Tint view_stid;
85 void *lights;
86 void *views;
87 Tfloat backg[3];
88 void *highlights;
89 void *depthcues;
90 Tint update_state;
91 Tint transparency;
92 Tint zbuffer;
93 Tint transient;
94 Tint retainMode;
95#ifndef WNT
96 Pixmap pixmap_id;
97 GLXPixmap
98 glx_pixmap;
99 Tint wsdepth;
100#else
101
102#endif
103#ifdef G003
104 Tint backfacing;
105#endif /* G003 */
106
107#ifdef BUC61044
108 Tint depth_test;
109#endif
110#ifdef BUC61045
111 Tint ws_gllight;
112#endif
113#ifdef OCC1188
114 WS_BG_TEXTURE bgTexture;
115#endif /* OCC1188 */
116 WS_BG_GRADIENT bgGradient;
117 IMPLEMENT_MEMORY_OPERATORS
118};
119typedef WS_REC *ws_rec;
120
121/*----------------------------------------------------------------------*/
122/*
123* Variables statiques
124*/
125
126typedef NCollection_DataMap< Standard_Integer, ws_rec> WS_Map;
127typedef WS_Map::Iterator WS_Map_Iterator;
128Handle(NCollection_BaseAllocator) ws_Allocator = NCollection_BaseAllocator::CommonBaseAllocator();
129WS_Map ws_map ( 1 , ws_Allocator );
130
131/*----------------------------------------------------------------------*/
132
133TStatus
134TsmRegisterWsid( Tint wsid )
135{
136 if( ws_Allocator.IsNull() )
137 return TFailure;
138
139 ws_rec rec = new WS_REC();
140 ws_map.Bind( wsid, rec );
141
142 return TSuccess;
143}
144
145/*----------------------------------------------------------------------*/
146
147TStatus
148TsmSetWSAttri( Tint wsid, TWSAttri attri, cmn_key_data data )
149{
150
151 if( ws_Allocator.IsNull() )
152 return TFailure;
153
154 if ( !ws_map.IsBound( wsid ) ) {
155 ws_rec rec = new WS_REC();
156 ws_map.Bind( wsid, new WS_REC() );
157 }
158 ws_rec wsr = ws_map.ChangeFind( wsid );
159
160 switch( attri )
161 {
162 case WSTextureEnv:
163 wsr->texture_env = data->ldata;
164 break;
165
166 case WSSurfaceDetail:
167 wsr->surface_detail = data->ldata;
168 break;
169
170 case WSFilters:
171 wsr->filters = data->pdata;
172 break;
173
174 case WSWindow:
175 wsr->window = data->ldata;
176 break;
177
178 case WSWidth:
179 wsr->width = data->ldata;
180 break;
181
182 case WSHeight:
183 wsr->height = data->ldata;
184 break;
185
186 case WSDbuff:
187 wsr->d_buff = data->ldata;
188 break;
189
190 case WSViewStid:
191 wsr->view_stid = data->ldata;
192 break;
193
194 case WSLights:
195 wsr->lights = data->pdata;
196 break;
197
198 case WSViews:
199 wsr->views = data->pdata;
200 break;
201
202 case WSBackground:
203 wsr->backg[0] = ((Tfloat*)data->pdata)[0],
204 wsr->backg[1] = ((Tfloat*)data->pdata)[1],
205 wsr->backg[2] = ((Tfloat*)data->pdata)[2];
206 break;
207
208 case WSHighlights:
209 wsr->highlights = data->pdata;
210 break;
211
212 case WSDepthCues:
213 wsr->depthcues = data->pdata;
214 break;
215
216 case WSTransparency:
217 wsr->transparency = data->ldata;
218 break;
219
220 case WSZbuffer:
221 wsr->zbuffer = data->ldata;
222 break;
223
224 case WSTransient:
225 wsr->transient = data->ldata;
226 break;
227
228 case WSRetainMode:
229 wsr->retainMode = data->ldata;
230 break;
231
232 case WSUpdateState:
233 wsr->update_state = data->ldata;
234 break;
235
236#ifndef WNT
237 case WSPixmap:
238 wsr->pixmap_id = data->pixmap;
239 break;
240
241 case WSGLXPixmap:
242 wsr->glx_pixmap = data->glxpixmap;
243 break;
244
245 case WSDepth:
246 wsr->wsdepth = data->ldata;
247 break;
248#endif
249#ifdef G003
250 case WSBackfacing:
251 wsr -> backfacing = data -> ldata;
252 break;
253#endif /* G003 */
254
255#ifdef BUC61044
256 case WSDepthTest:
257 wsr->depth_test = data->ldata;
258 break;
259#endif
260#ifdef BUC61045
261 case WSGLLight:
262 wsr->ws_gllight = data->ldata;
263 break;
264#endif
265#ifdef OCC1188
266 case WSBgTexture :
267 wsr->bgTexture.texId = ((Tuint*)data->pdata)[0],
268 wsr->bgTexture.width = ((Tint*)data->pdata)[1],
269 wsr->bgTexture.height = ((Tint*)data->pdata)[2];
270 wsr->bgTexture.style = ((Tint*)data->pdata)[3];
271 break;
272#endif
273 case WSBgGradient :
274 wsr->bgGradient = *((WS_BG_GRADIENT*)(data->pdata));
275
276 default:
277 break;
278 }
279
280 return TSuccess;
281}
282
283/*----------------------------------------------------------------------*/
284
285TStatus
286TsmGetWSAttri( Tint wsid, TWSAttri attri, cmn_key_data data )
287{
288 if( ws_Allocator.IsNull() )
289 return TFailure;
290
291 if ( !ws_map.IsBound( wsid ) ) {
292 ws_rec rec = new WS_REC();
293 ws_map.Bind( wsid, rec );
294 }
295 ws_rec wsr = ws_map.Find( wsid );
296
297 switch( attri )
298 {
299 case WSTextureEnv:
300 data->ldata = wsr->texture_env;
301 break;
302
303 case WSSurfaceDetail:
304 data->ldata = wsr->surface_detail;
305 break;
306
307 case WSFilters:
308 data->pdata = wsr->filters;
309 break;
310
311 case WSWindow:
312 data->ldata = wsr->window;
313 break;
314
315 case WSWidth:
316 data->ldata = wsr->width;
317 break;
318
319 case WSHeight:
320 data->ldata = wsr->height;
321 break;
322
323 case WSDbuff:
324 data->ldata = wsr->d_buff;
325 break;
326
327 case WSViewStid:
328 data->ldata = wsr->view_stid;
329 break;
330
331 case WSLights:
332 data->pdata = wsr->lights;
333 break;
334
335 case WSViews:
336 data->pdata = wsr->views;
337 break;
338
339 case WSBackground:
340 data->pdata = wsr->backg;
341 break;
342
343 case WSHighlights:
344 data->pdata = wsr->highlights;
345 break;
346
347 case WSDepthCues:
348 data->pdata = wsr->depthcues;
349 break;
350
351 case WSTransparency:
352 data->ldata = wsr->transparency;
353 break;
354
355 case WSZbuffer:
356 data->ldata = wsr->zbuffer;
357 break;
358
359 case WSTransient:
360 data->ldata = wsr->transient;
361 break;
362
363 case WSRetainMode:
364 data->ldata = wsr->retainMode;
365 break;
366
367 case WSUpdateState:
368 data->ldata = wsr->update_state;
369 break;
370
371#ifndef WNT
372 case WSPixmap:
373 data->pixmap = wsr->pixmap_id;
374 break;
375
376 case WSGLXPixmap:
377 data->glxpixmap = wsr->glx_pixmap;
378 break;
379
380 case WSDepth:
381 data->ldata = wsr->wsdepth;
382 break;
383#endif
384#ifdef G003
385 case WSBackfacing:
386 data -> ldata = wsr -> backfacing;
387 break;
388#endif /* G003 */
389
390#ifdef BUC61044
391 case WSDepthTest:
392 data->ldata = wsr->depth_test;
393 break;
394#endif
395#ifdef BUC61045
396 case WSGLLight:
397 data->ldata = wsr->ws_gllight;
398 break;
399#endif
400#ifdef OCC1188
401 case WSBgTexture :
402 data->pdata = &wsr->bgTexture;
403 break;
404#endif
405 case WSBgGradient :
406 data->pdata = &wsr->bgGradient;
407 break;
408
409 default:
410 break;
411 }
412
413 return TSuccess;
414}
415
416/*----------------------------------------------------------------------*/
417
418TStatus
419TsmGetWSPosted( Tint struct_id, Tint size, Tint *ws, Tint *actual_size )
420{
421 if( ws_Allocator.IsNull() )
422 return TFailure;
423 Tint i=0;
424 WS_Map_Iterator it(ws_map);
425 for ( ; it.More(); it.Next()) {
426 if( it.Value()->view_stid == struct_id ) {
427 (*actual_size)++;
428 if( size > i )
429 ws[i++] = it.Key();
430 }
431 }
432
433 return TSuccess;
434}
435
436/*----------------------------------------------------------------------*/
437
438TStatus
439TsmUnregisterWsid( Tint wsid )
440{
441 if( ws_Allocator.IsNull() )
442 return TFailure;
443 if ( !ws_map.IsBound( wsid ) ) {
444 return TFailure;
445 }
446 ws_rec wsr = ws_map.ChangeFind( wsid );
447 ws_map.UnBind( wsid );
448 delete wsr;
449
450 return TSuccess;
451}
452
453/*----------------------------------------------------------------------*/
454
455TStatus
456TsmInitUpdateState()
457{
458 if( ws_Allocator.IsNull() )
459 return TFailure;
460 WS_Map_Iterator it(ws_map);
461 for ( ; it.More(); it.Next()) {
462 it.ChangeValue()->update_state = TNotDone;
463 (void) call_togl_erase_animation_mode();
464 }
465 return TSuccess;
466}
467
468/*----------------------------------------------------------------------*/