Debian Codegraph @

Source/Core/VideoCommon/TextureInfo.h

raw symbols SCIP
1 // Copyright 2021 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <optional>
7 #include <span>
8 #include <string>
9 #include <string_view>
10
11 #include "Common/CommonTypes.h"
12
13 enum class TextureFormat;
14 enum class TLUTFormat;
15
16 class TextureInfo final
17 {
18 public:
19 static TextureInfo FromStage(u32 stage);
20 TextureInfo(u32 stage, std::span<const u8> data, std::span<const u8> tlut_data, u32 address,
21 TextureFormat texture_format, TLUTFormat tlut_format, u32 width, u32 height,
22 bool from_tmem, std::span<const u8> tmem_odd, std::span<const u8> tmem_even,
23 std::optional<u32> mip_count);
24
25 struct NameDetails
26 {
27 std::string base_name;
28 std::string texture_name;
29 std::string tlut_name;
30 std::string format_name;
31
32 std::string GetFullName() const;
33 };
34 NameDetails CalculateTextureName() const;
35
36 bool IsDataValid() const { return m_data_valid; }
37
38 const u8* GetData() const { return m_data.data(); }
39 const u8* GetTlutAddress() const { return m_tlut_data.data(); }
40
41 u32 GetRawAddress() const { return m_address; }
42
43 bool IsFromTmem() const { return m_from_tmem; }
44 const u8* GetTmemOddAddress() const { return m_tmem_odd.data(); }
45
46 TextureFormat GetTextureFormat() const { return m_texture_format; }
47 TLUTFormat GetTlutFormat() const { return m_tlut_format; }
48
49 std::optional<u32> GetPaletteSize() const { return m_palette_size; }
50 u32 GetTextureSize() const { return m_texture_size; }
51
52 u32 GetBlockWidth() const { return m_block_width; }
53 u32 GetBlockHeight() const { return m_block_height; }
54
55 u32 GetExpandedWidth() const { return m_expanded_width; }
56 u32 GetExpandedHeight() const { return m_expanded_height; }
57
58 u32 GetRawWidth() const { return m_raw_width; }
59 u32 GetRawHeight() const { return m_raw_height; }
60
61 u32 GetStage() const { return m_stage; }
62
63 class MipLevel final
64 {
65 public:
66 MipLevel() = default;
67 MipLevel(u32 level, const TextureInfo& parent, std::span<const u8>* data);
68
69 bool IsDataValid() const { return m_data_valid; }
70
71 const u8* GetData() const { return m_ptr; }
72 u32 GetTextureSize() const { return m_texture_size; }
73
74 u32 GetExpandedWidth() const { return m_expanded_width; }
75 u32 GetExpandedHeight() const { return m_expanded_height; }
76
77 u32 GetRawWidth() const { return m_raw_width; }
78 u32 GetRawHeight() const { return m_raw_height; }
79
80 u32 GetLevel() const { return m_level; }
81
82 private:
83 bool m_data_valid = false;
84
85 const u8* m_ptr = nullptr;
86
87 u32 m_texture_size = 0;
88
89 u32 m_expanded_width = 0;
90 u32 m_raw_width = 0;
91
92 u32 m_expanded_height = 0;
93 u32 m_raw_height = 0;
94
95 u32 m_level = 0;
96 };
97
98 class MipLevelIterator final
99 {
100 friend TextureInfo;
101
102 public:
103 using difference_type = u32;
104 using value_type = MipLevel;
105
106 MipLevel& operator*() { return m_mip_level; }
107
108 const MipLevel& operator*() const { return m_mip_level; }
109
110 MipLevelIterator& operator++();
111
112 MipLevelIterator operator++(int)
113 {
114 auto tmp = *this;
115 ++*this;
116 return tmp;
117 }
118
119 bool operator==(const MipLevelIterator& other) const
120 {
121 return m_level_index == other.m_level_index;
122 }
123
124 private:
125 void CreateMipLevel();
126
127 MipLevel m_mip_level;
128
129 const TextureInfo* m_parent = nullptr;
130 u32 m_level_index = 0;
131 bool m_from_tmem = false;
132 std::span<const u8> m_data;
133 std::span<const u8> m_tmem_even;
134 std::span<const u8> m_tmem_odd;
135 };
136
137 class MipLevels final
138 {
139 public:
140 MipLevels(MipLevelIterator begin, MipLevelIterator end) : m_begin(begin), m_end(end) {}
141
142 MipLevelIterator begin() const { return m_begin; }
143 MipLevelIterator end() const { return m_end; }
144
145 private:
146 MipLevelIterator m_begin;
147 MipLevelIterator m_end;
148 };
149
150 bool HasMipMaps() const { return m_limited_mip_count != 0; }
151 u32 GetLevelCount() const { return m_limited_mip_count + 1; }
152 MipLevels GetMipMapLevels() const;
153 u32 GetFullLevelSize() const;
154
155 static constexpr std::string_view format_prefix{"tex1_"};
156
157 private:
158 std::span<const u8> m_data;
159 std::span<const u8> m_tlut_data;
160
161 u32 m_address;
162
163 bool m_data_valid;
164
165 bool m_from_tmem;
166 std::span<const u8> m_tmem_even;
167 std::span<const u8> m_tmem_odd;
168
169 TextureFormat m_texture_format;
170 TLUTFormat m_tlut_format;
171
172 bool m_mipmaps_enabled = false;
173 u32 m_limited_mip_count = 0;
174
175 u32 m_texture_size = 0;
176 std::optional<u32> m_palette_size;
177
178 u32 m_block_width;
179 u32 m_expanded_width;
180 u32 m_raw_width;
181
182 u32 m_block_height;
183 u32 m_expanded_height;
184 u32 m_raw_height;
185
186 u32 m_stage;
187 };