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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
// File OpenGl_GraphicDriver_7.cxx
// Created Mardi 28 janvier 1997
// Author CAL
// Modified GG 10/11/99 PRO19603 Change the Redraw method (add redraw area capabillity)
// EUG 07/10/99 G003 Add DegenerateStructure() and
// SetBackFacingModel() methods.
//-Copyright MatraDatavision 1997
//-Version
//-Design Declaration des variables specifiques aux Drivers
//-Warning Un driver encapsule les Pex et OpenGl drivers
//-References
//-Language C++ 2.0
//-Declarations
// for the class
#include <OpenGl_GraphicDriver.jxx>
#include <Aspect_DriverDefinitionError.hxx>
#include <InterfaceGraphic_RawBufferData.hxx>
#include <OpenGl_tgl_funcs.hxx>
#include <OpenGl_tsm_ws.hxx>
#include <OpenGl_tgl_tox.hxx>
#include <OpenGl_txgl.hxx>
#include <OpenGl_FrameBuffer.hxx>
//-Aliases
//-Global data definitions
//-Methods, in order
void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_activateview");
PrintCView (MyCView, 1);
}
call_togl_activateview (&MyCView);
}
void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_antialiasing");
PrintCView (MyCView, 1);
PrintBoolean ("AFlag", AFlag);
}
call_togl_antialiasing (&MyCView, (AFlag ? 1 : 0));
}
void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_background");
PrintCView (MyCView, 1);
}
call_togl_background (&MyCView);
}
void OpenGl_GraphicDriver::GradientBackground(const Graphic3d_CView& ACView,
const Quantity_Color& AColor1,
const Quantity_Color& AColor2,
const Aspect_GradientFillMethod AType){
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_gradient_background");
PrintCView (MyCView, 1);
}
Standard_Real R1,G1,B1,R2,G2,B2;
AColor1.Values( R1, G1, B1, Quantity_TOC_RGB );
AColor2.Values( R2, G2, B2, Quantity_TOC_RGB );
TEL_COLOUR tcolor1, tcolor2;
tcolor1.rgb[0] = (float)R1;
tcolor1.rgb[1] = (float)G1;
tcolor1.rgb[2] = (float)B1;
tcolor1.rgb[3] = 0;
tcolor2.rgb[0] = (float)R2;
tcolor2.rgb[1] = (float)G2;
tcolor2.rgb[2] = (float)B2;
tcolor2.rgb[3] = 0;
call_togl_gradient_background (MyCView.WsId, AType, &tcolor1, &tcolor2);
}
void OpenGl_GraphicDriver::Blink (const Graphic3d_CStructure& ACStructure, const Standard_Boolean Create) {
Graphic3d_CStructure MyCStructure = ACStructure;
if (MyTraceLevel) {
PrintFunction ("call_togl_blink");
PrintCStructure (MyCStructure, 1);
PrintBoolean ("Create", Create);
}
call_togl_blink (&MyCStructure, (Create ? 1 : 0));
}
void OpenGl_GraphicDriver::BoundaryBox (const Graphic3d_CStructure& ACStructure, const Standard_Boolean Create) {
Graphic3d_CStructure MyCStructure = ACStructure;
if (MyTraceLevel) {
PrintFunction ("call_togl_boundarybox");
PrintCStructure (MyCStructure, 1);
PrintBoolean ("Create", Create);
}
call_togl_boundarybox (&MyCStructure, (Create ? 1 : 0));
}
void OpenGl_GraphicDriver::HighlightColor (const Graphic3d_CStructure& ACStructure, const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B, const Standard_Boolean Create) {
Graphic3d_CStructure MyCStructure = ACStructure;
if (MyTraceLevel) {
PrintFunction ("call_togl_highlightcolor");
PrintCStructure (MyCStructure, 1);
PrintShortReal ("R", R);
PrintShortReal ("G", G);
PrintShortReal ("B", B);
}
CALL_DEF_COLOR acolor;
acolor.r = R;
acolor.g = G;
acolor.b = B;
call_togl_highlightcolor (&MyCStructure, &acolor, (Create ? 1 : 0));
}
void OpenGl_GraphicDriver::NameSetStructure (const Graphic3d_CStructure& ACStructure) {
Graphic3d_CStructure MyCStructure = ACStructure;
if (MyTraceLevel) {
PrintFunction ("call_togl_namesetstructure");
PrintCStructure (MyCStructure, 1);
}
call_togl_namesetstructure (&MyCStructure);
}
void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_cliplimit");
PrintCView (MyCView, 1);
PrintBoolean ("AWait", AWait);
}
call_togl_cliplimit (&MyCView, (AWait ? 1 : 0));
}
void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_deactivateview");
PrintCView (MyCView, 1);
}
call_togl_deactivateview (&MyCView);
}
void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_depthcueing");
PrintCView (MyCView, 1);
PrintBoolean ("AFlag", AFlag);
}
call_togl_depthcueing (&MyCView, (AFlag ? 1 : 0));
}
Standard_Boolean OpenGl_GraphicDriver::ProjectRaster (const Graphic3d_CView& ACView, const Standard_ShortReal AX, const Standard_ShortReal AY, const Standard_ShortReal AZ, Standard_Integer& AU, Standard_Integer& AV) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_project_raster");
PrintCView (MyCView, 1);
}
//if we want project something before to dump it into pixmap
if ( ACView.DefBitmap.bitmap ) {
Result = call_togl_adopt_to_rect( ACView.ViewId,
ACView.DefBitmap.width,
ACView.DefBitmap.height );
if (MyTraceLevel) {
PrintIResult ("call_togl_adopt_to_rect", Result);
}
if (Result)
return Standard_False;
}
Result = call_togl_project_raster (ACView.ViewId, AX, AY, AZ, &AU, &AV);
if (MyTraceLevel) {
PrintIResult ("call_togl_project_raster", Result);
}
if ( ACView.DefBitmap.bitmap ) {
Result = call_togl_adopt_to_rect( ACView.ViewId,
(int)ACView.DefWindow.dx,
(int)ACView.DefWindow.dy );
if (MyTraceLevel) {
PrintIResult ("call_togl_adopt_to_rect", Result);
}
if (Result)
return Standard_False;
}
return (Result == 0 ? Standard_True : Standard_False);
}
Standard_Boolean OpenGl_GraphicDriver::UnProjectRaster (const Graphic3d_CView& ACView, const Standard_Integer Axm, const Standard_Integer Aym, const Standard_Integer AXM, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_unproject_raster");
PrintCView (MyCView, 1);
}
Result = call_togl_unproject_raster
(ACView.ViewId, Axm, Aym, AXM, AYM, AU, AV, &Ax, &Ay, &Az);
if (MyTraceLevel) {
PrintIResult ("call_togl_unproject_raster", Result);
}
return (Result == 0 ? Standard_True : Standard_False);
}
Standard_Boolean OpenGl_GraphicDriver::UnProjectRasterWithRay (const Graphic3d_CView& ACView, const Standard_Integer Axm, const Standard_Integer Aym, const Standard_Integer AXM, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az, Standard_ShortReal& Dx, Standard_ShortReal& Dy, Standard_ShortReal& Dz) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_unproject_raster_with_ray");
PrintCView (MyCView, 1);
}
Result = call_togl_unproject_raster_with_ray
(ACView.ViewId, Axm, Aym, AXM, AYM, AU, AV, &Ax, &Ay, &Az, &Dx, &Dy, &Dz);
if (MyTraceLevel) {
PrintIResult ("call_togl_unproject_raster_with_ray", Result);
}
return (Result == 0 ? Standard_True : Standard_False);
}
void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_ratio_window");
PrintCView (MyCView, 1);
}
call_togl_ratio_window (&MyCView);
}
void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
Graphic3d_CView MyCView = ACView;
Aspect_CLayer2d MyCUnderLayer = ACUnderLayer;
Aspect_CLayer2d MyCOverLayer = ACOverLayer;
if (MyTraceLevel) {
PrintFunction ("call_togl_redraw");
PrintCView (MyCView, 1);
}
//PRO19603
if( width <= 0 || height <= 0 )
call_togl_redraw (&MyCView, &MyCUnderLayer, &MyCOverLayer);
else {
call_togl_redraw_area (&MyCView, &MyCUnderLayer, &MyCOverLayer,
x, y, width, height);
}
//PRO19603
}
Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& theCView,
const Standard_Integer theWidth,
const Standard_Integer theHeight) {
// activate OpenGL context
CMN_KEY_DATA aData;
if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
(TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
{
return NULL;
}
// create the FBO
OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
if (!aFrameBuffer->Init (theWidth, theHeight))
{
delete aFrameBuffer;
return NULL;
}
return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
}
void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& theCView,
Graphic3d_PtrFrameBuffer& theFBOPtr)
{
if (theFBOPtr == NULL)
{
return;
}
// activate OpenGL context
CMN_KEY_DATA aData;
if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
(TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
{
return;
}
// release the object
OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
delete aFrameBuffer;
theFBOPtr = NULL;
}
void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& ,
const Graphic3d_PtrFrameBuffer theFBOPtr,
Standard_Integer& theWidth, Standard_Integer& theHeight,
Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
{
if (theFBOPtr == NULL)
{
return;
}
const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr;
theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
theHeight = aFrameBuffer->GetVPSizeY();
theWidthMax = aFrameBuffer->GetSizeX(); // texture size
theHeightMax = aFrameBuffer->GetSizeY();
}
void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& ,
Graphic3d_PtrFrameBuffer& theFBOPtr,
const Standard_Integer theWidth, const Standard_Integer theHeight)
{
if (theFBOPtr == NULL)
{
return;
}
OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
aFrameBuffer->ChangeViewport (theWidth, theHeight);
}
// OpenGL 1.2 stuff
#ifndef GL_BGR
#define GL_BGR 0x80E0
#endif
#ifndef GL_BGRA
#define GL_BGRA 0x80E1
#endif
static inline GLenum TFormatToGLEnum (const TRawBufferDataFormat theTFormat)
{
switch (theTFormat)
{
case TRGB: return GL_RGB;
case TBGR: return GL_BGR;
case TRGBA: return GL_RGBA;
case TBGRA: return GL_BGRA;
case TDepthComponent: return GL_DEPTH_COMPONENT;
case TRed: return GL_RED;
case TGreen: return GL_GREEN;
case TBlue: return GL_BLUE;
case TAlpha: return GL_ALPHA;
default: return 0;
}
}
static inline GLenum TTypeToGLEnum (const TRawBufferDataType theTType)
{
switch (theTType)
{
case TUByte: return GL_UNSIGNED_BYTE;
case TFloat: return GL_FLOAT;
default: return 0;
}
}
Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView,
Image_CRawBufferData& theBuffer)
{
GLenum aFormat = TFormatToGLEnum (theBuffer.format);
GLenum aType = TTypeToGLEnum (theBuffer.type);
// safe checks
if (aFormat == 0 || aType == 0 ||
theBuffer.widthPx == 0 || theBuffer.heightPx == 0 ||
theBuffer.dataPtr == NULL)
{
return Standard_False;
}
// activate OpenGL context
CMN_KEY_DATA aData;
if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
(TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
{
return Standard_False;
}
// bind FBO if used
OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
GLint aReadBufferPrev = GL_BACK;
if (aFrameBuffer != NULL && aFrameBuffer->IsValid())
{
aFrameBuffer->BindBuffer();
}
else
{
glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
GLint aDrawBufferPrev = GL_BACK;
glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
glReadBuffer (aDrawBufferPrev);
}
GLint anAlignBack = 1;
glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack);
if (theBuffer.rowAligmentBytes == 0)
{
theBuffer.rowAligmentBytes = 1;
}
glPixelStorei (GL_PACK_ALIGNMENT, theBuffer.rowAligmentBytes);
// read pixels
glReadPixels (0, 0, theBuffer.widthPx, theBuffer.heightPx, aFormat, aType, (GLvoid* )theBuffer.dataPtr);
glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
if (aFrameBuffer != NULL && aFrameBuffer->IsValid())
{
aFrameBuffer->UnbindBuffer();
}
else
{
glReadBuffer (aReadBufferPrev);
}
return Standard_True;
}
void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_removeview");
PrintCView (MyCView, 1);
}
call_togl_removeview (&MyCView);
}
void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_setlight");
PrintCView (MyCView, 1);
}
call_togl_setlight (&MyCView);
}
void OpenGl_GraphicDriver::SetPlane (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_setplane");
PrintCView (MyCView, 1);
}
call_togl_setplane (&MyCView);
}
void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_setvisualisation");
PrintCView (MyCView, 1);
}
call_togl_setvisualisation (&MyCView);
}
void OpenGl_GraphicDriver::TransformStructure (const Graphic3d_CStructure& ACStructure) {
Graphic3d_CStructure MyCStructure = ACStructure;
if (MyTraceLevel) {
PrintFunction ("call_togl_transformstructure");
PrintCStructure (MyCStructure, 1);
}
call_togl_transformstructure (&MyCStructure);
}
void OpenGl_GraphicDriver :: DegenerateStructure (
const Graphic3d_CStructure& ACStructure
) {
Graphic3d_CStructure MyCStructure = ACStructure;
if ( MyTraceLevel ) {
PrintFunction ( "call_togl_degeneratestructure" );
PrintCStructure ( MyCStructure, 1 );
} // end if
call_togl_degeneratestructure ( &MyCStructure );
} // end OpenGl_GraphicDriver :: DegenerateStructure
void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
Graphic3d_CView MyCView = ACView;
if (MyTraceLevel) {
PrintFunction ("call_togl_transparency");
PrintCView (MyCView, 1);
PrintBoolean ("AFlag", AFlag);
}
call_togl_transparency (MyCView.WsId, MyCView.ViewId, (AFlag ? 1 : 0));
}
void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer) {
Graphic3d_CView MyCView = ACView;
Aspect_CLayer2d MyCUnderLayer = ACUnderLayer;
Aspect_CLayer2d MyCOverLayer = ACOverLayer;
if (MyTraceLevel) {
PrintFunction ("call_togl_update");
PrintCView (MyCView, 1);
}
call_togl_update (&MyCView, &MyCUnderLayer, &MyCOverLayer);
}
Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& ACView) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_view");
PrintCView (MyCView, 1);
}
Result = call_togl_view (&MyCView);
if (MyTraceLevel) {
PrintIResult ("call_togl_view", Result);
}
return (Result == 1 ? Standard_True : Standard_False);
}
void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_viewmapping");
PrintCView (MyCView, 1);
PrintBoolean ("AWait", AWait);
}
Result = call_togl_viewmapping (&MyCView, (AWait ? 1 : 0));
if (MyTraceLevel) {
PrintIResult ("call_togl_viewmapping", Result);
}
}
void OpenGl_GraphicDriver::ViewOrientation (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
Graphic3d_CView MyCView = ACView;
Standard_Integer Result;
if (MyTraceLevel) {
PrintFunction ("call_togl_vieworientation");
PrintCView (MyCView, 1);
PrintBoolean ("AWait", AWait);
}
Result = call_togl_vieworientation (&MyCView, (AWait ? 1 : 0));
if (MyTraceLevel) {
PrintIResult ("call_togl_viewmapping", Result);
}
}
void OpenGl_GraphicDriver :: SetBackFacingModel ( const Graphic3d_CView& aView )
{
Graphic3d_CView myView = aView;
if ( MyTraceLevel ) {
PrintFunction ( "call_togl_backfacing" );
PrintCView ( myView, 1 );
} // end if
call_togl_backfacing ( &myView );
} // end Graphic3d_GraphicDriver :: SetBackFacingModel
|