From cf0e116a56414884eae69db2d07d3c63c03c6432 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 May 2014 12:55:40 -0700 Subject: [PATCH 1/4] GL: Add R8B8_R8G8 / B8R8_G8R8 formats, tweak G8B8. Based on how the first two swizzle, most likely G8B8 works that way too. --- rpcs3/Emu/GS/GL/GLGSRender.h | 54 +++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index ef1dfe387e..3fd39e1498 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -210,7 +210,7 @@ public: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_UNSIGNED_BYTE, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D"); - static const GLint swizzleMaskG8B8[] = { GL_ONE, GL_GREEN, GL_RED, GL_GREEN }; + static const GLint swizzleMaskG8B8[] = { GL_RED, GL_GREEN, GL_RED, GL_GREEN }; glRemap = swizzleMaskG8B8; } break; @@ -324,6 +324,58 @@ public: } break; + case CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8: + { + // TODO: Probably need to actually unswizzle if is_swizzled. + const u32 numPixels = tex.GetWidth() * tex.GetHeight(); + unswizzledPixels = (u8 *)malloc(numPixels * 4); + // TODO: Speed. + for (u32 i = 0; i < numPixels; i += 2) { + unswizzledPixels[i * 4 + 0 + 0] = pixels[i * 2 + 3]; + unswizzledPixels[i * 4 + 0 + 1] = pixels[i * 2 + 2]; + unswizzledPixels[i * 4 + 0 + 2] = pixels[i * 2 + 0]; + unswizzledPixels[i * 4 + 0 + 3] = 255; + + // The second pixel is the same, except for red. + unswizzledPixels[i * 4 + 4 + 0] = pixels[i * 2 + 1]; + unswizzledPixels[i * 4 + 4 + 1] = pixels[i * 2 + 2]; + unswizzledPixels[i * 4 + 4 + 2] = pixels[i * 2 + 0]; + unswizzledPixels[i * 4 + 4 + 3] = 255; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); + checkForGlError("GLTexture::Init() -> glTexImage2D"); + + free(unswizzledPixels); + } + break; + + case CELL_GCM_TEXTURE_COMPRESSED_R8B8_R8G8: + { + // TODO: Probably need to actually unswizzle if is_swizzled. + const u32 numPixels = tex.GetWidth() * tex.GetHeight(); + unswizzledPixels = (u8 *)malloc(numPixels * 4); + // TODO: Speed. + for (u32 i = 0; i < numPixels; i += 2) { + unswizzledPixels[i * 4 + 0 + 0] = pixels[i * 2 + 2]; + unswizzledPixels[i * 4 + 0 + 1] = pixels[i * 2 + 3]; + unswizzledPixels[i * 4 + 0 + 2] = pixels[i * 2 + 1]; + unswizzledPixels[i * 4 + 0 + 3] = 255; + + // The second pixel is the same, except for red. + unswizzledPixels[i * 4 + 4 + 0] = pixels[i * 2 + 0]; + unswizzledPixels[i * 4 + 4 + 1] = pixels[i * 2 + 3]; + unswizzledPixels[i * 4 + 4 + 2] = pixels[i * 2 + 1]; + unswizzledPixels[i * 4 + 4 + 3] = 255; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, unswizzledPixels); + checkForGlError("GLTexture::Init() -> glTexImage2D"); + + free(unswizzledPixels); + } + break; + default: ConLog.Error("Init tex error: Bad tex format (0x%x | %s | 0x%x)", format, (is_swizzled ? "swizzled" : "linear"), tex.GetFormat() & 0x40); break; } From 439dd9d8a386af7ae1c3bbc3d0d3bb23c9231299 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 May 2014 13:11:32 -0700 Subject: [PATCH 2/4] GL: Add Y16_X16_FLOAT tex format (untested.) --- rpcs3/Emu/GS/GL/GLGSRender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index 3fd39e1498..a10d7f1fd4 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -324,6 +324,16 @@ public: } break; + case CELL_GCM_TEXTURE_Y16_X16_FLOAT: // Two fp16 values + { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_HALF_FLOAT, pixels); + checkForGlError("GLTexture::Init() -> glTexImage2D"); + + static const GLint swizzleMaskX32_Y16_X16_FLOAT[] = { GL_GREEN, GL_RED, GL_GREEN, GL_RED }; + glRemap = swizzleMaskX32_Y16_X16_FLOAT; + } + break; + case CELL_GCM_TEXTURE_COMPRESSED_B8R8_G8R8: { // TODO: Probably need to actually unswizzle if is_swizzled. From 28b10157add92f04f1ed0113d2a516caa266b26d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 May 2014 13:37:34 -0700 Subject: [PATCH 3/4] GL: Add Y16_X16 tex format (untested.) --- rpcs3/Emu/GS/GL/GLGSRender.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index a10d7f1fd4..145fdd3c09 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -266,6 +266,16 @@ public: } break; + case CELL_GCM_TEXTURE_Y16_X16: // A 16-bit fixed-point number + { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_SHORT, pixels); + checkForGlError("GLTexture::Init() -> glTexImage2D"); + + static const GLint swizzleMaskX32_Y16_X16[] = { GL_GREEN, GL_RED, GL_GREEN, GL_RED }; + glRemap = swizzleMaskX32_Y16_X16; + } + break; + case CELL_GCM_TEXTURE_R5G5B5A1: glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei"); From c8dea6b9315fe90edc31e1d1171bd06feb15a57d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 May 2014 14:55:23 -0700 Subject: [PATCH 4/4] Typo. --- rpcs3/Emu/GS/GL/GLGSRender.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/GS/GL/GLGSRender.h b/rpcs3/Emu/GS/GL/GLGSRender.h index 145fdd3c09..8f73f09ead 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.h +++ b/rpcs3/Emu/GS/GL/GLGSRender.h @@ -117,7 +117,7 @@ public: break; case CELL_GCM_TEXTURE_A1R5G5B5: - glPixelStorei(GL_UNPACK_SWAP_BYTES, TRUE); + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); checkForGlError("GLTexture::Init() -> glPixelStorei"); // TODO: texture swizzling @@ -266,7 +266,7 @@ public: } break; - case CELL_GCM_TEXTURE_Y16_X16: // A 16-bit fixed-point number + case CELL_GCM_TEXTURE_Y16_X16: // Two 16-bit fixed-point numbers { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RG, GL_SHORT, pixels); checkForGlError("GLTexture::Init() -> glTexImage2D");