From fe7f9cbed04303685ca8504f1715a4cb1ea874eb Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Sat, 7 May 2022 12:57:45 +0100 Subject: [PATCH] Fix crash when generating mipmaps on 4bpp textures --- GL/framebuffer.c | 10 ++++++++-- GL/texture.c | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/GL/framebuffer.c b/GL/framebuffer.c index 1a893c6..3729cfe 100644 --- a/GL/framebuffer.c +++ b/GL/framebuffer.c @@ -274,6 +274,12 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) { return; } + if((tex->color & GPU_TXRFMT_PAL4BPP) == GPU_TXRFMT_PAL4BPP) { + fprintf(stderr, "[GL ERROR] Mipmap generation not supported for 4BPP paletted textures\n"); + _glKosThrowError(GL_INVALID_OPERATION, __func__); + return; + } + if((tex->color & GPU_TXRFMT_NONTWIDDLED) == GPU_TXRFMT_NONTWIDDLED) { /* glTexImage2D should twiddle internally textures in nearly all cases * so this error is unlikely */ @@ -321,10 +327,10 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) { } /* generate mipmaps for any image provided by the user and then pass them to OpenGL */ -GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, +GLAPI GLvoid APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data){ - /* 2d texture, level of detail 0 (normal), 3 components (red, green, blue), + /* 2d texture, level of detail 0 (normal), 3 components (red, green, blue), width & height of the image, border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. */ glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); diff --git a/GL/texture.c b/GL/texture.c index 7846757..8410e5c 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -775,6 +775,7 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target, return; default: { + fprintf(stderr, "Unsupported internalFormat: %d\n", internalFormat); _glKosThrowError(GL_INVALID_OPERATION, __func__); return; }