Liberally assert stuff

This commit is contained in:
Luke Benstead 2023-05-17 20:39:58 +01:00
parent 462eb40d7a
commit d81472ef57

View File

@ -505,6 +505,8 @@ GLubyte _glInitTextures() {
#endif #endif
yalloc_init(YALLOC_BASE, YALLOC_SIZE); yalloc_init(YALLOC_BASE, YALLOC_SIZE);
gl_assert(TEXTURE_OBJECTS.element_size > 0);
return 1; return 1;
} }
@ -513,10 +515,12 @@ TextureObject* _glGetTexture0() {
} }
TextureObject* _glGetTexture1() { TextureObject* _glGetTexture1() {
gl_assert(1 < MAX_GLDC_TEXTURE_UNITS);
return TEXTURE_UNITS[1]; return TEXTURE_UNITS[1];
} }
TextureObject* _glGetBoundTexture() { TextureObject* _glGetBoundTexture() {
gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
return TEXTURE_UNITS[ACTIVE_TEXTURE]; return TEXTURE_UNITS[ACTIVE_TEXTURE];
} }
@ -541,6 +545,8 @@ GLboolean APIENTRY glIsTexture(GLuint texture) {
void APIENTRY glGenTextures(GLsizei n, GLuint *textures) { void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
TRACE(); TRACE();
gl_assert(TEXTURE_OBJECTS.element_size > 0);
while(n--) { while(n--) {
GLuint id = 0; GLuint id = 0;
TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id); TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id);
@ -550,10 +556,14 @@ void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
_glInitializeTextureObject(txr, id); _glInitializeTextureObject(txr, id);
*textures = id;
gl_assert(txr->index == id);
*textures = id;
textures++; textures++;
} }
gl_assert(TEXTURE_OBJECTS.element_size > 0);
} }
void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) { void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) {
@ -619,18 +629,20 @@ void APIENTRY glBindTexture(GLenum target, GLuint texture) {
return; return;
} }
if(texture) { TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture);
/* If this didn't come from glGenTextures, then we should initialize the /* If this didn't come from glGenTextures, then we should initialize the
* texture the first time it's bound */ * texture the first time it's bound */
if(!named_array_used(&TEXTURE_OBJECTS, texture)) { if(!txr) {
TextureObject* txr = named_array_reserve(&TEXTURE_OBJECTS, texture); TextureObject* txr = named_array_reserve(&TEXTURE_OBJECTS, texture);
_glInitializeTextureObject(txr, texture); _glInitializeTextureObject(txr, texture);
} }
TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture); gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
} else { TEXTURE_UNITS[ACTIVE_TEXTURE] = txr;
TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL; gl_assert(TEXTURE_UNITS[ACTIVE_TEXTURE]->index == texture);
}
gl_assert(TEXTURE_OBJECTS.element_size > 0);
_glGPUStateMarkDirty(); _glGPUStateMarkDirty();
} }
@ -643,9 +655,11 @@ void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param) {
GLint target_values [] = {GL_TEXTURE_ENV, GL_TEXTURE_FILTER_CONTROL_EXT, 0}; GLint target_values [] = {GL_TEXTURE_ENV, GL_TEXTURE_FILTER_CONTROL_EXT, 0};
failures += _glCheckValidEnum(target, target_values, __func__); failures += _glCheckValidEnum(target, target_values, __func__);
gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE]; TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
if(!active) { if(!active) {
_glKosThrowError(GL_INVALID_OPERATION, __func__);
return; return;
} }
@ -809,13 +823,15 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
} }
} }
if(TEXTURE_UNITS[ACTIVE_TEXTURE] == NULL) { gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
GLuint original_id = active->index;
if(!active) {
_glKosThrowError(GL_INVALID_OPERATION, __func__); _glKosThrowError(GL_INVALID_OPERATION, __func__);
return; return;
} }
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
/* Set the required mipmap count */ /* Set the required mipmap count */
active->width = width; active->width = width;
active->height = height; active->height = height;
@ -845,6 +861,8 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
FASTCPY(active->data, data, imageSize); FASTCPY(active->data, data, imageSize);
} }
gl_assert(original_id == active->index);
_glGPUStateMarkDirty(); _glGPUStateMarkDirty();
} }
@ -1345,6 +1363,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
} else { } else {
/* Mipmap Errors, kos crashes if 1x1 */ /* Mipmap Errors, kos crashes if 1x1 */
if((h < 2) || (w < 2)){ if((h < 2) || (w < 2)){
gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
gl_assert(TEXTURE_UNITS[ACTIVE_TEXTURE]); gl_assert(TEXTURE_UNITS[ACTIVE_TEXTURE]);
TEXTURE_UNITS[ACTIVE_TEXTURE]->mipmap |= (1 << level); TEXTURE_UNITS[ACTIVE_TEXTURE]->mipmap |= (1 << level);
return; return;
@ -1370,21 +1389,23 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
return; return;
} }
if(!TEXTURE_UNITS[ACTIVE_TEXTURE]) { gl_assert(ACTIVE_TEXTURE < MAX_GLDC_TEXTURE_UNITS);
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
if(!active) {
INFO_MSG("Called glTexImage2D on unbound texture"); INFO_MSG("Called glTexImage2D on unbound texture");
_glKosThrowError(GL_INVALID_OPERATION, __func__); _glKosThrowError(GL_INVALID_OPERATION, __func__);
return; return;
} }
gl_assert(active);
GLuint original_id = active->index;
GLboolean isPaletted = (internalFormat == GL_COLOR_INDEX8_EXT || internalFormat == GL_COLOR_INDEX4_EXT) ? GL_TRUE : GL_FALSE; GLboolean isPaletted = (internalFormat == GL_COLOR_INDEX8_EXT || internalFormat == GL_COLOR_INDEX4_EXT) ? GL_TRUE : GL_FALSE;
/* Calculate the format that we need to convert the data to */ /* Calculate the format that we need to convert the data to */
GLuint pvr_format = _determinePVRFormat(internalFormat, type); GLuint pvr_format = _determinePVRFormat(internalFormat, type);
TextureObject* active = TEXTURE_UNITS[ACTIVE_TEXTURE];
gl_assert(active);
if(active->data && (level == 0)) { if(active->data && (level == 0)) {
/* pre-existing texture - check if changed */ /* pre-existing texture - check if changed */
if(active->width != width || if(active->width != width ||
@ -1453,6 +1474,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
/* If we run out of PVR memory just return */ /* If we run out of PVR memory just return */
if(!active->data) { if(!active->data) {
_glKosThrowError(GL_OUT_OF_MEMORY, __func__); _glKosThrowError(GL_OUT_OF_MEMORY, __func__);
gl_assert(active->index == original_id);
return; return;
} }
@ -1500,6 +1522,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
if(!data) { if(!data) {
/* No data? Do nothing! */ /* No data? Do nothing! */
gl_assert(active->index == original_id);
return; return;
} else if(!needsConversion && !needsTwiddling) { } else if(!needsConversion && !needsTwiddling) {
gl_assert(targetData); gl_assert(targetData);
@ -1508,6 +1531,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
/* No conversion? Just copy the data, and the pvr_format is correct */ /* No conversion? Just copy the data, and the pvr_format is correct */
FASTCPY(targetData, data, bytes); FASTCPY(targetData, data, bytes);
gl_assert(active->index == original_id);
return; return;
} else if(needsConversion) { } else if(needsConversion) {
TextureConversionFunc convert = _determineConversion( TextureConversionFunc convert = _determineConversion(
@ -1582,6 +1606,7 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
conversionBuffer = NULL; conversionBuffer = NULL;
} }
gl_assert(active->index == original_id);
_glGPUStateMarkDirty(); _glGPUStateMarkDirty();
} }