mojoshader_opengl.c
branchtrunk
changeset 219 61167fc96790
parent 216 f5f4e5f05951
child 220 df5ea69833d5
--- a/mojoshader_opengl.c	Sun Apr 27 04:59:30 2008 -0400
+++ b/mojoshader_opengl.c	Sun Apr 27 05:01:18 2008 -0400
@@ -65,6 +65,14 @@
 // GL stuff...
 static MOJOSHADER_glProgram *bound_program = NULL;
 
+// Error state...
+static char error_buffer[1024] = { '\0' };
+
+static void set_error(const char *str)
+{
+    snprintf(error_buffer, sizeof (error_buffer), "%s", str);
+} // set_error
+
 
 // #define this to force app to supply an allocator, so there's no reference
 //  to the C runtime's malloc() and free()...
@@ -87,14 +95,25 @@
 } // Free
 
 
+const char *MOJOSHADER_glGetError(void)
+{
+    return error_buffer;
+} // MOJOSHADER_glGetError
+
+
 int MOJOSHADER_glInit(const char *_profile,
                       void *(*lookup)(const char *fnname),
                       MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
 {
+    error_buffer[0] = '\0';
+
     if (strcmp(_profile, MOJOSHADER_PROFILE_GLSL) != 0)
         profile = MOJOSHADER_PROFILE_GLSL;
     else
+    {
+        set_error("unknown profile");
         return 0;
+    } // else
 
     // !!! FIXME: lookup glGetString(), check extensions.
 
@@ -126,7 +145,10 @@
                                                       bufsize, malloc_fn,
                                                       free_fn, malloc_data);
     if (pd->error != NULL)
+    {
+        set_error(pd->error);
         goto compile_shader_fail;
+    } // if
 
     retval = (MOJOSHADER_glShader *) Malloc(sizeof (MOJOSHADER_glShader));
     if (retval == NULL)
@@ -143,10 +165,9 @@
 
     if (!ok)
     {
-        GLcharARB err[1024];
         GLsizei len = 0;
-        pglGetInfoLogARB(shader, sizeof (err), &len, err);
-        //printf("FAIL: %s glsl compile: %s\n", fname, err);
+        pglGetInfoLogARB(shader, sizeof (error_buffer), &len,
+                         (GLcharARB *) error_buffer);
         goto compile_shader_fail;
     } // if
 
@@ -262,10 +283,9 @@
     pglGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
     if (!ok)
     {
-        GLcharARB err[1024];
         GLsizei len = 0;
-        pglGetInfoLogARB(program, sizeof (err), &len, err);
-        //printf("FAIL: %s glsl link: %s\n", fname, err);
+        pglGetInfoLogARB(shader, sizeof (error_buffer), &len,
+                         (GLcharARB *) error_buffer);
         goto link_program_fail;
     } // if
 
@@ -568,6 +588,7 @@
     malloc_fn = NULL;
     free_fn = NULL;
     malloc_data = NULL;
+    error_buffer[0] = '\0';
 
     // !!! FIXME: NULL entry points.
 } // MOJOSHADER_glDeinit