X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fgliar.c;h=71f99e5eb528e3923982447e4768c1f47fcd7ff6;hb=c4d6e56bf892dd9c0de83eb2ff61375d333a8f52;hp=ccfa2ff6c1157e89f4763b67789df8730f129024;hpb=e49feadc7c6d267a329d35723b3291ae59099821;p=libgliar
diff --git a/src/gliar.c b/src/gliar.c
index ccfa2ff..71f99e5 100644
--- a/src/gliar.c
+++ b/src/gliar.c
@@ -11,11 +11,11 @@ the Free Software Foundation, either version 3 of the License, or
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+along with this program. If not, see .
Author: Eleni Maria Stea
*/
@@ -23,22 +23,64 @@ Author: Eleni Maria Stea
#include
#include
#include
+#include
#include
#include
#include
#include
#include "cfg.h"
+#ifndef GL_NUM_SHADING_LANGUAGE_VERSIONS
+#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9
+#endif
+
+static int init_valid_extensions(void);
+
static int done_init;
+
static const GLubyte* (*gl_get_string)(GLenum);
+static const GLubyte* (*gl_get_stringi)(GLenum, GLuint);
+static const void* (*gl_get_integerv)(GLenum, GLint*);
+
+/*static const void* (*gl_get_booleanv)(GLenum, GLboolean*);
+static const void* (*gl_get_doublev)(GLenum, GLdouble*);
+static const void* (*gl_get_floatv)(GLenum, GLfloat*);
+static const void* (*gl_get_integer64v)(GLenum, GLint64*);
+
+static const void* (*gl_get_booleani_v)(GLenum, GLuint, GLboolean*);
+static const void* (*gl_get_doublei_v)(GLenum, GLuint, GLdouble*);
+static const void* (*gl_get_floati_v)(GLenum, GLuint, GLfloat*);
+static const void* (*gl_get_integeri_v)(GLenum, GLuint, GLint*);
+static const void* (*gl_get_integer64i_v)(GLenum, GLuint, GLint64*);*/
+
static struct cfgopt *cfglist;
+
static int init(void)
{
if(done_init) {
return 0;
}
+ gl_get_string = dlsym(RTLD_NEXT, "glGetString");
+ gl_get_stringi = dlsym(RTLD_NEXT, "glGetStringi");
+ gl_get_integerv = dlsym(RTLD_NEXT, "glGetIntegerv");
+
+ /*gl_get_booleanv = dlsym(RTLD_NEXT, "glGetBooleanv");
+ gl_get_doublev = dlsym(RTLD_NEXT, "glGetDoublev");
+ gl_get_floatv = dlsym(RTLD_NEXT, "glGetFloatv");
+ gl_get_integer64v = dlsym(RTLD_NEXT, "glGetInteger64v");
+
+ gl_get_booleani_v = dlsym(RTLD_NEXT, "glGetBooleani_v");
+ gl_get_doublei_v = dlsym(RTLD_NEXT, "glGetDoublei_v");
+ gl_get_floati_v = dlsym(RTLD_NEXT, "glGetFloati_v");
+ gl_get_integeri_v = dlsym(RTLD_NEXT, "glGetIntegeri_v");
+ gl_get_integer64i_v = dlsym(RTLD_NEXT, "glGetInteger64i_v");*/
+
+ if(init_valid_extensions() == -1) {
+ fprintf(stderr, "GLIAR: failed to initialize the valid extension list, might end up with unavailable extensions!\n");
+ }
+
if(!(cfglist = gliar_load_cfg("gliar.conf"))) {
struct passwd *pw;
char *homedir, *path;
@@ -57,15 +99,65 @@ static int init(void)
}
}
- gl_get_string = dlsym(RTLD_NEXT, "glGetString");
-
done_init = 1;
return 0;
}
+static int init_valid_extensions(void)
+{
+ int i, num_ext, prev_space = 0;
+ const char *gl_ext_str;
+ char *ext_str, *tok, *ptr, **ext_table;
+
+ /* initialize the list of valid extensions */
+ if(!(gl_ext_str = (const char*)gl_get_string(GL_EXTENSIONS))) {
+ return -1;
+ }
+
+ if(!(ext_str = malloc(strlen(gl_ext_str) + 1))) {
+ return -1;
+ }
+ strcpy(ext_str, gl_ext_str);
+
+ /* count the extensions */
+ num_ext = 0;
+ ptr = ext_str;
+ while(*ptr) {
+ if(isspace(*ptr) && prev_space == 0) {
+ prev_space = 1;
+ num_ext++;
+ } else {
+ prev_space = 0;
+ }
+ ptr++;
+ }
+
+ /* allocate extension table */
+ if(!(ext_table = malloc(num_ext * sizeof *ext_table))) {
+ free(ext_str);
+ return -1;
+ }
+
+ /* setup the ext_table slots to point to the start of each substring (extension) */
+ for(i=0; iconc_vals;
}
return gl_get_string(name);
}
+
+const GLubyte *glGetStringi(GLenum name, GLuint index)
+{
+ char *key;
+ const struct cfgopt *option;
+
+ init();
+
+ switch(name) {
+ case GL_EXTENSIONS:
+ key = "extensions";
+ break;
+
+ case GL_SHADING_LANGUAGE_VERSION:
+ key = "sl version";
+ break;
+
+ default:
+ key = 0;
+ }
+
+ if(key && (option = gliar_find_opt(cfglist, key))) {
+ return (const GLubyte*)option->str_val[index];
+ }
+
+ return gl_get_stringi(name, index);
+}
+
+void glGetIntegerv(GLenum name, GLint *val)
+{
+ char *key;
+ const struct cfgopt *option;
+
+ init();
+
+ switch(name) {
+ case GL_NUM_EXTENSIONS:
+ if(1) {
+ key = "extensions";
+ } else {
+ case GL_NUM_SHADING_LANGUAGE_VERSIONS:
+ key = "sl version";
+ }
+ if(key && (option = gliar_find_opt(cfglist, key))) {
+ *val = option->str_count;
+ return;
+ }
+ break;
+
+ case GL_MAX_TEXTURE_UNITS:
+ key = "max texture units";
+ break;
+
+ case GL_MAX_TEXTURE_SIZE:
+ key = "max texture size";
+ break;
+
+ case GL_MAX_TEXTURE_COORDS:
+ key = "max texture coordinates";
+ break;
+
+ case GL_MAX_VERTEX_ATTRIBS:
+ key = "max vertex attributes";
+ break;
+
+ case GL_MAX_RENDERBUFFER_SIZE_EXT:
+ key = "max renderbuffer size";
+ break;
+
+ default:
+ key = 0;
+ }
+
+ if(key && (option = gliar_find_opt(cfglist, key)) && option->type == GLIAR_NUMBER) {
+ *val = option->num_val;
+ return;
+ }
+
+ gl_get_integerv(name, val);
+}