aboutsummaryrefslogtreecommitdiffstats
path: root/gl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl.c')
-rw-r--r--gl.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/gl.c b/gl.c
new file mode 100644
index 0000000..8e84e16
--- /dev/null
+++ b/gl.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "eprintf.h"
+#include "gl.h"
+
+#define GL_FUNC(glname, rtype, name, ...) name##_func *name;
+#include "glfunc.h"
+#undef GL_FUNC
+
+static void *load_func(const char *name, gl_loadfunc *load)
+{
+ void *ret;
+
+ ret = load(name);
+ if (ret == NULL)
+ eprintf("Could not load OpenGL function: %s\n", name);
+
+ return ret;
+}
+
+void gl_load(gl_loadfunc *load)
+{
+#define GL_FUNC(glname, rtype, name, ...) \
+ name = (name##_func *)load_func(#glname, load);
+#include "glfunc.h"
+#undef GL_FUNC
+}
+
+const char *gl_strerror(GLenum error)
+{
+ switch (error) {
+ case GL_NO_ERROR: return "No error";
+ case GL_INVALID_ENUM: return "Invalid enumeration";
+ case GL_INVALID_VALUE: return "Invalid value";
+ case GL_INVALID_OPERATION: return "Invalid operation";
+ case GL_STACK_OVERFLOW: return "Stack overflow";
+ case GL_STACK_UNDERFLOW: return "Stack underflow";
+ case GL_OUT_OF_MEMORY: return "Out of memory";
+ case GL_INVALID_FRAMEBUFFER_OPERATION: return "Invalid framebuffer operation";
+ case GL_CONTEXT_LOST: return "Context lost";
+ }
+ return "Unknown";
+}