src/error.c

changeset 16
c5dde81b6fb2
parent 15
362b7659dc76
child 58
26ebb2f1e6e6
--- a/src/error.c	Wed Nov 08 23:17:07 2023 +0100
+++ b/src/error.c	Wed Nov 15 22:51:40 2023 +0100
@@ -30,6 +30,7 @@
 #include "ascension/utils.h"
 
 #include <cx/buffer.h>
+#include <GL/gl.h>
 
 void asc_error_cchar(char const* text) {
     asc_error_cxstr(cx_str(text));
@@ -69,3 +70,37 @@
     cxBufferClear(&asc_context.error_buffer);
     asc_clear_flag(&asc_context.flags, ASC_FLAG_HAS_ERROR);
 }
+
+void asc_error_gl(unsigned code, cxstring message) {
+    const char *glerr;
+    switch(code) {
+        case GL_NO_ERROR:
+            return;
+        case GL_INVALID_ENUM:
+            glerr = "invalid enum";
+            break;
+        case GL_INVALID_VALUE:
+            glerr = "invalid value";
+            break;
+        case GL_INVALID_OPERATION:
+            glerr = "invalid operation";
+            break;
+        case GL_INVALID_FRAMEBUFFER_OPERATION:
+            glerr = "invalid framebuffer operation";
+            break;
+        case GL_OUT_OF_MEMORY:
+            glerr = "out of memory";
+            break;
+        case GL_STACK_UNDERFLOW:
+            glerr = "stack underflow";
+            break;
+        case GL_STACK_OVERFLOW:
+            glerr = "stack overflow";
+            break;
+        default:
+            glerr = "unknown GL error";
+    }
+    cxmutstr msg = cx_strcat(3, message, CX_STR(" GL Error: "), cx_str(glerr));
+    asc_error_cxstr(cx_strcast(msg));
+    cx_strfree(&msg);
+}
\ No newline at end of file

mercurial