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