1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "state/cr_stateerror.h"
|
---|
8 | #include "state/cr_statetypes.h"
|
---|
9 | #include "state.h"
|
---|
10 | #include "cr_error.h"
|
---|
11 | #include "cr_environment.h"
|
---|
12 | #include <stdarg.h>
|
---|
13 | #include <stdio.h>
|
---|
14 |
|
---|
15 | void crStateError( int line, const char *file, GLenum error, const char *format, ... )
|
---|
16 | {
|
---|
17 | CRContext *g = GetCurrentContext();
|
---|
18 | char errstr[8096];
|
---|
19 | va_list args;
|
---|
20 |
|
---|
21 | g->error = error;
|
---|
22 |
|
---|
23 | if (1||crGetenv("CR_DEBUG"))
|
---|
24 | {
|
---|
25 | char *glerr;
|
---|
26 | va_start( args, format );
|
---|
27 | vsprintf( errstr, format, args );
|
---|
28 | va_end( args );
|
---|
29 |
|
---|
30 | switch (error) {
|
---|
31 | case GL_NO_ERROR:
|
---|
32 | glerr = "GL_NO_ERROR";
|
---|
33 | break;
|
---|
34 | case GL_INVALID_VALUE:
|
---|
35 | glerr = "GL_INVALID_VALUE";
|
---|
36 | break;
|
---|
37 | case GL_INVALID_ENUM:
|
---|
38 | glerr = "GL_INVALID_ENUM";
|
---|
39 | break;
|
---|
40 | case GL_INVALID_OPERATION:
|
---|
41 | glerr = "GL_INVALID_OPERATION";
|
---|
42 | break;
|
---|
43 | case GL_STACK_OVERFLOW:
|
---|
44 | glerr = "GL_STACK_OVERFLOW";
|
---|
45 | break;
|
---|
46 | case GL_STACK_UNDERFLOW:
|
---|
47 | glerr = "GL_STACK_UNDERFLOW";
|
---|
48 | break;
|
---|
49 | case GL_OUT_OF_MEMORY:
|
---|
50 | glerr = "GL_OUT_OF_MEMORY";
|
---|
51 | break;
|
---|
52 | case GL_TABLE_TOO_LARGE:
|
---|
53 | glerr = "GL_TABLE_TOO_LARGE";
|
---|
54 | break;
|
---|
55 | default:
|
---|
56 | glerr = "unknown";
|
---|
57 | break;
|
---|
58 | }
|
---|
59 |
|
---|
60 | crWarning( "OpenGL error in %s, line %d: %s: %s\n",
|
---|
61 | file, line, glerr, errstr );
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | GLenum STATE_APIENTRY crStateGetError(void)
|
---|
67 | {
|
---|
68 | CRContext *g = GetCurrentContext();
|
---|
69 | GLenum e = g->error;
|
---|
70 |
|
---|
71 | if (g->current.inBeginEnd)
|
---|
72 | {
|
---|
73 | crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
74 | "glStateGetError() called between glBegin/glEnd" );
|
---|
75 | return 0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | g->error = GL_NO_ERROR;
|
---|
79 |
|
---|
80 | return e;
|
---|
81 | }
|
---|