aboutsummaryrefslogtreecommitdiffstats
path: root/gl.c
blob: 99f537e30f90bbf00ace583762939ed9988543de (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
/*
 * 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

// load_func: load OpenGL function
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;
}

// gl_load: load required OpenGL functions
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
}

// gl_strerror: format OpenGL error code into a string
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";
}