1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin/Revolution gx demo
3   File:     geo-vtx-fmt.c
4 
5   Copyright 1998-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 
14 #include <demo.h>
15 #include <math.h>
16 
17 /*---------------------------------------------------------------------------*
18    Forward references
19  *---------------------------------------------------------------------------*/
20 
21 void        main            ( void );
22 
23 static void CameraInit      ( void );
24 static void DrawInit        ( void );
25 static void DrawTick        ( void );
26 static void VertexLightInit ( void );
27 
28 static void AnimTick        ( void );
29 
30 static void SetColorParams      ( void );
31 static void SetTexCoordParams   ( void );
32 static void SetNormalParams     ( void );
33 static void SetPositionParams   ( void );
34 
35 static void PrintIntro          ( void );
36 
37 void DrawQuadCube( void );
38 void DrawTriCube( void );
39 void DrawPointCube( void );
40 void DrawLineCube( void );
41 void DrawLineStripCube( void );
42 void DrawTriStripCube( void );
43 void DrawTriFanCube( void );
44 
45 /*---------------------------------------------------------------------------*
46    Defines
47  *---------------------------------------------------------------------------*/
48 #define SIDE 50
49 #define WOOD1_TEX_ID        5
50 
51 /*---------------------------------------------------------------------------*
52    Global variables
53  *---------------------------------------------------------------------------*/
54 Mtx v;
55 
56 TPLPalettePtr tpl = 0;
57 
58 u32 rot;
59 
60 float FloatVert[] ATTRIBUTE_ALIGN(32) =
61                      {  -SIDE, SIDE, -SIDE,
62                         -SIDE, SIDE, SIDE,
63                         -SIDE, -SIDE, SIDE,
64                         -SIDE, -SIDE, -SIDE,
65                         SIDE, SIDE, -SIDE,
66                         SIDE, -SIDE, -SIDE,
67                         SIDE, -SIDE, SIDE,
68                         SIDE, SIDE, SIDE
69                     };
70 s16 Vert16[] ATTRIBUTE_ALIGN(32) =
71                     {   -SIDE, SIDE, -SIDE,
72                         -SIDE, SIDE, SIDE,
73                         -SIDE, -SIDE, SIDE,
74                         -SIDE, -SIDE, -SIDE,
75                         SIDE, SIDE, -SIDE,
76                         SIDE, -SIDE, -SIDE,
77                         SIDE, -SIDE, SIDE,
78                         SIDE, SIDE, SIDE
79                     };
80 s8 Vert8[] ATTRIBUTE_ALIGN(32) =
81                     {   -SIDE, SIDE, -SIDE,
82                         -SIDE, SIDE, SIDE,
83                         -SIDE, -SIDE, SIDE,
84                         -SIDE, -SIDE, -SIDE,
85                         SIDE, SIDE, -SIDE,
86                         SIDE, -SIDE, -SIDE,
87                         SIDE, -SIDE, SIDE,
88                         SIDE, SIDE, SIDE
89                     };
90 
91 float FloatNorm[] ATTRIBUTE_ALIGN(32) =
92                     {   -1.0F, 0.0F, 0.0F,
93                         1.0F, 0.0F, 0.0F,
94                         0.0F, -1.0F, 0.0F,
95                         0.0F, 1.0F, 0.0F,
96                         0.0F, 0.0F, -1.0F,
97                         0.0F, 0.0F, 1.0F
98                     };
99 s16 Norm16[] ATTRIBUTE_ALIGN(32) =
100                     {   -1, 0, 0,
101                         1, 0, 0,
102                         0, -1, 0,
103                         0, 1, 0,
104                         0, 0, -1,
105                         0, 0, 1
106                     };
107 s8 Norm8[] ATTRIBUTE_ALIGN(32) =
108                     {   -1, 0, 0,
109                         1, 0, 0,
110                         0, -1, 0,
111                         0, 1, 0,
112                         0, 0, -1,
113                         0, 0, 1
114                     };
115 
116 u8  ColorRGBA8[] ATTRIBUTE_ALIGN(32) =
117                         {   255, 0, 0, 255,
118                             255, 0, 0, 192,
119                             255, 0, 0, 128,
120                             255, 0, 0, 64,
121                             255, 0, 0, 0};      //GX_RGBA8
122 u8  ColorRGBA6[] ATTRIBUTE_ALIGN(32) =
123                         {   0xFC, 0x00, 0x3F,
124                             0xFC, 0x00, 0x30,
125                             0xFC, 0x00, 0x20,
126                             0xFC, 0x00, 0x10,
127                             0xFC, 0x00, 0x00};  //GX_RGBA6
128 u8  ColorRGBA4[] ATTRIBUTE_ALIGN(32) =
129                         {   0xF0, 0x0F,
130                             0xF0, 0x0C,
131                             0xF0, 0x08,
132                             0xF0, 0x04,
133                             0xF0, 0x00};            //GX_RGBA4
134 u8  ColorRGBX8[] ATTRIBUTE_ALIGN(32) =
135                         {   255, 0, 0, 0,
136                             255, 0, 0, 0,
137                             255, 0, 0, 0,
138                             255, 0, 0, 0,
139                             255, 0, 0, 0};      //GX_RGBX8
140 u8  ColorRGB8[] ATTRIBUTE_ALIGN(32) =
141                         {   255, 0, 0,
142                             255, 0, 0,
143                             255, 0, 0,
144                             255, 0, 0,
145                             255, 0, 0};             //GX_RGB8
146 u8  ColorRGB565[] ATTRIBUTE_ALIGN(32) =
147                         {   0xF8, 0x00,
148                             0xF8, 0x00,
149                             0xF8, 0x00,
150                             0xF8, 0x00,
151                             0xF8, 0x00};            //GX_RGB565
152 
153 
154 float FloatTex[] ATTRIBUTE_ALIGN(32) =
155                     {   0.0F, 0.0F,
156                         1.0F, 0.0F,
157                         1.0F, 1.0F,
158                         0.0F, 1.0F
159                     };
160 u16 Tex16[] ATTRIBUTE_ALIGN(32) =
161                     {   0, 0,
162                         1, 0,
163                         1, 1,
164                         0, 1
165                     };
166 u8 Tex8[] ATTRIBUTE_ALIGN(32) =
167                     {   0, 0,
168                         1, 0,
169                         1, 1,
170                         0, 1
171                     };
172 
173 
174 u8  CurrentControl = 0;
175 u8  PositionControl = 0;
176 u8  ColorControl = 1;
177 u8  NormalControl = 0;
178 u8  TexCoordControl = 0;
179 
180 GXBool  LightingOn = GX_TRUE;
181 GXColorSrc MatSrc = GX_SRC_VTX;
182 
183 u8  PositionShift = 0;
184 u8  TexCoordShift = 0;
185 
186 
187 /*---------------------------------------------------------------------------*
188    Application main loop
189  *---------------------------------------------------------------------------*/
main(void)190 void main ( void )
191 {
192     DEMOInit(NULL);
193 
194     DrawInit();         // Define my vertex formats and set array pointers.
195 
196     VertexLightInit();
197 
198     PrintIntro();
199     DEMOPadRead();      // Read the joystick for this frame
200 
201     // While the quit button is not pressed
202     while(!(DEMOPadGetButton(0) & PAD_BUTTON_MENU))
203     {
204         DEMOPadRead();  // Read the joystick for this frame
205 
206         AnimTick();     // Do animation based on input
207         DEMOBeforeRender();
208 
209         DrawTick();     // Draw the model.
210 
211         DEMODoneRender();
212     }
213 
214     OSHalt("End of test");
215 }
216 
217 /*---------------------------------------------------------------------------*
218    Functions
219  *---------------------------------------------------------------------------*/
220 
221 
222 /*---------------------------------------------------------------------------*
223     Name:           CameraInit
224 
225     Description:    Initialize the projection matrix and load into hardware.
226 
227     Arguments:      v   view matrix to be passed to ViewInit
228                     cameraLocScale  scale for the camera's distance from the
229                                     object - to be passed to ViewInit
230 
231     Returns:        none
232  *---------------------------------------------------------------------------*/
CameraInit(void)233 static void CameraInit      ( void )
234 {
235     Mtx44 p;
236     Vec camPt = {0.0F, 0.0F, 650.0F};
237     Vec up = {0.0F, 1.0F, 0.0F};
238     Vec origin = {0.0F, 0.0F, 0.0F};
239 
240     MTXFrustum(p, 240, -240, -320, 320, 500, 2000);
241 
242     GXSetProjection(p, GX_PERSPECTIVE);
243 
244     MTXLookAt(v, &camPt, &up, &origin);
245 }
246 
247 /*---------------------------------------------------------------------------*
248     Name:           DrawInit
249 
250     Description:    Calls the correct initialization function for the current
251                     model.
252 
253     Arguments:      none
254 
255     Returns:        none
256  *---------------------------------------------------------------------------*/
DrawInit(void)257 static void DrawInit( void )
258 {
259     GXTexObj to;
260 
261     SetPositionParams();
262     SetColorParams();
263     SetNormalParams();
264     SetTexCoordParams();
265 
266     CameraInit();   // Initialize the camera.
267 
268     TPLGetPalette(&tpl, "gxTextrs.tpl");
269 
270     TPLGetGXTexObjFromPalette(tpl, &to, WOOD1_TEX_ID);
271 
272     GXLoadTexObj(&to, GX_TEXMAP0);
273 
274     GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA,
275                        GX_LO_CLEAR);
276 }
277 
278 /*---------------------------------------------------------------------------*
279     Name:           DrawTick
280 
281     Description:    Draw the current model once.
282 
283     Arguments:      v       view matrix
284                     m       model matrix
285 
286     Returns:        none
287  *---------------------------------------------------------------------------*/
DrawTick(void)288 static void DrawTick( void )
289 {
290     DrawQuadCube();
291     DrawTriCube();
292     DrawPointCube();
293     DrawLineCube();
294     DrawLineStripCube();
295     DrawTriStripCube();
296     DrawTriFanCube();
297 }
298 
299 /*---------------------------------------------------------------------------*/
VertexLightInit(void)300 static void VertexLightInit ( void )
301 {
302     GXLightObj MyLight;
303     GXColor color = {255, 255, 255, 255};
304 
305     GXInitLightPos(&MyLight, 0.0F, 0.0F, 0.0F);
306     GXInitLightColor(&MyLight, color);
307     GXLoadLightObjImm(&MyLight, GX_LIGHT0);
308 
309     GXSetChanMatColor(GX_COLOR0A0, color);
310     //GXSetChanMatColor(GX_ALPHA0, color);
311 
312     /*GXSetChanCtrl(
313                 GX_ALPHA0,
314                 GX_FALSE,   // enable channel
315                 GX_SRC_REG, // amb source
316                 GX_SRC_REG, // mat source
317                 GX_LIGHT0,  // light mask
318                 GX_DF_CLAMP,// diffuse function
319                 GX_AF_NONE);*/
320 }
321 
322 /*---------------------------------------------------------------------------*
323     Name:           AnimTick
324 
325     Description:    Animates the camera and object based on the joystick's
326                     state.
327 
328     Arguments:      none
329 
330     Returns:        none
331  *---------------------------------------------------------------------------*/
AnimTick(void)332 static void AnimTick ( void )
333 {
334     u16 buttons = DEMOPadGetButtonDown(0);
335     s8 stickX = DEMOPadGetStickX(0);
336     s8 stickY = DEMOPadGetStickY(0);
337 
338     rot ++;
339     if(rot > 719)
340         rot = 0;
341 
342     if(buttons & PAD_BUTTON_X)
343     {
344         CurrentControl ++;
345         if(CurrentControl > 5)
346             CurrentControl = 0;
347 
348         switch(CurrentControl)
349         {
350             case 0:
351                 OSReport("\n\nPosition Control\n\n");
352                 break;
353             case 1:
354                 OSReport("\n\nColor Control\n\n");
355                 break;
356             case 2:
357                 OSReport("\n\nNormal Control\n\n");
358                 break;
359             case 3:
360                 OSReport("\n\nTextureCoord Control\n\n");
361                 break;
362             case 4:
363                 OSReport("\n\nPosition Shift Control\n\n");
364                 break;
365             case 5:
366                 OSReport("\n\nTextureCoord Shift Control\n\n");
367                 break;
368         }
369     }
370     if(CurrentControl == 0)
371     {
372         if(buttons & PAD_BUTTON_B)
373         {
374             PositionControl ++;
375             if(PositionControl > 8)
376                 PositionControl = 0;
377 
378             switch(PositionControl)
379             {
380                 case 0:
381                     OSReport("Position on - 16 bit indexed floating point data\n");
382                     break;
383                 case 1:
384                     OSReport("Position on - 16 bit indexed 16 bit data\n");
385                     break;
386                 case 2:
387                     OSReport("Position on - 16 bit indexed 8 bit data\n");
388                     break;
389                 case 3:
390                     OSReport("Position on - 8 bit indexed floating point data\n");
391                     break;
392                 case 4:
393                     OSReport("Position on - 8 bit indexed 16 bit data\n");
394                     break;
395                 case 5:
396                     OSReport("Position on - 8 bit indexed 8 bit data\n");
397                     break;
398                 case 6:
399                     OSReport("Position on - Direct floating point data\n");
400                     break;
401                 case 7:
402                     OSReport("Position on - Direct 16 bit data\n");
403                     break;
404                 case 8:
405                     OSReport("Position on - Direct 8 bit data\n");
406                     break;
407             }
408 
409             SetPositionParams();
410         }
411     }
412     else if(CurrentControl == 1)
413     {
414         if(buttons & PAD_BUTTON_B)
415         {
416             ColorControl ++;
417             if(ColorControl > 20)
418                 ColorControl = 0;
419 
420             switch(ColorControl)
421             {
422                 case 0:
423                     OSReport("Color off\n");
424                     break;
425                 case 1:
426                     OSReport("Color on - 16 bit indexed RGBA8\n");
427                     break;
428                 case 2:
429                     OSReport("Color on - 16 bit indexed RGBA6\n");
430                     break;
431                 case 3:
432                     OSReport("Color on - 16 bit indexed RGBA4\n");
433                     break;
434                 case 4:
435                     OSReport("Color on - 16 bit indexed RGBX8\n");
436                     break;
437                 case 5:
438                     OSReport("Color on - 16 bit indexed RGB8\n");
439                     break;
440                 case 6:
441                     OSReport("Color on - 16 bit indexed RGB565\n");
442                     break;
443                 case 7:
444                     OSReport("Color on - 8 bit indexed RGBA8\n");
445                     break;
446                 case 8:
447                     OSReport("Color on - 8 bit indexed RGBA6\n");
448                     break;
449                 case 9:
450                     OSReport("Color on - 8 bit indexed RGBA4\n");
451                     break;
452                 case 10:
453                     OSReport("Color on - 8 bit indexed RGBX8\n");
454                     break;
455                 case 11:
456                     OSReport("Color on - 8 bit indexed RGB8\n");
457                     break;
458                 case 12:
459                     OSReport("Color on - 8 bit indexed RGB565\n");
460                     break;
461 
462                 case 13:
463                     OSReport("Color on - direct RGBA8 (4 u8's)\n");
464                     break;
465                 case 14:
466                     OSReport("Color on - direct RGBA8 (1 u32)\n");
467                     break;
468 
469                 case 15:
470                     OSReport("Color on - direct RGBA6 (3 u8's)\n");
471                     break;
472                 case 16:
473                     OSReport("Color on - direct RGBA4 (1 u16)\n");
474                     break;
475 
476                 case 17:
477                     OSReport("Color on - direct RGBX8 (4 u8's)\n");
478                     break;
479                 case 18:
480                     OSReport("Color on - direct RGBX8 (1 u32)\n");
481                     break;
482 
483                 case 19:
484                     OSReport("Color on - direct RGB8 (3 u8's)\n");
485                     break;
486                 case 20:
487                     OSReport("Color on - direct RGB565 (1 u16)\n");
488                     break;
489             }
490 
491             SetColorParams();
492         }
493     }
494     else if(CurrentControl == 2)
495     {
496         if(buttons & PAD_BUTTON_B)
497         {
498             NormalControl ++;
499             if(NormalControl > 9)
500                 NormalControl = 0;
501 
502             switch(NormalControl)
503             {
504                 case 0:
505                     OSReport("Normal off\n");
506                     break;
507                 case 1:
508                     OSReport("Normal on - 16 bit indexed floating point data\n");
509                     break;
510                 case 2:
511                     OSReport("Normal on - 16 bit indexed 16 bit data\n");
512                     break;
513                 case 3:
514                     OSReport("Normal on - 16 bit indexed 8 bit data\n");
515                     break;
516                 case 4:
517                     OSReport("Normal on - 8 bit indexed floating point data\n");
518                     break;
519                 case 5:
520                     OSReport("Normal on - 8 bit indexed 16 bit data\n");
521                     break;
522                 case 6:
523                     OSReport("Normal on - 8 bit indexed 8 bit data\n");
524                     break;
525                 case 7:
526                     OSReport("Normal on - Direct floating point data\n");
527                     break;
528                 case 8:
529                     OSReport("Normal on - Direct 16 bit data\n");
530                     break;
531                 case 9:
532                     OSReport("Normal on - Direct 8 bit data\n");
533                     break;
534             }
535 
536             SetNormalParams();
537         }
538     }
539     else if(CurrentControl == 3)
540     {
541         if(buttons & PAD_BUTTON_B)
542         {
543             TexCoordControl ++;
544             if(TexCoordControl > 9)
545                 TexCoordControl = 0;
546 
547             switch(TexCoordControl)
548             {
549                 case 0:
550                     OSReport("TexCoord off\n");
551                     break;
552                 case 1:
553                     OSReport("TexCoord on - 16 bit indexed floating point data\n");
554                     break;
555                 case 2:
556                     OSReport("TexCoord on - 16 bit indexed 16 bit data\n");
557                     break;
558                 case 3:
559                     OSReport("TexCoord on - 16 bit indexed 8 bit data\n");
560                     break;
561                 case 4:
562                     OSReport("TexCoord on - 8 bit indexed floating point data\n");
563                     break;
564                 case 5:
565                     OSReport("TexCoord on - 8 bit indexed 16 bit data\n");
566                     break;
567                 case 6:
568                     OSReport("TexCoord on - 8 bit indexed 8 bit data\n");
569                     break;
570                 case 7:
571                     OSReport("TexCoord on - Direct floating point data\n");
572                     break;
573                 case 8:
574                     OSReport("TexCoord on - Direct 16 bit data\n");
575                     break;
576                 case 9:
577                     OSReport("TexCoord on - Direct 8 bit data\n");
578                     break;
579             }
580 
581             SetTexCoordParams();
582         }
583     }
584     else if(CurrentControl == 4)
585     {
586         if(buttons & PAD_BUTTON_B)
587         {
588             PositionShift ++;
589             if(PositionShift > 16)
590                 PositionShift = 0;
591 
592             OSReport("Position shift  - %d\n", PositionShift);
593 
594             SetPositionParams();
595         }
596     }
597     else if(CurrentControl == 5)
598     {
599         if(buttons & PAD_BUTTON_B)
600         {
601             TexCoordShift ++;
602             if(TexCoordShift > 16)
603                 TexCoordShift = 0;
604 
605             OSReport("TexCoord shift  - %d\n", TexCoordShift);
606 
607             SetTexCoordParams();
608         }
609     }
610 
611 }
612 
613 /*---------------------------------------------------------------------------*/
SetColorParams(void)614 static void SetColorParams( void )
615 {
616     GXSetNumChans(1);
617 
618     switch(ColorControl)
619     {
620         case 0:
621             GXSetVtxDesc(GX_VA_CLR0, GX_NONE);
622             MatSrc = GX_SRC_REG;
623             GXSetChanCtrl(
624                 GX_COLOR0,
625                 LightingOn, // enable channel
626                 GX_SRC_REG, // amb source
627                 MatSrc,     // mat source
628                 GX_LIGHT0,  // light mask
629                 GX_DF_CLAMP,// diffuse function
630                 GX_AF_NONE);
631             GXSetChanCtrl(
632                 GX_ALPHA0,
633                 GX_FALSE,   // enable channel
634                 GX_SRC_REG, // amb source
635                 GX_SRC_REG, // mat source
636                 GX_LIGHT0,  // light mask
637                 GX_DF_CLAMP,// diffuse function
638                 GX_AF_NONE);
639             break;
640         case 1:
641             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
642             GXSetVtxDesc(GX_VA_CLR0, GX_INDEX16);
643             GXSetArray(GX_VA_CLR0, ColorRGBA8, 4);
644             MatSrc = GX_SRC_VTX;
645             GXSetChanCtrl(
646                 GX_COLOR0,
647                 LightingOn, // enable channel
648                 GX_SRC_REG, // amb source
649                 MatSrc,     // mat source
650                 GX_LIGHT0,  // light mask
651                 GX_DF_CLAMP,// diffuse function
652                 GX_AF_NONE);
653             GXSetChanCtrl(
654                 GX_ALPHA0,
655                 GX_FALSE,   // enable channel
656                 GX_SRC_REG, // amb source
657                 GX_SRC_VTX, // mat source
658                 GX_LIGHT0,  // light mask
659                 GX_DF_CLAMP,// diffuse function
660                 GX_AF_NONE);
661             break;
662         case 2:
663             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA6, 0);
664             GXSetArray(GX_VA_CLR0, ColorRGBA6, 3);
665             break;
666         case 3:
667             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA4, 0);
668             GXSetArray(GX_VA_CLR0, ColorRGBA4, 2);
669             break;
670         case 4:
671             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGBX8, 0);
672             GXSetArray(GX_VA_CLR0, ColorRGBX8, 4);
673             break;
674         case 5:
675             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB8, 0);
676             GXSetArray(GX_VA_CLR0, ColorRGB8, 3);
677             break;
678         case 6:
679             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB565, 0);
680             GXSetArray(GX_VA_CLR0, ColorRGB565, 2);
681             break;
682         case 7:
683             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
684             GXSetVtxDesc(GX_VA_CLR0, GX_INDEX8);
685             GXSetArray(GX_VA_CLR0, ColorRGBA8, 4);
686             break;
687         case 8:
688             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA6, 0);
689             GXSetArray(GX_VA_CLR0, ColorRGBA6, 3);
690             break;
691         case 9:
692             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA4, 0);
693             GXSetArray(GX_VA_CLR0, ColorRGBA4, 2);
694             break;
695         case 10:
696             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGBX8, 0);
697             GXSetArray(GX_VA_CLR0, ColorRGBX8, 4);
698             break;
699         case 11:
700             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB8, 0);
701             GXSetArray(GX_VA_CLR0, ColorRGB8, 3);
702             break;
703         case 12:
704             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB565, 0);
705             GXSetArray(GX_VA_CLR0, ColorRGB565, 2);
706             break;
707         case 13:
708         case 14:
709             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
710             GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT);
711             break;
712         case 15:
713             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA6, 0);
714             break;
715         case 16:
716             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA4, 0);
717             break;
718         case 17:
719         case 18:
720             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGBX8, 0);
721             break;
722         case 19:
723             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB8, 0);
724             break;
725         case 20:
726             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB565, 0);
727             break;
728     }
729 }
730 
731 /*---------------------------------------------------------------------------*/
SetTexCoordParams(void)732 static void SetTexCoordParams( void )
733 {
734     switch(TexCoordControl)
735     {
736         case 0:
737             GXSetVtxDesc(GX_VA_TEX0, GX_NONE);
738             GXSetNumTexGens(0);
739             GXSetNumTevStages(1);
740             GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
741             GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
742             break;
743         case 1:
744             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, TexCoordShift);
745             GXSetVtxDesc(GX_VA_TEX0, GX_INDEX16);
746             GXSetArray(GX_VA_TEX0, FloatTex, 8);
747             GXSetNumTexGens(1);
748             GXSetNumTevStages(1);
749             GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
750             GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE);
751             break;
752         case 2:
753             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, TexCoordShift);
754             GXSetArray(GX_VA_TEX0, Tex16, 4);
755             break;
756         case 3:
757             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, TexCoordShift);
758             GXSetArray(GX_VA_TEX0, Tex8, 2);
759             break;
760         case 4:
761             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, TexCoordShift);
762             GXSetVtxDesc(GX_VA_TEX0, GX_INDEX8);
763             GXSetArray(GX_VA_TEX0, FloatTex, 8);
764             break;
765         case 5:
766             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, TexCoordShift);
767             GXSetArray(GX_VA_TEX0, Tex16, 4);
768             break;
769         case 6:
770             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, TexCoordShift);
771             GXSetArray(GX_VA_TEX0, Tex8, 2);
772             break;
773         case 7:
774             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, TexCoordShift);
775             GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
776             break;
777         case 8:
778             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, TexCoordShift);
779             break;
780         case 9:
781             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, TexCoordShift);
782             break;
783     }
784 }
785 
786 /*---------------------------------------------------------------------------*/
SetNormalParams(void)787 static void SetNormalParams( void )
788 {
789     switch(NormalControl)
790     {
791         case 0:
792             GXSetVtxDesc(GX_VA_NRM, GX_NONE);
793             LightingOn = GX_FALSE;
794             GXSetChanCtrl(
795                 GX_COLOR0,
796                 LightingOn, // enable channel
797                 GX_SRC_REG, // amb source
798                 MatSrc,     // mat source
799                 GX_LIGHT0,  // light mask
800                 GX_DF_CLAMP,// diffuse function
801                 GX_AF_NONE);
802             break;
803         case 1:
804             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
805             GXSetVtxDesc(GX_VA_NRM, GX_INDEX16);
806             GXSetArray(GX_VA_NRM, FloatNorm, 12);
807             LightingOn = GX_TRUE;
808             GXSetChanCtrl(
809                 GX_COLOR0,
810                 LightingOn, // enable channel
811                 GX_SRC_REG, // amb source
812                 MatSrc,     // mat source
813                 GX_LIGHT0,  // light mask
814                 GX_DF_CLAMP,// diffuse function
815                 GX_AF_NONE);
816             break;
817         case 2:
818             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S16, 14);
819             GXSetArray(GX_VA_NRM, Norm16, 6);
820             break;
821         case 3:
822             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S8, 6);
823             GXSetArray(GX_VA_NRM, Norm8, 3);
824             break;
825         case 4:
826             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
827             GXSetVtxDesc(GX_VA_NRM, GX_INDEX8);
828             GXSetArray(GX_VA_NRM, FloatNorm, 12);
829             break;
830         case 5:
831             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S16, 14);
832             GXSetArray(GX_VA_NRM, Norm16, 6);
833             break;
834         case 6:
835             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S8, 6);
836             GXSetArray(GX_VA_NRM, Norm8, 3);
837             break;
838         case 7:
839             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
840             GXSetVtxDesc(GX_VA_NRM, GX_DIRECT);
841             break;
842         case 8:
843             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S16, 14);
844             break;
845         case 9:
846             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_S8, 6);
847             break;
848     }
849 }
850 
851 /*---------------------------------------------------------------------------*/
SetPositionParams(void)852 static void SetPositionParams( void )
853 {
854     switch(PositionControl)
855     {
856         case 0:
857             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, PositionShift);
858             GXSetVtxDesc (GX_VA_POS, GX_INDEX16);
859             GXSetArray(GX_VA_POS, FloatVert, 12);
860             break;
861         case 1:
862             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, PositionShift);
863             GXSetArray(GX_VA_POS, Vert16, 6);
864             break;
865         case 2:
866             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S8, PositionShift);
867             GXSetArray(GX_VA_POS, Vert8, 3);
868             break;
869         case 3:
870             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, PositionShift);
871             GXSetVtxDesc(GX_VA_POS, GX_INDEX8);
872             GXSetArray(GX_VA_POS, FloatVert, 12);
873             break;
874         case 4:
875             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, PositionShift);
876             GXSetArray(GX_VA_POS, Vert16, 6);
877             break;
878         case 5:
879             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S8, PositionShift);
880             GXSetArray(GX_VA_POS, Vert8, 3);
881             break;
882         case 6:
883             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, PositionShift);
884             GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
885             break;
886         case 7:
887             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, PositionShift);
888             break;
889         case 8:
890             GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S8, PositionShift);
891             break;
892     }
893 }
894 
895 /*---------------------------------------------------------------------------*
896     Name:           PrintIntro
897 
898     Description:    Prints the directions on how to use this demo.
899 
900     Arguments:      none
901 
902     Returns:        none
903  *---------------------------------------------------------------------------*/
PrintIntro(void)904 static void PrintIntro( void )
905 {
906     OSReport("\n\n");
907     OSReport("************************************************\n");
908     OSReport("geo-vtx-fmt: test combinations of vertex formats\n");
909     OSReport("************************************************\n");
910     OSReport("to quit hit the menu button\n");
911     OSReport("\n");
912     OSReport("  X button     : change attribute\n");
913     OSReport("  B button     : change current attribute format\n");
914     OSReport("************************************************\n\n");
915 }
916 
917