1
0
Fork 0
forked from suyu/suyu

Pica/DebugUtils: Add support for RGBA8, RGBA5551, RGBA4 and A8 texture formats.

This commit is contained in:
Tony Wasserka 2014-12-06 21:20:56 +01:00
parent 782592e6d3
commit c81f1a9ebc
2 changed files with 48 additions and 3 deletions

View file

@ -357,7 +357,6 @@ std::unique_ptr<PicaTrace> FinishPicaTracing()
} }
const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) {
_dbg_assert_(Debug_GPU, info.format == Pica::Regs::TextureFormat::RGB8);
// Cf. rasterizer code for an explanation of this algorithm. // Cf. rasterizer code for an explanation of this algorithm.
int texel_index_within_tile = 0; int texel_index_within_tile = 0;
@ -376,8 +375,52 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture
int coarse_x = (x / block_width) * block_width; int coarse_x = (x / block_width) * block_width;
int coarse_y = (y / block_height) * block_height; int coarse_y = (y / block_height) * block_height;
switch (info.format) {
case Regs::TextureFormat::RGBA8:
{
const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4;
return { source_ptr[3], source_ptr[2], source_ptr[1], 255 };
}
case Regs::TextureFormat::RGB8:
{
const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3; const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3;
return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; return { source_ptr[2], source_ptr[1], source_ptr[0], 255 };
}
case Regs::TextureFormat::RGBA5551:
{
const u16 source_ptr = *(const u16*)(source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2);
u8 r = (source_ptr >> 11) & 0x1F;
u8 g = ((source_ptr) >> 6) & 0x1F;
u8 b = (source_ptr >> 1) & 0x1F;
u8 a = 1;
return Math::MakeVec<u8>((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), a * 255);
}
case Regs::TextureFormat::RGBA4:
{
const u8* source_ptr = source + coarse_x * block_height * 2 + coarse_y * info.stride + texel_index_within_tile * 2;
u8 r = source_ptr[1] >> 4;
u8 g = source_ptr[1] & 0xFF;
u8 b = source_ptr[0] >> 4;
r = (r << 4) | r;
g = (g << 4) | g;
b = (b << 4) | b;
return { r, g, b, 255 };
}
case Regs::TextureFormat::A8:
{
const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile;
return { *source_ptr, *source_ptr, *source_ptr, 255 };
}
default:
LOG_ERROR(HW_GPU, "Unknown texture format: %x", (u32)info.format);
_dbg_assert_(HW_GPU, 0);
return {};
}
} }
TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,

View file

@ -132,6 +132,8 @@ struct Regs {
RGB565 = 3, RGB565 = 3,
RGBA4 = 4, RGBA4 = 4,
A8 = 8,
// TODO: Support for the other formats is not implemented, yet. // TODO: Support for the other formats is not implemented, yet.
// Seems like they are luminance formats and compressed textures. // Seems like they are luminance formats and compressed textures.
}; };