X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglprint.c;h=21f7fe5c65e962bf16ffad4ecfee42de3d149653;hb=3fce21d3193c09840cfbaa96fe05b00b7444fd66;hp=8dacdb338b1834765dcb25554835cea5fb31343e;hpb=03c86c2f632b642aa94f721e326787e91aa69c25;p=gldbg.git diff --git a/source/glprint.c b/source/glprint.c index 8dacdb3..21f7fe5 100644 --- a/source/glprint.c +++ b/source/glprint.c @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - #include #include #include @@ -14,6 +7,8 @@ Distributed under the GPL #include "glprint.h" #include "tmpalloc.h" +#define UNUSED __attribute__((unused)) + typedef struct sGlPrintData { char *buffer; @@ -24,6 +19,7 @@ typedef struct sGlPrintData static void init_print(GlDecoder *); static void glprint_free(void *); static void print_gldError(void *, GLenum); +static void print_unhandled(void *, unsigned short); GlDecoder *glprint_new(char *buffer, unsigned bufsize) { @@ -45,6 +41,7 @@ GlDecoder *glprint_new(char *buffer, unsigned bufsize) init_print(dec); dec->gldError = print_gldError; + dec->unhandled = print_unhandled; return dec; } @@ -103,9 +100,14 @@ static const char *print_array(const char *fmt, const void *data, unsigned elem_ *ptr++ = ' '; } memcpy(&element, (const char *)data+i*elem_size, elem_size); - if(type>='e' && type<='g' && elem_size==sizeof(float)) - *(double *)&element = *(float *)&element; - len = snprintf(ptr, buf_size, fmt, element); + if(type>='e' && type<='g') + { + if(elem_size==sizeof(float)) + *(double *)&element = *(float *)&element; + len = snprintf(ptr, buf_size, fmt, *(double *)&element); + } + else + len = snprintf(ptr, buf_size, fmt, element); ptr += len; buf_size -= len; } @@ -115,10 +117,83 @@ static const char *print_array(const char *fmt, const void *data, unsigned elem_ return buffer; } +static const char *print_array_described(const char *(*describe)(GLenum, const char *), const char *categ, const void *data, unsigned elem_size, unsigned count) +{ + char *buffer; + unsigned buf_size; + char *ptr; + unsigned i; + + if(!data) + return NULL; + + count /= elem_size; + buf_size = count*50; + buffer = tmpalloc(buf_size); + ptr = buffer; + *ptr++ = '{'; + for(i=0; i0) + { + *ptr++ = ','; + *ptr++ = ' '; + } + memcpy(&element, (const char *)data+i*elem_size, elem_size); + len = snprintf(ptr, buf_size, "%s", describe(element, categ)); + ptr += len; + buf_size -= len; + } + *ptr++ = '}'; + *ptr = 0; + + return buffer; +} + +static const char *print_parameter(int pname, int param) +{ + char *buffer; + + // XXX Need to move the param names to flavor + switch(pname) + { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + return describe_enum(param, ""); + } + + buffer = tmpalloc(11); + snprintf(buffer, 11, "%i", param); + return buffer; +} + +static const char *print_internal_format(int fmt) +{ + char *buffer; + + if(fmt>4) + return describe_enum(fmt, "PixelFormat"); + + buffer = tmpalloc(2); + snprintf(buffer, 2, "%i", fmt); + return buffer; +} + static const char *print_data(const void *data, unsigned size) { if(!data) return "NULL"; + else if((unsigned long)data<0x100000) + { + char *buffer = tmpalloc(20); + snprintf(buffer, 20, "%p", data); + return buffer; + } else if(!size) return "/* data */"; else @@ -136,3 +211,9 @@ static void print_gldError(void *user_data, GLenum code) GlPrintData *gpd = (GlPrintData *)user_data; snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode")); } + +static void print_unhandled(void *user_data, unsigned short func UNUSED) +{ + GlPrintData *gpd = (GlPrintData *)user_data; + gpd->buffer[0] = 0; +}