3 This file is part of gldbg
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
12 #include "arraysize.h"
17 #define UNUSED __attribute__((unused))
19 typedef struct sGlPrintData
26 static void init_print(GlDecoder *);
27 static void glprint_free(void *);
28 static void print_gldError(void *, GLenum);
29 static void print_unhandled(void *, unsigned short);
31 GlDecoder *glprint_new(char *buffer, unsigned bufsize)
36 gpd = (GlPrintData *)malloc(sizeof(GlPrintData));
38 gpd->bufsize = bufsize;
44 gpd->buffer = (char *)malloc(gpd->bufsize);
47 dec = gldecoder_new(gpd, glprint_free);
50 dec->gldError = print_gldError;
51 dec->unhandled = print_unhandled;
56 char *glprint_get_buffer(GlDecoder *dec)
58 return ((GlPrintData *)dec->user_data)->buffer;
61 static void glprint_free(void *data)
63 GlPrintData *gpd = (GlPrintData *)data;
72 static const char *print_array(const char *fmt, const void *data, unsigned elem_size, unsigned count)
84 for(cptr=fmt; (type<2 && *cptr); ++cptr)
88 else if(type==1 && isalpha(*cptr))
96 buffer = tmpalloc(buf_size);
99 for(i=0; i<count; ++i)
101 long long element = 0;
109 memcpy(&element, (const char *)data+i*elem_size, elem_size);
110 if(type>='e' && type<='g' && elem_size==sizeof(float))
111 *(double *)&element = *(float *)&element;
112 len = snprintf(ptr, buf_size, fmt, element);
122 static const char *print_array_described(const char *(*describe)(GLenum, const char *), const char *categ, const void *data, unsigned elem_size, unsigned count)
134 buffer = tmpalloc(buf_size);
137 for(i=0; i<count; ++i)
147 memcpy(&element, (const char *)data+i*elem_size, elem_size);
148 len = snprintf(ptr, buf_size, "%s", describe(element, categ));
158 static const char *print_data(const void *data, unsigned size)
162 else if((unsigned long)data<0x100000)
164 char *buffer = tmpalloc(20);
165 snprintf(buffer, 20, "%p", data);
172 char *buffer = tmpalloc(50);
173 snprintf(buffer, 50, "/* data: %d bytes */", size);
178 #include "gensrc/glprint.funcs"
180 static void print_gldError(void *user_data, GLenum code)
182 GlPrintData *gpd = (GlPrintData *)user_data;
183 snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode"));
186 static void print_unhandled(void *user_data, unsigned short func UNUSED)
188 GlPrintData *gpd = (GlPrintData *)user_data;