From 46447c9e90b845a49aa310defc497eee84d3fce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 23:01:45 +0200 Subject: [PATCH] Correct the wrong GL DataFormat enums --- Common/ColorConv.h | 3 +++ GPU/GLES/TextureCacheGLES.cpp | 36 ++++++++++++++-------------- GPU/GLES/TextureScalerGLES.cpp | 6 ++--- ext/native/gfx_es2/draw_text_win.cpp | 4 +++- ext/native/thin3d/DataFormatGL.cpp | 6 ++--- ext/native/thin3d/thin3d_gl.cpp | 6 ++--- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Common/ColorConv.h b/Common/ColorConv.h index 3947f8bf52..485bea2ac4 100644 --- a/Common/ColorConv.h +++ b/Common/ColorConv.h @@ -107,6 +107,9 @@ void convert5551_dx9(u16* data, u32* out, int width, int l, int u); // "Complete" set of color conversion functions between the usual formats. +// TODO: Need to revisit the naming convention of these. Seems totally backwards +// now that we've standardized on Draw::DataFormat. + typedef void (*Convert16bppTo16bppFunc)(u16 *dst, const u16 *src, u32 numPixels); typedef void (*Convert16bppTo32bppFunc)(u32 *dst, const u16 *src, u32 numPixels); typedef void (*Convert32bppTo16bppFunc)(u16 *dst, const u32 *src, u32 numPixels); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 410f50ea05..c326123a5a 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -89,11 +89,11 @@ void TextureCacheGLES::Clear(bool delete_them) { Draw::DataFormat getClutDestFormat(GEPaletteFormat format) { switch (format) { case GE_CMODE_16BIT_ABGR4444: - return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case GE_CMODE_16BIT_ABGR5551: - return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; case GE_CMODE_16BIT_BGR5650: - return Draw::DataFormat::B5G6R5_UNORM_PACK16; + return Draw::DataFormat::R5G6B5_UNORM_PACK16; case GE_CMODE_32BIT_ABGR8888: return Draw::DataFormat::R8G8B8A8_UNORM; } @@ -192,14 +192,14 @@ static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dst const u32 *src = (const u32 *)srcBuf; u32 *dst = (u32 *)dstBuf; switch (dstFmt) { - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: ConvertRGBA4444ToABGR4444((u16 *)dst, (const u16 *)src, numPixels); break; // Final Fantasy 2 uses this heavily in animated textures. - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: ConvertRGBA5551ToABGR1555((u16 *)dst, (const u16 *)src, numPixels); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: ConvertRGB565ToBGR565((u16 *)dst, (const u16 *)src, numPixels); break; default: @@ -517,18 +517,18 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram ReplacedTextureFormat FromDataFormat(Draw::DataFormat fmt) { // TODO: 16-bit formats are incorrect, since swizzled. switch (fmt) { - case Draw::DataFormat::B5G6R5_UNORM_PACK16: return ReplacedTextureFormat::F_0565_ABGR; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: return ReplacedTextureFormat::F_1555_ABGR; - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: return ReplacedTextureFormat::F_4444_ABGR; + case Draw::DataFormat::R5G6B5_UNORM_PACK16: return ReplacedTextureFormat::F_0565_ABGR; + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: return ReplacedTextureFormat::F_1555_ABGR; + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: return ReplacedTextureFormat::F_4444_ABGR; case Draw::DataFormat::R8G8B8A8_UNORM: default: return ReplacedTextureFormat::F_8888; } } Draw::DataFormat ToDataFormat(ReplacedTextureFormat fmt) { switch (fmt) { - case ReplacedTextureFormat::F_5650: return Draw::DataFormat::B5G6R5_UNORM_PACK16; - case ReplacedTextureFormat::F_5551: return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; - case ReplacedTextureFormat::F_4444: return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + case ReplacedTextureFormat::F_5650: return Draw::DataFormat::R5G6B5_UNORM_PACK16; + case ReplacedTextureFormat::F_5551: return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; + case ReplacedTextureFormat::F_4444: return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case ReplacedTextureFormat::F_8888: default: return Draw::DataFormat::R8G8B8A8_UNORM; } } @@ -708,11 +708,11 @@ Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPalet case GE_TFMT_CLUT32: return getClutDestFormat(clutFormat); case GE_TFMT_4444: - return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case GE_TFMT_5551: - return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; case GE_TFMT_5650: - return Draw::DataFormat::B5G6R5_UNORM_PACK16; + return Draw::DataFormat::R5G6B5_UNORM_PACK16; case GE_TFMT_8888: case GE_TFMT_DXT1: case GE_TFMT_DXT3: @@ -725,13 +725,13 @@ Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPalet TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, Draw::DataFormat dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: res = CheckAlphaABGR4444Basic((const uint32_t *)pixelData, stride, w, h); break; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: res = CheckAlphaABGR1555Basic((const uint32_t *)pixelData, stride, w, h); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: // Never has any alpha. res = CHECKALPHA_FULL; break; diff --git a/GPU/GLES/TextureScalerGLES.cpp b/GPU/GLES/TextureScalerGLES.cpp index 4d2ae06366..73c1b849a7 100644 --- a/GPU/GLES/TextureScalerGLES.cpp +++ b/GPU/GLES/TextureScalerGLES.cpp @@ -45,15 +45,15 @@ void TextureScalerGLES::ConvertTo8888(u32 format, u32* source, u32* &dest, int w dest = source; // already fine break; - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert4444_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert565_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert5551_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; diff --git a/ext/native/gfx_es2/draw_text_win.cpp b/ext/native/gfx_es2/draw_text_win.cpp index aaa3b1d859..a84ac84473 100644 --- a/ext/native/gfx_es2/draw_text_win.cpp +++ b/ext/native/gfx_es2/draw_text_win.cpp @@ -258,6 +258,8 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f texFormat = Draw::DataFormat::A4R4G4B4_UNORM_PACK16; else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + else if (draw_->GetDataFormatSupport(Draw::DataFormat::R4G4B4A4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; else texFormat = Draw::DataFormat::R8G8B8A8_UNORM; @@ -275,7 +277,7 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f } } desc.initData.push_back((uint8_t *)bitmapData32); - } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16) { + } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16 || texFormat == Draw::DataFormat::R4G4B4A4_UNORM_PACK16) { bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; for (int y = 0; y < entry->bmHeight; y++) { for (int x = 0; x < entry->bmWidth; x++) { diff --git a/ext/native/thin3d/DataFormatGL.cpp b/ext/native/thin3d/DataFormatGL.cpp index 3c7c3f82c5..b3a8092abf 100644 --- a/ext/native/thin3d/DataFormatGL.cpp +++ b/ext/native/thin3d/DataFormatGL.cpp @@ -36,21 +36,21 @@ bool Thin3DFormatToFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint alignment = 1; break; - case DataFormat::B4G4R4A4_UNORM_PACK16: + case DataFormat::R4G4B4A4_UNORM_PACK16: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_4_4_4_4; alignment = 2; break; - case DataFormat::B5G6R5_UNORM_PACK16: + case DataFormat::R5G6B5_UNORM_PACK16: internalFormat = GL_RGB; format = GL_RGB; type = GL_UNSIGNED_SHORT_5_6_5; alignment = 2; break; - case DataFormat::B5G5R5A1_UNORM_PACK16: + case DataFormat::R5G5B5A1_UNORM_PACK16: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_5_5_5_1; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 04e5c5ba4f..d31e63f892 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -1212,9 +1212,9 @@ void OpenGLContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h) { uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const { switch (fmt) { - case DataFormat::B4G4R4A4_UNORM_PACK16: - case DataFormat::B5G6R5_UNORM_PACK16: - case DataFormat::B5G5R5A1_UNORM_PACK16: + case DataFormat::R4G4B4A4_UNORM_PACK16: + case DataFormat::R5G6B5_UNORM_PACK16: + case DataFormat::R5G5B5A1_UNORM_PACK16: return FMT_RENDERTARGET | FMT_TEXTURE | FMT_AUTOGEN_MIPS; // native support case DataFormat::R8G8B8A8_UNORM: