Add glGetError() and gluErrorString().
This commit is contained in:
parent
dd765f80d6
commit
9fc75b6772
45
gl-error.c
Executable file → Normal file
45
gl-error.c
Executable file → Normal file
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
libgl/gl-error.c
|
libgl/gl-error.c
|
||||||
Copyright (C) 2014 Josh Pearson
|
Copyright (C) 2014 Josh Pearson
|
||||||
|
Copyright (C) 2016 Lawrence Sebald
|
||||||
|
|
||||||
KOS Open GL State Machine Error Code Implementation.
|
KOS Open GL State Machine Error Code Implementation.
|
||||||
*/
|
*/
|
||||||
|
@ -17,12 +18,27 @@
|
||||||
#define KOS_GL_INVALID_VALUE (1<<3)
|
#define KOS_GL_INVALID_VALUE (1<<3)
|
||||||
|
|
||||||
static GLsizei KOS_GL_ERROR_CODE;
|
static GLsizei KOS_GL_ERROR_CODE;
|
||||||
|
static GLenum gl_last_error = GL_NO_ERROR;
|
||||||
|
|
||||||
static char KOS_GL_ERROR_FUNCTION[64] = { '\0' };
|
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) {
|
void _glKosThrowError(GLenum error, char *function) {
|
||||||
|
|
||||||
sprintf(KOS_GL_ERROR_FUNCTION, "%s\n", function);
|
sprintf(KOS_GL_ERROR_FUNCTION, "%s\n", function);
|
||||||
|
set_err_flag(error);
|
||||||
|
|
||||||
switch(error) {
|
switch(error) {
|
||||||
case GL_INVALID_ENUM:
|
case GL_INVALID_ENUM:
|
||||||
|
@ -70,3 +86,32 @@ void _glKosPrintError() {
|
||||||
|
|
||||||
_glKosResetError();
|
_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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
libgl/gl.h
|
libgl/gl.h
|
||||||
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
|
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:
|
Some functionality adapted from the original KOS libgl:
|
||||||
Copyright (C) 2001 Dan Potter
|
Copyright (C) 2001 Dan Potter
|
||||||
|
@ -659,6 +659,9 @@ GLAPI void APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment,
|
||||||
GLenum textarget, GLuint texture, GLint level);
|
GLenum textarget, GLuint texture, GLint level);
|
||||||
GLAPI GLenum APIENTRY glCheckFramebufferStatus(GLenum target);
|
GLAPI GLenum APIENTRY glCheckFramebufferStatus(GLenum target);
|
||||||
|
|
||||||
|
/* Error handling */
|
||||||
|
GLAPI GLenum APIENTRY glGetError(void);
|
||||||
|
|
||||||
/* Non Operational Stubs for portability */
|
/* Non Operational Stubs for portability */
|
||||||
GLAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref);
|
GLAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref);
|
||||||
GLAPI void APIENTRY glLineWidth(GLfloat width);
|
GLAPI void APIENTRY glLineWidth(GLfloat width);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
libgl/glu.h
|
libgl/glu.h
|
||||||
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
|
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
|
||||||
|
Copyright (C) 2016 Lawrence Sebald
|
||||||
|
|
||||||
Some functionality adapted from the original KOS libgl:
|
Some functionality adapted from the original KOS libgl:
|
||||||
Copyright (C) 2001 Dan Potter
|
Copyright (C) 2001 Dan Potter
|
||||||
|
@ -42,6 +43,8 @@ GLAPI void APIENTRY glhLookAtf2(GLfloat *eyePosition3D,
|
||||||
GLfloat *center3D,
|
GLfloat *center3D,
|
||||||
GLfloat *upVector3D);
|
GLfloat *upVector3D);
|
||||||
|
|
||||||
|
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif /* !__GL_GLU_H */
|
#endif /* !__GL_GLU_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user