1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin GD library
3   File:     GDVert.h
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: GDVert.h,v $
14   Revision 1.2  2006/02/04 11:56:46  hashida
15   (none)
16 
17   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
18   Ported from dolphin source tree.
19 
20 
21     2     2001/10/13 2:12a Hirose
22     Added GDCmd() and GDParam() definitions.
23 
24     1     2001/09/12 1:55p Carl
25     Initial revision of GD: Graphics Display List Library.
26 
27   $NoKeywords: $
28  *---------------------------------------------------------------------------*/
29 
30 #ifndef __GDVERT_H__
31 #define __GDVERT_H__
32 
33 /*---------------------------------------------------------------------------*/
34 #include <revolution/types.h>
35 #include <revolution/gx/GXEnum.h>
36 /*---------------------------------------------------------------------------*/
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /*---------------------------------------------------------------------------*/
43 
44 /*---------------------------------------------*
45  * GD Vertex functions                         *
46  * Declarations & definitions!                 *
47  *---------------------------------------------*/
48 
49 //-------------------------------
50 // Define gfx function templates
51 //-------------------------------
52 
53 // Templates syntax:
54 //  __GXCDEF (function_prefix, num_of_components, component_type)
55 //  __GXCDEFX(function_name, num_of_comps, src_comp_type, dest_comp_type)
56 
57 #define __GXCDEF(prfx,n,t)  __GXCDEF##n(prfx##n##t,t,t)
58 #define __GXCDEFX(func,n,t) __GXCDEF##n(func,t,t)
59 
60 // 1 component
61 #define __GXCDEF1(func,ts,td) \
62     static inline void func(const ts x)  \
63     {                             \
64         GDWrite_##td(x); \
65     }
66 
67 // 2 components
68 #define __GXCDEF2(func,ts,td) \
69     static inline void func(const ts x, const ts y) \
70     {                             \
71         GDWrite_##td(x); \
72         GDWrite_##td(y); \
73     }
74 
75 // 3 components
76 #define __GXCDEF3(func,ts,td) \
77     static inline void func(const ts x, const ts y, const ts z) \
78     {                             \
79         GDWrite_##td(x); \
80         GDWrite_##td(y); \
81         GDWrite_##td(z); \
82     }
83 
84 // 4 components
85 #define __GXCDEF4(func,ts,td) \
86     static inline void func(const ts x, const ts y, const ts z, const ts w) \
87     {                             \
88         GDWrite_##td(x); \
89         GDWrite_##td(y); \
90         GDWrite_##td(z); \
91         GDWrite_##td(w); \
92     }
93 
94 
95 //---------------------------
96 // Generate inline functions
97 //---------------------------
98 
99 //---- GDCmd[n][t] ----
100 __GXCDEF( GDCmd, 1, u8  )
101 __GXCDEF( GDCmd, 1, u16 )
102 __GXCDEF( GDCmd, 1, u32 )
103 
104 //---- GDParam[n][t] ----
105 __GXCDEF( GDParam, 1, u8  )
106 __GXCDEF( GDParam, 1, u16 )
107 __GXCDEF( GDParam, 1, u32 )
108 __GXCDEF( GDParam, 1, s8  )
109 __GXCDEF( GDParam, 1, s16 )
110 __GXCDEF( GDParam, 1, s32 )
111 __GXCDEF( GDParam, 1, f32 )
112 __GXCDEF( GDParam, 3, f32 )
113 __GXCDEF( GDParam, 4, f32 )
114 
115 //---- GDPosition[n][t] ----
116   // For GD_POS_XYZ
117 __GXCDEF( GDPosition, 3, f32 )
118 __GXCDEF( GDPosition, 3, u8  )
119 __GXCDEF( GDPosition, 3, s8  )
120 __GXCDEF( GDPosition, 3, u16 )
121 __GXCDEF( GDPosition, 3, s16 )
122   // For GD_POS_XY
123 __GXCDEF( GDPosition, 2, f32 )
124 __GXCDEF( GDPosition, 2, u8  )
125 __GXCDEF( GDPosition, 2, s8  )
126 __GXCDEF( GDPosition, 2, u16 )
127 __GXCDEF( GDPosition, 2, s16 )
128   // For Index
129 __GXCDEFX( GDPosition1x16, 1, u16 )
130 __GXCDEFX( GDPosition1x8,  1, u8  )
131 
132 //---- GDNormal[n][t] ----
133   // For GD_NRM or GD_NBT
134 __GXCDEF( GDNormal, 3, f32 )
135 __GXCDEF( GDNormal, 3, s16 )
136 __GXCDEF( GDNormal, 3, s8  )
137   // For Index
138 __GXCDEFX( GDNormal1x16, 1, u16 )
139 __GXCDEFX( GDNormal1x8,  1, u8  )
140 
141 //---- GDColor[n][t] ----
142   // For GD_CLR_RGBA8 or RGBX8
143 __GXCDEF( GDColor, 4, u8  )
144 __GXCDEF( GDColor, 1, u32 )
145   // For GD_CLR_RGBA6 or RGB8
146 __GXCDEF( GDColor, 3, u8  )
147   // For GD_CLR_RGBA4 or RGB565
148 __GXCDEF( GDColor, 1, u16 )
149   // For Index
150 __GXCDEFX( GDColor1x16, 1, u16 )
151 __GXCDEFX( GDColor1x8,  1, u8  )
152 
153 //---- GDTexCoord[n][t] ----
154   // For GD_TEX_ST
155 __GXCDEF( GDTexCoord, 2, f32 )
156 __GXCDEF( GDTexCoord, 2, s16 )
157 __GXCDEF( GDTexCoord, 2, u16 )
158 __GXCDEF( GDTexCoord, 2, s8  )
159 __GXCDEF( GDTexCoord, 2, u8  )
160   // For GD_TEX_S
161 __GXCDEF( GDTexCoord, 1, f32 )
162 __GXCDEF( GDTexCoord, 1, s16 )
163 __GXCDEF( GDTexCoord, 1, u16 )
164 __GXCDEF( GDTexCoord, 1, s8  )
165 __GXCDEF( GDTexCoord, 1, u8  )
166   // For Index
167 __GXCDEFX( GDTexCoord1x16, 1, u16 )
168 __GXCDEFX( GDTexCoord1x8,  1, u8  )
169 
170 //---- GDMatrixIndex* ----
171 // GDMatrixIndex1u8
172 __GXCDEF( GDMatrixIndex, 1, u8 )
173 #define GDMatrixIndex1x8    GDMatrixIndex1u8
174 
175 //------------------------
176 // Undefine all templates
177 //------------------------
178 #undef  __GXCDEF
179 #undef  __GXCDEFX
180 #undef  __GXCDEF1
181 #undef  __GXCDEF2
182 #undef  __GXCDEF3
183 #undef  __GXCDEF4
184 
185 /*---------------------------------------------------------------------------*/
186 // Packing macro for a several color format
187 #define	GDPackedRGB565(r,g,b)   \
188 	((u16)((((r)&0xf8)<<8)|(((g)&0xfc)<<3)|(((b)&0xf8)>>3)))
189 #define	GDPackedRGBA4(r,g,b,a)  \
190 	((u16)((((r)&0xf0)<<8)|(((g)&0xf0)<<4)|(((b)&0xf0)   )|(((a)&0xf0)>>4)))
191 #define	GDPackedRGB5A3(r,g,b,a) \
192 	((u16)((a)>=224 ? \
193 	((((r)&0xf8)<<7)|(((g)&0xf8)<<2)|(((b)&0xf8)>>3)|(1<<15)): \
194 	((((r)&0xf0)<<4)|(((g)&0xf0)   )|(((b)&0xf0)>>4)|(((a)&0xe0)<<7))))
195 
196 /*---------------------------------------------------------------------------*/
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif  // __GDVERT_H__
202