3 This file is part of gldbg
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
12 #include "arraysize.h"
17 typedef struct sGlPrintData
24 static void init_print(GlDecoder *);
25 static void glprint_free(void *);
26 static void print_gldError(void *, GLenum);
28 GlDecoder *glprint_new(char *buffer, unsigned bufsize)
33 gpd = (GlPrintData *)malloc(sizeof(GlPrintData));
35 gpd->bufsize = bufsize;
41 gpd->buffer = (char *)malloc(gpd->bufsize);
44 dec = gldecoder_new(gpd, glprint_free);
47 dec->gldError = print_gldError;
52 char *glprint_get_buffer(GlDecoder *dec)
54 return ((GlPrintData *)dec->user_data)->buffer;
57 static void glprint_free(void *data)
59 GlPrintData *gpd = (GlPrintData *)data;
68 static const char *print_array(const char *fmt, const void *data, unsigned elem_size, unsigned count)
80 for(cptr=fmt; (type<2 && *cptr); ++cptr)
84 else if(type==1 && isalpha(*cptr))
92 buffer = tmpalloc(buf_size);
95 for(i=0; i<count; ++i)
97 long long element = 0;
105 memcpy(&element, (const char *)data+i*elem_size, elem_size);
106 if(type>='e' && type<='g' && elem_size==sizeof(float))
107 *(double *)&element = *(float *)&element;
108 len = snprintf(ptr, buf_size, fmt, element);
118 static const char *print_data(const void *data, unsigned size)
126 char *buffer = tmpalloc(50);
127 snprintf(buffer, 50, "/* data: %d bytes */", size);
132 #include "gensrc/glprint.funcs"
134 static void print_gldError(void *user_data, GLenum code)
136 GlPrintData *gpd = (GlPrintData *)user_data;
137 snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode"));