diff --git a/include/renderer_gl/textures.hpp b/include/renderer_gl/textures.hpp index 3abdece1..427c6361 100644 --- a/include/renderer_gl/textures.hpp +++ b/include/renderer_gl/textures.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include "boost/icl/interval.hpp" #include "helpers.hpp" #include "opengl.hpp" @@ -67,6 +68,14 @@ struct Texture { static u32 getSwizzledOffset(u32 u, u32 v, u32 width, u32 bytesPerPixel); static u32 getSwizzledOffset_4bpp(u32 u, u32 v, u32 width); + // Returns the string representation of a texture format + static std::string textureFormatToString(Formats fmt); + + // Returns the format of this texture as a string + std::string formatToString() { + return textureFormatToString(format); + } + // Returns the texel at coordinates (u, v) of an ETC1(A4) texture // TODO: Make hasAlpha a template parameter u32 getTexelETC(bool hasAlpha, u32 u, u32 v, u32 width, const void* data); diff --git a/src/core/renderer_gl/textures.cpp b/src/core/renderer_gl/textures.cpp index 6c42bfd4..e7e18034 100644 --- a/src/core/renderer_gl/textures.cpp +++ b/src/core/renderer_gl/textures.cpp @@ -229,4 +229,24 @@ void Texture::decodeTexture(const void* data) { texture.bind(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.u(), size.v(), GL_RGBA, GL_UNSIGNED_BYTE, decoded.data()); +} + +std::string Texture::textureFormatToString(Texture::Formats fmt) { + switch (fmt) { + case Formats::A4: return "A4"; + case Formats::A8: return "A8"; + case Formats::ETC1: return "ETC1"; + case Formats::ETC1A4: return "ETC1A4"; + case Formats::I4: return "I4"; + case Formats::I8: return "I8"; + case Formats::IA4: return "IA4"; + case Formats::IA8: return "IA8"; + case Formats::RG8: return "RG8"; + case Formats::RGB565: return "RGB565"; + case Formats::RGB8: return "RGB8"; + case Formats::RGBA4: return "RGBA4"; + case Formats::RGBA5551: return "RGBA5551"; + case Formats::RGBA8: return "RGBA8"; + default: return "Unknown"; + } } \ No newline at end of file