NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
g3d_resmat.h
1#ifndef NW4R_G3D_RES_RES_MAT_H
2#define NW4R_G3D_RES_RES_MAT_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/g3d/res/g3d_resanmtexsrt.h>
6#include <nw4r/g3d/res/g3d_rescommon.h>
7#include <nw4r/g3d/res/g3d_respltt.h>
8#include <nw4r/g3d/res/g3d_restev.h>
9#include <nw4r/g3d/res/g3d_restex.h>
10
11#include <nw4r/math.h>
12
13#include <revolution/GX.h>
14
15namespace nw4r {
16namespace g3d {
17
18// Forward declarations
19class ResFile;
20class ResMdl;
21
22/******************************************************************************
23 *
24 * ResGenMode
25 *
26 ******************************************************************************/
28 u8 nTexGens; // at 0x0
29 u8 nChans; // at 0x1
30 u8 nTevs; // at 0x2
31 u8 nInds; // at 0x3
32 GXCullMode cullMode; // at 0x4
33};
34
35class ResGenMode : public ResCommon<ResGenModeData> {
36public:
37 NW4R_G3D_RESOURCE_FUNC_DEF(ResGenMode);
38
39 ResGenMode CopyTo(void* pDst) const;
40
41 void GXSetNumTexGens(u8 num);
42 void GXSetNumChans(u8 num);
43 void GXSetNumTevStages(u8 num);
44 void GXSetNumIndStages(u8 num);
45 void GXSetCullMode(GXCullMode mode);
46
47 u8 GXGetNumTexGens() const {
48 return IsValid() ? ptr()->nTexGens : 0;
49 }
50
51 u8 GXGetNumChans() const {
52 return IsValid() ? ptr()->nChans : 0;
53 }
54
55 u8 GXGetNumTevStages() const {
56 return IsValid() ? ptr()->nTevs : 0;
57 }
58
59 u8 GXGetNumIndStages() const {
60 return IsValid() ? ptr()->nInds : 0;
61 }
62
63 GXCullMode GXGetCullMode() const {
64 return IsValid() ? ptr()->cullMode : GX_CULL_ALL;
65 }
66
67 void EndEdit() {}
68};
69
70/******************************************************************************
71 *
72 * ResMatMisc
73 *
74 ******************************************************************************/
76 enum IndirectMethod {
77 WARP,
78 NORMAL_MAP,
79 NORMAL_MAP_SPECULAR,
80 FUR,
81
82 _RESERVED0,
83 _RESERVED1,
84
85 USER0,
86 USER1,
87
88 NUM_OF_INDIRECT_METHOD,
89 };
90
91 GXBool zCompLoc; // at 0x0
92 s8 light_set_idx; // at 0x1
93 s8 fog_idx; // at 0x2
94 u8 PADDING_0x3; // at 0x3
95 u8 indirect_method[GX_ITM_2 + 1]; // at 0x4
96 s8 normal_map_ref_light[GX_ITM_2 + 1]; // at 0x8
97};
98
99class ResMatMisc : public ResCommon<ResMatMiscData> {
100public:
101 NW4R_G3D_RESOURCE_FUNC_DEF(ResMatMisc);
102
103 ResMatMisc CopyTo(void* pDst) const;
104
105 GXBool GXGetZCompLoc() const;
106 void SetLightSetIdx(int);
107 int GetLightSetIdx() const;
108 int GetFogIdx() const;
109
110 void GetIndirectTexMtxCalcMethod(GXIndTexMtxID id,
111 ResMatMiscData::IndirectMethod* pMethod,
112 s8* pLightRef);
113
114 void EndEdit() {}
115};
116
117/******************************************************************************
118 *
119 * ResMatTexCoordGen
120 *
121 ******************************************************************************/
123 union {
124 struct {
125 u8 texCoordGen[GX_MAX_TEXCOORD][GX_XF_CMD_SZ * 2]; // at 0x0
126 u8 PADDING_0x90[0xA0 - 0x90]; // at 0x90
127 } dl;
128
129 u8 data[0xA0];
130 };
131};
132
133class ResMatTexCoordGen : public ResCommon<ResTexCoordGenDL> {
134public:
135 NW4R_G3D_RESOURCE_FUNC_DEF_EX(ResMatTexCoordGen, ResTexCoordGenDL);
136
137 void DCStore(bool sync);
138 ResMatTexCoordGen CopyTo(void* pDst) const;
139
140 void CallDisplayList(u8 numGens, bool sync) const;
141
142 bool GXGetTexCoordGen2(GXTexCoordID id, GXTexGenType* pFunc,
143 GXTexGenSrc* pParam, GXBool* pNormalize,
144 ulong* pPostMtx) const;
145 void GXSetTexCoordGen2(GXTexCoordID id, GXTexGenType func,
146 GXTexGenSrc param, GXBool normalize, ulong postMtx);
147
148 void EndEdit() {
149 DCStore(false);
150 }
151};
152
153/******************************************************************************
154 *
155 * ResTexObj
156 *
157 ******************************************************************************/
159 ulong flagUsedTexMapID; // at 0x0
160 GXTexObj texObj[GX_MAX_TEXMAP]; // at 0x4
161};
162
163class ResTexObj : public ResCommon<ResTexObjData> {
164public:
165 NW4R_G3D_RESOURCE_FUNC_DEF(ResTexObj);
166
167 ResTexObj CopyTo(void* pDst) const;
168
169 const GXTexObj* GetTexObj(GXTexMapID id) const;
170 GXTexObj* GetTexObj(GXTexMapID id);
171
172 bool IsValidTexObj(GXTexMapID id) const;
173
174 void Validate(GXTexMapID id);
175 void Invalidate(GXTexMapID id);
176
177 void EndEdit() {}
178};
179
180/******************************************************************************
181 *
182 * ResTlutObj
183 *
184 ******************************************************************************/
186 ulong flagUsedTlutID; // at 0x0
187 GXTlutObj tlutObj[GX_TLUT8 - GX_TLUT0]; // at 0x4
188};
189
190class ResTlutObj : public ResCommon<ResTlutObjData> {
191public:
192 NW4R_G3D_RESOURCE_FUNC_DEF(ResTlutObj);
193
194 ResTlutObj CopyTo(void* pDst) const;
195
196 const GXTlutObj* GetTlut(GXTlut tlut) const;
197 GXTlutObj* GetTlut(GXTlut tlut);
198
199 bool IsValidTlut(GXTlut tlut) const;
200
201 void Validate(GXTlut tlut);
202 void Invalidate(GXTlut tlut);
203
204 void EndEdit() {}
205};
206
207/******************************************************************************
208 *
209 * ResTexSrt
210 *
211 ******************************************************************************/
213 enum Flag {
214 FLAG_IDENT = (1 << 0),
215 };
216
217 s8 ref_camera; // at 0x0
218 s8 ref_light; // at 0x1
219 u8 map_mode; // at 0x2
220 u8 misc_flag; // at 0x3
221 math::_MTX34 effectMtx; // at 0x4
222};
223
225 static const int NUM_OF_TEXTURE = 8;
226
227 ulong flag; // at 0x0
228 TexMatrixMode texMtxMode; // at 0x4
229 TexSrt texSrt[NUM_OF_TEXTURE]; // at 0x8
230 TexMtxEffect effect[NUM_OF_TEXTURE]; // at 0xA8
231};
232
233class ResTexSrt : public ResCommon<ResTexSrtData> {
234public:
235 NW4R_G3D_RESOURCE_FUNC_DEF(ResTexSrt);
236
237 ResTexSrt CopyTo(void* pDst) const;
238
239 bool GetEffectMtx(ulong id, math::MTX34* pMtx) const;
240 bool SetEffectMtx(ulong id, const math::MTX34* pMtx);
241
242 bool GetMapMode(ulong id, ulong* pMode, int* pCamRef, int* pLightRef) const;
243 bool SetMapMode(ulong id, ulong mode, int camRef, int lightRef);
244
245 TexSrt::Flag GetTexSrtFlag(ulong id) const {
246 return static_cast<TexSrt::Flag>(
247 (ref().flag >> id * TexSrt::NUM_OF_FLAGS) &
248 (TexSrt::FLAG_ANM_EXISTS | TexSrt::FLAG_SCALE_ONE |
249 TexSrt::FLAG_ROT_ZERO | TexSrt::FLAG_TRANS_ZERO));
250 }
251
252 bool IsExist(ulong id) const {
253 if (IsValid()) {
254 return ptr()->flag & (1 << id * TexSrt::NUM_OF_FLAGS);
255 } else {
256 return false;
257 }
258 }
259
260 bool IsIdentity(ulong id) const {
261 return (((ref().flag >> id * TexSrt::NUM_OF_FLAGS) &
262 TexSrt::FLAGSET_IDENTITY) == TexSrt::FLAGSET_IDENTITY) &&
263 (ref().effect[id].misc_flag & TexMtxEffect::FLAG_IDENT);
264 }
265
266 TexSrtTypedef::TexMatrixMode GetTexMtxMode() const {
267 return ref().texMtxMode;
268 }
269
270 void EndEdit() {}
271};
272
273/******************************************************************************
274 *
275 * ResMatChan
276 *
277 ******************************************************************************/
278struct Chan {
279 enum Flag {
280 FLAG_MAT_COLOR_ENABLE = (1 << 0),
281 FLAG_MAT_ALPHA_ENABLE = (1 << 1),
282
283 FLAG_AMB_COLOR_ENABLE = (1 << 2),
284 FLAG_AMB_ALPHA_ENABLE = (1 << 3),
285
286 FLAG_CTRL_COLOR_ENABLE = (1 << 4),
287 FLAG_CTRL_ALPHA_ENABLE = (1 << 5),
288 };
289
290 ulong flag; // at 0x0
291 GXColor matColor; // at 0x4
292 GXColor ambColor; // at 0x8
293 ulong paramChanCtrlC; // at 0xC
294 ulong paramChanCtrlA; // at 0x10
295};
296
298 Chan chan[2]; // at 0x0
299};
300
301class ResMatChan : public ResCommon<ResChanData> {
302public:
303 NW4R_G3D_RESOURCE_FUNC_DEF_EX(ResMatChan, ResChanData);
304
305 ResMatChan CopyTo(void* pDst) const;
306
307 bool GXGetChanMatColor(GXChannelID id, GXColor* pColor) const;
308 void GXSetChanMatColor(GXChannelID id, GXColor color);
309
310 bool GXGetChanAmbColor(GXChannelID id, GXColor* pColor) const;
311 void GXSetChanAmbColor(GXChannelID id, GXColor color);
312
313 bool GXGetChanCtrl(GXChannelID id, GXBool* pEnable, GXColorSrc* pAmbSrc,
314 GXColorSrc* pMatSrc, GXLightID* pLightMask,
315 GXDiffuseFn* pDiffuseFn, GXAttnFn* pAttnFn) const;
316 void GXSetChanCtrl(GXChannelID id, GXBool enable, GXColorSrc ambSrc,
317 GXColorSrc matSrc, GXLightID lightMask,
318 GXDiffuseFn diffuseFn, GXAttnFn attnFn);
319
320 void EndEdit() {}
321};
322
323/******************************************************************************
324 *
325 * ResMatPix
326 *
327 ******************************************************************************/
328struct ResPixDL {
329 union {
330 struct {
331 u8 alphaCompare[GX_BP_CMD_SZ]; // at 0x0
332 u8 zMode[GX_BP_CMD_SZ]; // at 0x5
333 u8 blendMode[GX_BP_CMD_SZ * 2]; // at 0xA
334 u8 setDstAlpha[GX_BP_CMD_SZ]; // at 0x14
335 u8 PADDING_0x19[32 - 0x19]; // at 0x19
336 } dl;
337
338 u8 data[32]; // at 0x0
339 };
340};
341
342class ResMatPix : public ResCommon<ResPixDL> {
343public:
344 NW4R_G3D_RESOURCE_FUNC_DEF_EX(ResMatPix, ResPixDL);
345
346 void DCStore(bool sync);
347 ResMatPix CopyTo(void* pDst) const;
348
349 void CallDisplayList(bool sync) const;
350
351 bool GXGetAlphaCompare(GXCompare* pComp0, u8* pRef0, GXAlphaOp* pLogic,
352 GXCompare* pComp1, u8* pRef1) const;
353 void GXSetAlphaCompare(GXCompare comp0, u8 ref0, GXAlphaOp logic,
354 GXCompare comp1, u8 ref1);
355
356 bool GXGetZMode(GXBool* pTest, GXCompare* pCompare, GXBool* pUpdate) const;
357 void GXSetZMode(GXBool test, GXCompare compare, GXBool update);
358
359 bool GXGetBlendMode(GXBlendMode* pMode, GXBlendFactor* pSrcFactor,
360 GXBlendFactor* pDstFactor, GXLogicOp* pLogic) const;
361 void GXSetBlendMode(GXBlendMode mode, GXBlendFactor srcFactor,
362 GXBlendFactor dstFactor, GXLogicOp logic);
363
364 bool GXGetDstAlpha(GXBool* pEnable, u8* pAlpha) const;
365 void GXSetDstAlpha(GXBool enable, u8 alpha);
366
367 void EndEdit() {
368 DCStore(false);
369 }
370};
371
372/******************************************************************************
373 *
374 * ResMatTevColor
375 *
376 ******************************************************************************/
378 union {
379 struct {
380 u8 tevColor[GX_MAX_TEVREG - GX_TEVREG0][GX_BP_CMD_SZ * 4]; // at 0x0
381 u8 PADDING_0x3C[64 - 0x3C]; // at 0x3C
382 u8 tevKColor[GX_MAX_KCOLOR][GX_BP_CMD_SZ * 2]; // at 0x40
383 u8 PADDING_0x68[128 - 0x68]; // at 0x68
384 } dl;
385
386 u8 data[128];
387 };
388};
389
390class ResMatTevColor : public ResCommon<ResTevColorDL> {
391public:
392 NW4R_G3D_RESOURCE_FUNC_DEF_EX(ResMatTevColor, ResTevColorDL);
393
394 void DCStore(bool sync);
395 ResMatTevColor CopyTo(void* pDst) const;
396
397 void CallDisplayList(bool sync) const;
398
399 bool GXGetTevColor(GXTevRegID id, GXColor* pColor) const;
400 void GXSetTevColor(GXTevRegID id, GXColor color);
401
402 bool GXGetTevColorS10(GXTevRegID id, GXColorS10* pColor) const;
403 void GXSetTevColorS10(GXTevRegID id, GXColorS10 color);
404
405 bool GXGetTevKColor(GXTevKColorID id, GXColor* pColor) const;
406 void GXSetTevKColor(GXTevKColorID id, GXColor color);
407
408 void EndEdit() {
409 DCStore(false);
410 }
411};
412
413/******************************************************************************
414 *
415 * ResMatIndMtxAndScale
416 *
417 ******************************************************************************/
419 union {
420 struct {
421 u8 indTexCoordScale[2][GX_BP_CMD_SZ]; // at 0x0
422 u8 indTexMtx0[GX_BP_CMD_SZ * 3]; // at 0xA
423 u8 PADDING_0x19[32 - 0x19]; // at 0x19
424 u8 indTexMtx1[GX_BP_CMD_SZ * 3]; // at 0x20
425 u8 indTexMtx2[GX_BP_CMD_SZ * 3]; // at 0x2F
426 u8 PADDING_0x3E[64 - 0x3E]; // at 0x3E
427 } dl;
428
429 u8 data[64]; // at 0x0
430 };
431};
432
433class ResMatIndMtxAndScale : public ResCommon<ResIndMtxAndScaleDL> {
434public:
435 NW4R_G3D_RESOURCE_FUNC_DEF_EX(ResMatIndMtxAndScale, ResIndMtxAndScaleDL);
436
437 void DCStore(bool sync);
438 ResMatIndMtxAndScale CopyTo(void* pDst) const;
439
440 void CallDisplayList(u8 indNum, bool sync) const;
441
442 bool GXGetIndTexMtx(GXIndTexMtxID id, math::MTX34* pMtx) const;
443 void GXSetIndTexMtx(GXIndTexMtxID id, const math::MTX34& rMtx, s8 scaleExp);
444
445 void EndEdit() {
446 DCStore(false);
447 }
448};
449
450/******************************************************************************
451 *
452 * ResTexPlttInfo
453 *
454 ******************************************************************************/
456 s32 nameTex; // at 0x0
457 s32 namePltt; // at 0x4
458 ResTexData* pTexData; // at 0x8
459 ResPlttData* pPlttData; // at 0xC
460 GXTexMapID mapID; // at 0x10
461 GXTlut tlutID; // at 0x14
462 GXTexWrapMode wrap_s; // at 0x18
463 GXTexWrapMode wrap_t; // at 0x1C
464 GXTexFilter min_filt; // at 0x20
465 GXTexFilter mag_filt; // at 0x24
466 f32 lod_bias; // at 0x28
467 GXAnisotropy max_aniso; // at 0x2C
468 bool bias_clamp; // at 0x30
469 bool do_edge_lod; // at 0x31
470 u8 PADDING_0x32; // at 0x32
471 u8 PADDING_0x33; // at 0x33
472};
473
474class ResTexPlttInfo : public ResCommon<ResTexPlttInfoData> {
475public:
476 NW4R_G3D_RESOURCE_FUNC_DEF(ResTexPlttInfo);
477
478 bool Bind(const ResFile file, ResTexObj texObj, ResTlutObj tlutObj);
479 void Release(ResTexObj texObj, ResTlutObj tlutObj);
480
481 ResName GetTexResName() const {
482 const ResTexPlttInfoData& r = ref();
483
484 if (r.nameTex != 0) {
485 return NW4R_G3D_OFS_TO_RESNAME(&r, r.nameTex);
486 }
487
488 return ResName(NULL);
489 }
490
491 ResName GetPlttResName() const {
492 const ResTexPlttInfoData& r = ref();
493
494 if (r.namePltt != 0) {
495 return NW4R_G3D_OFS_TO_RESNAME(&r, r.namePltt);
496 }
497
498 return ResName(NULL);
499 }
500
501 bool IsCIFmt() const {
502 return ref().namePltt != 0;
503 }
504
505private:
506 void BindTex_(const ResTex tex, ResTexObj texObj);
507 void BindPltt_(const ResPltt pltt, ResTlutObj tlutObj);
508};
509
510/******************************************************************************
511 *
512 * ResMat
513 *
514 ******************************************************************************/
516 ResPixDL dlPix; // at 0x0
517 ResTevColorDL dlTevColor; // at 0x20
518 ResIndMtxAndScaleDL dlIndMtxAndScale; // at 0xA0
519 ResTexCoordGenDL dlTexCoordGen; // at 0xE0
520};
521
523 ulong size; // at 0x0
524 s32 toResMdlData; // at 0x4
525 s32 name; // at 0x8
526 ulong id; // at 0xC
527 ulong flag; // at 0x10
528 ResGenModeData genMode; // at 0x14
529 ResMatMiscData misc; // at 0x1C
530 s32 toResTevData; // at 0x28
531 ulong numResTexPlttInfo; // at 0x2C
532 s32 toResTexPlttInfo; // at 0x30
533 s32 toResMatFurData; // at 0x34
534 s32 toResUserData; // at 0x38
535 s32 toResMatDLData; // at 0x40
536 ResTexObjData texObjData; // at 0x44
537 ResTlutObjData tlutObjData; // at 0x144
538 ResTexSrtData texSrtData; // at 0x1A8
539 ResChanData chan; // at 0x3F0
540};
541
542class ResMat : public ResCommon<ResMatData> {
543public:
544 NW4R_G3D_RESOURCE_FUNC_DEF(ResMat);
545
546 void Init();
547
548 bool Bind(const ResFile file);
549 void Release();
550
551 ResMdl GetParent();
552
553 ulong GetID() const {
554 return ref().id;
555 }
556
557 ResGenMode GetResGenMode() {
558 return ResGenMode(&ref().genMode);
559 }
560
561 ResMatMisc GetResMatMisc() {
562 return ResMatMisc(&ref().misc);
563 }
564
565 ResTev GetResTev();
566 ResTev GetResTev() const;
567
568 ulong GetNumResTexPlttInfo() const {
569 return ref().numResTexPlttInfo;
570 }
571
572 ResTexPlttInfo GetResTexPlttInfo(ulong id) {
573 ResTexPlttInfoData* pData =
574 ofs_to_ptr<ResTexPlttInfoData>(ref().toResTexPlttInfo);
575
576 return ResTexPlttInfo(&pData[id]);
577 }
578
579 ResMatDLData* GetResMatDLData() {
580 return ofs_to_ptr<ResMatDLData>(ref().toResMatDLData);
581 }
582
583 ResMatPix GetResMatPix() {
584 return ResMatPix(&GetResMatDLData()->dlPix);
585 }
586
587 ResMatTevColor GetResMatTevColor() {
588 return ResMatTevColor(&GetResMatDLData()->dlTevColor);
589 }
590
591 ResMatIndMtxAndScale GetResMatIndMtxAndScale() {
592 return ResMatIndMtxAndScale(&GetResMatDLData()->dlIndMtxAndScale);
593 }
594
595 ResMatTexCoordGen GetResMatTexCoordGen() {
596 return ResMatTexCoordGen(&GetResMatDLData()->dlTexCoordGen);
597 }
598
599 ResTlutObj GetResTlutObj() {
600 return ResTlutObj(&ref().tlutObjData);
601 }
602
603 ResTexObj GetResTexObj() {
604 return ResTexObj(&ref().texObjData);
605 }
606
607 ResTexSrt GetResTexSrt() {
608 return ResTexSrt(&ref().texSrtData);
609 }
610
611 ResMatChan GetResMatChan() {
612 return ResMatChan(&ref().chan);
613 }
614};
615
616} // namespace g3d
617} // namespace nw4r
618
619#endif
3D graphics drawing library.
Definition g3d_3dsmax.h:10