X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglwrap.c;h=52c6552e1f5c0c007939e62f07a31e233ba8e587;hb=03c86c2f632b642aa94f721e326787e91aa69c25;hp=a33021a70a89f70c988ea0694ff9f7910ff9e702;hpb=9d1825d591a7261b1cff620ba535d333352984bf;p=gldbg.git diff --git a/source/glwrap.c b/source/glwrap.c index a33021a..52c6552 100644 --- a/source/glwrap.c +++ b/source/glwrap.c @@ -1,7 +1,7 @@ /* $Id$ This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ @@ -10,222 +10,192 @@ Distributed under the GPL #include #include #include -#include -#include "functions.h" -static inline void *glsym(const char *sym) +#define INTERNAL __attribute__((visibility("internal"))) + +INTERNAL inline const char *get_lib_names(void) +{ + const char *env = getenv("GLWRAP_LIBS"); + if(env) + return env; + return "libGL.so"; +} + +INTERNAL inline void *glsym(const char *name) { - static void *libgl=NULL; - if(!libgl) + static void **gl_libs = NULL; + unsigned i; + + if(!gl_libs) { - libgl=dlopen("libGL.so", RTLD_NOW); - if(!libgl) + char *lib_names = strdup(get_lib_names()); + unsigned n_libs = 1; + unsigned j; + + for(i=0; lib_names[i]; ++i) + if(lib_names[i]==':') + ++n_libs; + + gl_libs = (void **)malloc((n_libs+1)*sizeof(void *)); + i = 0; + n_libs = 0; + for(j=0;; ++j) { - fprintf(stderr, "Could not open libGL: %s\n", dlerror()); - abort(); + if(lib_names[j]==':' || lib_names[j]==0) + { + int at_end = (lib_names[j]==0); + lib_names[j] = 0; + + gl_libs[n_libs] = dlopen(lib_names+i, RTLD_NOW); + if(!gl_libs[n_libs]) + { + fprintf(stderr, "Could not open %s: %s\n", lib_names+i, dlerror()); + abort(); + } + + i = j+1; + ++n_libs; + + if(at_end) + break; + } } + + gl_libs[n_libs] = 0; + free(lib_names); } - return dlsym(libgl, sym); + for(i=0; gl_libs[i]; ++i) + { + void *sym = dlsym(gl_libs[i], name); + if(sym) + return sym; + } + + return NULL; } -char *buffer=0; -char *write_pos; -struct iovec *iovecs=0; -struct iovec *cur_vec; +INTERNAL char *buffer = 0; +INTERNAL char *write_pos; +INTERNAL struct iovec *iovecs = 0; +INTERNAL struct iovec *cur_vec; +INTERNAL unsigned length; -static inline void next_vec() +INTERNAL inline void next_vec(void) { if(write_pos!=cur_vec->iov_base) { - cur_vec->iov_len=write_pos-(char *)cur_vec->iov_base; + cur_vec->iov_len = write_pos-(char *)cur_vec->iov_base; + length += cur_vec->iov_len; ++cur_vec; - cur_vec->iov_base=write_pos; + cur_vec->iov_base = write_pos; } } -static inline void write_bytes(const char *ptr, unsigned size) +INTERNAL inline void write_bytes(const char *ptr, unsigned size) { unsigned i; for(i=0; iiov_base=(void *)data; - cur_vec->iov_len=size; - ++cur_vec; - cur_vec->iov_base=write_pos; + if(data) + { + write_int(size); + next_vec(); + cur_vec->iov_base = (void *)data; + cur_vec->iov_len = size; + length += size; + ++cur_vec; + cur_vec->iov_base = write_pos; + } + else + write_int(0); } -static inline void write_string(const unsigned char *s) +INTERNAL inline void write_string(const char *s) { - write_data(s, strlen(s)); - /*int len=strlen(s); - write_int(len); - write_bytes(s, len);*/ + write_data(s, strlen(s)+1); } -static inline void begin_packet(int func) +INTERNAL inline void write_string_array(const char **sa, unsigned size) +{ + unsigned i; + size /= sizeof(const char *); + write_int(size); + for(i=0; iiov_base=write_pos; + iovecs = (struct iovec *)malloc(16*sizeof(struct iovec)); + write_pos = buffer; + cur_vec = iovecs; + cur_vec->iov_base = write_pos; + length = 0; + write_int(0); write_short(func); } -static inline void send_packet() +INTERNAL inline void send_packet(void) { - static int fd=-1; + static int fd = -1; if(fd<0) { - const char *var=getenv("GLWRAP_FD"); + const char *var = getenv("GLWRAP_FD"); if(var) - fd=strtol(var, NULL, 0); + fd = strtol(var, NULL, 0); else - fd=2; + fd = 2; } next_vec(); + write_pos = buffer; + write_int(length); writev(fd, iovecs, cur_vec-iovecs); } - -static inline int typesize(GLenum type) -{ - switch(type) - { - case GL_BYTE: return sizeof(GLbyte); - case GL_SHORT: return sizeof(GLshort); - case GL_INT: return sizeof(GLint); - case GL_UNSIGNED_BYTE: return sizeof(GLubyte); - case GL_UNSIGNED_SHORT: return sizeof(GLushort); - case GL_UNSIGNED_INT: return sizeof(GLuint); - case GL_FLOAT: return sizeof(GLfloat); - case GL_DOUBLE: return sizeof(GLdouble); - // Short and byte packed types are broken - default: return 1; - } -} - -static inline int formatsize(GLenum format) -{ - switch(format) - { - case GL_COLOR_INDEX: return 1; - case GL_STENCIL_INDEX: return 1; - case GL_DEPTH_COMPONENT: return 1; - case GL_RED: return 1; - case GL_GREEN: return 1; - case GL_BLUE: return 1; - case GL_ALPHA: return 1; - case GL_RGB: return 3; - case GL_RGBA: return 4; - case GL_BGR: return 3; - case GL_BGRA: return 4; - case GL_LUMINANCE: return 1; - case GL_LUMINANCE_ALPHA: return 2; - default: return 1; - } -} - -static inline int paramsize(GLenum pname) -{ - switch(pname) - { - // Lighting and material - case GL_AMBIENT: return 4; - case GL_DIFFUSE: return 4; - case GL_AMBIENT_AND_DIFFUSE: return 4; - case GL_SPECULAR: return 4; - case GL_EMISSION: return 4; - case GL_SHININESS: return 1; - case GL_COLOR_INDEXES: return 3; - case GL_POSITION: return 4; - case GL_SPOT_DIRECTION: return 3; - case GL_SPOT_EXPONENT: return 1; - case GL_SPOT_CUTOFF: return 1; - case GL_CONSTANT_ATTENUATION: return 1; - case GL_LINEAR_ATTENUATION: return 1; - case GL_QUADRATIC_ATTENUATION: return 1; - case GL_LIGHT_MODEL_AMBIENT: return 4; - case GL_LIGHT_MODEL_LOCAL_VIEWER: return 1; - case GL_LIGHT_MODEL_TWO_SIDE: return 1; - case GL_LIGHT_MODEL_COLOR_CONTROL: return 1; - - // Texture - case GL_TEXTURE_WRAP_S: return 1; - case GL_TEXTURE_WRAP_T: return 1; - case GL_TEXTURE_WRAP_R: return 1; - case GL_TEXTURE_MIN_FILTER: return 1; - case GL_TEXTURE_MAG_FILTER: return 1; - case GL_TEXTURE_BORDER_COLOR: return 4; - case GL_TEXTURE_MIN_LOD: return 1; - case GL_TEXTURE_MAX_LOD: return 1; - case GL_TEXTURE_BASE_LEVEL: return 1; - case GL_TEXTURE_MAX_LEVEL: return 1; - case GL_TEXTURE_LOD_BIAS: return 1; - case GL_DEPTH_TEXTURE_MODE: return 1; - case GL_TEXTURE_COMPARE_MODE: return 1; - case GL_TEXTURE_COMPARE_FUNC: return 1; - case GL_GENERATE_MIPMAP: return 1; - default: return 1; - } -} - -static inline int mapsize(GLenum target) -{ - return 1; -} - -#include "glwrap.funcs"