2 libgliar - a library that can fake the OpenGL context info returned by
5 Copyright (C) 2013 Canonical Ltd
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Author: Eleni Maria Stea <elene.mst@gmail.com>
33 #ifndef GL_NUM_SHADING_LANGUAGE_VERSIONS
34 #define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9
37 static int init_valid_extensions(void);
41 static const GLubyte* (*gl_get_string)(GLenum);
42 static const GLubyte* (*gl_get_stringi)(GLenum, GLuint);
43 static void (*gl_get_integerv)(GLenum, GLint*);
44 static void (*gl_get_programiv)(GLuint, GLenum, GLint*);
46 /*static const void* (*gl_get_booleanv)(GLenum, GLboolean*);
47 static const void* (*gl_get_doublev)(GLenum, GLdouble*);
48 static const void* (*gl_get_floatv)(GLenum, GLfloat*);
49 static const void* (*gl_get_integer64v)(GLenum, GLint64*);
50 static const void* (*gl_get_booleani_v)(GLenum, GLuint, GLboolean*);
51 static const void* (*gl_get_doublei_v)(GLenum, GLuint, GLdouble*);
52 static const void* (*gl_get_floati_v)(GLenum, GLuint, GLfloat*);
53 static const void* (*gl_get_integeri_v)(GLenum, GLuint, GLint*);
54 static const void* (*gl_get_integer64i_v)(GLenum, GLuint, GLint64*);*/
56 static struct cfgopt *cfglist;
64 gl_get_string = dlsym(RTLD_NEXT, "glGetString");
65 gl_get_stringi = dlsym(RTLD_NEXT, "glGetStringi");
66 gl_get_integerv = dlsym(RTLD_NEXT, "glGetIntegerv");
67 gl_get_programiv = dlsym(RTLD_NEXT, "glGetProgramivARB");
69 if(init_valid_extensions() == -1) {
70 fprintf(stderr, "GLIAR: failed to initialize the valid extension list, might end up with unavailable extensions!\n");
73 if(!(cfglist = gliar_load_cfg("gliar.conf"))) {
77 if((pw = getpwuid(getuid()))) {
80 homedir = getenv("HOME");
84 path = alloca(strlen(homedir) + strlen(".gliar.conf") + 2);
85 sprintf(path, "%s/.gliar.conf", homedir);
87 cfglist = gliar_load_cfg(path);
95 static int init_valid_extensions(void)
97 int i, num_ext, prev_space = 0;
98 const char *gl_ext_str;
99 char *ext_str, *tok, *ptr, **ext_table;
101 /* initialize the list of valid extensions */
102 if(!(gl_ext_str = (const char*)gl_get_string(GL_EXTENSIONS))) {
106 if(!(ext_str = malloc(strlen(gl_ext_str) + 1))) {
109 strcpy(ext_str, gl_ext_str);
111 /* count the extensions */
115 if(isspace(*ptr) && prev_space == 0) {
124 /* allocate extension table */
125 if(!(ext_table = malloc(num_ext * sizeof *ext_table))) {
130 /* setup the ext_table slots to point to the start of each substring (extension) */
131 for(i=0; i<num_ext; i++) {
132 if(!(tok = strtok(i == 0 ? ext_str : 0, " \t\v\n\r"))) {
133 fprintf(stderr, "DEBUG: strtok returned 0 at token %d\n", i);
139 gliar_value_set("extensions", ext_table, num_ext);
146 const GLubyte *glGetString(GLenum name)
149 const struct cfgopt *option;
154 fprintf(stderr, "Unable to fake the %s function. It is not supported by your OpenGL implementation.\n", __func__);
175 case GL_SHADING_LANGUAGE_VERSION:
183 if(key && (option = gliar_find_opt(cfglist, key))) {
184 return (const GLubyte*)option->conc_vals;
187 return gl_get_string(name);
190 const GLubyte *glGetStringi(GLenum name, GLuint index)
193 const struct cfgopt *option;
197 if(!gl_get_stringi) {
198 fprintf(stderr, "Unable to fake the %s function. It is not supported by your OpenGL implementation.\n", __func__);
207 case GL_SHADING_LANGUAGE_VERSION:
215 if(key && (option = gliar_find_opt(cfglist, key))) {
216 return (const GLubyte*)option->str_val[index];
219 return gl_get_stringi(name, index);
222 void glGetIntegerv(GLenum name, GLint *val)
225 const struct cfgopt *option;
229 if(!gl_get_integerv) {
230 fprintf(stderr, "Unable to fake the %s function. It is not supported by your OpenGL implementation.\n", __func__);
235 case GL_NUM_EXTENSIONS:
239 case GL_NUM_SHADING_LANGUAGE_VERSIONS:
242 if(key && (option = gliar_find_opt(cfglist, key))) {
243 *val = option->str_count;
248 case GL_MAJOR_VERSION:
249 key = "major version";
252 case GL_MINOR_VERSION:
253 key = "minor version";
256 case GL_MAX_TEXTURE_UNITS:
257 key = "max texture units";
260 case GL_MAX_TEXTURE_IMAGE_UNITS:
261 key = "max texture image units";
264 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
265 key = "max combined texture image units";
268 case GL_MAX_TEXTURE_SIZE:
269 key = "max texture size";
272 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
273 key = "max cube map texture size";
276 case GL_MAX_TEXTURE_COORDS:
277 key = "max texture coordinates";
280 case GL_MAX_VERTEX_ATTRIBS:
281 key = "max vertex attributes";
284 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
285 key = "max vertex texture image units";
288 case GL_MAX_VERTEX_UNIFORM_VECTORS:
289 key = "max vertex uniform vectors";
292 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
293 key = "max fragment uniform vectors";
296 case GL_MAX_VARYING_VECTORS:
297 key = "max varying vectors";
300 case GL_MAX_COLOR_ATTACHMENTS_EXT:
301 key = "max color attachments";
304 case GL_MAX_RENDERBUFFER_SIZE_EXT:
305 key = "max renderbuffer size ext";
312 if(key && (option = gliar_find_opt(cfglist, key)) && option->type == GLIAR_NUMBER) {
313 *val = option->num_val;
317 gl_get_integerv(name, val);
320 void glGetProgramivARB(GLuint program, GLenum pname, GLint *params)
323 const struct cfgopt *option;
327 if(!gl_get_programiv) {
328 fprintf(stderr, "Unable to fake the %s function. It is not supported by your OpenGL implementation.\n", __func__);
333 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
334 key = "max program instructions arb";
337 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
338 key = "max program native instructions arb";
341 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
342 key = "max program temporaries arb";
345 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
346 key = "max program native temporaries arb";
349 case GL_MAX_PROGRAM_PARAMETERS_ARB:
350 key = "max program parameters arb";
353 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
354 key = "max program native parameters arb";
357 case GL_MAX_PROGRAM_ATTRIBS_ARB:
358 key = "max program attribs arb";
361 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
362 key = "max program native attribs arb";
365 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
366 key = "max program address registers arb";
369 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
370 key = "max program native address registers arb";
373 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
374 key = "max program local parameters arb";
377 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
378 key = "max program env parameters arb";
381 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
382 key = "max program alu instructions arb";
385 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
386 key = "max program native alu instructions arb";
389 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
390 key = "max program tex instructions arb";
393 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
394 key = "max program native tex instructions arb";
401 if(key && (option = gliar_find_opt(cfglist, key)) && option->type == GLIAR_NUMBER) {
402 *params = option->num_val;
406 gl_get_programiv(program, pname, params);