PowerBlocks SDK
 
Loading...
Searching...
No Matches
gx_xf.h
Go to the documentation of this file.
1
11
12// This header is not supposed to be included directly.
13// Instead include gx.h
14
15#include <stdint.h>
16
19#include "powerblocks/core/utils/math/matrix34.h"
20
21/* -------------------XF Matrix Control--------------------- */
22
40typedef enum {
41 GX_MTX_ID_0 = (0*3),
42 GX_MTX_ID_1 = (1*3),
43 GX_MTX_ID_2 = (2*3),
44 GX_MTX_ID_3 = (3*3),
45 GX_MTX_ID_4 = (4*3),
46 GX_MTX_ID_5 = (5*3),
47 GX_MTX_ID_6 = (6*3),
48 GX_MTX_ID_7 = (7*3),
49 GX_MTX_ID_8 = (8*3),
50 GX_MTX_ID_9 = (9*3),
51 GX_MTX_ID_10 = (10*3),
52 GX_MTX_ID_11 = (11*3),
53 GX_MTX_ID_12 = (12*3),
54 GX_MTX_ID_13 = (13*3),
55 GX_MTX_ID_14 = (14*3),
56 GX_MTX_ID_15 = (15*3),
57 GX_MTX_ID_16 = (16*3),
58 GX_MTX_ID_17 = (17*3),
59 GX_MTX_ID_18 = (18*3),
60 GX_MTX_ID_19 = (19*3),
61 GX_MTX_ID_20 = (20*3),
62
63 GX_MTX_ID_IDENTITY = GX_MTX_ID_20
65
81extern void gx_flash_viewport(float x, float y, float width, float height, float near, float far, bool jitter);
82
92extern void gx_flash_projection(const matrix4 mtx, bool is_perspective);
93
111extern void gx_flash_matrix(const matrix34 mtx, gx_mtx_id_t index, bool type);
112
126extern void gx_flash_nrm_matrix(const matrix3 mtx, gx_mtx_id_t index);
127
140extern void gx_set_current_psn_matrix(gx_mtx_id_t index);
141
142/* -------------------XF Color Control--------------------- */
143
144typedef enum { // These are just the XF register addresses for them
145 GX_COLOR_CHANNEL_COLOR0 = 0,
146 GX_COLOR_CHANNEL_COLOR1 = 1,
147 GX_COLOR_CHANNEL_ALPHA0 = 2,
148 GX_COLOR_CHANNEL_ALPHA1 = 3
149} gx_color_channel_t;
150
151typedef enum {
152 GX_LIGHT_BIT_NONE,
153 GX_LIGHT_BIT_0 = (1<<2),
154 GX_LIGHT_BIT_1 = (1<<3),
155 GX_LIGHT_BIT_2 = (1<<4),
156 GX_LIGHT_BIT_3 = (1<<5),
157 GX_LIGHT_BIT_4 = (1<<11),
158 GX_LIGHT_BIT_5 = (1<<12),
159 GX_LIGHT_BIT_6 = (1<<13),
160 GX_LIGHT_BIT_7 = (1<<14)
161} gx_light_bit_t;
162
163typedef enum {
164 // Bit 1 is just the attenuation enable
165 // Bit 0 is the select. We just turned the binary to number here.
166 GX_ATTENUATION_MODE_NONE,
167 GX_ATTENUATION_MODE_SPECULAR = 1,
168 GX_ATTENUATION_MODE_SPOTLIGHT = 3
169} gx_attenuation_mode_t;
170
171typedef enum {
172 GX_DIFFUSE_MODE_NONE,
173 GX_DIFFUSE_SIGNED,
174 GX_DIFFUSE_CLAMPED, // From [0, 1]
175} gx_diffuse_mode_t;
176
177typedef enum {
178 GX_XF_COLOR_AMBIENT_0 = 0x100A,
179 GX_XF_COLOR_AMBIENT_1 = 0x100B,
180 GX_XF_COLOR_MATERIAL_0 = 0x100C,
181 GX_XF_COLOR_MATERIAL_1 = 0x100D
182} gx_xf_color_t;
183
184typedef enum { // Instead of raw XF addresses, indexes, so it can be used in texcoord gens.
185 GX_LIGHT_ID_0,
186 GX_LIGHT_ID_1,
187 GX_LIGHT_ID_2,
188 GX_LIGHT_ID_3,
189 GX_LIGHT_ID_4,
190 GX_LIGHT_ID_5,
191 GX_LIGHT_ID_6,
192 GX_LIGHT_ID_7
193} gx_light_id_t;
194
195typedef struct {
196 uint32_t color; // RGBA
197
198 // Light attenuation!
199 // Described as a quadratic with
200 // Angle is the light direction, and the vertex to light. basically the dot product/cosine
201 // attn.x + attn.y * cos(angle) + attn.z * cos(angle)^2
202 vec3 cos_attenuation;
203
204 // Same quadratic idea, inverse this time
205 vec3 distance_attenuation;
206
207 vec3 position;
208
209 // These are negative by the way
210 // Times them by -1. Fun hardware
211 vec3 direction;
212} gx_light_t;
213
226extern void gx_set_color_channels(uint32_t count);
227
247extern void gx_configure_color_channel(gx_color_channel_t channel, gx_light_bit_t lights,
248 bool lighting, bool ambient_source, bool material_source,
249 gx_diffuse_mode_t diffuse, gx_attenuation_mode_t attenuation);
250
254extern void gx_flash_xf_color(gx_xf_color_t id, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
255
264extern void gx_flash_light(gx_light_id_t id, const gx_light_t* light);
265
266/* -------------------XF TexCoord Control--------------------- */
267
268typedef enum {
269 GX_TEXGEN_TYPE_REGULAR,
270 GX_TEXGEN_TYPE_EMBOSS,
271 GX_TEXGEN_TYPE_COLOR_0,
272 GX_TEXGEN_TYPE_COLOR_1
273} gx_texgen_type_t;
274
275typedef enum {
276 GX_TEXGEN_SOURCE_POSITION,
277 GX_TEXGEN_SOURCE_NORMAL,
278 GX_TEXGEN_SOURCE_COLORS,
279 GX_TEXGEN_SOURCE_BINORMAL_T,
280 GX_TEXGEN_SOURCE_BINORMAL_B,
281 GX_TEXGEN_SOURCE_TEX0,
282 GX_TEXGEN_SOURCE_TEX1,
283 GX_TEXGEN_SOURCE_TEX2,
284 GX_TEXGEN_SOURCE_TEX3,
285 GX_TEXGEN_SOURCE_TEX4,
286 GX_TEXGEN_SOURCE_TEX5,
287 GX_TEXGEN_SOURCE_TEX6,
288 GX_TEXGEN_SOURCE_TEX7
289} gx_texgen_source_t;
290
291typedef enum {
292 GX_TEXTURE_MAP_0,
293 GX_TEXTURE_MAP_1,
294 GX_TEXTURE_MAP_2,
295 GX_TEXTURE_MAP_3,
296 GX_TEXTURE_MAP_4,
297 GX_TEXTURE_MAP_5,
298 GX_TEXTURE_MAP_6,
299 GX_TEXTURE_MAP_7
300} gx_texture_map_t;
301
309extern void gx_set_texcoord_channels(uint32_t count);
310
329extern void gx_configure_texcoord_channel(gx_texture_map_t map, gx_texgen_source_t source, gx_texgen_type_t type, bool projection, bool three_component, gx_light_id_t embossing_light);
330
346extern void gx_configure_dual_texcoord(gx_texture_map_t map, gx_mtx_id_t index, bool normalize);
347
357extern void gx_flash_dual_texcoord_matrix(matrix34 mtx, gx_mtx_id_t index, bool type);
358
372void gx_set_current_texcoord_matrix(gx_texture_map_t map, gx_mtx_id_t index);
373
382void gx_flash_enable_dual_texcoord(bool enable);
void gx_configure_dual_texcoord(gx_texture_map_t map, gx_mtx_id_t index, bool normalize)
Configure dual texcoords.
Definition gx.c:1346
void gx_configure_color_channel(gx_color_channel_t channel, gx_light_bit_t lights, bool lighting, bool ambient_source, bool material_source, gx_diffuse_mode_t diffuse, gx_attenuation_mode_t attenuation)
Configures 1 of the 2/4 color channels.
Definition gx.c:1284
void gx_flash_dual_texcoord_matrix(matrix34 mtx, gx_mtx_id_t index, bool type)
Fashes a dual texcoord matrix in the XF matrix stack.
Definition gx.c:1351
void gx_flash_projection(const matrix4 mtx, bool is_perspective)
Flashes the projection matrix onto the XF settings.
Definition gx.c:1228
void gx_set_current_psn_matrix(gx_mtx_id_t index)
Sets the current pair of position and normal matrices.
Definition gx.c:1270
void gx_set_texcoord_channels(uint32_t count)
Set a texture coord count.
Definition gx.c:1332
void gx_flash_matrix(const matrix34 mtx, gx_mtx_id_t index, bool type)
Fashes a matrix to the XF Stack.
Definition gx.c:1239
void gx_flash_enable_dual_texcoord(bool enable)
Sets the Dual Texture Coord Enable/Disable Register.
Definition gx.c:1407
void gx_flash_xf_color(gx_xf_color_t id, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Sets a XF Color Value.
Definition gx.c:1305
void gx_configure_texcoord_channel(gx_texture_map_t map, gx_texgen_source_t source, gx_texgen_type_t type, bool projection, bool three_component, gx_light_id_t embossing_light)
Configures 1 of the 8 texcoord channels.
Definition gx.c:1337
void gx_set_color_channels(uint32_t count)
Sets a color channel count.
Definition gx.c:1279
void gx_flash_nrm_matrix(const matrix3 mtx, gx_mtx_id_t index)
Fashes a normal matrix into the XF matrix stack.
Definition gx.c:1257
void gx_flash_light(gx_light_id_t id, const gx_light_t *light)
Flash one of the lights.
Definition gx.c:1310
void gx_flash_viewport(float x, float y, float width, float height, float near, float far, bool jitter)
Flashes the viewport onto the XF settings.
Definition gx.c:1201
gx_mtx_id_t
Universal matrix ids.
Definition gx_xf.h:40
void gx_set_current_texcoord_matrix(gx_texture_map_t map, gx_mtx_id_t index)
Sets the current texcoord matrix.
Definition gx.c:1369
3x3 Matrices
3x4 Matrices
Definition gx_xf.h:195
Definition vec3.h:16