forked from liballeg/allegro5
/
extensions.c
958 lines (784 loc) · 25.5 KB
/
extensions.c
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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* OpenGL extensions management subsystem
*
* By Elias Pschernig and Milan Mimica.
*
* Based on AllegroGL extensions management.
*/
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "allegro5/allegro.h"
#include "allegro5/allegro_opengl.h"
#include "allegro5/opengl/gl_ext.h"
#include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_opengl.h"
#include "allegro5/internal/aintern_display.h"
#include "allegro5/internal/aintern_system.h"
/* We need some driver specific details not worth of a vtable entry. */
#if defined ALLEGRO_WINDOWS
#include "../win/wgl.h"
#elif defined ALLEGRO_UNIX && !defined ALLEGRO_EXCLUDE_GLX
#include "allegro5/internal/aintern_xdisplay.h"
#include "allegro5/internal/aintern_xsystem.h"
#endif
#if defined ALLEGRO_MACOSX
#include <OpenGL/glu.h>
#elif !defined ALLEGRO_CFG_OPENGLES
#include <GL/glu.h>
#endif
ALLEGRO_DEBUG_CHANNEL("opengl")
#ifdef ALLEGRO_HAVE_DYNAMIC_LINK
#include <dlfcn.h>
/* Handle for dynamic library libGL.so */
static void *__libgl_handle = NULL;
/* Pointer to glXGetProcAddressARB */
typedef void *(*GLXGETPROCADDRESSARBPROC) (const GLubyte *);
static GLXGETPROCADDRESSARBPROC alXGetProcAddress;
#else /* #ifdef ALLEGRO_HAVE_DYNAMIC_LINK */
/* Tries static linking */
/* FIXME: set ALLEGRO_GLXGETPROCADDRESSARB on configure time, if
* glXGetProcAddressARB must be used!
*/
#if defined ALLEGRO_GLXGETPROCADDRESSARB
#define alXGetProcAddress glXGetProcAddressARB
#elif defined ALLEGRO_RASPBERRYPI
#define alXGetProcAddress eglGetProcAddress
#else
#define alXGetProcAddress glXGetProcAddress
#endif
#endif /* #ifdef ALLEGRO_HAVE_DYNAMIC_LINK */
#ifdef ALLEGRO_MACOSX
#include <CoreFoundation/CoreFoundation.h>
static CFBundleRef opengl_bundle_ref;
#endif
/* Define the GL API pointers.
* Example:
* _ALLEGRO_glBlendEquation_t _al_glBlendEquation = NULL;
*/
#define AGL_API(type, name, args) _ALLEGRO_gl##name##_t _al_gl##name = NULL;
# include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#ifdef ALLEGRO_WINDOWS
#define AGL_API(type, name, args) _ALLEGRO_wgl##name##_t _al_wgl##name = NULL;
# include "allegro5/opengl/GLext/wgl_ext_api.h"
#undef AGL_API
#elif defined ALLEGRO_UNIX
#define AGL_API(type, name, args) _ALLEGRO_glX##name##_t _al_glX##name = NULL;
# include "allegro5/opengl/GLext/glx_ext_api.h"
#undef AGL_API
#endif
static uint32_t parse_opengl_version(const char *s)
{
char *p = (char *) s;
int v[4] = {0, 0, 0, 0};
int n;
uint32_t ver;
/* For OpenGL ES version strings have the form:
* "OpenGL ES-<profile> <major>.<minor>"
* So for example: "OpenGL ES-CM 2.0". We simply skip any non-digit
* characters and then parse it like for normal OpenGL.
*/
while (*p && !isdigit(*p)) {
p++;
}
/* e.g. "4.0.0 Vendor blah blah" */
for (n = 0; n < 4; n++) {
char *end;
long l;
errno = 0;
l = strtol(p, &end, 10);
if (errno)
break;
v[n] = _ALLEGRO_CLAMP(0, l, 255);
if (*end != '.')
break;
p = end + 1; /* skip dot */
}
ver = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
ALLEGRO_DEBUG("Parsed '%s' as 0x%08x\n", s, ver);
return ver;
}
/* Reads version info out of glGetString(GL_VERSION) */
static uint32_t _al_ogl_version(void)
{
char const *value = al_get_config_value(al_get_system_config(), "opengl",
"force_opengl_version");
if (value) {
uint32_t v = parse_opengl_version(value);
ALLEGRO_INFO("OpenGL version forced to %d.%d.%d.%d.\n",
(v >> 24) & 0xff,
(v >> 16) & 0xff,
(v >> 8) & 0xff,
(v & 0xff));
return v;
}
const char *str;
str = (const char *)glGetString(GL_VERSION);
if (str) {
#ifdef ALLEGRO_CFG_OPENGLES
char *str2 = strstr(str, "ES ");
if (str2)
str = str2 + 3;
#endif
return parse_opengl_version(str);
}
else {
/* The OpenGL driver does not return a version
* number. However it probably supports at least OpenGL 1.0
*/
return _ALLEGRO_OPENGL_VERSION_1_0;
}
}
static bool _al_ogl_version_3_only(int flags)
{
const int mask = ALLEGRO_OPENGL_3_0 | ALLEGRO_OPENGL_FORWARD_COMPATIBLE;
return (flags & mask) == mask;
}
/* print_extensions:
* Given a string containing extensions (i.e. a NULL terminated string where
* each extension are separated by a space and which names do not contain any
* space)
*/
static void print_extensions(char const *extension)
{
char buf[80];
char *start;
ASSERT(extension);
while (*extension != '\0') {
start = buf;
_al_sane_strncpy(buf, extension, 80);
while ((*start != ' ') && (*start != '\0')) {
extension++;
start++;
}
*start = '\0';
if (*extension != '\0')
extension++;
ALLEGRO_DEBUG("%s\n", buf);
}
}
#if !defined ALLEGRO_CFG_OPENGLES
/* Print all extensions the OpenGL 3.0 way. */
static void print_extensions_3_0(void)
{
int i;
GLint n;
GLubyte const *name;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
for (i = 0; i < n; i++) {
name = glGetStringi(GL_EXTENSIONS, i);
ALLEGRO_DEBUG("%s\n", name);
}
}
#endif
/* Function: al_get_opengl_version
*/
uint32_t al_get_opengl_version(void)
{
ALLEGRO_DISPLAY *ogl_disp;
ogl_disp = al_get_current_display();
if (!ogl_disp || !ogl_disp->ogl_extras)
return 0x0;
return ogl_disp->ogl_extras->ogl_info.version;
}
/* NOTE: al_get_opengl_variant is pretty simple right now but may
* eventually need driver support.
*/
/* Function: al_get_opengl_variant
*/
int al_get_opengl_variant(void)
{
#if defined ALLEGRO_CFG_OPENGLES
return ALLEGRO_OPENGL_ES;
#else
return ALLEGRO_DESKTOP_OPENGL;
#endif
}
/* Create the extension list */
static ALLEGRO_OGL_EXT_LIST *create_extension_list(void)
{
ALLEGRO_OGL_EXT_LIST *ret = al_calloc(1, sizeof(ALLEGRO_OGL_EXT_LIST));
if (!ret) {
return NULL;
}
return ret;
}
/* Create the extension API table */
static ALLEGRO_OGL_EXT_API *create_extension_api_table(void)
{
ALLEGRO_OGL_EXT_API *ret = al_calloc(1, sizeof(ALLEGRO_OGL_EXT_API));
if (!ret) {
return NULL;
}
return ret;
}
typedef void (*VOID_FPTR)(void);
/* GCC 4.8.2 and possibly others are really slow at optimizing the 100's of the
* if statements in the load_extensions function below, so we extract them to
* this function.
*/
static VOID_FPTR load_extension(const char* name)
{
VOID_FPTR fptr = NULL;
#ifdef ALLEGRO_WINDOWS
fptr = (VOID_FPTR)wglGetProcAddress(name);
#elif defined ALLEGRO_UNIX
fptr = (VOID_FPTR)alXGetProcAddress((const GLubyte*)name);
#elif defined ALLEGRO_MACOSX
CFStringRef cfstr = CFStringCreateWithCStringNoCopy(NULL, name,
kCFStringEncodingUTF8, kCFAllocatorNull);
if (cfstr) {
fptr = (VOID_FPTR)CFBundleGetFunctionPointerForName(opengl_bundle_ref, cfstr);
CFRelease(cfstr);
}
#elif defined ALLEGRO_SDL
fptr = SDL_GL_GetProcAddress(name);
#endif
if (fptr) {
ALLEGRO_DEBUG("%s successfully loaded (%p)\n", name, fptr);
}
return fptr;
}
/* Load the extension API addresses into the table.
* Should only be done on context creation.
*/
static void load_extensions(ALLEGRO_OGL_EXT_API *ext)
{
if (!ext) {
return;
}
#ifdef ALLEGRO_UNIX
#ifdef ALLEGRO_HAVE_DYNAMIC_LINK
if (!alXGetProcAddress) {
return;
}
#endif
#endif
#ifdef ALLEGRO_WINDOWS
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_gl##name##_t)load_extension("gl" #name);
#include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_wgl##name##_t)load_extension("wgl" #name);
#include "allegro5/opengl/GLext/wgl_ext_api.h"
#undef AGL_API
#elif defined ALLEGRO_UNIX
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_gl##name##_t)load_extension("gl" #name);
#include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_glX##name##_t)load_extension("glX" #name);
#include "allegro5/opengl/GLext/glx_ext_api.h"
#undef AGL_API
#elif defined ALLEGRO_MACOSX
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_gl##name##_t)load_extension("gl" # name);
#include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#elif defined ALLEGRO_SDL
#define AGL_API(type, name, args) \
ext->name = (_ALLEGRO_gl##name##_t)load_extension("gl" # name);
#include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#endif
}
/* Set the GL API pointers to the current table
* Should only be called on context switches.
*/
void _al_ogl_set_extensions(ALLEGRO_OGL_EXT_API *ext)
{
if (!ext) {
return;
}
#define AGL_API(type, name, args) _al_gl##name = ext->name;
# include "allegro5/opengl/GLext/gl_ext_api.h"
#undef AGL_API
#ifdef ALLEGRO_WINDOWS
#define AGL_API(type, name, args) _al_wgl##name = ext->name;
# include "allegro5/opengl/GLext/wgl_ext_api.h"
#undef AGL_API
#elif defined ALLEGRO_UNIX
#define AGL_API(type, name, args) _al_glX##name = ext->name;
# include "allegro5/opengl/GLext/glx_ext_api.h"
#undef AGL_API
#endif
}
/* Destroys the extension API table */
static void destroy_extension_api_table(ALLEGRO_OGL_EXT_API *ext)
{
if (ext) {
al_free(ext);
}
}
/* Destroys the extension list */
static void destroy_extension_list(ALLEGRO_OGL_EXT_LIST *list)
{
if (list) {
al_free(list);
}
}
/* _al_ogl_look_for_an_extension:
* This function has been written by Mark J. Kilgard in one of his
* tutorials about OpenGL extensions
*/
int _al_ogl_look_for_an_extension(const char *name, const GLubyte *extensions)
{
const GLubyte *start;
GLubyte *where, *terminator;
ASSERT(extensions);
/* Extension names should not have spaces. */
where = (GLubyte *) strchr(name, ' ');
if (where || *name == '\0')
return false;
/* It takes a bit of care to be fool-proof about parsing the
* OpenGL extensions string. Don't be fooled by sub-strings, etc.
*/
start = extensions;
for (;;) {
where = (GLubyte *) strstr((const char *)start, name);
if (!where)
break;
terminator = where + strlen(name);
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return true;
start = terminator;
}
return false;
}
static bool _ogl_is_extension_supported(const char *extension,
ALLEGRO_DISPLAY *disp)
{
int ret = 0;
GLubyte const *ext_str;
#if !defined ALLEGRO_CFG_OPENGLES
int v = al_get_opengl_version();
#endif
(void)disp;
#if !defined ALLEGRO_CFG_OPENGLES
if (disp->flags & ALLEGRO_OPENGL_3_0 || v >= _ALLEGRO_OPENGL_VERSION_3_0) {
int i;
GLint ext_cnt;
glGetIntegerv(GL_NUM_EXTENSIONS, &ext_cnt);
for (i = 0; i < ext_cnt; i++) {
ext_str = glGetStringi(GL_EXTENSIONS, i);
if (ext_str && !strcmp(extension, (char*)ext_str)) {
ret = 1;
break;
}
}
}
else
#endif
{
ext_str = glGetString(GL_EXTENSIONS);
if (!ext_str)
return false;
ret = _al_ogl_look_for_an_extension(extension, ext_str);
}
#ifdef ALLEGRO_WINDOWS
if (!ret && strncmp(extension, "WGL", 3) == 0) {
ALLEGRO_DISPLAY_WGL *wgl_disp = (void*)disp;
_ALLEGRO_wglGetExtensionsStringARB_t _wglGetExtensionsStringARB;
if (!wgl_disp->dc)
return false;
_wglGetExtensionsStringARB = (void *)
wglGetProcAddress("wglGetExtensionsStringARB");
if (_wglGetExtensionsStringARB) {
ret = _al_ogl_look_for_an_extension(extension, (const GLubyte *)
_wglGetExtensionsStringARB(wgl_disp->dc));
}
}
#elif defined ALLEGRO_UNIX && !defined ALLEGRO_EXCLUDE_GLX
if (!ret && strncmp(extension, "GLX", 3) == 0) {
ALLEGRO_SYSTEM_XGLX *sys = (void*)al_get_system_driver();
ALLEGRO_DISPLAY_XGLX *glx_disp = (void*)disp;
char const *ext;
if (!sys->gfxdisplay)
return false;
ext = glXQueryExtensionsString(sys->gfxdisplay, glx_disp->xscreen);
if (!ext) {
/* work around driver bugs? */
ext = "";
}
ret = _al_ogl_look_for_an_extension(extension, (const GLubyte *)ext);
}
#endif
return ret;
}
static bool _ogl_is_extension_with_version_supported(
const char *extension, ALLEGRO_DISPLAY *disp, uint32_t ver)
{
char const *value;
/* For testing purposes, any OpenGL extension can be disable in
* the config by using something like:
*
* [opengl_disabled_extensions]
* GL_ARB_texture_non_power_of_two=0
* GL_EXT_framebuffer_object=0
*
*/
value = al_get_config_value(al_get_system_config(),
"opengl_disabled_extensions", extension);
if (value) {
ALLEGRO_WARN("%s found in [opengl_disabled_extensions].\n",
extension);
return false;
}
/* If the extension is included in the OpenGL version, there is no
* need to check the extensions list.
*/
if (ver > 0 && disp->ogl_extras->ogl_info.version >= ver) {
return true;
}
return _ogl_is_extension_supported(extension, disp);
}
/* Function: al_have_opengl_extension
*/
bool al_have_opengl_extension(const char *extension)
{
ALLEGRO_DISPLAY *disp;
disp = al_get_current_display();
if (!disp)
return false;
if (!(disp->flags & ALLEGRO_OPENGL))
return false;
return _ogl_is_extension_supported(extension, disp);
}
/* Function: al_get_opengl_proc_address
*/
void *al_get_opengl_proc_address(const char *name)
{
void *symbol = NULL;
#ifdef ALLEGRO_MACOSX
CFStringRef function;
#endif
ALLEGRO_DISPLAY *disp;
disp = al_get_current_display();
if (!disp)
return NULL;
if (!(disp->flags & ALLEGRO_OPENGL))
return NULL;
#if defined ALLEGRO_WINDOWS
/* For once Windows is the easiest platform to use :)
* It provides a standardized way to get a function address
* But of course there is a drawback : the symbol is only valid
* under the current context :P
*/
{
ALLEGRO_DISPLAY_WGL *wgl_disp = (void*)disp;
if (!wgl_disp->dc)
return NULL;
symbol = wglGetProcAddress(name);
}
#elif defined ALLEGRO_UNIX
#if defined ALLEGRO_HAVE_DYNAMIC_LINK
if (alXGetProcAddress)
#endif
{
/* This is definitely the *good* way on Unix to get a GL proc
* address. Unfortunately glXGetProcAddress is an extension
* and may not be available on all platforms
*/
#if defined ALLEGRO_RASPBERRYPI
symbol = alXGetProcAddress(name);
#else
symbol = alXGetProcAddress((const GLubyte *)name);
#endif
}
#elif defined ALLEGRO_HAVE_DYNAMIC_LINK
else {
/* Hack if glXGetProcAddress is not available :
* we try to find the symbol into libGL.so
*/
if (__al_handle) {
symbol = dlsym(__al_handle, name);
}
}
#elif defined ALLEGRO_MACOSX
function = CFStringCreateWithCString(kCFAllocatorDefault, name,
kCFStringEncodingASCII);
if (function) {
symbol =
CFBundleGetFunctionPointerForName(opengl_bundle_ref, function);
CFRelease(function);
}
#endif
if (!symbol) {
#if defined ALLEGRO_HAVE_DYNAMIC_LINK
if (!alXGetProcAddress) {
ALLEGRO_WARN("get_proc_address: libdl::dlsym: %s\n", dlerror());
}
#endif
ALLEGRO_WARN("get_proc_address : Unable to load symbol %s\n", name);
}
else {
ALLEGRO_DEBUG("get_proc_address : Symbol %s successfully loaded\n", name);
}
return symbol;
}
/* fill_in_info_struct:
* Fills in the OPENGL_INFO info struct for blacklisting video cards.
*/
static void fill_in_info_struct(const GLubyte *rendereru, OPENGL_INFO *info)
{
const char *renderer = (const char *)rendereru;
ASSERT(renderer);
/* Some cards are "special"... */
if (strstr(renderer, "3Dfx/Voodoo")) {
info->is_voodoo = 1;
}
else if (strstr(renderer, "Matrox G200")) {
info->is_matrox_g200 = 1;
}
else if (strstr(renderer, "RagePRO")) {
info->is_ati_rage_pro = 1;
}
else if (strstr(renderer, "RADEON 7000")) {
info->is_ati_radeon_7000 = 1;
}
else if (strstr(renderer, "Mesa DRI R200")) {
info->is_ati_r200_chip = 1;
}
else if (strstr(renderer, "Intel HD Graphics 3000 OpenGL Engine")) {
info->is_intel_hd_graphics_3000 = 1;
}
if ((strncmp(renderer, "3Dfx/Voodoo3 ", 13) == 0)
|| (strncmp(renderer, "3Dfx/Voodoo2 ", 13) == 0)
|| (strncmp(renderer, "3Dfx/Voodoo ", 12) == 0)) {
info->is_voodoo3_and_under = 1;
}
/* Read OpenGL properties */
info->version = _al_ogl_version();
ALLEGRO_INFO("Assumed OpenGL version: %d.%d.%d.%d\n",
(info->version >> 24) & 0xff,
(info->version >> 16) & 0xff,
(info->version >> 8) & 0xff,
(info->version ) & 0xff);
return;
}
/* _al_ogl_manage_extensions:
* This functions fills the extensions API table and extension list
* structures and displays on the log file which extensions are available.
*/
void _al_ogl_manage_extensions(ALLEGRO_DISPLAY *gl_disp)
{
//const GLubyte *buf;
#if defined ALLEGRO_MACOSX
CFURLRef bundle_url;
#endif
ALLEGRO_OGL_EXT_API *ext_api;
ALLEGRO_OGL_EXT_LIST *ext_list;
/* Print out OpenGL extensions
* We should use glGetStringi(GL_EXTENSIONS, i) for OpenGL 3.0+
* but it doesn't seem to work until later.
*/
if (!_al_ogl_version_3_only(gl_disp->flags)) {
ALLEGRO_DEBUG("OpenGL Extensions:\n");
print_extensions((char const *)glGetString(GL_EXTENSIONS));
}
/* Print out GLU version */
//buf = gluGetString(GLU_VERSION);
//ALLEGRO_INFO("GLU Version : %s\n", buf);
#ifdef ALLEGRO_HAVE_DYNAMIC_LINK
/* Get glXGetProcAddress entry */
__libgl_handle = dlopen("libGL.so", RTLD_LAZY);
if (__libgl_handle) {
alXGetProcAddress = (GLXGETPROCADDRESSARBPROC) dlsym(__libgl_handle,
"glXGetProcAddressARB");
if (!alXGetProcAddress) {
alXGetProcAddress = (GLXGETPROCADDRESSARBPROC) dlsym(__libgl_handle,
"glXGetProcAddress");
if (!alXGetProcAddress) {
alXGetProcAddress = (GLXGETPROCADDRESSARBPROC) dlsym(__libgl_handle,
"eglGetProcAddress");
}
}
}
else {
ALLEGRO_WARN("Failed to dlopen libGL.so : %s\n", dlerror());
}
ALLEGRO_INFO("glXGetProcAddress Extension: %s\n",
alXGetProcAddress ? "Supported" : "Unsupported");
#elif defined ALLEGRO_UNIX
#ifdef ALLEGROGL_GLXGETPROCADDRESSARB
ALLEGRO_INFO("glXGetProcAddressARB Extension: supported\n");
#else
ALLEGRO_INFO("glXGetProcAddress Extension: supported\n");
#endif
#endif
#ifdef ALLEGRO_MACOSX
bundle_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
CFSTR
("/System/Library/Frameworks/OpenGL.framework"),
kCFURLPOSIXPathStyle, true);
opengl_bundle_ref = CFBundleCreate(kCFAllocatorDefault, bundle_url);
CFRelease(bundle_url);
#endif
#if defined ALLEGRO_UNIX && !defined ALLEGRO_EXCLUDE_GLX
ALLEGRO_DEBUG("GLX Extensions:\n");
ALLEGRO_SYSTEM_XGLX *glx_sys = (void*)al_get_system_driver();
ALLEGRO_DISPLAY_XGLX *glx_disp = (void *)gl_disp;
char const *ext = glXQueryExtensionsString(
glx_sys->gfxdisplay, glx_disp->xscreen);
if (!ext) {
/* work around driver bugs? */
ext = "";
}
print_extensions(ext);
#endif
fill_in_info_struct(glGetString(GL_RENDERER), &(gl_disp->ogl_extras->ogl_info));
/* Create & load extension API table */
ext_api = create_extension_api_table();
load_extensions(ext_api);
gl_disp->ogl_extras->extension_api = ext_api;
#if !defined ALLEGRO_CFG_OPENGLES
/* Need that symbol already so can't wait until it is assigned later. */
glGetStringi = ext_api->GetStringi;
if (_al_ogl_version_3_only(gl_disp->flags)) {
ALLEGRO_DEBUG("OpenGL Extensions:\n");
print_extensions_3_0();
}
#endif
/* Create the list of supported extensions. */
ext_list = create_extension_list();
gl_disp->ogl_extras->extension_list = ext_list;
/* Fill the list. */
#define AGL_EXT(name, ver) { \
ext_list->ALLEGRO_GL_##name = \
_ogl_is_extension_with_version_supported("GL_" #name, gl_disp, \
_ALLEGRO_OPENGL_VERSION_##ver); \
}
#include "allegro5/opengl/GLext/gl_ext_list.h"
#undef AGL_EXT
#ifdef ALLEGRO_UNIX
#define AGL_EXT(name, ver) { \
ext_list->ALLEGRO_GLX_##name = \
_ogl_is_extension_with_version_supported("GLX_" #name, gl_disp, \
_ALLEGRO_OPENGL_VERSION_##ver); \
}
#include "allegro5/opengl/GLext/glx_ext_list.h"
#undef AGL_EXT
#elif defined ALLEGRO_WINDOWS
#define AGL_EXT(name, ver) { \
ext_list->ALLEGRO_WGL_##name = \
_ogl_is_extension_with_version_supported("WGL_" #name, gl_disp, \
_ALLEGRO_OPENGL_VERSION_##ver); \
}
#include "allegro5/opengl/GLext/wgl_ext_list.h"
#undef AGL_EXT
#endif
/* Get max texture size */
glGetIntegerv(GL_MAX_TEXTURE_SIZE,
(GLint *) & gl_disp->ogl_extras->ogl_info.max_texture_size);
/* Note: Voodoo (even V5) don't seem to correctly support
* packed pixel formats. Disabling them for those cards.
*/
ext_list->ALLEGRO_GL_EXT_packed_pixels &= !gl_disp->ogl_extras->ogl_info.is_voodoo;
if (ext_list->ALLEGRO_GL_EXT_packed_pixels) {
ALLEGRO_INFO("Packed Pixels formats available\n");
/* XXX On NV cards, we want to use BGRA instead of RGBA for speed */
/* Fills the __allegro_gl_texture_format array */
/* TODO: use these somewhere */
#if 0
__allegro_gl_texture_read_format[0] = GL_UNSIGNED_BYTE_3_3_2;
__allegro_gl_texture_read_format[1] = GL_UNSIGNED_SHORT_5_5_5_1;
__allegro_gl_texture_read_format[2] = GL_UNSIGNED_SHORT_5_6_5;
#endif /* #if 0 */
}
/* NVidia and ATI cards expose OpenGL 2.0 but often don't accelerate
* non-power-of-2 textures. This check is how you verify that NP2
* textures are hardware accelerated or not.
* We should clobber the NPOT support if it's not accelerated.
*/
{
const char *vendor = (const char *)glGetString(GL_VENDOR);
if (strstr(vendor, "NVIDIA Corporation")) {
if (!ext_list->ALLEGRO_GL_NV_fragment_program2
|| !ext_list->ALLEGRO_GL_NV_vertex_program3) {
ext_list->ALLEGRO_GL_ARB_texture_non_power_of_two = 0;
}
}
else if (strstr(vendor, "ATI Technologies")) {
if (_al_ogl_version_3_only(gl_disp->flags)) {
/* Assume okay. */
}
else if (!strstr((const char *)glGetString(GL_EXTENSIONS),
"GL_ARB_texture_non_power_of_two")
&& gl_disp->ogl_extras->ogl_info.version >= _ALLEGRO_OPENGL_VERSION_2_0) {
ext_list->ALLEGRO_GL_ARB_texture_non_power_of_two = 0;
}
}
}
{
int *s = gl_disp->extra_settings.settings;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, s + ALLEGRO_MAX_BITMAP_SIZE);
if (gl_disp->ogl_extras->ogl_info.version >= _ALLEGRO_OPENGL_VERSION_2_0)
s[ALLEGRO_SUPPORT_SEPARATE_ALPHA] = 1;
s[ALLEGRO_SUPPORT_NPOT_BITMAP] =
ext_list->ALLEGRO_GL_ARB_texture_non_power_of_two ||
ext_list->ALLEGRO_GL_OES_texture_npot;
ALLEGRO_INFO("Use of non-power-of-two textures %s.\n",
s[ALLEGRO_SUPPORT_NPOT_BITMAP] ? "enabled" : "disabled");
#if defined ALLEGRO_CFG_OPENGLES
if (gl_disp->flags & ALLEGRO_PROGRAMMABLE_PIPELINE) {
s[ALLEGRO_CAN_DRAW_INTO_BITMAP] = true;
}
else {
s[ALLEGRO_CAN_DRAW_INTO_BITMAP] =
ext_list->ALLEGRO_GL_OES_framebuffer_object;
}
ALLEGRO_INFO("Use of FBO to draw to textures %s.\n",
s[ALLEGRO_CAN_DRAW_INTO_BITMAP] ? "enabled" :
"disabled");
#else
s[ALLEGRO_CAN_DRAW_INTO_BITMAP] =
ext_list->ALLEGRO_GL_EXT_framebuffer_object;
ALLEGRO_INFO("Use of FBO to draw to textures %s.\n",
s[ALLEGRO_CAN_DRAW_INTO_BITMAP] ? "enabled" :
"disabled");
#endif
}
}
/* Function: al_get_opengl_extension_list
*/
ALLEGRO_OGL_EXT_LIST *al_get_opengl_extension_list(void)
{
ALLEGRO_DISPLAY *disp;
disp = al_get_current_display();
ASSERT(disp);
if (!(disp->flags & ALLEGRO_OPENGL))
return NULL;
ASSERT(disp->ogl_extras);
return disp->ogl_extras->extension_list;
}
void _al_ogl_unmanage_extensions(ALLEGRO_DISPLAY *gl_disp)
{
destroy_extension_api_table(gl_disp->ogl_extras->extension_api);
destroy_extension_list(gl_disp->ogl_extras->extension_list);
gl_disp->ogl_extras->extension_api = NULL;
gl_disp->ogl_extras->extension_list = NULL;
#ifdef ALLEGRO_MACOSX
CFRelease(opengl_bundle_ref);
#endif
#ifdef ALLEGRO_HAVE_DYNAMIC_LINK
if (__libgl_handle) {
dlclose(__libgl_handle);
__libgl_handle = NULL;
}
#endif
}
/* vim: set sts=3 sw=3 et: */