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)
77 for(cptr=fmt; (type<2 && *cptr); ++cptr)
81 else if(type==1 && isalpha(*cptr))
89 buffer = tmpalloc(buf_size);
92 for(i=0; i<count; ++i)
94 long long element = 0;
102 memcpy(&element, (const char *)data+i*elem_size, elem_size);
103 if(type>='e' && type<='g' && elem_size==sizeof(float))
104 *(double *)&element = *(float *)&element;
105 len = snprintf(ptr, buf_size, fmt, element);
115 static const char *print_data(const void *data, unsigned size)
123 char *buffer = tmpalloc(50);
124 snprintf(buffer, 50, "/* data: %d bytes */", size);
129 #include "glprint.funcs"
131 static void print_gldError(void *user_data, GLenum code)
133 GlPrintData *gpd = (GlPrintData *)user_data;
134 snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode"));