NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
GX.h
1#pragma once
2#include <types.h>
3#include <lib/rvl/mtx/mtx.h>
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
11
13typedef struct _GXColor {
14 union {
15 struct {
16 u8 r;
17 u8 g;
18 u8 b;
19 u8 a;
20 };
21 u32 rgba;
22 };
24
25typedef enum _GXAttr {
26 GX_VA_PNMTXIDX,
27 GX_VA_TEX0MTXIDX,
28 GX_VA_TEX1MTXIDX,
29 GX_VA_TEX2MTXIDX,
30 GX_VA_TEX3MTXIDX,
31 GX_VA_TEX4MTXIDX,
32 GX_VA_TEX5MTXIDX,
33 GX_VA_TEX6MTXIDX,
34 GX_VA_TEX7MTXIDX,
35 GX_VA_POS,
36 GX_VA_NRM,
37 GX_VA_CLR0,
38 GX_VA_CLR1,
39 GX_VA_TEX0,
40 GX_VA_TEX1,
41 GX_VA_TEX2,
42 GX_VA_TEX3,
43 GX_VA_TEX4,
44 GX_VA_TEX5,
45 GX_VA_TEX6,
46 GX_VA_TEX7,
47 GX_POS_MTX_ARRAY,
48 GX_NRM_MTX_ARRAY,
49 GX_TEX_MTX_ARRAY,
50 GX_LIGHT_ARRAY,
51 GX_VA_NBT,
52
53 GX_VA_MAX_ATTR,
54 GX_VA_NULL = 255
55} GXAttr;
56
57typedef enum _GXMtxType {
58 GX_MTX_3x4,
59 GX_MTX_2x4,
60} GXMtxType;
61
62typedef enum _GXVtxFmtIdx {
63 GX_VTXFMT0,
64} GXVtxFmtIdx;
65
66typedef enum _GXPrimitive {
67 GX_POINTS = 0xB8,
68 GX_LINES = 0xA8,
69 GX_LINESTRIP = 0xB0,
70 GX_TRIANGLES = 0x90,
71 GX_TRIANGLESTRIP = 0x98,
72 GX_TRIANGLEFAN = 0xA0,
73 GX_QUADS = 0x80,
74} GXPrimitive;
75
76typedef enum _GXCompare {
77 GX_NEVER,
78 GX_LESS,
79 GX_EQUAL,
80 GX_LEQUAL,
81 GX_GREATER,
82 GX_NEQUAL,
83 GX_GEQUAL,
84 GX_ALWAYS
85} GXCompare;
86
87typedef enum _GXTevStageID {
88 GX_TEVSTAGE0,
89 GX_TEVSTAGE1,
90 GX_TEVSTAGE2,
91 GX_TEVSTAGE3,
92 GX_TEVSTAGE4,
93 GX_TEVSTAGE5,
94 GX_TEVSTAGE6,
95 GX_TEVSTAGE7,
96 GX_TEVSTAGE8,
97 GX_TEVSTAGE9,
98 GX_TEVSTAGE10,
99 GX_TEVSTAGE11,
100 GX_TEVSTAGE12,
101 GX_TEVSTAGE13,
102 GX_TEVSTAGE14,
103 GX_TEVSTAGE15,
104
105 GX_MAX_TEVSTAGE
106} GXTevStageID;
107
108typedef enum _GXTevColorArg {
109 GX_CC_CPREV,
110 GX_CC_APREV,
111 GX_CC_C0,
112 GX_CC_A0,
113 GX_CC_C1,
114 GX_CC_A1,
115 GX_CC_C2,
116 GX_CC_A2,
117 GX_CC_TEXC,
118 GX_CC_TEXA,
119 GX_CC_RASC,
120 GX_CC_RASA,
121 GX_CC_ONE,
122 GX_CC_HALF,
123 GX_CC_KONST,
124 GX_CC_ZERO,
125 GX_CC_TEXRRR,
126 GX_CC_TEXGGG,
127 GX_CC_TEXBBB,
128
129 GX_CC_QUARTER = GX_CC_KONST
130} GXTevColorArg;
131
132typedef enum _GXTevAlphaArg {
133 GX_CA_APREV,
134 GX_CA_A0,
135 GX_CA_A1,
136 GX_CA_A2,
137 GX_CA_TEXA,
138 GX_CA_RASA,
139 GX_CA_KONST,
140 GX_CA_ZERO,
141 GX_CA_ONE
142} GXTevAlphaArg;
143
144typedef enum _GXTevBias {
145 GX_TB_ZERO,
146 GX_TB_ADDHALF,
147 GX_TB_SUBHALF,
148
149 GX_MAX_TEVBIAS
150} GXTevBias;
151
152typedef enum _GXTevScale {
153 GX_TEV_SCALE_0,
154 GX_TEV_SCALE_1,
155 GX_TEV_SCALE_2,
156 GX_TEV_SCALE_3,
157} GXTevScale;
158
159typedef enum _GXTevOp {
160 GX_TEV_ADD,
161 GX_TEV_SUB,
162
163 GX_TEV_COMP_R8_GT = 8,
164 GX_TEV_COMP_R8_EQ,
165 GX_TEV_COMP_GR16_GT,
166 GX_TEV_COMP_GR16_EQ,
167 GX_TEV_COMP_BGR24_GT,
168 GX_TEV_COMP_BGR24_EQ,
169 GX_TEV_COMP_RGB8_GT,
170 GX_TEV_COMP_RGB8_EQ,
171
172 GX_TEV_COMP_A8_GT = GX_TEV_COMP_RGB8_GT,
173 GX_TEV_COMP_A8_EQ = GX_TEV_COMP_RGB8_EQ
174} GXTevOp;
175
176typedef enum _GXTevRegID {
177 GX_TEVPREV,
178 GX_TEVREG0,
179 GX_TEVREG1,
180 GX_TEVREG2,
181
182 GX_MAX_TEVREG
183} GXTevRegID;
184
185typedef enum _GXAlphaOp {
186 GX_AOP_AND,
187 GX_AOP_OR,
188 GX_AOP_XOR,
189 GX_AOP_XNOR,
190
191 GX_MAX_ALPHAOP
192} GXAlphaOp;
193
194typedef struct _GXTexObj {
195 char data[28];
196} GXTexObj;
197
198typedef enum _GXTexFmt {
199 GX_TF_I4,
200 GX_TF_I8,
201 GX_TF_IA4,
202 GX_TF_IA8,
203 GX_TF_RGB565,
204 GX_TF_RGB5A3,
205 GX_TF_RGBA8,
206 GX_TF_CMPR = 14,
207
208 GX_CTF_R4 = 32,
209 GX_CTF_RA4 = 34,
210 GX_CTF_RA8 = 35,
211 GX_CTF_YUVA8 = 38,
212 GX_CTF_A8 = 39,
213 GX_CTF_R8 = 40,
214 GX_CTF_G8 = 41,
215 GX_CTF_B8 = 42,
216 GX_CTF_RG8 = 43,
217 GX_CTF_GB8 = 44,
218
219 GX_TF_Z8 = 17,
220 GX_TF_Z16 = 19,
221 GX_TF_Z24X8 = 22,
222
223 GX_CTF_Z4 = 48,
224 GX_CTF_Z8M = 57,
225 GX_CTF_Z8L = 58,
226 GX_CTF_Z16L = 60,
227
228 GX_TF_A8 = GX_CTF_YUVA8
229} GXTexFmt;
230
231typedef enum _GXTexWrapMode {
232 GX_CLAMP,
233 GX_REPEAT,
234 GX_MIRROR,
235
236 GX_MAX_TEXWRAPMODE
237} GXTexWrapMode;
238
239typedef enum _GXTexCoordID {
240 GX_TEXCOORD0,
241 GX_TEXCOORD1,
242 GX_TEXCOORD2,
243 GX_TEXCOORD3,
244 GX_TEXCOORD4,
245 GX_TEXCOORD5,
246 GX_TEXCOORD6,
247 GX_TEXCOORD7,
248
249 GX_MAX_TEXCOORD,
250 GX_TEXCOORD_NULL = 255
251} GXTexCoordID;
252
253typedef enum _GXTexGenSrc {
254 GX_TG_POS,
255 GX_TG_NRM,
256 GX_TG_BINRM,
257 GX_TG_TANGENT,
258 GX_TG_TEX0,
259 GX_TG_TEX1,
260 GX_TG_TEX2,
261 GX_TG_TEX3,
262 GX_TG_TEX4,
263 GX_TG_TEX5,
264 GX_TG_TEX6,
265 GX_TG_TEX7,
266 GX_TG_TEXCOORD0,
267 GX_TG_TEXCOORD1,
268 GX_TG_TEXCOORD2,
269 GX_TG_TEXCOORD3,
270 GX_TG_TEXCOORD4,
271 GX_TG_TEXCOORD5,
272 GX_TG_TEXCOORD6,
273 GX_TG_COLOR0,
274 GX_TG_COLOR1,
275} GXTexGenSrc;
276
277typedef enum _GXTexGenType {
278 GX_TG_MTX3x4,
279 GX_TG_MTX2x4,
280 GX_TG_BUMP0,
281 GX_TG_BUMP1,
282 GX_TG_BUMP2,
283 GX_TG_BUMP3,
284 GX_TG_BUMP4,
285 GX_TG_BUMP5,
286 GX_TG_BUMP6,
287 GX_TG_BUMP7,
288 GX_TG_SRTG
289} GXTexGenType;
290
291typedef enum _GXTexMapID {
292 GX_TEXMAP0,
293 GX_TEXMAP1,
294 GX_TEXMAP2,
295 GX_TEXMAP3,
296 GX_TEXMAP4,
297 GX_TEXMAP5,
298 GX_TEXMAP6,
299 GX_TEXMAP7,
300 GX_MAX_TEXMAP,
301
302 GX_TEXMAP_NULL = 255,
303 GX_TEX_DISABLE
304} GXTexMapID;
305
306typedef enum _GXProjectionType {
307 GX_PERSPECTIVE,
308 GX_ORTHOGRAPHIC
309} GXProjectionType;
310
311typedef enum _GXChannelID {
312 GX_COLOR0,
313 GX_COLOR1,
314 GX_ALPHA0,
315 GX_ALPHA1,
316 GX_COLOR0A0,
317 GX_COLOR1A1,
318 GX_COLOR_ZERO,
319 GX_ALPHA_BUMP,
320 GX_ALPHA_BUMPN,
321
322 GX_COLOR_NULL = 255
323} GXChannelID;
324
325typedef enum _GXColorSrc { GX_SRC_REG, GX_SRC_VTX } GXColorSrc;
326
327typedef enum _GXLightID {
328 GX_LIGHT0 = 1,
329 GX_LIGHT1 = 2,
330 GX_LIGHT2 = 4,
331 GX_LIGHT3 = 8,
332 GX_LIGHT4 = 16,
333 GX_LIGHT5 = 32,
334 GX_LIGHT6 = 64,
335 GX_LIGHT7 = 128,
336
337 GX_MAX_LIGHT = 256,
338 GX_LIGHT_NULL = 0
339} GXLightID;
340
341typedef enum _GXDiffuseFn { GX_DF_NONE, GX_DF_SIGN, GX_DF_CLAMP } GXDiffuseFn;
342
343typedef enum _GXAttnFn {
344 GX_AF_SPEC,
345 GX_AF_SPOT,
346 GX_AF_NONE,
347} GXAttnFn;
348
349typedef enum _GXBlendMode {
350 GX_BM_NONE,
351 GX_BM_BLEND,
352 GX_BM_LOGIC,
353 GX_BM_SUBTRACT,
354
355 GX_MAX_BLENDMODE
356} GXBlendMode;
357
358typedef enum _GXBlendFactor {
359 GX_BL_ZERO,
360 GX_BL_ONE,
361 GX_BL_SRCCLR,
362 GX_BL_INVSRCCLR,
363 GX_BL_SRCALPHA,
364 GX_BL_INVSRCALPHA,
365 GX_BL_DSTALPHA,
366 GX_BL_INVDSTALPHA,
367
368 GX_BL_DSTCLR = GX_BL_SRCCLR,
369 GX_BL_INVDSTCLR = GX_BL_INVSRCCLR
370} GXBlendFactor;
371
372typedef enum _GXLogicOp {
373 GX_LO_CLEAR,
374 GX_LO_AND,
375 GX_LO_REVAND,
376 GX_LO_COPY,
377 GX_LO_INVAND,
378 GX_LO_NOOP,
379 GX_LO_XOR,
380 GX_LO_OR,
381 GX_LO_NOR,
382 GX_LO_EQUIV,
383 GX_LO_INV,
384 GX_LO_REVOR,
385 GX_LO_INVCOPY,
386 GX_LO_INVOR,
387 GX_LO_NAND,
388 GX_LO_SET
389} GXLogicOp;
390
391typedef union _GXFifo {
392 // 1-byte
393 char c;
394 unsigned char uc;
395 // 2-byte
396 short s;
397 unsigned short us;
398 // 4-byte
399 int i;
400 unsigned int ui;
401 void* p;
402 float f;
403} GXFifo;
404
405#ifdef __CWCC__
406extern volatile GXFifo WGPIPE : 0xcc008000;
407#else
408// For non-mwcc compiler error checking
409extern volatile GXFifo WGPIPE;
410#endif
411
412void GXSetProjection(const Mtx44 *, int);
413void GXLoadPosMtxImm(const Mtx *, u32);
414void GXSetCurrentMtx(u32 id);
415void GXLoadTexMtxImm(const Mtx *, u32, GXMtxType);
416void GXSetViewport(float, float, float, float, float, float);
417void GXSetScissor(u32, u32, u32, u32);
418
419void GXSetVtxDesc(GXAttr, GXAttr);
420void GXClearVtxDesc();
421void GXSetVtxAttrFmt(u32, GXAttr, u32, u32, u8);
422void GXSetNumTexGens(u8);
423void GXSetTexCoordGen2(GXTexCoordID, GXTexGenType, GXTexGenSrc, u8, u8, u32);
424
425void GXBegin(GXPrimitive, GXVtxFmtIdx, u16);
426void GXSetCullMode(int);
427
428inline static void GXEnd() {}
429
430void GXSetNumIndStages(u8);
431void __GXSetIndirectMask(u32);
432
433void GXSetColorUpdate(u8);
434void GXSetAlphaUpdate(u8);
435void GXSetZMode(u8, GXCompare, u8);
436void GXSetZCompLoc(u8);
437
438void GXSetTevColorIn(GXTevStageID, GXTevColorArg, GXTevColorArg, GXTevColorArg, GXTevColorArg);
439void GXSetTevAlphaIn(GXTevStageID, GXTevAlphaArg, GXTevAlphaArg, GXTevAlphaArg, GXTevAlphaArg);
440void GXSetTevColorOp(GXTevStageID, GXTevOp, GXTevBias, GXTevScale, u8, GXTevRegID);
441void GXSetTevAlphaOp(GXTevStageID, GXTevOp, GXTevBias, GXTevScale, u8, GXTevRegID);
442void GXSetTevOp(GXTevStageID, u32);
443void GXSetTevOrder(GXTevStageID, GXTexCoordID, GXTexMapID, GXChannelID);
444void GXSetAlphaCompare(GXCompare, u8, GXAlphaOp, GXCompare, u8);
445void GXSetNumTevStages(u8);
446
447void GXInitTexObj(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8);
448void GXLoadTexObj(GXTexObj *, GXTexMapID);
449
450void GXSetChanMatColor(GXChannelID, GXColor);
451void GXSetNumChans(u8);
452void GXSetChanCtrl(GXChannelID, u8, GXColorSrc, GXColorSrc, GXLightID, GXDiffuseFn, GXAttnFn);
453
454void GXSetBlendMode(GXBlendMode, GXBlendFactor, GXBlendFactor, GXLogicOp);
455
456void GXInvalidateVtxCache();
457
458static inline void GXPosition3f32(float x, float y, float z) {
459 WGPIPE.f = x;
460 WGPIPE.f = y;
461 WGPIPE.f = z;
462}
463
464static inline void GXTexCoord2f32(float x, float y) {
465 WGPIPE.f = x;
466 WGPIPE.f = y;
467}
468
470
471#ifdef __cplusplus
472}
473#endif
struct _GXColor GXColor
A 32-bit RGBA color.
float Mtx44[4][4]
A 4x4 matrix.
Definition mtx.h:13
float Mtx[3][4]
A 3x4 matrix.
Definition mtx.h:12
A 32-bit RGBA color.
Definition GX.h:13
Definition GX.h:391