Detect multiple mipmap levels being uploaded to glCompressedTexImage2D
This commit is contained in:
parent
86dd5dd2b2
commit
b06f6116c8
30
GL/error.c
30
GL/error.c
|
@ -40,29 +40,23 @@ static void _glKosResetError() {
|
|||
sprintf(error_function, "\n");
|
||||
}
|
||||
|
||||
static const char* _glErrorEnumAsString(GLenum error) {
|
||||
switch(error) {
|
||||
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
|
||||
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
|
||||
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
|
||||
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
|
||||
default:
|
||||
return "GL_UNKNOWN_ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
void _glKosPrintError() {
|
||||
if(!_glKosHasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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");
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
printf("KOS GL ERROR: GL_OUT_OF_MEMORY\n");
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
printf("KOS GL ERROR: GL_INVALID_OPERATION\n");
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
printf("KOS GL ERROR: GL_INVALID_VALUE\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "GL ERROR: %s when calling %s\n", _glErrorEnumAsString(last_error), error_function);
|
||||
}
|
||||
|
||||
GLenum glGetError(void) {
|
||||
|
|
16
GL/texture.c
16
GL/texture.c
|
@ -200,6 +200,22 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
|
|||
_glKosThrowError(GL_INVALID_OPERATION, __func__);
|
||||
}
|
||||
|
||||
/* Guess whether we have mipmaps or not */
|
||||
|
||||
/* `expected` is the uncompressed size */
|
||||
GLuint expected = sizeof(GLshort) * width * height;
|
||||
|
||||
/* The ratio is the uncompressed vs compressed data size */
|
||||
GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) imageSize));
|
||||
|
||||
if(ratio < 7) {
|
||||
/* If the ratio is less than 1:7 then we assume that the reason for that
|
||||
is the extra data used for mipmaps. Testing shows that a single VQ compressed
|
||||
image is around 1:7 or 1:8. We may need to tweak this if it detects false positives */
|
||||
fprintf(stderr, "GL ERROR: Detected multiple mipmap levels being uploaded to %s\n", __func__);
|
||||
_glKosThrowError(GL_INVALID_OPERATION, __func__);
|
||||
}
|
||||
|
||||
if(_glKosHasError()) {
|
||||
_glKosPrintError();
|
||||
return;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "gl.h"
|
||||
#include "glu.h"
|
||||
#include "glkos.h"
|
||||
#include "glext.h"
|
||||
|
||||
extern uint8 romdisk[];
|
||||
KOS_INIT_ROMDISK(romdisk);
|
||||
|
@ -56,6 +57,9 @@ int ImageLoad(char *filename, Image *image) {
|
|||
image->sizeY = header.height;
|
||||
image->dataSize = header.size;
|
||||
|
||||
GLuint expected = 2 * header.width * header.height;
|
||||
GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) header.size));
|
||||
|
||||
fread(image->data, image->dataSize, 1, file);
|
||||
fclose(file);
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 24 KiB |
Binary file not shown.
Loading…
Reference in New Issue
Block a user