1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX -
3 File: g3c.h
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_G3C_H_
19 #define NITRO_G3C_H_
20
21 #include <nitro/gx/g3.h>
22 #include <nitro/fx/fx_const.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 // no assert on win32
29 #if (defined(SDK_WIN32) || defined(SDK_FROM_TOOL))
30 #define SDK_ASSERT(exp) ((void) 0)
31 #define SDK_ALIGN4_ASSERT(exp) ((void) 0)
32 #define SDK_MINMAX_ASSERT(exp, min, max) ((void) 0)
33 #define SDK_NULL_ASSERT(exp) ((void) 0)
34 #if (defined(_MSC_VER) && !defined(__cplusplus))
35 #define inline __inline
36 #endif
37 #endif
38
39 //----------------------------------------------------------------------------
40 // Type definition
41 //----------------------------------------------------------------------------
42
43 //----------------------------------------------------------------------------
44 // Declaration of function
45 //----------------------------------------------------------------------------
46
47 // G3CS_*
48 void G3CS_Direct0(GXDLInfo *info, int op);
49 void G3CS_Direct1(GXDLInfo *info, int op, u32 param0);
50 void G3CS_Direct2(GXDLInfo *info, int op, u32 param0, u32 param1);
51 void G3CS_Direct3(GXDLInfo *info, int op, u32 param0, u32 param1, u32 param2);
52 void G3CS_DirectN(GXDLInfo *info, int op, int nParams, const u32 *params);
53
54 static void G3CS_Nop(GXDLInfo *info);
55 static void G3CS_MtxMode(GXDLInfo *info, GXMtxMode mode);
56 static void G3CS_PushMtx(GXDLInfo *info);
57 static void G3CS_PopMtx(GXDLInfo *info, int num);
58 static void G3CS_StoreMtx(GXDLInfo *info, int num);
59 static void G3CS_RestoreMtx(GXDLInfo *info, int num);
60 static void G3CS_Identity(GXDLInfo *info);
61 void G3CS_LoadMtx44(GXDLInfo *info, const MtxFx44 *m);
62 void G3CS_LoadMtx43(GXDLInfo *info, const MtxFx43 *m);
63 void G3CS_MultMtx44(GXDLInfo *info, const MtxFx44 *m);
64 void G3CS_MultMtx43(GXDLInfo *info, const MtxFx43 *m);
65 void G3CS_MultMtx33(GXDLInfo *info, const MtxFx33 *m);
66 void G3CS_MultTransMtx33(GXDLInfo *info, const MtxFx33 *mtx, const VecFx32 *trans);
67 static void G3CS_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
68 static void G3CS_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
69 static void G3CS_Color(GXDLInfo *info, GXRgb rgb);
70 static void G3CS_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
71 static void G3CS_TexCoord(GXDLInfo *info, fx32 s, fx32 t);
72 static void G3CS_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
73 static void G3CS_Vtx10(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
74 static void G3CS_VtxXY(GXDLInfo *info, fx16 x, fx16 y);
75 static void G3CS_VtxXZ(GXDLInfo *info, fx16 x, fx16 z);
76 static void G3CS_VtxYZ(GXDLInfo *info, fx16 y, fx16 z);
77 static void G3CS_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
78 static void G3CS_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc // GXPolygonAttrMisc
79 );
80 static void G3CS_TexImageParam(GXDLInfo *info,
81 GXTexFmt texFmt,
82 GXTexGen texGen,
83 GXTexSizeS s,
84 GXTexSizeT t,
85 GXTexRepeat repeat, GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr);
86 static void G3CS_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt);
87 static void G3CS_MaterialColorDiffAmb(GXDLInfo *info, GXRgb diffuse, GXRgb ambient,
88 BOOL IsSetVtxColor);
89 static void G3CS_MaterialColorSpecEmi(GXDLInfo *info, GXRgb specular, GXRgb emission,
90 BOOL IsShininess);
91 static void G3CS_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z);
92 static void G3CS_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb);
93 static void G3CS_Shininess(GXDLInfo *info, const u32 *table);
94 static void G3CS_Begin(GXDLInfo *info, GXBegin primitive);
95 static void G3CS_End(GXDLInfo *info);
96 static void G3CS_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw);
97 static void G3CS_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2);
98 static void G3CS_BoxTest(GXDLInfo *info, const GXBoxTestParam *box);
99 static void G3CS_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
100 static void G3CS_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
101
102 // G3C_*
103 void G3C_UpdateGXDLInfo(GXDLInfo *info, int n);
104 void G3C_Direct0(GXDLInfo *info, int op);
105 void G3C_Direct1(GXDLInfo *info, int op, u32 param0);
106 void G3C_Direct2(GXDLInfo *info, int op, u32 param0, u32 param1);
107 void G3C_Direct3(GXDLInfo *info, int op, u32 param0, u32 param1, u32 param2);
108 void G3C_DirectN(GXDLInfo *info, int op, int nParams, const u32 *params);
109
110 void G3C_Nop(GXDLInfo *info);
111 void G3C_MtxMode(GXDLInfo *info, GXMtxMode mode);
112 void G3C_PushMtx(GXDLInfo *info);
113 void G3C_PopMtx(GXDLInfo *info, int num);
114 void G3C_StoreMtx(GXDLInfo *info, int num);
115 void G3C_RestoreMtx(GXDLInfo *info, int num);
116 void G3C_Identity(GXDLInfo *info);
117 void G3C_LoadMtx44(GXDLInfo *info, const MtxFx44 *m);
118 void G3C_LoadMtx43(GXDLInfo *info, const MtxFx43 *m);
119 void G3C_MultMtx44(GXDLInfo *info, const MtxFx44 *m);
120 void G3C_MultMtx43(GXDLInfo *info, const MtxFx43 *m);
121 void G3C_MultMtx33(GXDLInfo *info, const MtxFx33 *m);
122 void G3C_MultTransMtx33(GXDLInfo *info, const MtxFx33 *mtx, const VecFx32 *trans);
123 void G3C_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
124 void G3C_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z);
125 void G3C_Color(GXDLInfo *info, GXRgb rgb);
126 void G3C_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
127 void G3C_TexCoord(GXDLInfo *info, fx32 s, fx32 t);
128 void G3C_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
129 void G3C_Vtx10(GXDLInfo *info, fx16, fx16, fx16);
130 void G3C_VtxXY(GXDLInfo *info, fx16 x, fx16 y);
131 void G3C_VtxXZ(GXDLInfo *info, fx16 x, fx16 z);
132 void G3C_VtxYZ(GXDLInfo *info, fx16 y, fx16 z);
133 void G3C_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
134 void G3C_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc // GXPolygonAttrMisc
135 );
136 void G3C_TexImageParam(GXDLInfo *info,
137 GXTexFmt texFmt,
138 GXTexGen texGen,
139 GXTexSizeS s,
140 GXTexSizeT t,
141 GXTexRepeat repeat, GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr);
142 void G3C_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt);
143 void G3C_MaterialColorDiffAmb(GXDLInfo *info, GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor);
144 void G3C_MaterialColorSpecEmi(GXDLInfo *info, GXRgb specular, GXRgb emission, BOOL IsShininess);
145 void G3C_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z);
146 void G3C_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb);
147 void G3C_Shininess(GXDLInfo *info, const u32 *table);
148 void G3C_Begin(GXDLInfo *info, GXBegin primitive);
149 void G3C_End(GXDLInfo *info);
150 void G3C_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw);
151 void G3C_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2);
152 void G3C_BoxTest(GXDLInfo *info, const GXBoxTestParam *box);
153 void G3C_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
154 void G3C_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z);
155
156 //----------------------------------------------------------------------------
157 // Implementation of inline function
158 //----------------------------------------------------------------------------
159
160 // G3CS_*
161
162
163
164
165 /*---------------------------------------------------------------------------*
166 Name: G3CS_Nop
167
168 Description: Makes a geometry command which does nothing on a display list.
169 Note that the command is packed.
170
171 Arguments: info a pointer to GXDLInfo
172
173 Returns: none
174 *---------------------------------------------------------------------------*/
G3CS_Nop(GXDLInfo * info)175 static inline void G3CS_Nop(GXDLInfo *info)
176 {
177 G3CS_Direct0(info, G3OP_NOP);
178 }
179
180
181 /*---------------------------------------------------------------------------*
182 Name: G3CS_MtxMode
183
184 Description: Makes a geometry command, which sets a matrix mode,
185 on a display list. Note that the command is packed.
186
187 Arguments: info a pointer to GXDLInfo
188 mode a matrix mode
189
190 Returns: none
191 *---------------------------------------------------------------------------*/
G3CS_MtxMode(GXDLInfo * info,GXMtxMode mode)192 static inline void G3CS_MtxMode(GXDLInfo *info, GXMtxMode mode)
193 {
194 GX_MTXMODE_ASSERT(mode);
195
196 G3CS_Direct1(info, G3OP_MTX_MODE, GX_PACK_MTXMODE_PARAM(mode));
197 }
198
199
200 /*---------------------------------------------------------------------------*
201 Name: G3CS_PushMtx
202
203 Description: Makes a geometry command, which stores a current matrix to
204 the top of the matrix stack and increments the stack pointer,
205 on a display list. Note that the command is packed.
206
207 Arguments: info a pointer to GXDLInfo
208
209 Returns: none
210 *---------------------------------------------------------------------------*/
G3CS_PushMtx(GXDLInfo * info)211 static inline void G3CS_PushMtx(GXDLInfo *info)
212 {
213 G3CS_Direct0(info, G3OP_MTX_PUSH);
214 }
215
216
217 /*---------------------------------------------------------------------------*
218 Name: G3CS_PopMtx
219
220 Description: Makes a geometry command, which pops the num'th matrix
221 from the matrix stack pointer on the stack,
222 and adds num to the pointer. Note that the command is packed.
223
224 Arguments: info a pointer to GXDLInfo
225 num an offset to the stack pointer
226
227 Returns: none
228 *---------------------------------------------------------------------------*/
G3CS_PopMtx(GXDLInfo * info,int num)229 static inline void G3CS_PopMtx(GXDLInfo *info, int num)
230 {
231 GX_MTX_POP_NUM_ASSERT(num);
232
233 G3CS_Direct1(info, G3OP_MTX_POP, GX_PACK_POPMTX_PARAM(num));
234 }
235
236
237 /*---------------------------------------------------------------------------*
238 Name: G3CS_StoreMtx
239
240 Description: Makes a geometry command, which stores a current matrix
241 to the num'th matrix from the matrix stack pointer on the stack,
242 on a display list. Note that the command is packed.
243
244 Arguments: info a pointer to GXDLInfo
245 num an offset to the stack pointer
246
247 Returns: none
248 *---------------------------------------------------------------------------*/
G3CS_StoreMtx(GXDLInfo * info,int num)249 static inline void G3CS_StoreMtx(GXDLInfo *info, int num)
250 {
251 GX_MTX_STORE_NUM_ASSERT(num);
252
253 G3CS_Direct1(info, G3OP_MTX_STORE, GX_PACK_STOREMTX_PARAM(num));
254 }
255
256
257 /*---------------------------------------------------------------------------*
258 Name: G3CS_RestoreMtx
259
260 Description: Makes a geometry command, which gets the num'th matrix from
261 the matrix stack pointer on the stack, on a display list.
262 Note that the command is packed.
263
264 Arguments: info a pointer to GXDLInfo
265 num an offset to the stack pointer
266
267 Returns: none
268 *---------------------------------------------------------------------------*/
G3CS_RestoreMtx(GXDLInfo * info,int num)269 static inline void G3CS_RestoreMtx(GXDLInfo *info, int num)
270 {
271 GX_MTX_RESTORE_NUM_ASSERT(num);
272
273 G3CS_Direct1(info, G3OP_MTX_RESTORE, GX_PACK_RESTOREMTX_PARAM(num));
274 }
275
276
277 /*---------------------------------------------------------------------------*
278 Name: G3CS_Identity
279
280 Description: Makes a geometry command, which sets an identity matrix
281 to the current matrix, on a display list.
282 Note that the command is packed.
283
284 Arguments: info a pointer to GXDLInfo
285
286 Returns: none
287 *---------------------------------------------------------------------------*/
G3CS_Identity(GXDLInfo * info)288 static inline void G3CS_Identity(GXDLInfo *info)
289 {
290 G3CS_Direct0(info, G3OP_MTX_IDENTITY);
291 }
292
293
294 /*---------------------------------------------------------------------------*
295 Name: G3CS_Scale
296
297 Description: Makes a geometry command, which multiplies the current matrix
298 by a scale matrix. Note that the command is packed.
299
300 Arguments: info a pointer to GXDLInfo
301 x X coordinate of a scale
302 y Y coordinate of a scale
303 z Z coordinate of a scale
304
305 Returns: none
306 *---------------------------------------------------------------------------*/
G3CS_Scale(GXDLInfo * info,fx32 x,fx32 y,fx32 z)307 static inline void G3CS_Scale(GXDLInfo *info, fx32 x, fx32 y, fx32 z)
308 {
309 G3CS_Direct3(info, G3OP_MTX_SCALE, (u32)x, (u32)y, (u32)z);
310 }
311
312
313 /*---------------------------------------------------------------------------*
314 Name: G3CS_Translate
315
316 Description: Makes a geometry command, which multiplies the current matrix
317 by a translation matrix. Note that the command is packed.
318
319 Arguments: info a pointer to GXDLInfo
320 x X coordinate of a translation vector
321 y Y coordinate of a translation vector
322 z Z coordinate of a translation vector
323
324 Returns: none
325 *---------------------------------------------------------------------------*/
G3CS_Translate(GXDLInfo * info,fx32 x,fx32 y,fx32 z)326 static inline void G3CS_Translate(GXDLInfo *info, fx32 x, fx32 y, fx32 z)
327 {
328 G3CS_Direct3(info, G3OP_MTX_TRANS, (u32)x, (u32)y, (u32)z);
329 }
330
331
332 /*---------------------------------------------------------------------------*
333 Name: G3CS_Color
334
335 Description: Makes a geometry command, which sends a vertex color.
336
337 Arguments: info a pointer to GXDLInfo
338 rgb a vertex color(R:5, G:5, B:5)
339
340 Returns: none
341 *---------------------------------------------------------------------------*/
G3CS_Color(GXDLInfo * info,GXRgb rgb)342 static inline void G3CS_Color(GXDLInfo *info, GXRgb rgb)
343 {
344 GXRGB_ASSERT(rgb);
345
346 G3CS_Direct1(info, G3OP_COLOR, GX_PACK_COLOR_PARAM(rgb));
347 }
348
349
350 /*---------------------------------------------------------------------------*
351 Name: G3CS_Normal
352
353 Description: Makes a geometry command, which sends a normal vector.
354
355 Arguments: info a pointer to GXDLInfo
356 x X coordinate of a normal vector
357 y Y coordinate of a normal vector
358 z Z coordinate of a normal vector
359
360 Returns: none
361 *---------------------------------------------------------------------------*/
G3CS_Normal(GXDLInfo * info,fx16 x,fx16 y,fx16 z)362 static inline void G3CS_Normal(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
363 {
364 SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
365 SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
366 SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
367
368 G3CS_Direct1(info, G3OP_NORMAL, GX_PACK_NORMAL_PARAM(x, y, z));
369 }
370
371
372 /*---------------------------------------------------------------------------*
373 Name: G3CS_TexCoord
374
375 Description: Makes a geometry command, which sends a texture coordinate.
376
377 Arguments: info a pointer to GXDLInfo
378 s an S of a texture coordinate
379 t a T of a texture coordinate
380
381 Returns: none
382 *---------------------------------------------------------------------------*/
G3CS_TexCoord(GXDLInfo * info,fx32 s,fx32 t)383 static inline void G3CS_TexCoord(GXDLInfo *info, fx32 s, fx32 t)
384 {
385 SDK_MINMAX_ASSERT(s, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
386 SDK_MINMAX_ASSERT(t, -2048 * FX32_ONE, 2048 * FX32_ONE - 1);
387
388 G3CS_Direct1(info, G3OP_TEXCOORD, GX_PACK_TEXCOORD_PARAM(s, t));
389 }
390
391
392 /*---------------------------------------------------------------------------*
393 Name: G3CS_Vtx
394
395 Description: Makes a geometry command, which sends a vertex as a fx16 vector.
396
397 Arguments: info a pointer to GXDLInfo
398 x X coordinate of a vertex
399 y Y coordinate of a vertex
400 z Z coordinate of a vertex
401
402 Returns: none
403 *---------------------------------------------------------------------------*/
G3CS_Vtx(GXDLInfo * info,fx16 x,fx16 y,fx16 z)404 static inline void G3CS_Vtx(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
405 {
406 G3CS_Direct2(info, G3OP_VTX_16, GX_FX16PAIR(x, y), (u32)(u16)z);
407 }
408
409
410 /*---------------------------------------------------------------------------*
411 Name: G3CS_Vtx10
412
413 Description: Makes a geometry command, which sends a vertex as a s3.6 vector.
414
415 Arguments: info a pointer to GXDLInfo
416 x X coordinate of a vertex
417 y Y coordinate of a vertex
418 z Z coordinate of a vertex
419
420 Returns: none
421 *---------------------------------------------------------------------------*/
G3CS_Vtx10(GXDLInfo * info,fx16 x,fx16 y,fx16 z)422 static inline void G3CS_Vtx10(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
423 {
424 G3CS_Direct1(info, G3OP_VTX_10, GX_PACK_VTX10_PARAM(x, y, z));
425 }
426
427
428 /*---------------------------------------------------------------------------*
429 Name: G3CS_VtxXY
430
431 Description: Makes a geometry command, which sends XY components of a vertex.
432 The Z coordinate is the same to the vertex sent just before.
433
434 Arguments: info a pointer to GXDLInfo
435 x X coordinate of a vertex
436 y Y coordinate of a vertex
437
438 Returns: none
439 *---------------------------------------------------------------------------*/
G3CS_VtxXY(GXDLInfo * info,fx16 x,fx16 y)440 static inline void G3CS_VtxXY(GXDLInfo *info, fx16 x, fx16 y)
441 {
442 G3CS_Direct1(info, G3OP_VTX_XY, GX_PACK_VTXXY_PARAM(x, y));
443 }
444
445
446 /*---------------------------------------------------------------------------*
447 Name: G3CS_VtxXZ
448
449 Description: Makes a geometry command, which sends XZ components of a vertex.
450 The Y coordinate is the same to the vertex sent just before.
451
452 Arguments: info a pointer to GXDLInfo
453 x X coordinate of a vertex
454 z Z coordinate of a vertex
455
456 Returns: none
457 *---------------------------------------------------------------------------*/
G3CS_VtxXZ(GXDLInfo * info,fx16 x,fx16 z)458 static inline void G3CS_VtxXZ(GXDLInfo *info, fx16 x, fx16 z)
459 {
460 G3CS_Direct1(info, G3OP_VTX_XZ, GX_PACK_VTXXZ_PARAM(x, z));
461 }
462
463
464 /*---------------------------------------------------------------------------*
465 Name: G3CS_VtxYZ
466
467 Description: Makes a geometry command, which sends YZ components of a vertex.
468 The X component is the same to the vertex sent just before.
469
470 Arguments: info a pointer to GXDLInfo
471 y Y coordinate of a vertex
472 z Z coordinate of a vertex
473
474 Returns: none
475 *---------------------------------------------------------------------------*/
G3CS_VtxYZ(GXDLInfo * info,fx16 y,fx16 z)476 static inline void G3CS_VtxYZ(GXDLInfo *info, fx16 y, fx16 z)
477 {
478 G3CS_Direct1(info, G3OP_VTX_YZ, GX_PACK_VTXYZ_PARAM(y, z));
479 }
480
481
482 /*---------------------------------------------------------------------------*
483 Name: G3CS_VtxDiff
484
485 Description: Makes a geometry commnad, which sends a vector as an offset
486 to the last vertex sent.
487
488 Arguments: info a pointer to GXDLInfo
489 x X coordinate of an offset
490 y Y coordinate of an offset
491 z Z coordinate of an offset
492
493 Returns: none
494 *---------------------------------------------------------------------------*/
G3CS_VtxDiff(GXDLInfo * info,fx16 x,fx16 y,fx16 z)495 static inline void G3CS_VtxDiff(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
496 {
497 SDK_MINMAX_ASSERT(x, (fx16)0xfe00, (fx16)0x1ff);
498 SDK_MINMAX_ASSERT(y, (fx16)0xfe00, (fx16)0x1ff);
499 SDK_MINMAX_ASSERT(z, (fx16)0xfe00, (fx16)0x1ff);
500
501 G3CS_Direct1(info, G3OP_VTX_DIFF, GX_PACK_VTXDIFF_PARAM(x, y, z));
502 }
503
504
505 /*---------------------------------------------------------------------------*
506 Name: G3CS_PolygonAttr
507
508 Description: Makes a geometry command, which sends attributes for polygons.
509
510 Arguments: info a pointer to GXDLInfo
511 light a 4bits field specifying light enable/disable
512 polyMode a polygon mode
513 cullMode a cull mode
514 polygonID a polygon ID
515 alpha an alpha value
516 misc miscellaneous flags
517
518 Returns: none
519 *---------------------------------------------------------------------------*/
G3CS_PolygonAttr(GXDLInfo * info,int light,GXPolygonMode polyMode,GXCull cullMode,int polygonID,int alpha,int misc)520 static inline void G3CS_PolygonAttr(GXDLInfo *info, int light, GXPolygonMode polyMode, GXCull cullMode, int polygonID, int alpha, int misc // GXPolygonAttrMisc
521 )
522 {
523 GX_LIGHTMASK_ASSERT(light);
524 GX_POLYGONMODE_ASSERT(polyMode);
525 GX_CULL_ASSERT(cullMode);
526 GX_POLYGON_ATTR_POLYGONID_ASSERT(polygonID);
527 GX_POLYGON_ATTR_ALPHA_ASSERT(alpha);
528
529 G3CS_Direct1(info,
530 G3OP_POLYGON_ATTR,
531 GX_PACK_POLYGONATTR_PARAM(light, polyMode, cullMode, polygonID, alpha, misc));
532 }
533
534
535 /*---------------------------------------------------------------------------*
536 Name: G3CS_TexImageParam
537
538 Description: Makes a geometry command, which sends parameters for a texture.
539
540 Arguments: info a pointer to GXDLInfo
541 texFmt format of a texture
542 texGen selects the source of a texture coordinate
543 s the size of a texture in the direction of the S-axis
544 t the size of a texture in the direction of the T-axis
545 repeat repeat
546 flip flip
547 pltt0 use/not use the color of pltt. 0
548 addr the offset address in the texture image slots
549 (shift 3bits internally)
550
551 Returns: none
552 *---------------------------------------------------------------------------*/
G3CS_TexImageParam(GXDLInfo * info,GXTexFmt texFmt,GXTexGen texGen,GXTexSizeS s,GXTexSizeT t,GXTexRepeat repeat,GXTexFlip flip,GXTexPlttColor0 pltt0,u32 addr)553 static inline void G3CS_TexImageParam(GXDLInfo *info,
554 GXTexFmt texFmt,
555 GXTexGen texGen,
556 GXTexSizeS s,
557 GXTexSizeT t,
558 GXTexRepeat repeat,
559 GXTexFlip flip, GXTexPlttColor0 pltt0, u32 addr)
560 {
561 GX_TEXREPEAT_ASSERT(repeat);
562 GX_TEXFLIP_ASSERT(flip);
563 GX_TEXSIZE_S_ASSERT(s);
564 GX_TEXSIZE_T_ASSERT(t);
565 GX_TEXFMT_ASSERT(texFmt);
566 GX_TEXPLTTCOLOR0_ASSERT(pltt0);
567 GX_TEXGEN_ASSERT(texGen);
568 GX_TEXIMAGE_PARAM_ADDR_ASSERT(addr);
569
570 G3CS_Direct1(info,
571 G3OP_TEXIMAGE_PARAM,
572 GX_PACK_TEXIMAGE_PARAM(texFmt, texGen, s, t, repeat, flip, pltt0, addr));
573 }
574
575
576 /*---------------------------------------------------------------------------*
577 Name: G3CS_TexPlttBase
578
579 Description: Makes a geometry command, which sends a base address of
580 a texture palette.
581
582 Arguments: info a pointer to GXDLInfo
583 addr the offset address in the texture palette slots
584 texFmt format of a texture
585
586 Returns: none
587 *---------------------------------------------------------------------------*/
G3CS_TexPlttBase(GXDLInfo * info,u32 addr,GXTexFmt texfmt)588 static inline void G3CS_TexPlttBase(GXDLInfo *info, u32 addr, GXTexFmt texfmt)
589 {
590 u32 param = GX_PACK_TEXPLTTBASE_PARAM(addr, texfmt);
591 GX_TEXPLTTBASEPARAM_ASSERT(param);
592
593 G3CS_Direct1(info, G3OP_TEXPLTT_BASE, param);
594 }
595
596
597 /*---------------------------------------------------------------------------*
598 Name: G3CS_MaterialColorDiffAmb
599
600 Description: Makes a geometry command, which sends diffuse and ambient.
601
602 Arguments: info a pointer to GXDLInfo
603 diffuse a diffuse color
604 ambient an ambient color
605 IsSetVtxColor sets a diffuse color as a vertex color if TRUE
606
607 Returns: none
608 *---------------------------------------------------------------------------*/
G3CS_MaterialColorDiffAmb(GXDLInfo * info,GXRgb diffuse,GXRgb ambient,BOOL IsSetVtxColor)609 static inline void G3CS_MaterialColorDiffAmb(GXDLInfo *info,
610 GXRgb diffuse, GXRgb ambient, BOOL IsSetVtxColor)
611 {
612 GXRGB_ASSERT(diffuse);
613 GXRGB_ASSERT(ambient);
614
615 G3CS_Direct1(info, G3OP_DIF_AMB, GX_PACK_DIFFAMB_PARAM(diffuse, ambient, IsSetVtxColor));
616 }
617
618
619 /*---------------------------------------------------------------------------*
620 Name: G3CS_MaterialColorSpecEmi
621
622 Description: Makes a geometry command, which sends specular and emission.
623
624 Arguments: info a pointer to GXDLInfo
625 specular a specular color
626 emission an emission color
627 IsShininess use the shininess table to change a specular
628 color if TRUE
629
630 Returns: none
631 *---------------------------------------------------------------------------*/
G3CS_MaterialColorSpecEmi(GXDLInfo * info,GXRgb specular,GXRgb emission,BOOL IsShininess)632 static inline void G3CS_MaterialColorSpecEmi(GXDLInfo *info,
633 GXRgb specular, GXRgb emission, BOOL IsShininess)
634 {
635 GXRGB_ASSERT(specular);
636 GXRGB_ASSERT(emission);
637
638 G3CS_Direct1(info, G3OP_SPE_EMI, GX_PACK_SPECEMI_PARAM(specular, emission, IsShininess));
639 }
640
641
642 /*---------------------------------------------------------------------------*
643 Name: G3CS_LightVector
644
645 Description: Makes a geometry command, which sends a light vector.
646
647 Arguments: info a pointer to GXDLInfo
648 lightID light ID
649 x X coordinate of a light vector
650 y Y coordinate of a light vector
651 z Z coordinate of a light vector
652
653 Returns: none
654 *---------------------------------------------------------------------------*/
G3CS_LightVector(GXDLInfo * info,GXLightId lightID,fx16 x,fx16 y,fx16 z)655 static inline void G3CS_LightVector(GXDLInfo *info, GXLightId lightID, fx16 x, fx16 y, fx16 z)
656 {
657 GX_LIGHTID_ASSERT(lightID);
658 SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
659 SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
660 SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
661
662 G3CS_Direct1(info, G3OP_LIGHT_VECTOR, GX_PACK_LIGHTVECTOR_PARAM(lightID, x, y, z));
663 }
664
665
666 /*---------------------------------------------------------------------------*
667 Name: G3CS_LightColor
668
669 Description: Makes a geometry command, which sends a light color.
670
671 Arguments: info a pointer to GXDLInfo
672 lightID light ID
673 rgb a light color(R:5, G:5, B:5)
674
675 Returns: none
676 *---------------------------------------------------------------------------*/
G3CS_LightColor(GXDLInfo * info,GXLightId lightID,GXRgb rgb)677 static inline void G3CS_LightColor(GXDLInfo *info, GXLightId lightID, GXRgb rgb)
678 {
679 GX_LIGHTID_ASSERT(lightID);
680 GXRGB_ASSERT(rgb);
681
682 G3CS_Direct1(info, G3OP_LIGHT_COLOR, GX_PACK_LIGHTCOLOR_PARAM(lightID, rgb));
683 }
684
685
686 /*---------------------------------------------------------------------------*
687 Name: G3CS_Shininess
688
689 Description: Makes a geometry command, which sets up the shininess table.
690
691 Arguments: info a pointer to GXDLInfo
692 table a pointer to the shininess data(32 words)
693
694 Returns: none
695 *---------------------------------------------------------------------------*/
G3CS_Shininess(GXDLInfo * info,const u32 * table)696 static inline void G3CS_Shininess(GXDLInfo *info, const u32 *table)
697 {
698 G3CS_DirectN(info, G3OP_SHININESS, 32, table);
699 }
700
701
702 /*---------------------------------------------------------------------------*
703 Name: G3CS_Begin
704
705 Description: Makes a geometry command, which starts sending primitives.
706
707 Arguments: info a pointer to GXDLInfo
708 primitive the type of primitives
709
710 Returns: none
711 *---------------------------------------------------------------------------*/
G3CS_Begin(GXDLInfo * info,GXBegin primitive)712 static inline void G3CS_Begin(GXDLInfo *info, GXBegin primitive)
713 {
714 GX_BEGIN_ASSERT(primitive);
715
716 G3CS_Direct1(info, G3OP_BEGIN, GX_PACK_BEGIN_PARAM(primitive));
717 }
718
719
720 /*---------------------------------------------------------------------------*
721 Name: G3CS_End
722
723 Description: Makes a geometry command, which ends sending primitives.
724
725 Arguments: info a pointer to GXDLInfo
726
727 Returns: none
728 *---------------------------------------------------------------------------*/
G3CS_End(GXDLInfo * info)729 static inline void G3CS_End(GXDLInfo *info)
730 {
731 G3CS_Direct0(info, G3OP_END);
732 }
733
734
735 /*---------------------------------------------------------------------------*
736 Name: G3CS_SwapBuffers
737
738 Description: Makes a geometry command, which swaps the polygon list RAM,
739 the vertex RAM, etc.
740
741 Arguments: info a pointer to GXDLInfo
742 am auto sort/manual sort
743 zw Z buffer/W buffer
744
745 Returns: none
746 *---------------------------------------------------------------------------*/
G3CS_SwapBuffers(GXDLInfo * info,GXSortMode am,GXBufferMode zw)747 static inline void G3CS_SwapBuffers(GXDLInfo *info, GXSortMode am, GXBufferMode zw)
748 {
749 GX_SORTMODE_ASSERT(am);
750 GX_BUFFERMODE_ASSERT(zw);
751
752 G3CS_Direct1(info, G3OP_SWAP_BUFFERS, GX_PACK_SWAPBUFFERS_PARAM(am, zw));
753 }
754
755
756 /*---------------------------------------------------------------------------*
757 Name: G3CS_ViewPort
758
759 Description: Makes a geometry command, which specifies viewport.
760
761 Arguments: info a pointer to GXDLInfo
762 x1 the X coordinate of the lower left
763 y1 the Y coordinate of the lower left
764 x2 the X coordinate of the upper right
765 y2 the Y coordinate of the upper right
766
767 Returns: none
768 *---------------------------------------------------------------------------*/
G3CS_ViewPort(GXDLInfo * info,int x1,int y1,int x2,int y2)769 static inline void G3CS_ViewPort(GXDLInfo *info, int x1, int y1, int x2, int y2)
770 {
771 GX_VIEWPORT_ASSERT(x1, y1, x2, y2);
772
773 G3CS_Direct1(info, G3OP_VIEWPORT, GX_PACK_VIEWPORT_PARAM(x1, y1, x2, y2));
774 }
775
776
777 /*---------------------------------------------------------------------------*
778 Name: G3CS_BoxTest
779
780 Description: Makes a geometry command, which tests if a box is
781 in the frustum or not.
782
783 Arguments: info a pointer to GXDLInfo
784 box a pointer to GXBoxTestParam
785
786 Returns: none
787 *---------------------------------------------------------------------------*/
G3CS_BoxTest(GXDLInfo * info,const GXBoxTestParam * box)788 static inline void G3CS_BoxTest(GXDLInfo *info, const GXBoxTestParam *box)
789 {
790 G3CS_Direct3(info, G3OP_BOX_TEST, box->val[0], box->val[1], box->val[2]);
791 }
792
793
794 /*---------------------------------------------------------------------------*
795 Name: G3CS_PositionTest
796
797 Description: Makes a geometry command, which applies a position vector
798 to the current clip matrix.
799
800 Arguments: info a pointer to GXDLInfo
801 x X coordinate of a position
802 y Y coordinate of a position
803 z Z coordinate of a position
804
805 Returns: none
806 *---------------------------------------------------------------------------*/
G3CS_PositionTest(GXDLInfo * info,fx16 x,fx16 y,fx16 z)807 static inline void G3CS_PositionTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
808 {
809 G3CS_Direct2(info, G3OP_POS_TEST, GX_FX16PAIR(x, y), (u32)(u16)z);
810 }
811
812
813 /*---------------------------------------------------------------------------*
814 Name: G3CS_VectorTest
815
816 Description: Makes a geometry command, which applies a vector
817 to the current vector matrix.
818
819 Arguments: info a pointer to GXDLInfo
820 x X coordinate of a vector
821 y Y coordinate of a vector
822 z Z coordinate of a vector
823
824 Returns: none
825 *---------------------------------------------------------------------------*/
G3CS_VectorTest(GXDLInfo * info,fx16 x,fx16 y,fx16 z)826 static inline void G3CS_VectorTest(GXDLInfo *info, fx16 x, fx16 y, fx16 z)
827 {
828 SDK_MINMAX_ASSERT(x, -FX16_ONE, FX16_ONE - 1);
829 SDK_MINMAX_ASSERT(y, -FX16_ONE, FX16_ONE - 1);
830 SDK_MINMAX_ASSERT(z, -FX16_ONE, FX16_ONE - 1);
831
832 G3CS_Direct1(info, G3OP_VEC_TEST, GX_PACK_VECTORTEST_PARAM(x, y, z));
833 }
834
835 #if (defined(_MSC_VER) && !defined(_cplusplus))
836 #undef inline
837 #endif
838
839 #ifdef __cplusplus
840 }/* extern "C" */
841 #endif
842
843 /* NITRO_G3C_H_ */
844 #endif
845