From 558963c57c8b25766c055b075bb82a4f24e9cebe Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 13:27:25 +0100 Subject: [PATCH] Use GL_LUMINANCE8 for 3d palette lookup texture on OpenGL versions older than 3.0 --- src/hardware/r_opengl/r_opengl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f9d0e44e9..83f5c3b31 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -4355,13 +4355,27 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut) { + GLenum internalFormat; + if (gl_version[0] == '1' || gl_version[0] == '2') + { + // if the OpenGL version is below 3.0, then the GL_R8 format may not be available. + // so use GL_LUMINANCE8 instead to get a single component 8-bit format + // (it is possible to have access to shaders even in some OpenGL 1.x systems, + // so palette rendering can still possibly be achieved there) + internalFormat = GL_LUMINANCE8; + } + else + { + internalFormat = GL_R8; + } + if (!paletteLookupTex) pglGenTextures(1, &paletteLookupTex); pglActiveTexture(GL_TEXTURE1); pglBindTexture(GL_TEXTURE_3D, paletteLookupTex); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, + pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, lut); pglActiveTexture(GL_TEXTURE0); }