1 #include "idlib/precompiled.h"
2 #include "renderer/tr_local.h"
3 #include "sys/linux/local.h"
4 #include "glimp_local.h"
8 dnl =====================================================
10 dnl =====================================================
13 `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
15 `$4`'ifelse($1, `$3', ,
16 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
18 dnl =====================================================
19 dnl the gl wgl glX definitions
20 dnl =====================================================
21 include(../gllog/gl_def.m4)
23 dnl =====================================================
25 dnl =====================================================
27 define(`instance_funcptr', ``$1' ( APIENTRY * qgl`$2' )(`$3');')
28 forloop(`i', gl_start, gl_end, `instance_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
31 dnl =====================================================
33 dnl =====================================================
35 define(`instance_funcptr', ``$1' ( * qglX`$2' )(`$3');')
36 forloop(`i', glX_start, glX_end, `instance_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
39 dnl =====================================================
41 dnl those are the actual dlsym'ed pointers
42 dnl logging configuration redirects qgl / qglX to either log or dll versions
43 dnl =====================================================
45 define(`instance_funcptr', ``$1' ( * dll`$2' )(`$3');')
46 forloop(`i', gl_start, gl_end, `instance_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
48 forloop(`i', glX_start, glX_end, `instance_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
51 dnl =====================================================
53 dnl =====================================================
56 ======================
58 ======================
60 void GLimp_BindNative() {
61 define(`assign_funcptr', `qgl`$1' = dll`$1';')
62 forloop(`i', gl_start, gl_end, `assign_funcptr(indir(`f'i`_name'))
65 define(`assign_funcptr', `qglX`$1' = dll`$1';')
66 forloop(`i', glX_start, glX_end, `assign_funcptr(indir(`f'i`_name'))
70 static void *glHandle = NULL;
73 ======================
75 ======================
77 void GLimp_dlsym_failed(const char *name) {
78 common->DPrintf("dlsym(%s) failed: %s\n", name, dlerror());
82 ======================
84 ======================
87 const char *driverName = r_glDriver.GetString()[0] ? r_glDriver.GetString() : "libGL.so.1";
88 common->Printf("dlopen(%s)\n", driverName);
89 if ( !( glHandle = dlopen( driverName, RTLD_NOW | RTLD_GLOBAL ) ) ) {
90 common->DPrintf("dlopen(%s) failed: %s\n", driverName, dlerror());
96 define(`dlsym_funcptr', `dll`$2' = ( `$1' ( APIENTRY *)(`$3') ) dlsym( glHandle, "gl`$2'" );')
97 define(`safe_dlsym_funcptr', `dlsym_funcptr(`$1', `$2', `$3')
98 if (!dll`$2') { GLimp_dlsym_failed("gl`$2'"); return false; }')
99 forloop(`i', gl_start, gl_end, `safe_dlsym_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
102 define(`dlsym_funcptr', `dll`$2' = ( `$1' ( APIENTRY *)(`$3') ) dlsym( glHandle, "glX`$2'" );')
103 define(`safe_dlsym_funcptr', `dlsym_funcptr(`$1', `$2', `$3')
104 if (!dll`$2') { GLimp_dlsym_failed("glX`$2'"); return false; }')
105 forloop(`i', glX_start, glX_end, `safe_dlsym_funcptr(indir(`f'i`_ret'), indir(`f'i`_name'), indir(`f'i`_params'))
108 // make the initial binding
115 ======================
117 ======================
119 void GLimp_dlclose() {
121 common->DPrintf("dlclose: GL handle is NULL\n");
127 define(`reset_funcptr', `qgl`$1' = NULL;')
128 forloop(`i', gl_start, gl_end, `reset_funcptr(indir(`f'i`_name'))
131 define(`reset_funcptr', `qglX`$1' = NULL;')
132 forloop(`i', glX_start, glX_end, `reset_funcptr(indir(`f'i`_name'))