mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-05-13 11:11:22 +00:00
Fix RGB5A3 alpha, we want to swap before assigning the color or we stomp on alpha
This commit is contained in:
parent
a5d521b652
commit
247f36102b
@ -258,22 +258,22 @@ void CTexture::MangleMipmap(u32 mip) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint colors[4] = {
|
constexpr uint colors[4] = {
|
||||||
0x000000FF,
|
0x000000FF,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
0x00FF0000,
|
0x00FF0000,
|
||||||
0x0000FFFF,
|
0x0000FFFF,
|
||||||
};
|
};
|
||||||
const uint color = colors[(mip - 1) & 3];
|
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 >> 5) & 0x07E0) | // G
|
||||||
((color >> 8) & 0xF800); // R
|
((color >> 8) & 0xF800); // R
|
||||||
ushort rgb555Color = ((color >> 3) & 0x001F) | // B
|
const ushort rgb555Color = ((color >> 3) & 0x001F) | // B
|
||||||
((color >> 6) & 0x03E0) | // G
|
((color >> 6) & 0x03E0) | // G
|
||||||
((color >> 9) & 0x7C00); // R
|
((color >> 9) & 0x7C00); // R
|
||||||
ushort rgb4Color = ((color >> 4) & 0x000F) | // B
|
const ushort rgb4Color = ((color >> 4) & 0x000F) | // B
|
||||||
((color >> 8) & 0x00F0) | // G
|
((color >> 8) & 0x00F0) | // G
|
||||||
((color >> 12) & 0x0F00); // R
|
((color >> 12) & 0x0F00); // R
|
||||||
|
|
||||||
int width = GetWidth();
|
int width = GetWidth();
|
||||||
int height = GetHeight();
|
int height = GetHeight();
|
||||||
@ -287,7 +287,7 @@ void CTexture::MangleMipmap(u32 mip) {
|
|||||||
|
|
||||||
switch (GetTexelFormat()) {
|
switch (GetTexelFormat()) {
|
||||||
case ETexelFormat::RGB565: {
|
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) {
|
for (int i = 0; i < width * height; ++i) {
|
||||||
ptr[i + offset] = rgb565Color;
|
ptr[i + offset] = rgb565Color;
|
||||||
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[i + offset]));
|
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[i + offset]));
|
||||||
@ -295,7 +295,7 @@ void CTexture::MangleMipmap(u32 mip) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ETexelFormat::CMPR: {
|
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) {
|
for (int i = 0; i < width * height / 16; ++i, ptr += 4) {
|
||||||
ptr[0] = rgb565Color;
|
ptr[0] = rgb565Color;
|
||||||
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[0]));
|
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&ptr[0]));
|
||||||
@ -307,10 +307,11 @@ void CTexture::MangleMipmap(u32 mip) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ETexelFormat::RGB5A3: {
|
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) {
|
for (int i = 0; i < width * height; ++i) {
|
||||||
ushort& val = ptr[i + offset];
|
ushort& val = ptr[i + offset];
|
||||||
if (val & 0x8000) {
|
CBasics::Swap2Bytes(reinterpret_cast<u8*>(&val));
|
||||||
|
if ((val & 0x8000) != 0) {
|
||||||
val = rgb555Color | 0x8000;
|
val = rgb555Color | 0x8000;
|
||||||
} else {
|
} else {
|
||||||
val = (val & 0xF000) | rgb4Color;
|
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::sCurrentFrameCount = 0;
|
||||||
u32 CTexture::sTotalAllocatedMemory = 0;
|
u32 CTexture::sTotalAllocatedMemory = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user