Simplify gl-error.c
This commit is contained in:
parent
6a4a6a157b
commit
79b8e9af3c
3
gl-api.h
3
gl-api.h
|
@ -173,9 +173,8 @@ void _glKosInitFrameBuffers();
|
|||
|
||||
/* Error Codes */
|
||||
void _glKosThrowError(GLenum error, char *functionName);
|
||||
void _glKosResetError();
|
||||
void _glKosPrintError();
|
||||
GLsizei _glKosGetError();
|
||||
GLubyte _glKosHasError();
|
||||
|
||||
GLuint _glKosTextureWidth(GLuint index);
|
||||
GLuint _glKosTextureHeight(GLuint index);
|
||||
|
|
18
gl-arrays.c
18
gl-arrays.c
|
@ -102,7 +102,7 @@ GLAPI void APIENTRY glVertexPointer(GLint size, GLenum type,
|
|||
if(stride < 0)
|
||||
_glKosThrowError(GL_INVALID_VALUE, "glVertexPointer");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ GLAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *p
|
|||
if(stride < 0)
|
||||
_glKosThrowError(GL_INVALID_VALUE, "glNormalPointer");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ GLAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type,
|
|||
if(stride < 0)
|
||||
_glKosThrowError(GL_INVALID_VALUE, "glTexCoordPointer");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ static inline void _glKosElementColor3fU8(pvr_vertex_t *dst, GLuint count) {
|
|||
for(i = 0; i < count; i++) {
|
||||
index = GL_KOS_INDEX_POINTER_U8[i] * GL_KOS_COLOR_STRIDE;
|
||||
element = (GLrgb3f *) (color + index);
|
||||
dst[i].argb = (0xFF000000
|
||||
dst[i].argb = (0xFF000000
|
||||
| ((GLubyte)((*element)[0] * 0xFF)) << 16
|
||||
| ((GLubyte)((*element)[1] * 0xFF)) << 8
|
||||
| ((GLubyte)((*element)[2] * 0xFF)));
|
||||
|
@ -456,7 +456,7 @@ static inline void _glKosElementColor3fU16(pvr_vertex_t *dst, GLuint count) {
|
|||
for(i = 0; i < count; i++) {
|
||||
index = GL_KOS_INDEX_POINTER_U16[i] * GL_KOS_COLOR_STRIDE;
|
||||
element = (GLrgb3f *) (color + index);
|
||||
dst[i].argb = (0xFF000000
|
||||
dst[i].argb = (0xFF000000
|
||||
| ((GLubyte)((*element)[0] * 0xFF)) << 16
|
||||
| ((GLubyte)((*element)[1] * 0xFF)) << 8
|
||||
| ((GLubyte)((*element)[2] * 0xFF)));
|
||||
|
@ -754,7 +754,7 @@ static GLuint _glKosArraysVerifyParameter(GLenum mode, GLsizei count, GLenum typ
|
|||
else if(type > count)
|
||||
_glKosThrowError(GL_INVALID_VALUE, "glDrawArrays");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1298,7 +1298,7 @@ void APIENTRY glClientActiveTextureARB(GLenum texture) {
|
|||
if(texture < GL_TEXTURE0_ARB || texture > GL_TEXTURE0_ARB + _glKosMaxTextureUnits())
|
||||
_glKosThrowError(GL_INVALID_ENUM, "glClientActiveTextureARB");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
|
||||
_glKosPrintError();
|
||||
return;
|
||||
|
@ -1319,14 +1319,14 @@ void APIENTRY glEnableClientState(GLenum cap) {
|
|||
GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_NORMAL;
|
||||
break;
|
||||
case GL_TEXTURE_COORD_ARRAY:
|
||||
(GL_KOS_CLIENT_ACTIVE_TEXTURE) ?
|
||||
(GL_KOS_CLIENT_ACTIVE_TEXTURE) ?
|
||||
(GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_TEXTURE1):
|
||||
(GL_KOS_VERTEX_PTR_MODE |= GL_KOS_USE_TEXTURE0);
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, "glEnableClientState");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void APIENTRY glDisableClientState(GLenum cap) {
|
||||
|
|
82
gl-error.c
82
gl-error.c
|
@ -3,6 +3,7 @@
|
|||
libgl/gl-error.c
|
||||
Copyright (C) 2014 Josh Pearson
|
||||
Copyright (C) 2016 Lawrence Sebald
|
||||
* Copyright (C) 2017 Luke Benstead
|
||||
|
||||
KOS Open GL State Machine Error Code Implementation.
|
||||
*/
|
||||
|
@ -12,15 +13,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#define KOS_GL_INVALID_ENUM (1<<0)
|
||||
#define KOS_GL_OUT_OF_MEMORY (1<<1)
|
||||
#define KOS_GL_INVALID_OPERATION (1<<2)
|
||||
#define KOS_GL_INVALID_VALUE (1<<3)
|
||||
|
||||
static GLsizei KOS_GL_ERROR_CODE = 0;
|
||||
static GLenum gl_last_error = GL_NO_ERROR;
|
||||
|
||||
static char KOS_GL_ERROR_FUNCTION[64] = { '\0' };
|
||||
static GLenum last_error = GL_NO_ERROR;
|
||||
static char error_function[64] = { '\0' };
|
||||
|
||||
/* Quoth the GL Spec:
|
||||
When an error occurs, the error flag is set to the appropriate error code
|
||||
|
@ -30,67 +24,51 @@ static char KOS_GL_ERROR_FUNCTION[64] = { '\0' };
|
|||
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:
|
||||
KOS_GL_ERROR_CODE |= KOS_GL_INVALID_ENUM;
|
||||
break;
|
||||
|
||||
case GL_OUT_OF_MEMORY:
|
||||
KOS_GL_ERROR_CODE |= KOS_GL_OUT_OF_MEMORY;
|
||||
break;
|
||||
|
||||
case GL_INVALID_OPERATION:
|
||||
KOS_GL_ERROR_CODE |= KOS_GL_INVALID_OPERATION;
|
||||
break;
|
||||
|
||||
case GL_INVALID_VALUE:
|
||||
KOS_GL_ERROR_CODE |= KOS_GL_INVALID_VALUE;
|
||||
break;
|
||||
|
||||
if(last_error == GL_NO_ERROR) {
|
||||
last_error = error;
|
||||
sprintf(error_function, "%s\n", function);
|
||||
}
|
||||
}
|
||||
|
||||
GLsizei _glKosGetError() {
|
||||
return KOS_GL_ERROR_CODE;
|
||||
GLubyte _glKosHasError() {
|
||||
return (last_error != GL_NO_ERROR) ? GL_TRUE : GL_FALSE;
|
||||
}
|
||||
|
||||
void _glKosResetError() {
|
||||
KOS_GL_ERROR_CODE = 0;
|
||||
sprintf(KOS_GL_ERROR_FUNCTION, "\n");
|
||||
static void _glKosResetError() {
|
||||
last_error = GL_NO_ERROR;
|
||||
sprintf(error_function, "\n");
|
||||
}
|
||||
|
||||
void _glKosPrintError() {
|
||||
printf("\nKOS GL ERROR THROWN BY FUNCTION: %s\n", KOS_GL_ERROR_FUNCTION);
|
||||
if(!_glKosHasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(KOS_GL_ERROR_CODE & KOS_GL_INVALID_ENUM)
|
||||
printf("\nKOS GL ERROR THROWN BY FUNCTION: %s\n", error_function);
|
||||
|
||||
switch(last_error) {
|
||||
case GL_INVALID_ENUM:
|
||||
printf("KOS GL ERROR: GL_INVALID_ENUM\n");
|
||||
|
||||
if(KOS_GL_ERROR_CODE & KOS_GL_OUT_OF_MEMORY)
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
printf("KOS GL ERROR: GL_OUT_OF_MEMORY\n");
|
||||
|
||||
if(KOS_GL_ERROR_CODE & KOS_GL_INVALID_OPERATION)
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
printf("KOS GL ERROR: GL_INVALID_OPERATION\n");
|
||||
|
||||
if(KOS_GL_ERROR_CODE & KOS_GL_INVALID_VALUE)
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
printf("KOS GL ERROR: GL_INVALID_VALUE\n");
|
||||
|
||||
_glKosResetError();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GLenum glGetError(void) {
|
||||
GLenum rv = gl_last_error;
|
||||
|
||||
gl_last_error = GL_NO_ERROR;
|
||||
GLenum rv = last_error;
|
||||
_glKosResetError();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ GLAPI void APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment,
|
|||
if(!FRAMEBUF_OBJECT)
|
||||
_glKosThrowError(GL_INVALID_OPERATION, "glFramebufferTexture2D");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -178,4 +178,4 @@ GLAPI GLenum APIENTRY glCheckFramebufferStatus(GLenum target) {
|
|||
return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
||||
|
||||
return GL_FRAMEBUFFER_COMPLETE;
|
||||
}
|
||||
}
|
||||
|
|
10
gl-texture.c
10
gl-texture.c
|
@ -103,7 +103,7 @@ GL_TEXTURE_OBJECT *_glKosBoundMultiTexObject() {
|
|||
}
|
||||
|
||||
GLuint _glKosBoundMultiTexID() {
|
||||
return GL_KOS_TEXTURE_UNIT[GL_TEXTURE1_ARB & 0xF] ?
|
||||
return GL_KOS_TEXTURE_UNIT[GL_TEXTURE1_ARB & 0xF] ?
|
||||
GL_KOS_TEXTURE_UNIT[GL_TEXTURE1_ARB & 0xF]->index : 0;
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ void APIENTRY glCompressedTexImage2D(GLenum target,
|
|||
if(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE] == NULL)
|
||||
_glKosThrowError(GL_INVALID_OPERATION, "glCompressedTexImage2D");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
|||
if(GL_KOS_TEXTURE_UNIT[GL_KOS_ACTIVE_TEXTURE] == NULL)
|
||||
_glKosThrowError(GL_INVALID_OPERATION, "glTexImage2D");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param) {
|
|||
if(pname != GL_TEXTURE_ENV_MODE)
|
||||
_glKosThrowError(GL_INVALID_ENUM, "glTexEnvi");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ void APIENTRY glActiveTextureARB(GLenum texture) {
|
|||
if(texture < GL_TEXTURE0_ARB || texture > GL_TEXTURE0_ARB + GL_KOS_MAX_TEXTURE_UNITS)
|
||||
_glKosThrowError(GL_INVALID_ENUM, "glActiveTextureARB");
|
||||
|
||||
if(_glKosGetError()) {
|
||||
if(_glKosHasError()) {
|
||||
|
||||
_glKosPrintError();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue
Block a user