From ca761a910c25197b10aeadcb0120dae132442d56 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Mon, 26 Mar 2018 16:38:09 +0100 Subject: init commit --- loadgl.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 loadgl.c (limited to 'loadgl.c') 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 + * SPDX-License-Identifier: MIT + */ +#include + +#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"; +} -- cgit v1.2.3-54-g00ecf