1 /*---------------------------------------------------------------------------*
2 Project: Dolphin/Revolution GD library
3 File: GDGeometry.c
4
5 Copyright 2001-2006 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 $Log: GDGeometry.c,v $
14 Revision 1.3 02/20/2006 04:24:39 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.2 02/03/2006 08:54:44 hirose
18 Avoided use of EPPC and use WIN32.
19
20 Revision 1.1.1.1 2005/05/12 02:15:49 yasuh-to
21 transitioned from the Dolphin source tree
22
23
24 7 02/08/05 19:53 Hirose
25 Const type specifier support.
26
27 6 10/13/01 2:25a Hirose
28 Added GDSetCullMode().
29
30 5 9/29/01 3:36p Hirose
31 Fixed emboss texgen bug.
32
33 4 9/24/01 3:19p Carl
34 Fixed problem with cull mode conversion.
35
36 3 9/19/01 6:34p Carl
37 Added GDSetLPSize.
38
39 2 9/14/01 6:42p Carl
40 Fixed bug with GDSetVtxAttrFmtv.
41 Made OSCachedToPhysical a macro for non-EPPC.
42
43 1 9/12/01 1:52p Carl
44 Initial revision of GD: Graphics Display List Library.
45
46 $NoKeywords: $
47 *---------------------------------------------------------------------------*/
48
49 #include <revolution/gd.h>
50 #include <revolution/os.h>
51
52 #if defined(WIN32) && !defined(OSCachedToPhysical)
53 #define OSCachedToPhysical(caddr) ((u32)((u8*)(caddr) - (0x80000000)))
54 #endif
55
56 /*---------------------------------------------------------------------------*/
57
58 /*---------------------------------------------------------------------------*/
59 // Name: GDSetVtxDescv
60 //
61 // Description: Sets vertex description registers.
62 //
63 // Arguments: attrPtr: pointer to an (attr, type) array.
64 // End of the array is indicated by GX_VA_NULL
65 // attribute.
66 //
67 // Returns: None
68 //
69 /*---------------------------------------------------------------------------*/
70
GDSetVtxDescv(const GXVtxDescList * attrPtr)71 void GDSetVtxDescv ( const GXVtxDescList *attrPtr )
72 {
73 // These are default values for all the VCD fields.
74 // You cannot change most of these defaults without adjusting
75 // the code below as well. The code assumes GX_NONE defaults
76 // (for normals, colors, and texture coordinates).
77
78 u32 nnorms = 0;
79 u32 ncols = 0;
80 u32 ntexs = 0;
81
82 u32 pnMtxIdx = GX_NONE;
83 u32 txMtxIdxMask = 0;
84 u32 posn = GX_DIRECT;
85 u32 norm = GX_NONE;
86 u32 col0 = GX_NONE;
87 u32 col1 = GX_NONE;
88 u32 tex0 = GX_NONE;
89 u32 tex1 = GX_NONE;
90 u32 tex2 = GX_NONE;
91 u32 tex3 = GX_NONE;
92 u32 tex4 = GX_NONE;
93 u32 tex5 = GX_NONE;
94 u32 tex6 = GX_NONE;
95 u32 tex7 = GX_NONE;
96
97 while (attrPtr->attr != GX_VA_NULL) {
98 ASSERTMSG(((attrPtr->attr >= GX_VA_PNMTXIDX) &&
99 (attrPtr->attr <= GX_VA_MAX_ATTR)),
100 "GDSetVtxDescv: invalid attribute");
101
102 ASSERTMSG(((attrPtr->type >= GX_NONE) &&
103 (attrPtr->type <= GX_INDEX16)),
104 "GDSetVtxDescv: invalid type");
105
106 ASSERTMSG(((attrPtr->attr >= GX_VA_PNMTXIDX) &&
107 (attrPtr->attr <= GX_VA_TEX7MTXIDX)) ?
108 ((attrPtr->type == GX_NONE) ||
109 (attrPtr->type == GX_DIRECT)) : 1,
110 "GDSetVtxDescv: invalid type for given attribute");
111
112 switch (attrPtr->attr) {
113
114 case GX_VA_PNMTXIDX: pnMtxIdx = attrPtr->type; break;
115
116 case GX_VA_TEX0MTXIDX:
117 txMtxIdxMask = (txMtxIdxMask & ~1) | (attrPtr->type << 0); break;
118 case GX_VA_TEX1MTXIDX:
119 txMtxIdxMask = (txMtxIdxMask & ~2) | (attrPtr->type << 1); break;
120 case GX_VA_TEX2MTXIDX:
121 txMtxIdxMask = (txMtxIdxMask & ~4) | (attrPtr->type << 2); break;
122 case GX_VA_TEX3MTXIDX:
123 txMtxIdxMask = (txMtxIdxMask & ~8) | (attrPtr->type << 3); break;
124 case GX_VA_TEX4MTXIDX:
125 txMtxIdxMask = (txMtxIdxMask & ~16) | (attrPtr->type << 4); break;
126 case GX_VA_TEX5MTXIDX:
127 txMtxIdxMask = (txMtxIdxMask & ~32) | (attrPtr->type << 5); break;
128 case GX_VA_TEX6MTXIDX:
129 txMtxIdxMask = (txMtxIdxMask & ~64) | (attrPtr->type << 6); break;
130 case GX_VA_TEX7MTXIDX:
131 txMtxIdxMask = (txMtxIdxMask & ~128) | (attrPtr->type << 7); break;
132
133 case GX_VA_POS: posn = attrPtr->type; break;
134
135 case GX_VA_NRM:
136 if (attrPtr->type != GX_NONE)
137 { norm = attrPtr->type; nnorms = 1; }
138 break;
139 case GX_VA_NBT:
140 if (attrPtr->type != GX_NONE)
141 { norm = attrPtr->type; nnorms = 2; }
142 break;
143
144 case GX_VA_CLR0: col0=attrPtr->type; ncols+=(col0 != GX_NONE); break;
145 case GX_VA_CLR1: col1=attrPtr->type; ncols+=(col1 != GX_NONE); break;
146
147 case GX_VA_TEX0: tex0=attrPtr->type; ntexs+=(tex0 != GX_NONE); break;
148 case GX_VA_TEX1: tex1=attrPtr->type; ntexs+=(tex1 != GX_NONE); break;
149 case GX_VA_TEX2: tex2=attrPtr->type; ntexs+=(tex2 != GX_NONE); break;
150 case GX_VA_TEX3: tex3=attrPtr->type; ntexs+=(tex3 != GX_NONE); break;
151 case GX_VA_TEX4: tex4=attrPtr->type; ntexs+=(tex4 != GX_NONE); break;
152 case GX_VA_TEX5: tex5=attrPtr->type; ntexs+=(tex5 != GX_NONE); break;
153 case GX_VA_TEX6: tex6=attrPtr->type; ntexs+=(tex6 != GX_NONE); break;
154 case GX_VA_TEX7: tex7=attrPtr->type; ntexs+=(tex7 != GX_NONE); break;
155 default: break;
156 }
157 attrPtr++;
158 }
159
160 GDWriteCPCmd( CP_VCD_LO_ID, CP_VCD_REG_LO_PS( pnMtxIdx, txMtxIdxMask,
161 posn, norm, col0, col1 ));
162
163 GDWriteCPCmd( CP_VCD_HI_ID, CP_VCD_REG_HI( tex0, tex1, tex2, tex3,
164 tex4, tex5, tex6, tex7 ));
165
166 GDWriteXFCmd( XF_INVTXSPEC_ID, XF_INVTXSPEC( ncols, nnorms, ntexs ));
167 }
168
169 /*---------------------------------------------------------------------------*/
170 // Name: GDSetVtxAttrFmt
171 //
172 // Description: Sets format of a given attribute in the vertex format array.
173 //
174 // Arguments: vtxFmt Name of the format array register.
175 // list pointer to an array of attribute format structures.
176 //
177 // list structure elements:
178 // attr Name of the attribute.
179 // cnt Number of components for the attribute.
180 // type Data type of the attribute.
181 // frac number of fraction bits for int data types.
182 //
183 // Returns: None
184 //
185 /*---------------------------------------------------------------------------*/
186
GDSetVtxAttrFmtv(GXVtxFmt vtxfmt,const GXVtxAttrFmtList * list)187 void GDSetVtxAttrFmtv ( GXVtxFmt vtxfmt, const GXVtxAttrFmtList *list )
188 {
189 // These are default values for all the VAT fields.
190 // You may change them as you wish.
191
192 u32 posCnt = GX_POS_XYZ;
193 u32 posType = GX_F32;
194 u32 posFrac = 0;
195
196 u32 nrmCnt = GX_NRM_XYZ;
197 u32 nrmType = GX_F32;
198 u32 nrmIdx3 = 0;
199
200 u32 c0Cnt = GX_CLR_RGBA;
201 u32 c0Type = GX_RGBA8;
202 u32 c1Cnt = GX_CLR_RGBA;
203 u32 c1Type = GX_RGBA8;
204
205 u32 tx0Cnt = GX_TEX_ST;
206 u32 tx0Type = GX_F32;
207 u32 tx0Frac = 0;
208 u32 tx1Cnt = GX_TEX_ST;
209 u32 tx1Type = GX_F32;
210 u32 tx1Frac = 0;
211 u32 tx2Cnt = GX_TEX_ST;
212 u32 tx2Type = GX_F32;
213 u32 tx2Frac = 0;
214 u32 tx3Cnt = GX_TEX_ST;
215 u32 tx3Type = GX_F32;
216 u32 tx3Frac = 0;
217 u32 tx4Cnt = GX_TEX_ST;
218 u32 tx4Type = GX_F32;
219 u32 tx4Frac = 0;
220 u32 tx5Cnt = GX_TEX_ST;
221 u32 tx5Type = GX_F32;
222 u32 tx5Frac = 0;
223 u32 tx6Cnt = GX_TEX_ST;
224 u32 tx6Type = GX_F32;
225 u32 tx6Frac = 0;
226 u32 tx7Cnt = GX_TEX_ST;
227 u32 tx7Type = GX_F32;
228 u32 tx7Frac = 0;
229
230 ASSERTMSG((vtxfmt < GX_MAX_VTXFMT), "GDSetVtxAttrFmtv: invalid vtx fmt");
231
232 while (list->attr != GX_VA_NULL) {
233 ASSERTMSG(((list->attr >= GX_VA_POS) &&
234 (list->attr <= GX_VA_TEX7)),
235 "GDSetVtxAttrFmtv: invalid attribute");
236 ASSERTMSG((list->frac < 32), "GDSetVtxAttrFmtv: invalid frac value");
237
238 switch (list->attr) {
239 case GX_VA_POS:
240 posCnt = list->cnt;
241 posType = list->type;
242 posFrac = list->frac;
243 break;
244 case GX_VA_NRM:
245 case GX_VA_NBT:
246 nrmType = list->type;
247 if (list->cnt == GX_NRM_NBT3)
248 {
249 nrmCnt = GX_NRM_NBT;
250 nrmIdx3 = 1;
251 } else {
252 nrmCnt = list->cnt;
253 nrmIdx3 = 0;
254 }
255 break;
256 case GX_VA_CLR0:
257 c0Cnt = list->cnt;
258 c0Type = list->type;
259 break;
260 case GX_VA_CLR1:
261 c1Cnt = list->cnt;
262 c1Type = list->type;
263 break;
264 case GX_VA_TEX0:
265 tx0Cnt = list->cnt;
266 tx0Type = list->type;
267 tx0Frac = list->frac;
268 break;
269 case GX_VA_TEX1:
270 tx1Cnt = list->cnt;
271 tx1Type = list->type;
272 tx1Frac = list->frac;
273 break;
274 case GX_VA_TEX2:
275 tx2Cnt = list->cnt;
276 tx2Type = list->type;
277 tx2Frac = list->frac;
278 break;
279 case GX_VA_TEX3:
280 tx3Cnt = list->cnt;
281 tx3Type = list->type;
282 tx3Frac = list->frac;
283 break;
284 case GX_VA_TEX4:
285 tx4Cnt = list->cnt;
286 tx4Type = list->type;
287 tx4Frac = list->frac;
288 break;
289 case GX_VA_TEX5:
290 tx5Cnt = list->cnt;
291 tx5Type = list->type;
292 tx5Frac = list->frac;
293 break;
294 case GX_VA_TEX6:
295 tx6Cnt = list->cnt;
296 tx6Type = list->type;
297 tx6Frac = list->frac;
298 break;
299 case GX_VA_TEX7:
300 tx7Cnt = list->cnt;
301 tx7Type = list->type;
302 tx7Frac = list->frac;
303 break;
304 default:
305 break;
306 }
307 list++;
308 }
309
310 GDWriteCPCmd( (u8)(CP_VAT_A_ID + vtxfmt),
311 CP_VAT_REG_A(posCnt, posType, posFrac,
312 nrmCnt, nrmType,
313 c0Cnt, c0Type, c1Cnt, c1Type,
314 tx0Cnt, tx0Type, tx0Frac,
315 nrmIdx3 ));
316
317 GDWriteCPCmd( (u8)(CP_VAT_B_ID + vtxfmt),
318 CP_VAT_REG_B(tx1Cnt, tx1Type, tx1Frac,
319 tx2Cnt, tx2Type, tx2Frac,
320 tx3Cnt, tx3Type, tx3Frac,
321 tx4Cnt, tx4Type ));
322
323 GDWriteCPCmd( (u8)(CP_VAT_C_ID + vtxfmt),
324 CP_VAT_REG_C(tx4Frac,
325 tx5Cnt, tx5Type, tx5Frac,
326 tx6Cnt, tx6Type, tx6Frac,
327 tx7Cnt, tx7Type, tx7Frac ));
328 }
329
330 /*---------------------------------------------------------------------------*/
331 // Name: GDSetArray
332 //
333 // Description: Sets the base address and stride of data array for the given
334 // attribute. This will be used by indexed vertex data.
335 // The base address should be an EPPC cached memory address.
336 //
337 // Arguments: attr Name of the attribute.
338 // base_ptr pointer to an array of data in cached memory.
339 // stride number of bytes between each attribute unit.
340 //
341 // Returns: None
342 //
343 /*---------------------------------------------------------------------------*/
344
GDSetArray(GXAttr attr,const void * base_ptr,u8 stride)345 void GDSetArray ( GXAttr attr, const void *base_ptr, u8 stride )
346 {
347 s32 cpAttr;
348
349 cpAttr = (attr == GX_VA_NBT) ? (GX_VA_NRM - GX_VA_POS) : (attr - GX_VA_POS);
350
351 GDWriteCPCmd( (u8) (CP_ARRAY_BASE_ID + cpAttr),
352 CP_ARRAY_BASE_REG( OSCachedToPhysical( base_ptr ) ));
353
354 GDWriteCPCmd( (u8) (CP_ARRAY_STRIDE_ID + cpAttr),
355 CP_ARRAY_STRIDE_REG( stride ));
356 }
357
358 /*---------------------------------------------------------------------------*/
359 // Name: GDSetArrayRaw
360 //
361 // Description: Sets the base address and stride of data array for the given
362 // attribute. This will be used by indexed vertex data.
363 // The base address is just a raw u32 number in this case.
364 //
365 // Arguments: attr Name of the attribute.
366 // base_ptr_raw raw number to be inserted for base address.
367 // stride number of bytes between each attribute unit.
368 //
369 // Returns: None
370 //
371 /*---------------------------------------------------------------------------*/
372
GDSetArrayRaw(GXAttr attr,u32 base_ptr_raw,u8 stride)373 void GDSetArrayRaw ( GXAttr attr, u32 base_ptr_raw, u8 stride )
374 {
375 s32 cpAttr;
376
377 cpAttr = (attr == GX_VA_NBT) ? (GX_VA_NRM - GX_VA_POS) : (attr - GX_VA_POS);
378
379 GDWriteCPCmd( (u8) (CP_ARRAY_BASE_ID + cpAttr),
380 CP_ARRAY_BASE_REG( base_ptr_raw ));
381
382 GDWriteCPCmd( (u8) (CP_ARRAY_STRIDE_ID + cpAttr),
383 CP_ARRAY_STRIDE_REG( stride ));
384 }
385
386 /*---------------------------------------------------------------------------*/
387 // Name: GDPatchArrayPtr
388 //
389 // Description: Alters array base memory address for a GDSetArray command.
390 // We assume that the DL offset has been moved to the point
391 // CP_DATA_OFFSET bytes after where the GDSetArray command
392 // was inserted. Only the array base address is changed.
393 //
394 // Arguments: base_ptr pointer to an array of data in cached memory.
395 //
396 // Returns: None
397 //
398 /*---------------------------------------------------------------------------*/
399
GDPatchArrayPtr(const void * base_ptr)400 void GDPatchArrayPtr ( const void *base_ptr )
401 {
402 GDWrite_u32(CP_ARRAY_BASE_REG( OSCachedToPhysical( base_ptr ) ));
403 }
404
405 /*---------------------------------------------------------------------------*/
406 // Name: GDSetTexCoordGen
407 //
408 // Description: Sets the texture coordinate control state in XF block.
409 //
410 // Arguments: dst_coord: Texture Coordinate Name.
411 // func : Texture Generation Function.
412 // src_param: Texture Generation Source coordinates.
413 // mtx : Default texture matrix index.
414 // normalize: Normalize results between transforms?
415 // pt_texmtx: Post-transform matrix index.
416 //
417 // Returns: None
418 //
419 /*---------------------------------------------------------------------------*/
420
GDSetTexCoordGen(GXTexCoordID dst_coord,GXTexGenType func,GXTexGenSrc src_param,GXBool normalize,u32 postmtx)421 void GDSetTexCoordGen ( GXTexCoordID dst_coord,
422 GXTexGenType func,
423 GXTexGenSrc src_param,
424 GXBool normalize,
425 u32 postmtx )
426 {
427 u32 form;
428 u32 tgType;
429 u32 proj;
430 u32 row;
431 u32 embossRow;
432 u32 embossLit;
433
434 form = XF_TEX_AB11;
435 proj = XF_TEX_ST;
436 row = XF_TEX0_INROW;
437 embossRow = XF_TEX0_INROW;
438 embossLit = 0;
439
440 ASSERTMSG((dst_coord < GX_MAX_TEXCOORD),
441 "GDSetTexCoordGen: invalid texcoord ID");
442
443 switch (src_param) {
444 case GX_TG_POS: row = XF_GEOM_INROW; form = XF_TEX_ABC1; break;
445 case GX_TG_NRM: row = XF_NORMAL_INROW; form = XF_TEX_ABC1; break;
446 case GX_TG_BINRM: row = XF_BINORMAL_T_INROW; form = XF_TEX_ABC1; break;
447 case GX_TG_TANGENT: row = XF_BINORMAL_B_INROW; form = XF_TEX_ABC1; break;
448 case GX_TG_COLOR0: row = XF_COLORS_INROW; break;
449 case GX_TG_COLOR1: row = XF_COLORS_INROW; break;
450 case GX_TG_TEX0: row = XF_TEX0_INROW; break;
451 case GX_TG_TEX1: row = XF_TEX1_INROW; break;
452 case GX_TG_TEX2: row = XF_TEX2_INROW; break;
453 case GX_TG_TEX3: row = XF_TEX3_INROW; break;
454 case GX_TG_TEX4: row = XF_TEX4_INROW; break;
455 case GX_TG_TEX5: row = XF_TEX5_INROW; break;
456 case GX_TG_TEX6: row = XF_TEX6_INROW; break;
457 case GX_TG_TEX7: row = XF_TEX7_INROW; break;
458 case GX_TG_TEXCOORD0: embossRow = 0; break;
459 case GX_TG_TEXCOORD1: embossRow = 1; break;
460 case GX_TG_TEXCOORD2: embossRow = 2; break;
461 case GX_TG_TEXCOORD3: embossRow = 3; break;
462 case GX_TG_TEXCOORD4: embossRow = 4; break;
463 case GX_TG_TEXCOORD5: embossRow = 5; break;
464 case GX_TG_TEXCOORD6: embossRow = 6; break;
465 default:
466 ASSERTMSG(0, "GDSetTexCoordGen: invalid texgen source");
467 break;
468 }
469
470 switch (func) {
471 case GX_TG_MTX2x4:
472 tgType = XF_TEXGEN_REGULAR;
473 break;
474
475 case GX_TG_MTX3x4:
476 tgType = XF_TEXGEN_REGULAR;
477 proj = XF_TEX_STQ;
478 break;
479
480 case GX_TG_BUMP0:
481 case GX_TG_BUMP1:
482 case GX_TG_BUMP2:
483 case GX_TG_BUMP3:
484 case GX_TG_BUMP4:
485 case GX_TG_BUMP5:
486 case GX_TG_BUMP6:
487 case GX_TG_BUMP7:
488 ASSERTMSG((src_param >= GX_TG_TEXCOORD0) &&
489 (src_param <= GX_TG_TEXCOORD6),
490 "GDSetTexCoordGen: invalid emboss source");
491 tgType = XF_TEXGEN_EMBOSS_MAP;
492 embossLit = (u32) (func - GX_TG_BUMP0);
493 break;
494
495 case GX_TG_SRTG:
496 if (src_param == GX_TG_COLOR0) {
497 tgType = XF_TEXGEN_COLOR_STRGBC0;
498 } else {
499 tgType = XF_TEXGEN_COLOR_STRGBC1;
500 }
501 break;
502
503 default:
504 ASSERTMSG(0, "GDSetTexCoordGen: invalid texgen function");
505 break;
506 }
507
508 GDWriteXFCmd( (u16) (XF_TEX0_ID + dst_coord),
509 XF_TEX( proj, form, tgType, row,
510 embossRow, embossLit ));
511
512 //---------------------------------------------------------------------
513 // Update DUALTEX state
514 //---------------------------------------------------------------------
515
516 GDWriteXFCmd( (u16) (XF_DUALTEX0_ID + dst_coord), XF_DUALTEX(
517 (postmtx - GX_PTTEXMTX0), normalize ));
518 }
519
520 /*---------------------------------------------------------------------------*/
521 // Name: GDSetCullMode
522 //
523 // Description: Sets front/back face culling mode. The register mask
524 // is used to changing anything other than cull mode.
525 // Note: The HW's notion of front face is opposite of the
526 // api's notion of front face so we need to translate the
527 // enums.
528 //
529 // Arguments: mode cull mode.
530 //
531 // Returns: None
532 //
533 /*---------------------------------------------------------------------------*/
534
535 #define GEN_MODE_MASK_SETCULLMODE \
536 ( 0x000003 << GEN_MODE_REJECT_EN_SHIFT )
537
GDSetCullMode(GXCullMode mode)538 void GDSetCullMode( GXCullMode mode )
539 {
540 static u8 cm2hw[] = { 0, 2, 1, 3 };
541
542 GDWriteBPCmd( SS_MASK( GEN_MODE_MASK_SETCULLMODE ));
543
544 GDWriteBPCmd( GEN_MODE( 0, 0, 0, 0, cm2hw[mode], 0, 0, GEN_MODE_ID ));
545 }
546
547 /*---------------------------------------------------------------------------*/
548 // Name: GDSetGenMode
549 //
550 // Description: Sets the gen mode register for the raster pipe.
551 // The register mask is used to prevent changing the cull mode,
552 // the coplanar bit, AA mode, or number of indirect stages.
553 //
554 // Arguments: nTexGens: Number of texgens.
555 // nChans: Number of active lighting channels.
556 // nTevs: Number of active TEV stages.
557 //
558 // Returns: None
559 //
560 /*---------------------------------------------------------------------------*/
561
562 #define GEN_MODE_MASK_SETGENMODE \
563 (( 0x00000F << GEN_MODE_NTEX_SHIFT ) | \
564 ( 0x000003 << GEN_MODE_NCOL_SHIFT ) | \
565 ( 0x00000F << GEN_MODE_NTEV_SHIFT ))
566
567
GDSetGenMode(u8 nTexGens,u8 nChans,u8 nTevs)568 void GDSetGenMode( u8 nTexGens, u8 nChans, u8 nTevs )
569 {
570 GDWriteBPCmd( SS_MASK( GEN_MODE_MASK_SETGENMODE ));
571
572 GDWriteBPCmd( GEN_MODE( nTexGens, nChans, 0, (nTevs-1),
573 0, 0, 0, GEN_MODE_ID ));
574
575 GDWriteXFCmd( XF_NUMCOLORS_ID, XF_NUMCOLORS( nChans ));
576 GDWriteXFCmd( XF_NUMTEX_ID, XF_NUMTEX( nTexGens ));
577 }
578
579 /*---------------------------------------------------------------------------*/
580 // Name: GDSetGenMode2
581 //
582 // Description: Sets the gen mode register for the raster pipe.
583 // Also lets you specify the culling mode. The mask is used
584 // to prevent changing the coplanar bit or AA mode.
585 //
586 // NOTE: The indirect mask is not dealt with! If you change the
587 // number of indirect stages, you'd better also set the
588 // indirect mask as appropriate.
589 //
590 // Arguments: nTexGens: Number of texgens.
591 // nChans: Number of active lighting channels.
592 // nTev: Number of active TEV stages.
593 // nInds: Number of active indirect texture stages.
594 // cm: Front/back-face culling mode.
595 //
596 // Returns: None
597 //
598 /*---------------------------------------------------------------------------*/
599
600 #define GEN_MODE_MASK_SETGENMODE2 \
601 (( 0x00000F << GEN_MODE_NTEX_SHIFT ) | \
602 ( 0x000003 << GEN_MODE_NCOL_SHIFT ) | \
603 ( 0x00000F << GEN_MODE_NTEV_SHIFT ) | \
604 ( 0x000003 << GEN_MODE_REJECT_EN_SHIFT ) | \
605 ( 0x000007 << GEN_MODE_NBMP_SHIFT ))
606
607
GDSetGenMode2(u8 nTexGens,u8 nChans,u8 nTevs,u8 nInds,GXCullMode cm)608 void GDSetGenMode2( u8 nTexGens, u8 nChans, u8 nTevs, u8 nInds, GXCullMode cm )
609 {
610 static u8 cm2hw[] = { 0, 2, 1, 3 };
611
612 GDWriteBPCmd( SS_MASK( GEN_MODE_MASK_SETGENMODE2 ));
613
614 GDWriteBPCmd( GEN_MODE( nTexGens, nChans, 0, (nTevs-1),
615 cm2hw[cm], nInds, 0, GEN_MODE_ID ));
616
617 GDWriteXFCmd( XF_NUMCOLORS_ID, XF_NUMCOLORS( nChans ));
618 GDWriteXFCmd( XF_NUMTEX_ID, XF_NUMTEX( nTexGens ));
619 }
620
621 /*---------------------------------------------------------------------------*/
622 // Name: GDSetLPSize
623 //
624 // Description: Sets the line width & texture offset, point size &
625 // texture offset, and line aspect ratio.
626 //
627 // Arguments: lineWidth: line width, in 1/6's
628 // pointSize: point size, in 1/6's
629 // lineOffset: line texture offset
630 // pointOffset: point texture offset
631 // lineHalfAspect: TRUE for drawing lines in field mode
632 // FALSE for drawing lines in frame mode
633 //
634 // Returns: None
635 //
636 /*---------------------------------------------------------------------------*/
637
GDSetLPSize(u8 lineWidth,u8 pointSize,GXTexOffset lineOffset,GXTexOffset pointOffset,GXBool lineHalfAspect)638 void GDSetLPSize( u8 lineWidth, u8 pointSize,
639 GXTexOffset lineOffset, GXTexOffset pointOffset,
640 GXBool lineHalfAspect )
641 {
642 GDWriteBPCmd( SU_LPSIZE( lineWidth, pointSize,
643 lineOffset, pointOffset,
644 lineHalfAspect, SU_LPSIZE_ID ));
645 }
646
647 /*---------------------------------------------------------------------------*/
648 // Name: GDSetCoPlanar
649 //
650 // Description: Sets the coplanar mode within the gen mode register.
651 // This freezes the Z slopes of the last triangle sent.
652 // All subsequent triangles will use the same Z slopes,
653 // meaning that they will be coplanar. The register mask
654 // is used to set only this bit within gen mode.
655 //
656 // Arguments: enable : GX_TRUE to enable coplanar mode
657 //
658 // Returns: None
659 //
660 /*---------------------------------------------------------------------------*/
661
662 #define GEN_MODE_MASK_SETCOPLANAR \
663 ( 0x000001 << GEN_MODE_ZFREEZE_SHIFT )
664
GDSetCoPlanar(GXBool enable)665 void GDSetCoPlanar( GXBool enable )
666 {
667 GDWriteBPCmd( SS_MASK( GEN_MODE_MASK_SETCOPLANAR ));
668
669 GDWriteBPCmd( GEN_MODE( 0, 0, 0, 0, 0, 0, enable, GEN_MODE_ID ));
670 }
671