aboutsummaryrefslogtreecommitdiff
path: root/debuggl/debuggl.c
blob: 4775ade489ebcbccfe35d40bf25d1ab2d51311cd (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
65
66
67
#include "debuggl.h"
#include <GL/gl.h>
#include <stdio.h>

int debuggl_check_call(
	char const * const file,
	char const * const func,
	unsigned int const line,
	char const * const what)
{
	int errors = 0;
        GLenum err;
	while( (err = glGetError()) != GL_NO_ERROR) {
		++errors;
		char const * errstr = NULL;
		switch( err ) {
			case GL_INVALID_ENUM:      errstr = "invalid enum"; break;
			case GL_INVALID_VALUE:     errstr = "invalid value"; break;
			case GL_INVALID_OPERATION: errstr = "invalid operation"; break;
			case GL_STACK_OVERFLOW:    errstr = "invalid overflow"; break;
			case GL_STACK_UNDERFLOW:   errstr = "invalid underflow"; break;
			case GL_OUT_OF_MEMORY:     errstr = "invalid memory"; break;
		}
		fprintf(stderr,
			"%s(%d)/%s: %s => OpenGL Error: %s\n",
			file, (int)line, func, what,
			errstr );
	}
	return errors;
}

int debuggl_trace_call(
	char const * const file,
	char const * const func,
	unsigned int const line,
	char const * const what)
{
	int errors = 0;
        GLenum err;
	do {
		err = glGetError();
		char const * errstr = NULL;
		switch( err ) {
			case GL_INVALID_ENUM:      errstr = "invalid enum"; break;
			case GL_INVALID_VALUE:     errstr = "invalid value"; break;
			case GL_INVALID_OPERATION: errstr = "invalid operation"; break;
			case GL_STACK_OVERFLOW:    errstr = "invalid overflow"; break;
			case GL_STACK_UNDERFLOW:   errstr = "invalid underflow"; break;
			case GL_OUT_OF_MEMORY:     errstr = "invalid memory"; break;
		}

		if( errstr ) {
			++errors;
			fprintf(stderr,
				"%s(%d)/%s: %s => OpenGL Error: %s\n",
				file, (int)line, func, what,
				errstr );
		}
		else {
			fprintf(stderr,
				"%s(%d): %s OK\n",
				func, (int)line, what);
		}
	} while( GL_NO_ERROR != err );
	return errors;
}