summaryrefslogtreecommitdiff
path: root/src/OpenGl/OpenGl_ws.cxx
blob: 118305a6be34002da0e1387f56fd5e4f818ac9a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/***********************************************************************

FONCTION :
----------
File OpenGl_ws :


REMARQUES:
----------       

HISTORIQUE DES MODIFICATIONS   :
--------------------------------
xx-xx-xx : xxx ; Creation.
02-07-96 : FMN ; Suppression WSWSHeight, WSWSWidth et WSType
17-07-96 : FMN ; Ajout WSZbuffer
24-04-97 : FMN ; (PRO4063) Ajout displaylist pour le mode transient
27-07-97 : CAL ; Portage NT (GLuint)
28-08-97 : PCT ; ajout texture mapping
13-03-98 : FMN ; Suppression variable WSNeedsClear
08-07-98 : FMN ; Changement du nom de la primitive call_togl_erase_immediat_mode()
-> call_togl_erase_animation_mode.

************************************************************************/

#define G003  /* EUG 11-01-00 backfacing management 
*/

#define OCC1188 /* SAV 23/12/02 background texture management */

/*----------------------------------------------------------------------*/
/*
* Includes
*/ 

#include <OpenGl_tgl_all.hxx>

#include <OpenGl_tsm.hxx>

#include <OpenGl_tsm_ws.hxx>
#include <OpenGl_animation.hxx>
#include <OpenGl_Memory.hxx>

/*----------------------------------------------------------------------*/
/*
* Constantes
*/ 

#define  WS_HTBL_SIZE  23
#define  BUC61044    /* 25/10/01 SAV ; added functionality to control gl depth testing
from higher API */
#define  BUC61045    /* 25/10/01 SAV ; added functionality to control gl lighting 
from higher API */

/*----------------------------------------------------------------------*/
/*
* Types definitions
*/ 

#ifdef OCC1188
/* background texture properties */
struct WS_BG_TEXTURE
{
  Tuint texId;
  Tint width;
  Tint height;
  Tint style; /* 0 - centered, 1 - tiled, 2 - stretch */
  IMPLEMENT_MEMORY_OPERATORS
};
typedef WS_BG_TEXTURE *ws_bg_texture;
#endif

typedef TSM_BG_GRADIENT WS_BG_GRADIENT;
typedef WS_BG_GRADIENT *ws_bg_gradient;

struct WS_REC
{
  Tint    texture_env;
  Tint    surface_detail;
  void    *filters;
  Tint     window;
  Tint     width;
  Tint     height;
  Tint     d_buff;
  Tint     view_stid;
  void    *lights;
  void    *views;
  Tfloat   backg[3];
  void    *highlights;
  void    *depthcues;
  Tint     update_state;
  Tint     transparency;
  Tint     zbuffer;
  Tint     transient;
  Tint     retainMode;
#ifndef WNT
  Pixmap   pixmap_id;
  GLXPixmap
    glx_pixmap;
  Tint     wsdepth;
#else

#endif
#ifdef G003
  Tint     backfacing;
#endif  /* G003 */

#ifdef BUC61044
  Tint     depth_test;
#endif
#ifdef BUC61045
  Tint     ws_gllight;
#endif
#ifdef OCC1188    
  WS_BG_TEXTURE bgTexture;
#endif /* OCC1188 */
  WS_BG_GRADIENT bgGradient;
  IMPLEMENT_MEMORY_OPERATORS
};
typedef WS_REC *ws_rec;

/*----------------------------------------------------------------------*/
/*
* Variables statiques
*/ 

typedef NCollection_DataMap< Standard_Integer, ws_rec>  WS_Map;
typedef WS_Map::Iterator                                WS_Map_Iterator;
Handle(NCollection_BaseAllocator)  ws_Allocator = NCollection_BaseAllocator::CommonBaseAllocator();
WS_Map  ws_map ( 1 , ws_Allocator );

/*----------------------------------------------------------------------*/

TStatus
TsmRegisterWsid( Tint wsid )
{
  if( ws_Allocator.IsNull() )
    return TFailure;

  ws_rec rec = new WS_REC();
  ws_map.Bind( wsid, rec );

  return TSuccess;
}

/*----------------------------------------------------------------------*/

TStatus
TsmSetWSAttri( Tint wsid, TWSAttri  attri, cmn_key_data data )
{    

  if( ws_Allocator.IsNull() )
    return TFailure;

  if ( !ws_map.IsBound( wsid ) ) {
    ws_map.Bind( wsid, new WS_REC() );
  }
  ws_rec wsr = ws_map.ChangeFind( wsid );

  switch( attri )
  {
  case WSTextureEnv:
    wsr->texture_env = data->ldata;
    break;

  case WSSurfaceDetail:
    wsr->surface_detail = data->ldata;
    break;

  case  WSFilters:
    wsr->filters = data->pdata;
    break;

  case  WSWindow:
    wsr->window = data->ldata;
    break;

  case  WSWidth:
    wsr->width = data->ldata;
    break;

  case  WSHeight:
    wsr->height = data->ldata;
    break;

  case  WSDbuff:
    wsr->d_buff = data->ldata;
    break;

  case  WSViewStid:
    wsr->view_stid = data->ldata;
    break;

  case  WSLights:
    wsr->lights = data->pdata;
    break;

  case  WSViews:
    wsr->views = data->pdata;
    break;

  case  WSBackground:
    wsr->backg[0] = ((Tfloat*)data->pdata)[0],
      wsr->backg[1] = ((Tfloat*)data->pdata)[1],
      wsr->backg[2] = ((Tfloat*)data->pdata)[2];
    break;

  case  WSHighlights:
    wsr->highlights = data->pdata;
    break;

  case  WSDepthCues:
    wsr->depthcues = data->pdata;
    break;

  case  WSTransparency:
    wsr->transparency = data->ldata;
    break;

  case  WSZbuffer:
    wsr->zbuffer = data->ldata;
    break;

  case  WSTransient:
    wsr->transient = data->ldata;
    break;

  case  WSRetainMode:
    wsr->retainMode = data->ldata;
    break;

  case  WSUpdateState:
    wsr->update_state = data->ldata;
    break;

#ifndef WNT
  case  WSPixmap:
    wsr->pixmap_id = data->pixmap;
    break;

  case  WSGLXPixmap:
    wsr->glx_pixmap = data->glxpixmap;
    break;

  case  WSDepth:
    wsr->wsdepth = data->ldata;
    break;
#endif
#ifdef G003
  case WSBackfacing:
    wsr -> backfacing = data -> ldata;
    break;
#endif  /* G003 */

#ifdef BUC61044
  case WSDepthTest:
    wsr->depth_test = data->ldata;
    break;
#endif
#ifdef BUC61045
  case WSGLLight:
    wsr->ws_gllight = data->ldata;
    break;
#endif
#ifdef OCC1188
  case WSBgTexture : 
    wsr->bgTexture.texId  = ((Tuint*)data->pdata)[0],
    wsr->bgTexture.width  = ((Tint*)data->pdata)[1],
    wsr->bgTexture.height = ((Tint*)data->pdata)[2];
    wsr->bgTexture.style  = ((Tint*)data->pdata)[3];
    break;
#endif
  case WSBgGradient :
    wsr->bgGradient = *((WS_BG_GRADIENT*)(data->pdata));

  default:
    break;
  }

  return TSuccess;
}

/*----------------------------------------------------------------------*/

TStatus
TsmGetWSAttri( Tint wsid, TWSAttri attri, cmn_key_data data )
{
  if( ws_Allocator.IsNull() )
    return TFailure;

  if ( !ws_map.IsBound( wsid ) ) {
    ws_rec rec = new WS_REC();
    ws_map.Bind( wsid, rec );
  }
  ws_rec wsr = ws_map.Find( wsid );

  switch( attri )
  {
  case WSTextureEnv:
    data->ldata = wsr->texture_env;
    break;

  case WSSurfaceDetail:
    data->ldata = wsr->surface_detail;
    break;

  case  WSFilters:
    data->pdata = wsr->filters;
    break;

  case  WSWindow:
    data->ldata = wsr->window;
    break;

  case  WSWidth:
    data->ldata = wsr->width;
    break;

  case  WSHeight:
    data->ldata = wsr->height;
    break;

  case  WSDbuff:
    data->ldata = wsr->d_buff;
    break;

  case  WSViewStid:
    data->ldata = wsr->view_stid;
    break;

  case  WSLights:
    data->pdata = wsr->lights;
    break;

  case  WSViews:
    data->pdata = wsr->views;
    break;

  case  WSBackground:
    data->pdata = wsr->backg;
    break;

  case  WSHighlights:
    data->pdata = wsr->highlights;
    break;

  case  WSDepthCues:
    data->pdata = wsr->depthcues;
    break;

  case  WSTransparency:
    data->ldata = wsr->transparency;
    break;

  case  WSZbuffer:
    data->ldata = wsr->zbuffer;
    break;

  case  WSTransient:
    data->ldata = wsr->transient;
    break;

  case  WSRetainMode:
    data->ldata = wsr->retainMode;
    break;

  case  WSUpdateState:
    data->ldata = wsr->update_state;
    break;

#ifndef WNT
  case  WSPixmap:
    data->pixmap = wsr->pixmap_id;
    break;

  case  WSGLXPixmap:
    data->glxpixmap = wsr->glx_pixmap;
    break;

  case  WSDepth:
    data->ldata = wsr->wsdepth;
    break;
#endif
#ifdef G003
  case WSBackfacing:
    data -> ldata = wsr -> backfacing;
    break;
#endif  /* G003 */

#ifdef BUC61044
  case WSDepthTest:
    data->ldata = wsr->depth_test;
    break;
#endif
#ifdef BUC61045
  case WSGLLight:
    data->ldata = wsr->ws_gllight;
    break;
#endif
#ifdef OCC1188
  case WSBgTexture : 
    data->pdata = &wsr->bgTexture;
    break;
#endif 
  case WSBgGradient : 
    data->pdata = &wsr->bgGradient;
    break; 

  default:
    break;
  }

  return TSuccess;
}

/*----------------------------------------------------------------------*/

TStatus
TsmGetWSPosted( Tint struct_id, Tint size, Tint *ws, Tint *actual_size )
{
  if( ws_Allocator.IsNull() )
    return TFailure;
  Tint i=0;
  WS_Map_Iterator it(ws_map);
  for ( ; it.More(); it.Next()) {
    if( it.Value()->view_stid == struct_id ) {
      (*actual_size)++;
      if( size > i )
        ws[i++] = it.Key();
    }
  }

  return TSuccess;
}

/*----------------------------------------------------------------------*/

TStatus
TsmUnregisterWsid( Tint wsid )
{
  if( ws_Allocator.IsNull() )
    return TFailure;
  if ( !ws_map.IsBound( wsid ) ) {
    return TFailure;
  }
  ws_rec wsr = ws_map.ChangeFind( wsid );
  ws_map.UnBind( wsid );
  delete wsr;

  return TSuccess;
}

/*----------------------------------------------------------------------*/

TStatus
TsmInitUpdateState()
{
  if( ws_Allocator.IsNull() )
    return TFailure; 
  WS_Map_Iterator it(ws_map);
  for ( ; it.More(); it.Next()) {
    it.ChangeValue()->update_state = TNotDone;
    (void) call_togl_erase_animation_mode();
  }
  return TSuccess;
}

/*----------------------------------------------------------------------*/