aboutsummaryrefslogtreecommitdiffstats
path: root/loadgl.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-03-26 16:38:09 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-03-26 19:49:24 +0100
commitca761a910c25197b10aeadcb0120dae132442d56 (patch)
treef28b134d78b87628178fb28130728c56c9949f26 /loadgl.c
downloadfaqe-ca761a910c25197b10aeadcb0120dae132442d56.tar.gz
faqe-ca761a910c25197b10aeadcb0120dae132442d56.tar.xz
faqe-ca761a910c25197b10aeadcb0120dae132442d56.zip
init commit
Diffstat (limited to 'loadgl.c')
-rw-r--r--loadgl.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/loadgl.c b/loadgl.c
new file mode 100644
index 0000000..0dbd720
--- /dev/null
+++ b/loadgl.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+#include <setjmp.h>
+
+#include "loadgl.h"
+
+#define LGL_FUNC(name, glname) \
+ name##_func *name; \
+ static const char *name##_gln = #glname;
+
+LGL_FUNC(gl_viewport, glViewport);
+LGL_FUNC(gl_clearcolor, glClearColor);
+LGL_FUNC(gl_clear, glClear);
+LGL_FUNC(gl_buf_gen, glGenBuffers);
+LGL_FUNC(gl_buf_bind, glBindBuffer);
+LGL_FUNC(gl_buf_data, glBufferData);
+LGL_FUNC(gl_shdr_create, glCreateShader);
+LGL_FUNC(gl_shdr_del, glDeleteShader);
+LGL_FUNC(gl_shdr_source, glShaderSource);
+LGL_FUNC(gl_shdr_compile, glCompileShader);
+LGL_FUNC(gl_shdr_param, glGetShaderiv);
+LGL_FUNC(gl_shdr_infolog, glGetShaderInfoLog);
+LGL_FUNC(gl_prog_create, glCreateProgram);
+LGL_FUNC(gl_prog_attachshdr, glAttachShader);
+LGL_FUNC(gl_prog_link, glLinkProgram);
+LGL_FUNC(gl_prog_use, glUseProgram);
+LGL_FUNC(gl_prog_del, glDeleteProgram);
+LGL_FUNC(gl_prog_param, glGetProgramiv);
+LGL_FUNC(gl_prog_infolog, glGetProgramInfoLog);
+LGL_FUNC(gl_va_define, glVertexAttribPointer);
+LGL_FUNC(gl_va_enable, glEnableVertexAttribArray);
+LGL_FUNC(gl_va_disable, glDisableVertexAttribArray);
+LGL_FUNC(gl_va_gen, glGenVertexArrays);
+LGL_FUNC(gl_va_bind, glBindVertexArray);
+LGL_FUNC(gl_draw_arrays, glDrawArrays);
+LGL_FUNC(gl_draw_elems, glDrawElements);
+LGL_FUNC(gl_poly_mode, glPolygonMode);
+
+static void *load_func(const char *name, lgl_loadfunc *load, jmp_buf env)
+{
+ void *ret;
+
+ ret = load(name);
+ if (ret == NULL)
+ longjmp(env, LGL_MISSING);
+
+ return ret;
+}
+
+enum lgl_status lgl_load(lgl_loadfunc *load)
+{
+ enum lgl_status status;
+ jmp_buf env;
+
+ status = setjmp(env);
+ if (status != 0)
+ return status;
+
+#define LGL_LOAD(name) name = (name##_func *)load_func(name##_gln, load, env);
+ LGL_LOAD(gl_viewport);
+ LGL_LOAD(gl_clearcolor);
+ LGL_LOAD(gl_clear);
+ LGL_LOAD(gl_buf_gen);
+ LGL_LOAD(gl_buf_bind);
+ LGL_LOAD(gl_buf_data);
+ LGL_LOAD(gl_shdr_create);
+ LGL_LOAD(gl_shdr_del);
+ LGL_LOAD(gl_shdr_source);
+ LGL_LOAD(gl_shdr_compile);
+ LGL_LOAD(gl_shdr_param);
+ LGL_LOAD(gl_shdr_infolog);
+ LGL_LOAD(gl_prog_create);
+ LGL_LOAD(gl_prog_attachshdr);
+ LGL_LOAD(gl_prog_link);
+ LGL_LOAD(gl_prog_use);
+ LGL_LOAD(gl_prog_del);
+ LGL_LOAD(gl_prog_param);
+ LGL_LOAD(gl_prog_infolog);
+ LGL_LOAD(gl_va_define);
+ LGL_LOAD(gl_va_enable);
+ LGL_LOAD(gl_va_disable);
+ LGL_LOAD(gl_va_gen);
+ LGL_LOAD(gl_va_bind);
+ LGL_LOAD(gl_draw_arrays);
+ LGL_LOAD(gl_draw_elems);
+ LGL_LOAD(gl_poly_mode);
+
+ return LGL_OK;
+}
+
+const char *lgl_strerror(enum lgl_status status)
+{
+ switch (status) {
+ case LGL_OK: return "Success";
+ case LGL_MISSING: return "Missing function";
+ }
+ return "Unknown";
+}