1 /*---------------------------------------------------------------------------*
2 Project: Dolphin
3 File: gd-light-create.c
4
5 Copyright 2001 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: gd-light-create.c,v $
14 Revision 1.1 02/08/2006 11:19:43 mitu
15 1st version.
16
17
18 1 9/21/01 4:06p Hirose
19 Initial check in.
20
21 $NoKeywords: $
22 *---------------------------------------------------------------------------*/
23 /*---------------------------------------------------------------------------*
24 gd-light
25 Displaylist demo with lighting commands
26 [Displaylist creation function for both off-line/runtime]
27 *---------------------------------------------------------------------------*/
28
29
30 /*---------------------------------------------------------------------------*
31 Header files
32 *---------------------------------------------------------------------------*/
33 #include "gd-light.h"
34
35 /*---------------------------------------------------------------------------*
36 Forward references
37 *---------------------------------------------------------------------------*/
38 static void SendPartOfTorus ( u32 start, u32 end );
39
40 /*---------------------------------------------------------------------------*
41 Data
42 *---------------------------------------------------------------------------*/
43 static GXColor AmbColor0 = { 0x20, 0x20, 0x20, 0x20 };
44 static GXColor AmbColor1 = { 0x00, 0x00, 0x00, 0x00 };
45 static GXColor LightColor = { 0xC0, 0xC0, 0xC0, 0xC0 };
46 static GXColor MatColors[8] =
47 {
48 { 0x20, 0xA0, 0xA0, 0xFF },
49 { 0xA0, 0xA0, 0xA0, 0xA0 },
50 { 0xA0, 0x80, 0x40, 0xFF },
51 { 0x80, 0x80, 0x20, 0x60 },
52 { 0x30, 0x30, 0x30, 0xFF },
53 { 0xFF, 0xFF, 0xFF, 0xFF },
54 { 0xFF, 0xC0, 0xC0, 0xFF },
55 { 0x30, 0x30, 0x30, 0x30 }
56 };
57
58 static GXVtxDescList VcdSetting[] =
59 {
60 { GX_VA_POS, GX_INDEX16 },
61 { GX_VA_NRM, GX_INDEX16 },
62 { GX_VA_NULL, GX_NONE }, // NULL Terminator
63 };
64
65
66 /*---------------------------------------------------------------------------*
67 Functions
68 *---------------------------------------------------------------------------*/
69 /*---------------------------------------------------------------------------*
70 Name: CreateModelDL
71
72 Description: Creates the display list used by the program.
73 GD library is used for creating the display list.
74
75 Arguments: dlPtr : pointer to memory for the display list
76 plPtr : pointer to memory for patch list
77
78 Returns: actual size of the display list
79 *---------------------------------------------------------------------------*/
CreateModelDL(void * dlPtr,u32 * plPtr)80 u32 CreateModelDL ( void* dlPtr, u32* plPtr )
81 {
82 GDLObj dlObj;
83 u32 size;
84
85 GDInitGDLObj(&dlObj, dlPtr, MODELDL_SIZE_MAX);
86 GDSetCurrent(&dlObj);
87
88 // Lighting channel setting
89 GDSetChanCtrl(GX_COLOR0, GX_ENABLE, GX_SRC_REG, GX_SRC_REG,
90 GX_LIGHT0, GX_DF_CLAMP, GX_AF_NONE);
91 GDSetChanCtrl(GX_COLOR1, GX_ENABLE, GX_SRC_REG, GX_SRC_REG,
92 GX_LIGHT1, GX_DF_NONE, GX_AF_SPEC);
93 GDSetChanCtrl(GX_ALPHA0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG,
94 GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
95 GDSetChanCtrl(GX_ALPHA1, GX_DISABLE, GX_SRC_REG, GX_SRC_REG,
96 GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
97
98 // Ambient color
99 GDSetChanAmbColor(GX_COLOR0A0, AmbColor0);
100 GDSetChanAmbColor(GX_COLOR1A1, AmbColor1);
101
102
103 // Light setting
104 GDSetLightColor(GX_LIGHT0, LightColor);
105 GDSetLightColor(GX_LIGHT1, LightColor);
106 // LIGHT0(Pos) will be patched in run-time. Put dummy for now.
107 plPtr[MODELDL_PATCH_LIGHT0POS] = GDGetCurrOffset();
108 GDSetLightPos(GX_LIGHT0, 0.0F, 0.0F, 0.0F);
109 // LIGHT1(Dir) will be patched in run-time. Put dummy for now.
110 plPtr[MODELDL_PATCH_LIGHT1DIR] = GDGetCurrOffset();
111 GDSetSpecularDir(GX_LIGHT1, 0.0F, 0.0F, 1.0F);
112
113
114 // Vertex descriptor
115 GDSetVtxDescv(VcdSetting);
116
117
118 // 1st./5th. parts (material + body)
119 GDSetLightShininess(GX_LIGHT1, 256.0F);
120 GDSetChanMatColor(GX_COLOR0A0, MatColors[0]);
121 GDSetChanMatColor(GX_COLOR1A1, MatColors[1]);
122 SendPartOfTorus( 0, 8);
123 SendPartOfTorus(32, 40);
124
125 // 2nd./6th. parts (material + body)
126 GDSetLightShininess(GX_LIGHT1, 48.0F);
127 GDSetChanMatColor(GX_COLOR0A0, MatColors[2]);
128 GDSetChanMatColor(GX_COLOR1A1, MatColors[3]);
129 SendPartOfTorus( 8, 16);
130 SendPartOfTorus(40, 48);
131
132 // 3rd./7th. parts (material + body)
133 GDSetLightShininess(GX_LIGHT1, 128.0F);
134 GDSetChanMatColor(GX_COLOR0A0, MatColors[4]);
135 GDSetChanMatColor(GX_COLOR1A1, MatColors[5]);
136 SendPartOfTorus(16, 24);
137 SendPartOfTorus(48, 56);
138
139 // 4th./8th. parts (material + body)
140 GDSetLightShininess(GX_LIGHT1, 16.0F);
141 GDSetChanMatColor(GX_COLOR0A0, MatColors[6]);
142 GDSetChanMatColor(GX_COLOR1A1, MatColors[7]);
143 SendPartOfTorus(24, 32);
144 SendPartOfTorus(56, 64);
145
146
147 // close the DL (padding + flush)
148 GDPadCurr32();
149 GDFlushCurrToMem();
150
151 // get actual DL size
152 size = GDGetCurrOffset();
153
154 // release GD object
155 GDSetCurrent(NULL);
156
157 return size;
158 }
159
160 /*---------------------------------------------------------------------------*
161 Draw a part of the torus model
162 *---------------------------------------------------------------------------*/
SendPartOfTorus(u32 start,u32 end)163 static void SendPartOfTorus ( u32 start, u32 end )
164 {
165 u32 i, j, k;
166 u16 idx;
167
168 // send vertex data by using GD functions.
169 for ( i = start ; i < end ; i++ )
170 {
171 GDBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, (u16)((MODEL_N0+1)*2));
172 for ( j = 0 ; j <= MODEL_N0 ; j++ )
173 {
174 k = (j % MODEL_N0) * MODEL_N1;
175
176 idx = (u16)(k + ((i+1) % MODEL_N1));
177 // Position
178 GDPosition1x16(idx);
179 // Normal
180 GDNormal1x16(idx);
181
182 idx = (u16)(k + (i % MODEL_N1));
183 // Position
184 GDPosition1x16(idx);
185 // Normal
186 GDNormal1x16(idx);
187 }
188 GDEnd();
189 }
190 }
191
192
193 /*============================================================================*/
194