mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 20:37:18 +12:00
Bisect TextureFmt
and ColorFmt
Makes framebuffer-formats unrepresentable from texture formats while allowing them to alias each other. Add utility functions as well that just re-use the `TextureFmt` ones.
This commit is contained in:
parent
134e16d8ea
commit
6ee3f73335
5 changed files with 70 additions and 54 deletions
|
@ -130,7 +130,7 @@ namespace PICA {
|
|||
};
|
||||
}
|
||||
|
||||
enum class ColorFmt : u32 {
|
||||
enum class TextureFmt : u32 {
|
||||
RGBA8 = 0x0,
|
||||
RGB8 = 0x1,
|
||||
RGBA5551 = 0x2,
|
||||
|
@ -147,6 +147,14 @@ namespace PICA {
|
|||
ETC1A4 = 0xD,
|
||||
};
|
||||
|
||||
enum class ColorFmt : u32 {
|
||||
RGBA8 = 0x0,
|
||||
RGB8 = 0x1,
|
||||
RGBA5551 = 0x2,
|
||||
RGB565 = 0x3,
|
||||
RGBA4 = 0x4,
|
||||
};
|
||||
|
||||
enum class DepthFmt : u32 {
|
||||
Depth16 = 0,
|
||||
Unknown1 = 1, // Technically selectable, but function is unknown
|
||||
|
@ -155,39 +163,47 @@ namespace PICA {
|
|||
};
|
||||
|
||||
// Returns the string representation of a texture format
|
||||
inline constexpr const char* textureFormatToString(ColorFmt fmt) {
|
||||
inline constexpr const char* textureFormatToString(TextureFmt fmt) {
|
||||
switch (fmt) {
|
||||
case ColorFmt::RGBA8: return "RGBA8";
|
||||
case ColorFmt::RGB8: return "RGB8";
|
||||
case ColorFmt::RGBA5551: return "RGBA5551";
|
||||
case ColorFmt::RGB565: return "RGB565";
|
||||
case ColorFmt::RGBA4: return "RGBA4";
|
||||
case ColorFmt::IA8: return "IA8";
|
||||
case ColorFmt::RG8: return "RG8";
|
||||
case ColorFmt::I8: return "I8";
|
||||
case ColorFmt::A8: return "A8";
|
||||
case ColorFmt::IA4: return "IA4";
|
||||
case ColorFmt::I4: return "I4";
|
||||
case ColorFmt::A4: return "A4";
|
||||
case ColorFmt::ETC1: return "ETC1";
|
||||
case ColorFmt::ETC1A4: return "ETC1A4";
|
||||
case TextureFmt::RGBA8: return "RGBA8";
|
||||
case TextureFmt::RGB8: return "RGB8";
|
||||
case TextureFmt::RGBA5551: return "RGBA5551";
|
||||
case TextureFmt::RGB565: return "RGB565";
|
||||
case TextureFmt::RGBA4: return "RGBA4";
|
||||
case TextureFmt::IA8: return "IA8";
|
||||
case TextureFmt::RG8: return "RG8";
|
||||
case TextureFmt::I8: return "I8";
|
||||
case TextureFmt::A8: return "A8";
|
||||
case TextureFmt::IA4: return "IA4";
|
||||
case TextureFmt::I4: return "I4";
|
||||
case TextureFmt::A4: return "A4";
|
||||
case TextureFmt::ETC1: return "ETC1";
|
||||
case TextureFmt::ETC1A4: return "ETC1A4";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
inline constexpr const char* textureFormatToString(ColorFmt fmt) {
|
||||
return textureFormatToString(static_cast<TextureFmt>(fmt));
|
||||
}
|
||||
|
||||
inline constexpr bool hasStencil(DepthFmt format) { return format == PICA::DepthFmt::Depth24Stencil8; }
|
||||
|
||||
// Size occupied by each pixel in bytes
|
||||
|
||||
// All formats are 16BPP except for RGBA8 (32BPP) and BGR8 (24BPP)
|
||||
inline constexpr usize sizePerPixel(ColorFmt format) {
|
||||
inline constexpr usize sizePerPixel(TextureFmt format) {
|
||||
switch (format) {
|
||||
case ColorFmt::RGB8: return 3;
|
||||
case ColorFmt::RGBA8: return 4;
|
||||
case TextureFmt::RGB8: return 3;
|
||||
case TextureFmt::RGBA8: return 4;
|
||||
default: return 2;
|
||||
}
|
||||
}
|
||||
|
||||
inline constexpr usize sizePerPixel(ColorFmt format) {
|
||||
return sizePerPixel(static_cast<TextureFmt>(format));
|
||||
}
|
||||
|
||||
inline constexpr usize sizePerPixel(DepthFmt format) {
|
||||
switch (format) {
|
||||
case DepthFmt::Depth16: return 2;
|
||||
|
|
|
@ -46,7 +46,7 @@ class Renderer {
|
|||
|
||||
OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)'
|
||||
|
||||
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
|
||||
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
|
||||
PICA::ColorFmt colourBufferFormat; // Format of the colours stored in the colour buffer
|
||||
|
||||
// Same for the depth/stencil buffer
|
||||
|
|
|
@ -12,7 +12,7 @@ using Interval = boost::icl::right_open_interval<T>;
|
|||
struct Texture {
|
||||
u32 location;
|
||||
u32 config; // Magnification/minification filter, wrapping configs, etc
|
||||
PICA::ColorFmt format;
|
||||
PICA::TextureFmt format;
|
||||
OpenGL::uvec2 size;
|
||||
bool valid;
|
||||
|
||||
|
@ -23,7 +23,7 @@ struct Texture {
|
|||
|
||||
Texture() : valid(false) {}
|
||||
|
||||
Texture(u32 loc, PICA::ColorFmt format, u32 x, u32 y, u32 config, bool valid = true)
|
||||
Texture(u32 loc, PICA::TextureFmt format, u32 x, u32 y, u32 config, bool valid = true)
|
||||
: location(loc), format(format), size({x, y}), config(config), valid(valid) {
|
||||
|
||||
u64 endLoc = (u64)loc + sizeInBytes();
|
||||
|
@ -44,7 +44,7 @@ struct Texture {
|
|||
void free();
|
||||
u64 sizeInBytes();
|
||||
|
||||
u32 decodeTexel(u32 u, u32 v, PICA::ColorFmt fmt, const void* data);
|
||||
u32 decodeTexel(u32 u, u32 v, PICA::TextureFmt fmt, const void* data);
|
||||
|
||||
// Get the morton interleave offset of a texel based on its U and V values
|
||||
static u32 mortonInterleave(u32 u, u32 v);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue