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 const void* (*gl_get_integerv)(GLenum, GLint*);
45 /*static const void* (*gl_get_booleanv)(GLenum, GLboolean*);
46 static const void* (*gl_get_doublev)(GLenum, GLdouble*);
47 static const void* (*gl_get_floatv)(GLenum, GLfloat*);
48 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;
65 gl_get_string = dlsym(RTLD_NEXT, "glGetString");
66 gl_get_stringi = dlsym(RTLD_NEXT, "glGetStringi");
67 gl_get_integerv = dlsym(RTLD_NEXT, "glGetIntegerv");
69 /*gl_get_booleanv = dlsym(RTLD_NEXT, "glGetBooleanv");
70 gl_get_doublev = dlsym(RTLD_NEXT, "glGetDoublev");
71 gl_get_floatv = dlsym(RTLD_NEXT, "glGetFloatv");
72 gl_get_integer64v = dlsym(RTLD_NEXT, "glGetInteger64v");
74 gl_get_booleani_v = dlsym(RTLD_NEXT, "glGetBooleani_v");
75 gl_get_doublei_v = dlsym(RTLD_NEXT, "glGetDoublei_v");
76 gl_get_floati_v = dlsym(RTLD_NEXT, "glGetFloati_v");
77 gl_get_integeri_v = dlsym(RTLD_NEXT, "glGetIntegeri_v");
78 gl_get_integer64i_v = dlsym(RTLD_NEXT, "glGetInteger64i_v");*/
80 if(init_valid_extensions() == -1) {
81 fprintf(stderr, "GLIAR: failed to initialize the valid extension list, might end up with unavailable extensions!\n");
84 if(!(cfglist = gliar_load_cfg("gliar.conf"))) {
88 if((pw = getpwuid(getuid()))) {
91 homedir = getenv("HOME");
95 path = alloca(strlen(homedir) + strlen(".gliar.conf") + 2);
96 sprintf(path, "%s/.gliar.conf", homedir);
98 cfglist = gliar_load_cfg(path);
106 static int init_valid_extensions(void)
108 int i, num_ext, prev_space = 0;
109 const char *gl_ext_str;
110 char *ext_str, *tok, *ptr, **ext_table;
112 /* initialize the list of valid extensions */
113 if(!(gl_ext_str = (const char*)gl_get_string(GL_EXTENSIONS))) {
117 if(!(ext_str = malloc(strlen(gl_ext_str) + 1))) {
120 strcpy(ext_str, gl_ext_str);
122 /* count the extensions */
126 if(isspace(*ptr) && prev_space == 0) {
135 /* allocate extension table */
136 if(!(ext_table = malloc(num_ext * sizeof *ext_table))) {
141 /* setup the ext_table slots to point to the start of each substring (extension) */
142 for(i=0; i<num_ext; i++) {
143 if(!(tok = strtok(i == 0 ? ext_str : 0, " \t\v\n\r"))) {
144 fprintf(stderr, "DEBUG: strtok returned 0 at token %d\n", i);
150 gliar_value_set("extensions", ext_table, num_ext);
157 const GLubyte *glGetString(GLenum name)
160 const struct cfgopt *option;
181 case GL_SHADING_LANGUAGE_VERSION:
189 if(key && (option = gliar_find_opt(cfglist, key))) {
190 return (const GLubyte*)option->conc_vals;
193 return gl_get_string(name);
196 const GLubyte *glGetStringi(GLenum name, GLuint index)
199 const struct cfgopt *option;
208 case GL_SHADING_LANGUAGE_VERSION:
216 if(key && (option = gliar_find_opt(cfglist, key))) {
217 return (const GLubyte*)option->str_val[index];
220 return gl_get_stringi(name, index);
223 void glGetIntegerv(GLenum name, GLint *val)
226 const struct cfgopt *option;
231 case GL_NUM_EXTENSIONS:
235 case GL_NUM_SHADING_LANGUAGE_VERSIONS:
238 if(key && (option = gliar_find_opt(cfglist, key))) {
239 *val = option->str_count;
244 case GL_MAX_TEXTURE_UNITS:
245 key = "max texture units";
248 case GL_MAX_TEXTURE_SIZE:
249 key = "max texture size";
252 case GL_MAX_TEXTURE_COORDS:
253 key = "max texture coordinates";
260 if(key && (option = gliar_find_opt(cfglist, key)) && option->type == GLIAR_NUMBER) {
261 *val = option->num_val;
265 gl_get_integerv(name, val);