-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgl_loader.c
More file actions
129 lines (110 loc) · 2.81 KB
/
gl_loader.c
File metadata and controls
129 lines (110 loc) · 2.81 KB
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
#include <EGL/egl.h>
#include <GLES/gl.h>
//#include "gl_loader.h"
#include <dlfcn.h>
#include <stdio.h>
#if defined(__linux__)
static void *libegl;
static void *libgles;
#define FPTR(f) typeof(f) * p##f
FPTR(eglGetError);
FPTR(eglBindAPI);
FPTR(eglGetDisplay);
FPTR(eglInitialize);
FPTR(eglChooseConfig);
FPTR(eglCreateWindowSurface);
FPTR(eglSwapInterval);
FPTR(eglCreateContext);
FPTR(eglMakeCurrent);
FPTR(eglSwapBuffers);
FPTR(eglDestroyContext);
FPTR(eglDestroySurface);
FPTR(eglTerminate);
FPTR(glGetError);
FPTR(glGetString);
FPTR(glEnableClientState);
FPTR(glEnable);
FPTR(glGenTextures);
FPTR(glDeleteTextures);
FPTR(glBindTexture);
FPTR(glTexImage2D);
FPTR(glTexParameterf);
FPTR(glTexSubImage2D);
FPTR(glTexCoordPointer);
FPTR(glVertexPointer);
FPTR(glDrawArrays);
FPTR(glLoadIdentity);
FPTR(glClearColor);
FPTR(glClear);
FPTR(glFrontFace);
void gl_unload(void)
{
if (libegl)
dlclose(libegl);
libegl = NULL;
if (libgles)
dlclose(libgles);
libgles = NULL;
}
#define LOADSYM(l,n) p##n = dlsym(l,#n); if (!p##n) goto err;
int gl_load(void)
{
// possible library file name. Some systems have them versioned, others
// don't, old-style brcm naming on Raspberry Pi systems.
char *egl[] = { "libEGL.so.1", "libEGL.so", "libbrcmEGL.so", NULL };
char *gles[] = { "libGLESv1_CM.so.1", "libGLESv1_CM.so", "libGLES_CM.so.1",
"libGLES_CM.so", "libbrcmGLESv2.so", "libGLESv2.so", NULL };
int i;
for (i = 0, libegl = NULL; egl[i] && !libegl; i++)
libegl = dlopen(egl[i], RTLD_LAZY);
if (!libegl)
goto err;
LOADSYM(libegl, eglGetError);
LOADSYM(libegl, eglBindAPI);
LOADSYM(libegl, eglGetDisplay);
LOADSYM(libegl, eglInitialize);
LOADSYM(libegl, eglChooseConfig);
LOADSYM(libegl, eglCreateWindowSurface);
LOADSYM(libegl, eglSwapInterval);
LOADSYM(libegl, eglCreateContext);
LOADSYM(libegl, eglMakeCurrent);
LOADSYM(libegl, eglSwapBuffers);
LOADSYM(libegl, eglDestroyContext);
LOADSYM(libegl, eglDestroySurface);
LOADSYM(libegl, eglTerminate);
for (i = 0, libgles = NULL; gles[i] && !libgles; i++)
libgles = dlopen(gles[i], RTLD_LAZY);
if (!libgles)
goto err;
LOADSYM(libgles, glGetError);
LOADSYM(libgles, glGetString);
LOADSYM(libgles, glEnableClientState);
LOADSYM(libgles, glEnable);
LOADSYM(libgles, glGenTextures);
LOADSYM(libgles, glDeleteTextures);
LOADSYM(libgles, glBindTexture);
LOADSYM(libgles, glTexImage2D);
LOADSYM(libgles, glTexParameterf);
LOADSYM(libgles, glTexSubImage2D);
LOADSYM(libgles, glTexCoordPointer);
LOADSYM(libgles, glVertexPointer);
LOADSYM(libgles, glDrawArrays);
LOADSYM(libgles, glLoadIdentity);
LOADSYM(libgles, glClearColor);
LOADSYM(libgles, glClear);
LOADSYM(libgles, glFrontFace);
return 0;
err:
fprintf(stderr, "warning: OpenGLES libraries are not available\n");
gl_unload();
return 1;
}
#else
void gl_unload(void)
{
}
int gl_load(void)
{
return 0;
}
#endif