aboutsummaryrefslogtreecommitdiffstats
path: root/loadgl.c.in
blob: 1959b640e65e8d0ac2eda4aa2792761f4f9fe145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * 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;

FUNCS()dnl

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);
	LOADS()dnl

	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";
}

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";
}