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_parameter(int pname, int param)
162 // XXX Need to move the param names to flavor
165 case GL_TEXTURE_MIN_FILTER:
166 case GL_TEXTURE_MAG_FILTER:
167 case GL_TEXTURE_WRAP_S:
168 case GL_TEXTURE_WRAP_T:
169 return describe_enum(param, "");
172 buffer = tmpalloc(11);
173 snprintf(buffer, 11, "%i", param);
177 static const char *print_internal_format(int fmt)
182 return describe_enum(fmt, "PixelFormat");
184 buffer = tmpalloc(2);
185 snprintf(buffer, 2, "%i", fmt);
189 static const char *print_data(const void *data, unsigned size)
193 else if((unsigned long)data<0x100000)
195 char *buffer = tmpalloc(20);
196 snprintf(buffer, 20, "%p", data);
203 char *buffer = tmpalloc(50);
204 snprintf(buffer, 50, "/* data: %d bytes */", size);
209 #include "gensrc/glprint.funcs"
211 static void print_gldError(void *user_data, GLenum code)
213 GlPrintData *gpd = (GlPrintData *)user_data;
214 snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode"));
217 static void print_unhandled(void *user_data, unsigned short func UNUSED)
219 GlPrintData *gpd = (GlPrintData *)user_data;