File: Wm5WglExtensions.cpp

package info (click to toggle)
libwildmagic 5.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 89,572 kB
  • ctags: 26,264
  • sloc: cpp: 210,924; csh: 637; sh: 95; makefile: 36
file content (806 lines) | stat: -rw-r--r-- 31,744 bytes parent folder | download | duplicates (3)
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.0 (2010/01/01)

#include "Wm5WglExtensions.h"

#if defined(_MSC_VER)
// Disable the warning about "conditional expression is constant".  Without
// this, my macros will generate about 10 warnings.
#pragma warning( disable : 4127 )
#endif

//----------------------------------------------------------------------------
void* GTGetFunctionPointer (const char* acFunction)
{
    return (void*)wglGetProcAddress(acFunction);
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ***** ARB Extensions *****
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 04) WGL_ARB_buffer_region
//----------------------------------------------------------------------------
int GTExistsWglArbBufferRegion = 0;

typedef HANDLE (STDCALL* PswglCreateBufferRegionARB) (HDC, int, UINT);
typedef VOID (STDCALL* PswglDeleteBufferRegionARB) (HANDLE);
typedef BOOL (STDCALL* PswglSaveBufferRegionARB) (HANDLE, int, int, int, int);
typedef BOOL (STDCALL* PswglRestoreBufferRegionARB) (HANDLE, int, int, int,
    int, int, int);

static PswglCreateBufferRegionARB swglCreateBufferRegionARB = 0;
static PswglDeleteBufferRegionARB swglDeleteBufferRegionARB = 0;
static PswglSaveBufferRegionARB swglSaveBufferRegionARB = 0;
static PswglRestoreBufferRegionARB swglRestoreBufferRegionARB = 0;
//----------------------------------------------------------------------------
HANDLE GTwglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uiType)
{
    GT_BODY_A3_RET(swglCreateBufferRegionARB,hDC,iLayerPlane,uiType,
        HANDLE,0);
}
//----------------------------------------------------------------------------
VOID GTwglDeleteBufferRegionARB (HANDLE hRegion)
{
    GT_BODY_A1(swglDeleteBufferRegionARB,hRegion);
}
//----------------------------------------------------------------------------
BOOL GTwglSaveBufferRegionARB (HANDLE hRegion, int iX, int iY, int iWidth,
    int iHeight)
{
    GT_BODY_A5_RET(swglSaveBufferRegionARB,hRegion,iX,iY,iWidth,iHeight,
        BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglRestoreBufferRegionARB (HANDLE hRegion, int iX, int iY, int iWidth,
    int iHeight, int iXSrc, int iYSrc)
{
    GT_BODY_A7_RET(swglRestoreBufferRegionARB,hRegion,iX,iY,iWidth,iHeight,
        iXSrc,iYSrc,BOOL,FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglArbBufferRegion ()
{
    if (GTSupportsWglExtension("WGL_ARB_buffer_region")
    ||  GTSupportsExtension("WGL_ARB_buffer_region"))
    {
        GTExistsWglArbBufferRegion = 1;
        GT_GET_FUNCTION(swglCreateBufferRegionARB);
        GT_GET_FUNCTION(swglDeleteBufferRegionARB);
        GT_GET_FUNCTION(swglSaveBufferRegionARB);
        GT_GET_FUNCTION(swglRestoreBufferRegionARB);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 05) WGL_ARB_multisample
//----------------------------------------------------------------------------
int GTExistsWglArbMultisample = 0;
//----------------------------------------------------------------------------
void GTInitWglArbMultisample ()
{
    if (GTSupportsWglExtension("WGL_ARB_multisample")
    ||  GTSupportsExtension("WGL_ARB_multisample"))
    {
        GTExistsWglArbMultisample = 1;
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 08) WGL_ARB_extensions_string
//----------------------------------------------------------------------------
int GTExistsWglArbExtensionsString = 0;

typedef const char* (STDCALL* PswglGetExtensionsStringARB) (HDC);

static PswglGetExtensionsStringARB swglGetExtensionsStringARB = 0;
//----------------------------------------------------------------------------
const char* GTwglGetExtensionsStringARB (HDC hDC)
{
    GT_BODY_A1_RET(swglGetExtensionsStringARB,hDC,const char*,0);
}
//----------------------------------------------------------------------------
void GTInitWglArbExtensionsString ()
{
	GT_GET_FUNCTION(swglGetExtensionsStringARB);
	if (swglGetExtensionsStringARB)
    {
        GTExistsWglArbExtensionsString = 1;
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 09) WGL_ARB_pixel_format
//----------------------------------------------------------------------------
int GTExistsWglArbPixelFormat = 0;

typedef BOOL (STDCALL* PswglGetPixelFormatAttribivARB) (HDC, int, int, UINT,
    const int*, int*);
typedef BOOL (STDCALL* PswglGetPixelFormatAttribfvARB) (HDC, int, int, UINT,
    const int*, FLOAT*);
typedef BOOL (STDCALL* PswglChoosePixelFormatARB) (HDC, const int*,
    const FLOAT*, UINT, int*, UINT*);

static PswglGetPixelFormatAttribivARB swglGetPixelFormatAttribivARB = 0;
static PswglGetPixelFormatAttribfvARB swglGetPixelFormatAttribfvARB = 0;
static PswglChoosePixelFormatARB swglChoosePixelFormatARB = 0;
//----------------------------------------------------------------------------
BOOL GTwglGetPixelFormatAttribivARB (HDC hDC, int iPixelFormat,
    int iLayerPlane, UINT uiNumAttributes, const int* aiAttribute,
    int* aiValue)
{
    GT_BODY_A6_RET(swglGetPixelFormatAttribivARB,hDC,iPixelFormat,iLayerPlane,
        uiNumAttributes,aiAttribute,aiValue,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglGetPixelFormatAttribfvARB (HDC hDC, int iPixelFormat,
    int iLayerPlane, UINT uiNumAttributes, const int* aiAttribute,
    FLOAT* afValue)
{
    GT_BODY_A6_RET(swglGetPixelFormatAttribfvARB,hDC,iPixelFormat,iLayerPlane,
        uiNumAttributes,aiAttribute,afValue,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglChoosePixelFormatARB (HDC hDC, const int* aiAttribIList,
    const FLOAT* afAttribFList, UINT uiMaxFormats, int* aiFormat,
    UINT* puiNumFormats)
{
    GT_BODY_A6_RET(swglChoosePixelFormatARB,hDC,aiAttribIList,afAttribFList,
        uiMaxFormats,aiFormat,puiNumFormats,BOOL,FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglArbPixelFormat ()
{
    if (GTSupportsWglExtension("WGL_ARB_pixel_format")
    ||  GTSupportsExtension("WGL_ARB_pixel_format"))
    {
        GTExistsWglArbPixelFormat = 1;
        GT_GET_FUNCTION(swglGetPixelFormatAttribivARB);
        GT_GET_FUNCTION(swglGetPixelFormatAttribfvARB);
        GT_GET_FUNCTION(swglChoosePixelFormatARB);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 10) WGL_ARB_make_current_read
//----------------------------------------------------------------------------
int GTExistsWglArbMakeCurrentRead = 0;

typedef BOOL (STDCALL* PswglMakeContextCurrentARB) (HDC, HDC, HGLRC);
typedef HDC (STDCALL* PswglGetCurrentReadDCARB) ();

static PswglMakeContextCurrentARB swglMakeContextCurrentARB = 0;
static PswglGetCurrentReadDCARB swglGetCurrentReadDCARB = 0;
//----------------------------------------------------------------------------
BOOL GTwglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hWindowRC)
{
    GT_BODY_A3_RET(swglMakeContextCurrentARB,hDrawDC,hReadDC,hWindowRC,
        BOOL,FALSE);
}
//----------------------------------------------------------------------------
HDC GTwglGetCurrentReadDCARB ()
{
    GT_BODY_A0_RET(swglGetCurrentReadDCARB,HDC,0);
}
//----------------------------------------------------------------------------
void GTInitWglArbMakeCurrentRead ()
{
    if (GTSupportsWglExtension("WGL_ARB_make_current_read")
    ||  GTSupportsExtension("WGL_ARB_make_current_read"))
    {
        GTExistsWglArbMakeCurrentRead = 1;
        GT_GET_FUNCTION(swglMakeContextCurrentARB);
        GT_GET_FUNCTION(swglGetCurrentReadDCARB);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 11) WGL_ARB_pbuffer
//----------------------------------------------------------------------------
int GTExistsWglArbPBuffer = 0;

typedef HPBUFFERARB (STDCALL* PswglCreatePbufferARB) (HDC, int, int, int,
    const int*);
typedef HDC (STDCALL* PswglGetPbufferDCARB) (HPBUFFERARB);
typedef int (STDCALL* PswglReleasePbufferDCARB) (HPBUFFERARB, HDC);
typedef BOOL (STDCALL* PswglDestroyPbufferARB) (HPBUFFERARB);
typedef BOOL (STDCALL* PswglQueryPbufferARB) (HPBUFFERARB, int, int*);

static PswglCreatePbufferARB swglCreatePbufferARB = 0;
static PswglGetPbufferDCARB swglGetPbufferDCARB = 0;
static PswglReleasePbufferDCARB swglReleasePbufferDCARB = 0;
static PswglDestroyPbufferARB swglDestroyPbufferARB = 0;
static PswglQueryPbufferARB swglQueryPbufferARB = 0;
//----------------------------------------------------------------------------
HPBUFFERARB GTwglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth,
    int iHeight, const int* aiAttribList)
{
    GT_BODY_A5_RET(swglCreatePbufferARB,hDC,iPixelFormat,iWidth,iHeight,
        aiAttribList,HPBUFFERARB,0);
}
//----------------------------------------------------------------------------
HDC GTwglGetPbufferDCARB (HPBUFFERARB hPBuffer)
{
    GT_BODY_A1_RET(swglGetPbufferDCARB,hPBuffer,HDC,0);
}
//----------------------------------------------------------------------------
int GTwglReleasePbufferDCARB (HPBUFFERARB hPBuffer, HDC hDC)
{
    GT_BODY_A2_RET(swglReleasePbufferDCARB,hPBuffer,hDC,int,0);
}
//----------------------------------------------------------------------------
BOOL GTwglDestroyPbufferARB (HPBUFFERARB hPBuffer)
{
    GT_BODY_A1_RET(swglDestroyPbufferARB,hPBuffer,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglQueryPbufferARB (HPBUFFERARB hPBuffer, int iAttribute,
    int* piValue)
{
    GT_BODY_A3_RET(swglQueryPbufferARB,hPBuffer,iAttribute,piValue,BOOL,
        FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglArbPBuffer ()
{
    if (GTSupportsWglExtension("WGL_ARB_pbuffer")
     || GTSupportsExtension("WGL_ARB_pbuffer"))
    {
        GTExistsWglArbPBuffer = 1;
        GT_GET_FUNCTION(swglCreatePbufferARB);
        GT_GET_FUNCTION(swglGetPbufferDCARB);
        GT_GET_FUNCTION(swglReleasePbufferDCARB);
        GT_GET_FUNCTION(swglDestroyPbufferARB);
        GT_GET_FUNCTION(swglQueryPbufferARB);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 20) WGL_ARB_render_texture
//----------------------------------------------------------------------------
int GTExistsWglArbRenderTexture = 0;

typedef BOOL (STDCALL* PswglBindTexImageARB) (HPBUFFERARB, int);
typedef BOOL (STDCALL* PswglReleaseTexImageARB) (HPBUFFERARB, int);
typedef BOOL (STDCALL* PswglSetPbufferAttribARB) (HPBUFFERARB, const int*);

static PswglBindTexImageARB swglBindTexImageARB = 0;
static PswglReleaseTexImageARB swglReleaseTexImageARB = 0;
static PswglSetPbufferAttribARB swglSetPbufferAttribARB = 0;
//----------------------------------------------------------------------------
BOOL GTwglBindTexImageARB (HPBUFFERARB hPBuffer, int iBuffer)
{
    GT_BODY_A2_RET(swglBindTexImageARB,hPBuffer,iBuffer,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglReleaseTexImageARB (HPBUFFERARB hPBuffer, int iBuffer)
{
    GT_BODY_A2_RET(swglReleaseTexImageARB,hPBuffer,iBuffer,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglSetPbufferAttribARB (HPBUFFERARB hPBuffer, const int* aiAttribList)
{
    GT_BODY_A2_RET(swglSetPbufferAttribARB,hPBuffer,aiAttribList,BOOL,FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglArbRenderTexture ()
{
    if (GTSupportsWglExtension("WGL_ARB_render_texture")
    ||  GTSupportsExtension("WGL_ARB_render_texture"))
    {
        GTExistsWglArbRenderTexture = 1;
        GT_GET_FUNCTION(swglBindTexImageARB);
        GT_GET_FUNCTION(swglReleaseTexImageARB);
        GT_GET_FUNCTION(swglSetPbufferAttribARB);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (ARB 39) WGL_ARB_pixel_format_float
//----------------------------------------------------------------------------
int GTExistsWglArbPixelFormatFloat = 0;
//----------------------------------------------------------------------------
void GTInitWglArbPixelFormatFloat ()
{
    if (GTSupportsWglExtension("WGL_ARB_pixel_format_float")
    ||  GTSupportsExtension("WGL_ARB_pixel_format_float"))
    {
        GTExistsWglArbPixelFormatFloat = 1;
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ***** EXT Extensions *****
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 167) WGL_EXT_display_color_table
//----------------------------------------------------------------------------
int GTExistsWglExtDisplayColorTable = 0;

typedef GLboolean (STDCALL* PswglCreateDisplayColorTableEXT) (GLushort);
typedef GLboolean (STDCALL* PswglLoadDisplayColorTableEXT) (const GLushort*,
    GLuint);
typedef GLboolean (STDCALL* PswglBindDisplayColorTableEXT) (GLushort);
typedef VOID (STDCALL* PswglDestroyDisplayColorTableEXT) (GLushort);

static PswglCreateDisplayColorTableEXT swglCreateDisplayColorTableEXT = 0;
static PswglLoadDisplayColorTableEXT swglLoadDisplayColorTableEXT = 0;
static PswglBindDisplayColorTableEXT swglBindDisplayColorTableEXT = 0;
static PswglDestroyDisplayColorTableEXT swglDestroyDisplayColorTableEXT = 0;
//----------------------------------------------------------------------------
GLboolean GTwglCreateDisplayColorTableEXT (GLushort usID)
{
    GT_BODY_A1_RET(swglCreateDisplayColorTableEXT,usID,GLboolean,0);
}
//----------------------------------------------------------------------------
GLboolean GTwglLoadDisplayColorTableEXT (const GLushort* ausTable,
    GLuint uiLength)
{
    GT_BODY_A2_RET(swglLoadDisplayColorTableEXT,ausTable,uiLength,GLboolean,
        0);
}
//----------------------------------------------------------------------------
GLboolean GTwglBindDisplayColorTableEXT (GLushort usID)
{
    GT_BODY_A1_RET(swglBindDisplayColorTableEXT,usID,GLboolean,0);
}
//----------------------------------------------------------------------------
VOID GTwglDestroyDisplayColorTableEXT (GLushort usID)
{
    GT_BODY_A1(swglDestroyDisplayColorTableEXT,usID);
}
//----------------------------------------------------------------------------
void GTInitWglExtDisplayColorTable ()
{
    if (GTSupportsWglExtension("WGL_EXT_display_color_table")
    ||  GTSupportsExtension("WGL_EXT_display_color_table"))
    {
        GTExistsWglExtDisplayColorTable = 1;
        GT_GET_FUNCTION(swglCreateDisplayColorTableEXT);
        GT_GET_FUNCTION(swglLoadDisplayColorTableEXT);
        GT_GET_FUNCTION(swglBindDisplayColorTableEXT);
        GT_GET_FUNCTION(swglDestroyDisplayColorTableEXT);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 168) WGL_EXT_extensions_string
//----------------------------------------------------------------------------
int GTExistsWglExtExtensionsString = 0;

typedef const char* (STDCALL* PswglGetExtensionsStringEXT) ();

static PswglGetExtensionsStringEXT swglGetExtensionsStringEXT = 0;
//----------------------------------------------------------------------------
const char* GTwglGetExtensionsStringEXT ()
{
    GT_BODY_A0_RET(swglGetExtensionsStringEXT,const char*,0);
}
//----------------------------------------------------------------------------
void GTInitWglExtExtensionsString ()
{
	GT_GET_FUNCTION(swglGetExtensionsStringEXT);
	if (swglGetExtensionsStringEXT)
	{
        GTExistsWglExtExtensionsString = 1;
	}
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 169) WGL_EXT_make_current_read
//----------------------------------------------------------------------------
int GTExistsWglExtMakeCurrentRead = 0;

typedef BOOL (STDCALL* PswglMakeContextCurrentEXT) (HDC, HDC, HGLRC);
typedef HDC (STDCALL* PswglGetCurrentReadDCEXT) ();

static PswglMakeContextCurrentEXT swglMakeContextCurrentEXT = 0;
static PswglGetCurrentReadDCEXT swglGetCurrentReadDCEXT = 0;
//----------------------------------------------------------------------------
BOOL GTwglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hWindowRC)
{
    GT_BODY_A3_RET(swglMakeContextCurrentEXT,hDrawDC,hReadDC,hWindowRC,BOOL,
        FALSE);
}
//----------------------------------------------------------------------------
HDC GTwglGetCurrentReadDCEXT ()
{
    GT_BODY_A0_RET(swglGetCurrentReadDCEXT,HDC,0);
}
//----------------------------------------------------------------------------
void GTInitWglExtMakeCurrentRead ()
{
    if (GTSupportsWglExtension("WGL_EXT_make_current_read")
    ||  GTSupportsExtension("WGL_EXT_make_current_read"))
    {
        GTExistsWglExtMakeCurrentRead = 1;

        GT_GET_FUNCTION(swglMakeContextCurrentEXT);
        if (GT_EXT_OVERRIDE && !swglMakeContextCurrentARB)
        {
            swglMakeContextCurrentARB =
                (PswglMakeContextCurrentARB)swglMakeContextCurrentEXT;
        }

        GT_GET_FUNCTION(swglGetCurrentReadDCEXT);
        if (GT_EXT_OVERRIDE && !swglGetCurrentReadDCARB)
        {
            swglGetCurrentReadDCARB =
                (PswglGetCurrentReadDCARB)swglGetCurrentReadDCEXT;
        }
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 170) WGL_EXT_pixel_format
//----------------------------------------------------------------------------
int GTExistsWglExtPixelFormat = 0;

typedef BOOL (STDCALL* PswglGetPixelFormatAttribivEXT) (HDC, int, int, UINT,
    const int*, int*);
typedef BOOL (STDCALL* PswglGetPixelFormatAttribfvEXT) (HDC, int, int, UINT,
    const int*, FLOAT*);
typedef BOOL (STDCALL* PswglChoosePixelFormatEXT) (HDC, const int*,
    const FLOAT*, UINT, int*, UINT*);

static PswglGetPixelFormatAttribivEXT swglGetPixelFormatAttribivEXT = 0;
static PswglGetPixelFormatAttribfvEXT swglGetPixelFormatAttribfvEXT = 0;
static PswglChoosePixelFormatEXT swglChoosePixelFormatEXT = 0;
//----------------------------------------------------------------------------
BOOL GTwglGetPixelFormatAttribivEXT (HDC hDC, int iPixelFormat,
    int iLayerPlane, UINT uiNumAttributes, const int* aiAttribute,
    int* aiValue)
{
    GT_BODY_A6_RET(swglGetPixelFormatAttribivEXT,hDC,iPixelFormat,iLayerPlane,
        uiNumAttributes,aiAttribute,aiValue,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglGetPixelFormatAttribfvEXT (HDC hDC, int iPixelFormat,
    int iLayerPlane, UINT uiNumAttributes, const int* aiAttribute,
    FLOAT* afValue)
{
    GT_BODY_A6_RET(swglGetPixelFormatAttribfvEXT,hDC,iPixelFormat,iLayerPlane,
        uiNumAttributes,aiAttribute,afValue,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglChoosePixelFormatEXT (HDC hDC, const int* aiAttribIList,
    const FLOAT* afAttribFList, UINT uiMaxFormats, int* aiFormat,
    UINT* puiNumFormats)
{
    GT_BODY_A6_RET(swglChoosePixelFormatEXT,hDC,aiAttribIList,afAttribFList,
        uiMaxFormats,aiFormat,puiNumFormats,BOOL,FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglExtPixelFormat ()
{
    if (GTSupportsWglExtension("WGL_EXT_pixel_format")
    ||  GTSupportsExtension("WGL_EXT_pixel_format"))
    {
        GTExistsWglExtPixelFormat = 1;

        GT_GET_FUNCTION(swglGetPixelFormatAttribivEXT);
        if (GT_EXT_OVERRIDE && !swglGetPixelFormatAttribivARB)
        {
            swglGetPixelFormatAttribivARB =
                (PswglGetPixelFormatAttribivARB)swglGetPixelFormatAttribivEXT;
        }

        GT_GET_FUNCTION(swglGetPixelFormatAttribfvEXT);
        if (GT_EXT_OVERRIDE && !swglGetPixelFormatAttribfvARB)
        {
            swglGetPixelFormatAttribfvARB =
                (PswglGetPixelFormatAttribfvARB)swglGetPixelFormatAttribfvEXT;
        }

        GT_GET_FUNCTION(swglChoosePixelFormatEXT);
        if (GT_EXT_OVERRIDE && !swglChoosePixelFormatARB)
        {
            swglChoosePixelFormatARB =
                (PswglChoosePixelFormatARB)swglChoosePixelFormatEXT;
        }
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 171) WGL_EXT_pbuffer
//----------------------------------------------------------------------------
int GTExistsWglExtPBuffer = 0;

typedef HPBUFFEREXT (STDCALL* PswglCreatePbufferEXT) (HDC, int, int, int,
    const int*);
typedef HDC (STDCALL* PswglGetPbufferDCEXT) (HPBUFFEREXT);
typedef int (STDCALL* PswglReleasePbufferDCEXT) (HPBUFFEREXT, HDC);
typedef BOOL (STDCALL* PswglDestroyPbufferEXT) (HPBUFFEREXT);
typedef BOOL (STDCALL* PswglQueryPbufferEXT) (HPBUFFEREXT, int, int*);

static PswglCreatePbufferEXT swglCreatePbufferEXT = 0;
static PswglGetPbufferDCEXT swglGetPbufferDCEXT = 0;
static PswglReleasePbufferDCEXT swglReleasePbufferDCEXT = 0;
static PswglDestroyPbufferEXT swglDestroyPbufferEXT = 0;
static PswglQueryPbufferEXT swglQueryPbufferEXT = 0;
//----------------------------------------------------------------------------
HPBUFFEREXT GTwglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth,
    int iHeight, const int* aiAttribList)
{
    GT_BODY_A5_RET(swglCreatePbufferEXT,hDC,iPixelFormat,iWidth,iHeight,
        aiAttribList,HPBUFFEREXT,0);
}
//----------------------------------------------------------------------------
HDC GTwglGetPbufferDCEXT (HPBUFFEREXT hPBuffer)
{
    GT_BODY_A1_RET(swglGetPbufferDCEXT,hPBuffer,HDC,0);
}
//----------------------------------------------------------------------------
int GTwglReleasePbufferDCEXT (HPBUFFEREXT hPBuffer, HDC hDC)
{
    GT_BODY_A2_RET(swglReleasePbufferDCEXT,hPBuffer,hDC,int,0);
}
//----------------------------------------------------------------------------
BOOL GTwglDestroyPbufferEXT (HPBUFFEREXT hPBuffer)
{
    GT_BODY_A1_RET(swglDestroyPbufferEXT,hPBuffer,BOOL,FALSE);
}
//----------------------------------------------------------------------------
BOOL GTwglQueryPbufferEXT (HPBUFFEREXT hPBuffer, int iAttribute,
    int* piValue)
{
    GT_BODY_A3_RET(swglQueryPbufferEXT,hPBuffer,iAttribute,piValue,BOOL,
        FALSE);
}
//----------------------------------------------------------------------------
void GTInitWglExtPBuffer ()
{
    if (GTSupportsWglExtension("WGL_EXT_pbuffer")
    ||  GTSupportsExtension("WGL_EXT_pbuffer"))
    {
        GTExistsWglExtPBuffer = 1;

        GT_GET_FUNCTION(swglCreatePbufferEXT);
        if (GT_EXT_OVERRIDE && !swglCreatePbufferARB)
        {
            swglCreatePbufferARB =
                (PswglCreatePbufferARB)swglCreatePbufferEXT;
        }

        GT_GET_FUNCTION(swglGetPbufferDCEXT);
        if (GT_EXT_OVERRIDE && !swglGetPbufferDCARB)
        {
            swglGetPbufferDCARB =
                (PswglGetPbufferDCARB)swglGetPbufferDCEXT;
        }

        GT_GET_FUNCTION(swglReleasePbufferDCEXT);
        if (GT_EXT_OVERRIDE && !swglReleasePbufferDCARB)
        {
            swglReleasePbufferDCARB =
                (PswglReleasePbufferDCARB)swglReleasePbufferDCEXT;
        }

        GT_GET_FUNCTION(swglDestroyPbufferEXT);
        if (GT_EXT_OVERRIDE && !swglDestroyPbufferARB)
        {
            swglDestroyPbufferARB =
                (PswglDestroyPbufferARB)swglDestroyPbufferEXT;
        }

        GT_GET_FUNCTION(swglQueryPbufferEXT);
        if (GT_EXT_OVERRIDE && !swglQueryPbufferARB)
        {
            swglQueryPbufferARB =
                (PswglQueryPbufferARB)swglQueryPbufferEXT;
        }
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 172) WGL_EXT_swap_control
//----------------------------------------------------------------------------
int GTExistsWglExtSwapControl = 0;

typedef BOOL (STDCALL* PswglSwapIntervalEXT) (int);
typedef int (STDCALL* PswglGetSwapIntervalEXT) ();

static PswglSwapIntervalEXT swglSwapIntervalEXT = 0;
static PswglGetSwapIntervalEXT swglGetSwapIntervalEXT = 0;
//----------------------------------------------------------------------------
BOOL GTwglSwapIntervalEXT (int iInterval)
{
    BOOL tResult;
    GT_ENTER_FUNCTION(swglSwapIntervalEXT);
    if (swglSwapIntervalEXT)
    {
        // The application can run with vsync disabled.
        GT_NONNULL_FUNCTION(swglSwapIntervalEXT);
        tResult = swglSwapIntervalEXT(iInterval);
    }
    else
    {
        // The application must run with vsync enabled.  Do not use the
        // macro GT_NULL_FUNCTION(swglSwapIntervalEXT) here.
        tResult = FALSE;
    }
    GT_EXIT_FUNCTION(swglSwapIntervalEXT);
    return tResult;
}
//----------------------------------------------------------------------------
int GTwglGetSwapIntervalEXT ()
{
    GT_BODY_A0_RET(swglGetSwapIntervalEXT,int,0);
}
//----------------------------------------------------------------------------
void GTInitWglExtSwapControl ()
{
    if (GTSupportsWglExtension("WGL_EXT_swap_control")
    ||  GTSupportsExtension("WGL_EXT_swap_control"))
    {
        GTExistsWglExtSwapControl = 1;
        GT_GET_FUNCTION(swglSwapIntervalEXT);
        GT_GET_FUNCTION(swglGetSwapIntervalEXT);
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 177) WGL_EXT_depth_float
//----------------------------------------------------------------------------
int GTExistsWglExtDepthFloat = 0;
//----------------------------------------------------------------------------
void GTInitWglExtDepthFloat ()
{
    if (GTSupportsWglExtension("WGL_EXT_depth_float")
    ||  GTSupportsExtension("WGL_EXT_depth_float"))
    {
        GTExistsWglExtDepthFloat = 1;
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// (EXT 209) WGL_EXT_multisample
//----------------------------------------------------------------------------
int GTExistsWglExtMultisample = 0;
//----------------------------------------------------------------------------
void GTInitWglExtMultisample ()
{
    if (GTSupportsWglExtension("WGL_EXT_multisample")
    ||  GTSupportsExtension("WGL_EXT_multisample"))
    {
        GTExistsWglExtMultisample = 1;
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// Initialization of the WGL system
//----------------------------------------------------------------------------
#include <cstdio>
#include <cstdlib>

// Disable the MSVC8 warnings about deprecated functions.
#pragma warning( push )
#pragma warning( disable : 4996 )

void GTInitWGL (const char* acInfoFile)
{
    GTInitGL(acInfoFile);

    GTInitWglArbExtensionsString();
    GTInitWglExtExtensionsString();

	if (acInfoFile)
    {
        FILE* pkInfo = fopen(acInfoFile,"at");
        if (pkInfo)
        {
            const char* acWglExtensions;

            acWglExtensions = GTGetWglExtensionString();
            if (acWglExtensions)
            {
                char* acExt;
                char* pcToken;

                fprintf(pkInfo,"WGLextensions =\n");
                acExt = (char*)malloc((int)strlen(acWglExtensions)+1);
                strcpy(acExt,acWglExtensions);
                pcToken = strtok(acExt," \t\n");
                while (pcToken)
                {
                    fprintf(pkInfo,"    %s\n",pcToken);
                    pcToken = strtok(0," \t\n");
                }
                free(acExt);
            }
            else
            {
                fprintf(pkInfo,"WGLextensions = <null>\n");
            }

            fclose(pkInfo);
        }
    }

    GTInitWglArbBufferRegion();
    GTInitWglArbMultisample();
    GTInitWglArbPixelFormat();
    GTInitWglArbMakeCurrentRead();
    GTInitWglArbPBuffer();
    GTInitWglArbRenderTexture();
    GTInitWglArbPixelFormatFloat();

    GTInitWglExtDisplayColorTable();
    GTInitWglExtMakeCurrentRead();
    GTInitWglExtPixelFormat();
    GTInitWglExtPBuffer();
    GTInitWglExtSwapControl();
    GTInitWglExtDepthFloat();
    GTInitWglExtMultisample();
}
#pragma warning( pop )
//----------------------------------------------------------------------------
const char* GTGetWglExtensionString ()
{
	if (GTExistsWglExtExtensionsString && GT_EXT_OVERRIDE)
    {
		return GTwglGetExtensionsStringEXT();
    }
	else if (GTExistsWglArbExtensionsString)
    {
		return GTwglGetExtensionsStringARB(wglGetCurrentDC());
    }
	else
    {
		return 0;
    }
}
//----------------------------------------------------------------------------
int GTSupportsWglExtension (const char* acWglExtension)
{
    const char* acWglExtensionString;
    char* acBegin;
    char cEnd;

    if (!acWglExtension)
    {
        return 0;
    }

    acWglExtensionString = GTGetWglExtensionString();
    if (!acWglExtensionString)
    {
        return 0;
    }

    acBegin = (char*)strstr(acWglExtensionString,acWglExtension);
    if (!acBegin)
    {
        return 0;
    }

    // The extension was found, but make sure it is not a proper substring
    // of another extension.
    cEnd = *(acBegin + strlen(acWglExtension));
    return cEnd == ' ' || cEnd == 0 || cEnd == '\t' || cEnd == '\n';
}
//----------------------------------------------------------------------------