// Copyright 2021 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include "Common/CommonTypes.h" enum class TextureFormat; enum class TLUTFormat; class TextureInfo { public: static TextureInfo FromStage(u32 stage); TextureInfo(u32 stage, std::span data, std::span tlut_data, u32 address, TextureFormat texture_format, TLUTFormat tlut_format, u32 width, u32 height, bool from_tmem, std::span tmem_odd, std::span tmem_even, std::optional mip_count); struct NameDetails { std::string base_name; std::string texture_name; std::string tlut_name; std::string format_name; std::string GetFullName() const; }; NameDetails CalculateTextureName() const; bool IsDataValid() const; const u8* GetData() const; const u8* GetTlutAddress() const; u32 GetRawAddress() const; bool IsFromTmem() const; const u8* GetTmemOddAddress() const; TextureFormat GetTextureFormat() const; TLUTFormat GetTlutFormat() const; std::optional GetPaletteSize() const; u32 GetTextureSize() const; u32 GetBlockWidth() const; u32 GetBlockHeight() const; u32 GetExpandedWidth() const; u32 GetExpandedHeight() const; u32 GetRawWidth() const; u32 GetRawHeight() const; u32 GetStage() const; class MipLevel final { public: MipLevel() = default; MipLevel(u32 level, const TextureInfo& parent, std::span* data); bool IsDataValid() const; const u8* GetData() const; u32 GetTextureSize() const; u32 GetExpandedWidth() const; u32 GetExpandedHeight() const; u32 GetRawWidth() const; u32 GetRawHeight() const; u32 GetLevel() const; private: bool m_data_valid = false; const u8* m_ptr = nullptr; u32 m_texture_size = 0; u32 m_expanded_width = 0; u32 m_raw_width = 0; u32 m_expanded_height = 0; u32 m_raw_height = 0; u32 m_level = 0; }; class MipLevelIterator final { friend TextureInfo; public: using difference_type = u32; using value_type = MipLevel; MipLevel& operator*() { return m_mip_level; } const MipLevel& operator*() const { return m_mip_level; } MipLevelIterator& operator++(); MipLevelIterator operator++(int) { auto tmp = *this; ++*this; return tmp; } bool operator==(const MipLevelIterator& other) const { return m_level_index == other.m_level_index; } private: void CreateMipLevel(); MipLevel m_mip_level; const TextureInfo* m_parent = nullptr; u32 m_level_index = 0; bool m_from_tmem = false; std::span m_data; std::span m_tmem_even; std::span m_tmem_odd; }; class MipLevels final { public: MipLevels(MipLevelIterator begin, MipLevelIterator end) : m_begin(begin), m_end(end) {} MipLevelIterator begin() const { return m_begin; } MipLevelIterator end() const { return m_end; } private: MipLevelIterator m_begin; MipLevelIterator m_end; }; bool HasMipMaps() const; u32 GetLevelCount() const; MipLevels GetMipMapLevels() const; u32 GetFullLevelSize() const; static constexpr std::string_view format_prefix{"tex1_"}; private: std::span m_data; std::span m_tlut_data; u32 m_address; bool m_data_valid; bool m_from_tmem; std::span m_tmem_even; std::span m_tmem_odd; TextureFormat m_texture_format; TLUTFormat m_tlut_format; bool m_mipmaps_enabled = false; u32 m_limited_mip_count = 0; u32 m_texture_size = 0; std::optional m_palette_size; u32 m_block_width; u32 m_expanded_width; u32 m_raw_width; u32 m_block_height; u32 m_expanded_height; u32 m_raw_height; u32 m_stage; };