XF definitions and function of GX. More...
#include <stdint.h>#include "powerblocks/core/utils/math/matrix3.h"#include "powerblocks/core/utils/math/matrix4.h"#include "powerblocks/core/utils/math/matrix34.h"Go to the source code of this file.
Classes | |
| struct | gx_light_t |
Enumerations | |
| enum | gx_mtx_id_t { GX_MTX_ID_0 = (0*3) , GX_MTX_ID_1 = (1*3) , GX_MTX_ID_2 = (2*3) , GX_MTX_ID_3 = (3*3) , GX_MTX_ID_4 = (4*3) , GX_MTX_ID_5 = (5*3) , GX_MTX_ID_6 = (6*3) , GX_MTX_ID_7 = (7*3) , GX_MTX_ID_8 = (8*3) , GX_MTX_ID_9 = (9*3) , GX_MTX_ID_10 = (10*3) , GX_MTX_ID_11 = (11*3) , GX_MTX_ID_12 = (12*3) , GX_MTX_ID_13 = (13*3) , GX_MTX_ID_14 = (14*3) , GX_MTX_ID_15 = (15*3) , GX_MTX_ID_16 = (16*3) , GX_MTX_ID_17 = (17*3) , GX_MTX_ID_18 = (18*3) , GX_MTX_ID_19 = (19*3) , GX_MTX_ID_20 = (20*3) , GX_MTX_ID_IDENTITY = GX_MTX_ID_20 } |
| Universal matrix ids. More... | |
| enum | gx_color_channel_t { GX_COLOR_CHANNEL_COLOR0 = 0 , GX_COLOR_CHANNEL_COLOR1 = 1 , GX_COLOR_CHANNEL_ALPHA0 = 2 , GX_COLOR_CHANNEL_ALPHA1 = 3 } |
| enum | gx_light_bit_t { GX_LIGHT_BIT_NONE , GX_LIGHT_BIT_0 = (1<<2) , GX_LIGHT_BIT_1 = (1<<3) , GX_LIGHT_BIT_2 = (1<<4) , GX_LIGHT_BIT_3 = (1<<5) , GX_LIGHT_BIT_4 = (1<<11) , GX_LIGHT_BIT_5 = (1<<12) , GX_LIGHT_BIT_6 = (1<<13) , GX_LIGHT_BIT_7 = (1<<14) } |
| enum | gx_attenuation_mode_t { GX_ATTENUATION_MODE_NONE , GX_ATTENUATION_MODE_SPECULAR = 1 , GX_ATTENUATION_MODE_SPOTLIGHT = 3 } |
| enum | gx_diffuse_mode_t { GX_DIFFUSE_MODE_NONE , GX_DIFFUSE_SIGNED , GX_DIFFUSE_CLAMPED } |
| enum | gx_xf_color_t { GX_XF_COLOR_AMBIENT_0 = 0x100A , GX_XF_COLOR_AMBIENT_1 = 0x100B , GX_XF_COLOR_MATERIAL_0 = 0x100C , GX_XF_COLOR_MATERIAL_1 = 0x100D } |
| enum | gx_light_id_t { GX_LIGHT_ID_0 , GX_LIGHT_ID_1 , GX_LIGHT_ID_2 , GX_LIGHT_ID_3 , GX_LIGHT_ID_4 , GX_LIGHT_ID_5 , GX_LIGHT_ID_6 , GX_LIGHT_ID_7 } |
| enum | gx_texgen_type_t { GX_TEXGEN_TYPE_REGULAR , GX_TEXGEN_TYPE_EMBOSS , GX_TEXGEN_TYPE_COLOR_0 , GX_TEXGEN_TYPE_COLOR_1 } |
| enum | gx_texgen_source_t { GX_TEXGEN_SOURCE_POSITION , GX_TEXGEN_SOURCE_NORMAL , GX_TEXGEN_SOURCE_COLORS , GX_TEXGEN_SOURCE_BINORMAL_T , GX_TEXGEN_SOURCE_BINORMAL_B , GX_TEXGEN_SOURCE_TEX0 , GX_TEXGEN_SOURCE_TEX1 , GX_TEXGEN_SOURCE_TEX2 , GX_TEXGEN_SOURCE_TEX3 , GX_TEXGEN_SOURCE_TEX4 , GX_TEXGEN_SOURCE_TEX5 , GX_TEXGEN_SOURCE_TEX6 , GX_TEXGEN_SOURCE_TEX7 } |
| enum | gx_texture_map_t { GX_TEXTURE_MAP_0 , GX_TEXTURE_MAP_1 , GX_TEXTURE_MAP_2 , GX_TEXTURE_MAP_3 , GX_TEXTURE_MAP_4 , GX_TEXTURE_MAP_5 , GX_TEXTURE_MAP_6 , GX_TEXTURE_MAP_7 } |
Functions | |
| 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. | |
| void | gx_flash_projection (const matrix4 mtx, bool is_perspective) |
| Flashes the projection matrix onto the XF settings. | |
| void | gx_flash_matrix (const matrix34 mtx, gx_mtx_id_t index, bool type) |
| Fashes a matrix to the XF Stack. | |
| void | gx_flash_nrm_matrix (const matrix3 mtx, gx_mtx_id_t index) |
| Fashes a normal matrix into the XF matrix stack. | |
| void | gx_set_current_psn_matrix (gx_mtx_id_t index) |
| Sets the current pair of position and normal matrices. | |
| void | gx_set_color_channels (uint32_t count) |
| Sets a color channel count. | |
| 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. | |
| 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. | |
| void | gx_flash_light (gx_light_id_t id, const gx_light_t *light) |
| Flash one of the lights. | |
| void | gx_set_texcoord_channels (uint32_t count) |
| Set a texture coord count. | |
| 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. | |
| void | gx_configure_dual_texcoord (gx_texture_map_t map, gx_mtx_id_t index, bool normalize) |
| Configure dual texcoords. | |
| 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. | |
| void | gx_set_current_texcoord_matrix (gx_texture_map_t map, gx_mtx_id_t index) |
| Sets the current texcoord matrix. | |
| void | gx_flash_enable_dual_texcoord (bool enable) |
| Sets the Dual Texture Coord Enable/Disable Register. | |
XF definitions and function of GX.
XF definitions and function of GX.
| enum gx_mtx_id_t |
Universal matrix ids.
These are used for addressing geometry, normal, texcoord matrices and dual texcoord matrices.
Depending on what of these its for, some or all of these may be valid.
Geometry and texcoord share the same memory, and use GX_MTX_ID_0 through GX_MTX_ID_20. Where GX_MTX_ID_20 by default is loaded as an idiniticy matrix for them to use.
Normal matrices can only use GX_MTX_ID_0 through GX_MTX_ID_9.
Dual texcoords have their own stack and can use GX_MTX_ID_0, GX_MTX_ID_20.
|
extern |
Configures 1 of the 2/4 color channels.
There are 2 color channels, like in gx_set_color_channels Now each has settings for how its transformed for lighting.
Unlike gx_set_color_channels though this has its own 4 channels. 2 colors, 2 alphas.
Default config just passes the vertex colors with no modifications.
| channel | Color channel to use |
| lights | Enable lights, like GX_LIGHT_ENABLE_0 | GX_LIGHT_ENABLE_1 |
| lighting | Enable lighting in general, so you can have a dark scene with no lights if you wish |
| ambient_source | True = use vertex color, otherwise use XF register |
| material_source | True = use vertex color, otherwise use XF register. |
| diffuse | Diffuse Mode to use |
| attenuation | Attenuation Mode to use |
TODO: Why did you not use defines to control some of these XF parameters.
|
extern |
Configure dual texcoords.
These allow to transform texcoords after the main transformation. This means the main transformation can be used for. i.e. putting geometry into a texture format, then you can use this to scroll around that texture.
Its often that if your doing this, you may want to normalize the inputs as well before the first transformation.
| map | Texture map to configure |
| index | Matrix index to transform texcoord after transformation |
| normalize | Normalize the inputs before transforming |
|
extern |
Configures 1 of the 8 texcoord channels.
Sets up how a texture coordinate will be transformed from the XF.
The source contains what XF input is used for this texture coordinate. This data is processed according to type, where you can change how colors are processed for example.
You can only use sources GX_TEXGEN_SOURCE_TEX0 through GX_TEXGEN_SOURCE_TEX7 for embossing, since it calculates the embossing source to be the texgen source, but it can only use texcoords 0-7.
| map | Texture map to configure |
| gx_texgen_source_t | Sets where the data will be pulled from. |
| gx_texgen_type | Sets how inputs are processed. As eather normal values, emboss, or from color data |
| projection | If set 3x4 texture matrices are used instead. For 3D texcoords. |
| three_component | Is set, (X, Y, Z, 1.0) is passed, otherwise its just (X, Y, 1.0, 1.0) |
| embossing_light | Light used for embossing. |
|
extern |
Fashes a dual texcoord matrix in the XF matrix stack.
GX_MTX_ID_0 through GX_MTX_ID_20 is valid for this.
| mtx | Matrix to flash |
| index | Matrix index to flash into. |
| type | If type is true, the full 3x4 will be loaded, otherwise 2x4 will be loaded |
| void gx_flash_enable_dual_texcoord | ( | bool | enable | ) |
Sets the Dual Texture Coord Enable/Disable Register.
If disabled, as is by default, non will be transformed.
If enabled, all dual tex coords will be transformed.
|
extern |
Flash one of the lights.
Copys the light data structure to XF memory of one of the 1-8 lights
| id | ID of the light to use |
| light | Light data structure |
|
extern |
Fashes a matrix to the XF Stack.
The same matrix memory is shared for geometry matrices and texcoord transformation matrices. GX_MTX_ID_IDENTITY is automatically flashed with an identity matrices during initialization and is the default matrix in texcoord and geometry generations.
The IDs themselves address 3x4 matrices, but hardware does support using 2x4 matrices. In this case, you can fit more matrices. Since having both 2x4 and 3x4 matrices in the same memory space without an allocator gets a bit messy, I will leave it up to you to use that if needed.
| mtx | The matrix to load |
| index | The index of the matrix in the matrix stack. |
| type | If type is true, a full 3x4 matrices will be loaded, otherwise its just 2x4. |
|
extern |
Fashes a normal matrix into the XF matrix stack.
Normal matrices have their own separate stack.
Only the first 10 matrices, GX_MTX_ID_0 through GX_MTX_ID_9, exist in the normal matrix stack.
You then can set this with gx_set_current_psn_matrix or with matrix indices in vertex attributes.
| mtx | The matrix to load |
| index | The index of the matrix in the matrix stack. |
|
extern |
Flashes the projection matrix onto the XF settings.
Sets the projection matrix in the XF registers that is used when transforming vertices.
| mtx | 4x4 Projection Matrix |
| is_perspective | If the matrix is perspective, or orthographic. |
|
extern |
Flashes the viewport onto the XF settings.
Set the viewport in the XF registers. This is needed to scale geometry to the screen. It also handles scaling Z buffer.
| x | Top Left of the Screen Position |
| y | Top Left of the Screen Position |
| width | Width of the Screen |
| height | Height of the Screen |
| near | Closest Z values to not be culled |
| far | Farthest Z values to not be culled |
| jitter | Will shift up the X a bit. Can reduce blur/flickering in interlaced mode. This is usually true. |
|
extern |
Sets a color channel count.
The vertex descriptors contain how many colors are passed to the XF. This controls how many of those colors are passed to the BP/TEV from the XF.
These colors will be rasterized and interpolated.
Hardware supports 0-2 colors.
| count | Number of color channels to supply the BP/TEV |
|
extern |
Sets the current pair of position and normal matrices.
10 matrices can be set in the XF, set with functions like gx_flash_projection.
This will set the current one to use, if matrix indices are not enabled in the vertex descriptor. If they are, this will be overriden.
This value will be flushed on the next draw call.
Cleared to GX_MTX_ID_IDENTITY by gx_initialize()
| void gx_set_current_texcoord_matrix | ( | gx_texture_map_t | map, |
| gx_mtx_id_t | index ) |
Sets the current texcoord matrix.
This is the current matrix used to transform the texcoord generation input.
Set to GX_MTX_ID_IDENTITY by default.
Flushed in the next draw call
| map | Texture map to set |
| index | Matrix index to set it to |
|
extern |
Set a texture coord count.
Like gx_set_color_channels, set the number of texcoords that should be generated.
| count | Number of color channels to supply the BP/TEV |