#include "glprint.h"
#include "tmpalloc.h"
+#define UNUSED __attribute__((unused))
+
typedef struct sGlPrintData
{
char *buffer;
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)
{
init_print(dec);
dec->gldError = print_gldError;
+ dec->unhandled = print_unhandled;
return dec;
}
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; i<count; ++i)
+ {
+ int element = 0;
+ unsigned len;
+
+ if(i>0)
+ {
+ *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_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
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;
+}