9 #include "coregl_internal.h"
10 #include "coregl_export.h"
15 int driver_gl_version = 0;
16 static int api_gl_version = COREGL_GLAPI_2;
18 // Symbol definition for real
19 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) RET_TYPE(*_sym_##FUNC_NAME) PARAM_LIST;
20 #include "headers/sym.h"
23 static unsigned int coregl_log_lvl;
24 static unsigned int coregl_dlog_enable;
25 static unsigned int coregl_log_initialized;
30 return coregl_log_lvl;
34 coregl_set_log_lvl(unsigned int value)
36 coregl_log_lvl = value;
40 coregl_get_dlog_enable()
42 return coregl_dlog_enable;
46 coregl_set_dlog_enable(unsigned int value)
48 coregl_dlog_enable = value;
54 return coregl_log_initialized;
58 coregl_set_log_init(unsigned int value)
60 coregl_log_initialized = value;
64 get_env_setting(const char *name)
67 static char *fp_default = "\0";
68 fp_env = getenv(name);
69 if (fp_env == NULL) fp_env = fp_default;
74 cleanup_current_thread_state()
76 GLThreadState *tstate = NULL;
78 tstate = get_current_thread_state();
81 COREGL_DBG("de-init thread state");
82 deinit_modules_tstate(tstate);
83 remove_from_general_trace_list(&thread_trace_list, tstate);
88 set_current_thread_state(NULL);
92 init_new_thread_state()
95 GLThreadState *tstate = NULL;
97 tstate = get_current_thread_state();
100 tstate = (GLThreadState *)calloc(1, sizeof(GLThreadState));
102 if (tstate == NULL) {
107 tstate->thread_id = get_current_thread();
108 add_to_general_trace_list(&thread_trace_list, tstate);
110 init_modules_tstate(tstate);
111 set_current_thread_state(tstate);
123 COREGL_ERR("GL symbol missing! Check client version!");
126 #define FINDGLSYM(libhandle, getproc, dst, sym) \
127 if (api_gl_version <= driver_gl_version) { \
128 if (!dst || (void *)dst == (void *)_sym_missing) \
129 if (getproc) dst = (__typeof__(dst))getproc(sym); \
130 if (!dst || (void *)dst == (void *)_sym_missing) \
131 dst = (__typeof__(dst))dlsym(libhandle, sym); \
132 if (!dst) dst = (__typeof__(dst))_sym_missing; \
135 #define FINDEGLSYM(libhandle, getproc, dst, sym) { \
136 if (!dst || (void *)dst == (void *)_sym_missing) \
137 if (getproc) dst = (__typeof__(dst))getproc(sym); \
138 if (!dst || (void *)dst == (void *)_sym_missing) \
139 dst = (__typeof__(dst))dlsym(libhandle, sym); \
140 if (!dst) dst = (__typeof__(dst))_sym_missing;\
146 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
147 FINDEGLSYM(egl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
148 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
149 FINDEGLSYM(egl_lib_handle, _sym_eglGetProcAddress, _sym_##ALIAS_NAME, #FUNC_NAME);
151 #include "headers/sym_egl.h"
153 #undef _COREGL_EXT_SYMBOL_ALIAS
154 #undef _COREGL_SYMBOL
160 _gl_sym_init(int init_version)
163 #define _COREGL_START_API(version) api_gl_version = version;
164 #define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
165 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
166 FINDGLSYM(gl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
167 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
168 FINDGLSYM(gl_lib_handle, _sym_eglGetProcAddress, _sym_##ALIAS_NAME, #FUNC_NAME);
170 if (init_version == COREGL_GLAPI_1) {
171 #include "headers/sym_gl1.h"
172 #include "headers/sym_gl_common.h"
173 } else if (init_version == COREGL_GLAPI_2) {
174 #include "headers/sym_gl2.h"
175 #include "headers/sym_gl_common.h"
178 #undef _COREGL_EXT_SYMBOL_ALIAS
179 #undef _COREGL_SYMBOL
180 #undef _COREGL_START_API
181 #undef _COREGL_END_API
190 COREGL_API void coregl_symbol_exported()
192 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL)");
195 COREGL_API void set_driver_gl_version(int version)
197 driver_gl_version = version;
203 //------------------------------------------------//
204 // Open EGL Library as EGL is separate
205 egl_lib_handle = dlopen(_COREGL_VENDOR_EGL_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
206 if (!egl_lib_handle) {
207 COREGL_ERR("%s", dlerror());
208 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
209 _COREGL_VENDOR_EGL_LIB_PATH);
213 // test for invalid linking egl
214 if (dlsym(egl_lib_handle, "coregl_symbol_exported")) {
215 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
216 _COREGL_VENDOR_EGL_LIB_PATH);
220 // use gl_lib handle for GL symbols
221 if (driver_gl_version == COREGL_GLAPI_1) {
222 gl_lib_handle = dlopen(_COREGL_VENDOR_GLV1_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
223 if (!gl_lib_handle) {
224 COREGL_ERR("%s", dlerror());
225 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
226 _COREGL_VENDOR_GLV1_LIB_PATH);
228 // test for invalid linking gl
229 if (dlsym(gl_lib_handle, "coregl_symbol_exported")) {
230 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
231 _COREGL_VENDOR_GLV1_LIB_PATH);
234 COREGL_DBG("Driver GL version 1.1");
235 _gl_sym_init(COREGL_GLAPI_1);
237 } else if (driver_gl_version == COREGL_GLAPI_2) {
238 // in case of driver library is separated
239 gl_lib_handle = dlopen(_COREGL_VENDOR_GLV1_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
241 _gl_sym_init(COREGL_GLAPI_1);
243 gl_lib_handle = dlopen(_COREGL_VENDOR_GLV2_LIB_PATH, RTLD_LAZY | RTLD_LOCAL);
244 if (!gl_lib_handle) {
245 COREGL_ERR("%s", dlerror());
246 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
247 _COREGL_VENDOR_GLV2_LIB_PATH);
249 // test for invalid linking gl
250 if (dlsym(gl_lib_handle, "coregl_symbol_exported")) {
251 COREGL_ERR("Invalid library link! (Check linkage of libCOREGL -> %s)",
252 _COREGL_VENDOR_GLV2_LIB_PATH);
256 // test for a GLES 3.x symbol
257 if (dlsym(gl_lib_handle, "glBlendBarrier")) {
258 COREGL_DBG("Driver GL version 3.2");
259 driver_gl_version = COREGL_GLAPI_32;
260 } else if (dlsym(gl_lib_handle, "glBindProgramPipeline")) {
261 COREGL_DBG("Driver GL version 3.1");
262 driver_gl_version = COREGL_GLAPI_31;
263 } else if (dlsym(gl_lib_handle, "glReadBuffer")) {
264 COREGL_DBG("Driver GL version 3.0");
265 driver_gl_version = COREGL_GLAPI_3;
267 COREGL_DBG("Driver GL version 2.0");
270 _gl_sym_init(COREGL_GLAPI_2);
282 if (egl_lib_handle) dlclose(egl_lib_handle);
283 if (gl_lib_handle) dlclose(gl_lib_handle);
291 COREGL_DBG("(%s) Library initializing...", _COREGL_COMPILE_DATE);
293 if (!_gl_lib_init()) return 0;
295 init_export(GL_TRUE, GL_TRUE);
297 COREGL_DBG(" -> Completed");
304 __attribute__((destructor))
308 if (export_initialized != 0) {
313 export_initialized = 0;