Add glGetError() and gluErrorString().

This commit is contained in:
Lawrence Sebald 2016-01-03 22:23:32 -05:00
parent dd765f80d6
commit 9fc75b6772
3 changed files with 53 additions and 2 deletions

47
gl-error.c Executable file → Normal file
View File

@ -2,6 +2,7 @@
libgl/gl-error.c
Copyright (C) 2014 Josh Pearson
Copyright (C) 2016 Lawrence Sebald
KOS Open GL State Machine Error Code Implementation.
*/
@ -17,12 +18,27 @@
#define KOS_GL_INVALID_VALUE (1<<3)
static GLsizei KOS_GL_ERROR_CODE;
static GLenum gl_last_error = GL_NO_ERROR;
static char KOS_GL_ERROR_FUNCTION[64] = { '\0' };
/* Quoth the GL Spec:
When an error occurs, the error flag is set to the appropriate error code
value. No other errors are recorded until glGetError is called, the error
code is returned, and the flag is reset to GL_NO_ERROR.
So, we only record an error here if the error code is currently unset.
Nothing in the spec requires recording multiple error flags, although it is
allowed by the spec. We take the easy way out for now. */
static void set_err_flag(GLenum error) {
if(gl_last_error == GL_NO_ERROR)
gl_last_error = error;
}
void _glKosThrowError(GLenum error, char *function) {
sprintf(KOS_GL_ERROR_FUNCTION, "%s\n", function);
set_err_flag(error);
switch(error) {
case GL_INVALID_ENUM:
@ -69,4 +85,33 @@ void _glKosPrintError() {
printf("KOS GL ERROR: GL_INVALID_VALUE\n");
_glKosResetError();
}
}
GLenum glGetError(void) {
GLenum rv = gl_last_error;
gl_last_error = GL_NO_ERROR;
return rv;
}
const GLubyte *gluErrorString(GLenum error) {
switch(error) {
case GL_NO_ERROR:
return (GLubyte *)"no error";
case GL_INVALID_ENUM:
return (GLubyte *)"invalid enumerant";
case GL_INVALID_OPERATION:
return (GLubyte *)"invalid operation";
case GL_INVALID_VALUE:
return (GLubyte *)"invalid value";
case GL_OUT_OF_MEMORY:
return (GLubyte *)"out of memory";
default:
return (GLubyte *)"unknown error";
}
}

View File

@ -2,7 +2,7 @@
libgl/gl.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Copyright (C) 2014 Lawrence Sebald
Copyright (C) 2014, 2016 Lawrence Sebald
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
@ -659,6 +659,9 @@ GLAPI void APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment,
GLenum textarget, GLuint texture, GLint level);
GLAPI GLenum APIENTRY glCheckFramebufferStatus(GLenum target);
/* Error handling */
GLAPI GLenum APIENTRY glGetError(void);
/* Non Operational Stubs for portability */
GLAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref);
GLAPI void APIENTRY glLineWidth(GLfloat width);

View File

@ -2,6 +2,7 @@
libgl/glu.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Copyright (C) 2016 Lawrence Sebald
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
@ -42,6 +43,8 @@ GLAPI void APIENTRY glhLookAtf2(GLfloat *eyePosition3D,
GLfloat *center3D,
GLfloat *upVector3D);
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error);
__END_DECLS
#endif /* !__GL_GLU_H */