NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
lyt_material.h
1#ifndef NW4R_LYT_MATERIAL_H
2#define NW4R_LYT_MATERIAL_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/lyt/lyt_common.h>
6#include <nw4r/lyt/lyt_animation.h>
7#include <nw4r/lyt/lyt_texMap.h>
8#include <nw4r/lyt/lyt_types.h>
9
10#include <nw4r/ut.h>
11
12#include <revolution/GX.h>
13
14namespace nw4r {
15namespace lyt {
16
17// Forward declarations
18class AnimTransform;
19struct ResBlockSet;
20
21namespace detail {
22
23/******************************************************************************
24 *
25 * BitGXNums
26 *
27 ******************************************************************************/
28struct BitGXNums {
29 ulong texMap : 4;
30 ulong texSRT : 4;
31 ulong texCoordGen : 4;
32 ulong indSRT : 2;
33 ulong indStage : 3;
34 ulong tevSwap : 1;
35 ulong tevStage : 5;
36 ulong chanCtrl : 1;
37 ulong matCol : 1;
38 ulong alpComp : 1;
39 ulong blendMode : 1;
40};
41
42} // namespace detail
43
44namespace res {
45
46/******************************************************************************
47 *
48 * MAT1 binary layout
49 *
50 ******************************************************************************/
51struct Material {
52 char name[NW4R_LYT_MATERIAL_NAME_LEN]; // at 0x0
53 GXColorS10 tevCols[TEVCOLOR_MAX]; // at 0x14
54 GXColor tevKCols[GX_MAX_KCOLOR]; // at 0x2C
55 MaterialResourceNum resNum; // at 0x3C
56};
57
58} // namespace res
59
60/******************************************************************************
61 *
62 * Material
63 *
64 ******************************************************************************/
65class Material {
66public:
67 Material(const res::Material* pRes, const ResBlockSet& rBlockSet);
68 virtual ~Material(); // at 0x8
69
70 virtual bool SetupGX(bool modulate, u8 alpha); // at 0xC
71
72 virtual void BindAnimation(AnimTransform* pAnimTrans); // at 0x10
73 virtual void UnbindAnimation(AnimTransform* pAnimTrans); // at 0x14
74 virtual void UnbindAllAnimation(); // at 0x18
75
76 virtual void Animate(); // at 0x1C
77
78 virtual AnimationLink*
79 FindAnimationLink(AnimTransform* pAnimTrans); // at 0x20
80 virtual AnimationLink*
81 FindAnimationLink(const AnimResource& animRes); // at 0x24
82
83 virtual void SetAnimationEnable(AnimTransform* pAnimTrans,
84 bool enable); // at 0x28
85 virtual void SetAnimationEnable(const AnimResource& animRes,
86 bool enable); // at 0x2C
87
88 void AddAnimationLink(AnimationLink* pAnimLink);
89
90 GXColorS10 GetTevColor(ulong idx) {
91 return mTevCols[idx];
92 }
93 void SetTevColor(ulong idx, const GXColorS10& rColor) {
94 mTevCols[idx] = rColor;
95 }
96
97 ut::Color GetTevKColor(ulong idx) {
98 return mTevKCols[idx];
99 }
100 void SetTevKColor(ulong idx, ut::Color color) {
101 mTevKCols[idx] = color;
102 }
103
104 u8 GetTextureNum() const {
105 return mGXMemNum.texMap;
106 }
107 u8 GetTextureCap() const {
108 return mGXMemCap.texMap;
109 }
110 void SetTextureNum(u8 num);
111
112 u8 GetTexSRTCap() const {
113 return mGXMemCap.texSRT;
114 }
115
116 u8 GetTexCoordGenCap() const {
117 return mGXMemCap.texCoordGen;
118 }
119 void SetTexCoordGenNum(u8 num);
120
121 u8 GetIndTexSRTCap() const {
122 return mGXMemCap.indSRT;
123 }
124
125 u8 GetTevStageNum() const {
126 return mGXMemNum.tevStage;
127 }
128 void SetTevStageNum(u8 num);
129
130 void SetIndStageNum(u8 num);
131
132 void SetColorElement(ulong idx, s16 value);
133
134 bool IsTevSwapCap() const {
135 return mGXMemCap.tevSwap;
136 }
137 bool IsChanCtrlCap() const {
138 return mGXMemCap.chanCtrl;
139 }
140 bool IsMatColorCap() const {
141 return mGXMemCap.matCol;
142 }
143 bool IsAlphaCompareCap() const {
144 return mGXMemCap.alpComp;
145 }
146 bool IsBlendModeCap() const {
147 return mGXMemCap.blendMode;
148 }
149
150 const TexMap* GetTexMapAry() const;
151 TexMap* GetTexMapAry();
152
153 const TexSRT* GetTexSRTAry() const;
154 TexSRT* GetTexSRTAry();
155
156 const TexCoordGen* GetTexCoordGenAry() const;
157 TexCoordGen* GetTexCoordGenAry();
158
159 const ChanCtrl* GetChanCtrlAry() const;
160 ChanCtrl* GetChanCtrlAry();
161
162 const ut::Color* GetMatColAry() const;
163 ut::Color* GetMatColAry();
164
165 const TevSwapMode* GetTevSwapAry() const;
166 TevSwapMode* GetTevSwapAry();
167
168 const AlphaCompare* GetAlphaComparePtr() const;
169 AlphaCompare* GetAlphaComparePtr();
170
171 const BlendMode* GetBlendModePtr() const;
172 BlendMode* GetBlendModePtr();
173
174 const IndirectStage* GetIndirectStageAry() const;
175 IndirectStage* GetIndirectStageAry();
176
177 const TexSRT* GetIndTexSRTAry() const;
178 TexSRT* GetIndTexSRTAry();
179
180 const TevStage* GetTevStageAry() const;
181 TevStage* GetTevStageAry();
182
183 const TexMap& GetTexture(u8 idx) const {
184 return GetTexMapAry()[idx];
185 }
186 void GetTexture(GXTexObj* pTexObj, u8 idx) const {
187 GetTexMapAry()[idx].Get(pTexObj);
188 }
189 void SetTexture(u8 idx, const TexMap& rTexMap) {
190 GetTexMapAry()[idx].Set(rTexMap);
191 }
192 void SetTextureNoWrap(u8 idx, const TexMap& rTexMap) {
193 GetTexMapAry()[idx].SetNoWrap(rTexMap);
194 }
195
196 const TexSRT& GetTexSRT(ulong idx) const {
197 return GetTexSRTAry()[idx];
198 }
199 void SetTexSRT(const TexSRT& rTexSRT, ulong idx) {
200 GetTexSRTAry()[idx] = rTexSRT;
201 }
202
203 void SetTexSRTElement(ulong srt, ulong idx, f32 value) {
204 f32* const pArray = reinterpret_cast<f32*>(&GetTexSRTAry()[srt]);
205 pArray[idx] = value;
206 }
207
208 void SetTexCoordGen(ulong idx, TexCoordGen gen) {
209 GetTexCoordGenAry()[idx] = gen;
210 }
211
212 ut::Color GetMatColor() const {
213 return GetMatColAry()[0];
214 }
215
216 void SetIndTexSRTElement(ulong srt, ulong idx, f32 value) {
217 f32* const pArray = reinterpret_cast<f32*>(&GetIndTexSRTAry()[srt]);
218 pArray[idx] = value;
219 }
220
221 void SetName(const char* pName);
222 const char* GetName() const {
223 return mName;
224 }
225
226 bool IsUserAllocated() const {
227 return mbUserAllocated;
228 }
229
230protected:
231 static const int MAX_TEX_SRT = (GX_TEXMTX9 - GX_TEXMTX0) / 3 + 1;
232 static const int MAX_IND_SRT = (GX_ITM_2 - GX_ITM_0) + 1;
233
234protected:
235 AnimationLinkList mAnimList; // at 0x4
236
237 GXColorS10 mTevCols[TEVCOLOR_MAX]; // at 0x10
238 ut::Color mTevKCols[GX_MAX_KCOLOR]; // at 0x28
239
240 detail::BitGXNums mGXMemCap; // at 0x38
241 detail::BitGXNums mGXMemNum; // at 0x3C
242 void* mpGXMem; // at 0x40
243
244 char mName[NW4R_LYT_MATERIAL_NAME_LEN + 1]; // at 0x44
245 bool mbUserAllocated; // at 0x59
246
247 u8 PADDING_0x5A[0x5C - 0x5A]; // at 0x5A
248
249private:
250 void Init();
251 void InitBitGXNums(detail::BitGXNums* pNums);
252
253 void ReserveGXMem(u8 texMapNum, u8 texSrtNum, u8 texCoordGenNum,
254 u8 tevStageNum, bool allocTevSwap, u8 indStageNum,
255 u8 indSrtNum, bool allocChanCtrl, bool allocMatCol,
256 bool allocAlpComp, bool allocBlendMode);
257};
258
259/******************************************************************************
260 *
261 * Functions
262 *
263 ******************************************************************************/
264namespace detail {
265
266Size GetTextureSize(Material* pMaterial, u8 idx);
267
268} // namespace detail
269} // namespace lyt
270} // namespace nw4r
271
272#endif
2D graphics drawing library.