2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-05-13 11:51:21 +00:00

Fix RGB5A3 alpha, we want to swap before assigning the color or we stomp on alpha

This commit is contained in:
Phillip Stephens 2025-04-14 18:36:21 -07:00
parent a5d521b652
commit 247f36102b

View File

@ -258,20 +258,20 @@ void CTexture::MangleMipmap(u32 mip) {
return;
}
const uint colors[4] = {
constexpr uint colors[4] = {
0x000000FF,
0x0000FF00,
0x00FF0000,
0x0000FFFF,
};
const uint color = colors[(mip - 1) & 3];
ushort rgb565Color = ((color >> 3) & 0x001F) | // B
const ushort rgb565Color = ((color >> 3) & 0x001F) | // B
((color >> 5) & 0x07E0) | // G
((color >> 8) & 0xF800); // R
ushort rgb555Color = ((color >> 3) & 0x001F) | // B
const ushort rgb555Color = ((color >> 3) & 0x001F) | // B
((color >> 6) & 0x03E0) | // G
((color >> 9) & 0x7C00); // R
ushort rgb4Color = ((color >> 4) & 0x000F) | // B
const ushort rgb4Color = ((color >> 4) & 0x000F) | // B
((color >> 8) & 0x00F0) | // G
((color >> 12) & 0x0F00); // R
@ -287,7 +287,7 @@ void CTexture::MangleMipmap(u32 mip) {
switch (GetTexelFormat()) {
case ETexelFormat::RGB565: {
ushort* ptr = reinterpret_cast< ushort* >(x44_aramToken_x4_buff.get());//mARAMToken.GetMRAMSafe());
const auto ptr = reinterpret_cast<ushort*>(x44_aramToken_x4_buff.get()); // mARAMToken.GetMRAMSafe());
for (int i = 0; i < width * height; ++i) {
ptr[i + offset] = rgb565Color;
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[i + offset]));
@ -295,7 +295,7 @@ void CTexture::MangleMipmap(u32 mip) {
break;
}
case ETexelFormat::CMPR: {
ushort* ptr = reinterpret_cast< ushort* >(x44_aramToken_x4_buff.get()) + offset / 4;
auto ptr = reinterpret_cast<ushort*>(x44_aramToken_x4_buff.get()) + offset / 4;
for (int i = 0; i < width * height / 16; ++i, ptr += 4) {
ptr[0] = rgb565Color;
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[0]));
@ -307,10 +307,11 @@ void CTexture::MangleMipmap(u32 mip) {
break;
}
case ETexelFormat::RGB5A3: {
ushort* ptr = reinterpret_cast< ushort* >(x44_aramToken_x4_buff.get());
const auto ptr = reinterpret_cast<ushort*>(x44_aramToken_x4_buff.get());
for (int i = 0; i < width * height; ++i) {
ushort& val = ptr[i + offset];
if (val & 0x8000) {
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&val));
if ((val & 0x8000) != 0) {
val = rgb555Color | 0x8000;
} else {
val = (val & 0xF000) | rgb4Color;
@ -346,7 +347,7 @@ u32 CTexture::TexelFormatBitsPerPixel(ETexelFormat fmt) {
}
}
bool CTexture::sMangleMips = false;
bool CTexture::sMangleMips = true;
u32 CTexture::sCurrentFrameCount = 0;
u32 CTexture::sTotalAllocatedMemory = 0;