PowerBlocks SDK
 
Loading...
Searching...
No Matches
gx.h File Reference

Manages graphics on the system. More...

#include <stdint.h>
#include <stdbool.h>
#include "framebuffer.h"
#include "video.h"
#include "FreeRTOS.h"
#include "task.h"
#include "gx_xf.h"
#include "gx_tev.h"
#include "gx_immediate.h"

Go to the source code of this file.

Classes

struct  gx_fifo_t
 Represents the a fifo for the Command Processor. More...
 
struct  gx_texture_t
 Cool little texture object. Really just a copy of the registers that will be set onto the GPU when the texture is loaded. More...
 

Macros

#define GX_WPAR_ADDRESS   0xCC008000
 
#define GX_WPAR_U8   (*(volatile uint8_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_U16   (*(volatile uint16_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_U32   (*(volatile uint32_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_S8   (*(volatile int8_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_S16   (*(volatile int16_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_S32   (*(volatile int32_t*)GX_WPAR_ADDRESS)
 
#define GX_WPAR_F32   (*(volatile float*)GX_WPAR_ADDRESS)
 
#define GX_FIFO_MINIMUM_SIZE   (64 * 1024)
 
#define GX_FIFO_WATERMARK   (16 * 1024)
 
#define GX_WPAR_OPCODE_LOAD_CP   0x08
 
#define GX_WPAR_OPCODE_LOAD_XF   0x10
 
#define GX_WPAR_OPCODE_LOAD_BP   0x61
 
#define GX_WPAR_OPCODE_PRIMITIVE(type, format)
 
#define GX_XF_MEMORY_POSTEX_MTX_0   0x0000
 
#define GX_XF_MEMORY_NORMAL_MTX_0   0x0400
 
#define GX_XF_MEMORY_DUALTEX_MTX_0   0x0500
 
#define GX_XF_MEMORY_LIGHT0   0x0600
 
#define GX_XF_REGISTER_VERTEX_STATS   0x1008
 
#define GX_XF_REGISTER_COLOR_COUNT   0x1009
 
#define GX_XF_REGISTER_COLOR_CONTROL   0x100E
 
#define GX_XF_REGISTER_DUALTEXTRANS   0x1012
 
#define GX_XF_REGISTER_MTXIDX_A   0x1018
 
#define GX_XF_REGISTER_MTXIDX_B   0x1019
 
#define GX_XF_REGISTER_VIEWPORT   0x101A
 
#define GX_XF_REGISTER_PROJECTION   0x1020
 
#define GX_XF_REGISTER_TEXCOORD_COUNT   0x103F
 
#define GX_XF_REGISTER_TEX0   0x1040
 
#define GX_XF_REGISTER_DUALTEX0   0x1050
 
#define GX_BP_REGISTERS_GENMODE   (0x00 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_POS_A   (0x01 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_POS_B   (0x02 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_POS_C   (0x03 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_POS_D   (0x04 << 24)
 
#define GX_BP_REGISTERS_SCISSOR_TL   (0x20 << 24)
 
#define GX_BP_REGISTERS_SCISSOR_BR   (0x21 << 24)
 
#define GX_BP_REGISTERS_SSIZE0   (0x30 << 24)
 
#define GX_BP_REGISTERS_TSIZE0   (0x31 << 24)
 
#define GX_BP_REGISTERS_Z_MODE   (0x40 << 24)
 
#define GX_BP_REGISTERS_CMODE_0   (0x41 << 24)
 
#define GX_BP_REGISTERS_CMODE_1   (0x42 << 24)
 
#define GX_BP_REGISTERS_PE_CONTROL   (0X43 << 24)
 
#define GX_BP_REGISTERS_PE_DONE   (0x45 << 24)
 
#define GX_BP_REGISTERS_EFB_SOURCE_TOP_LEFT   (0x49 << 24)
 
#define GX_BP_REGISTERS_EFB_SOURCE_WIDTH_HEIGHT   (0x4A << 24)
 
#define GX_BP_REGISTERS_XFB_TARGET_ADDRESS   (0x4B << 24)
 
#define GX_BP_REGISTERS_EFB_DESTINATION_WIDTH   (0x4D << 24)
 
#define GX_BP_REGISTERS_Y_SCALE   (0x4E << 24)
 
#define GX_BP_REGISTERS_PE_COPY_CLEAR_AR   (0x4F << 24)
 
#define GX_BP_REGISTERS_PE_COPY_CLEAR_GB   (0x50 << 24)
 
#define GX_BP_REGISTERS_PE_COPY_CLEAR_Z   (0x51 << 24)
 
#define GX_BP_REGISTERS_PE_COPY_EXECUTE   (0x52 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_COEFF_A   (0x53 << 24)
 
#define GX_BP_REGISTERS_COPY_FILTER_COEFF_B   (0x54 << 24)
 
#define GX_BP_REGISTERS_SCISSOR_OFFSET   (0x59 << 24)
 
#define GX_BP_REGISTERS_TX_SETMODE0_I0   (0x80 << 24)
 
#define GX_BP_REGISTERS_TX_SETMODE1_I0   (0x84 << 24)
 
#define GX_BP_REGISTERS_TX_SETIMAGE0_I0   (0x88 << 24)
 
#define GX_BP_REGISTERS_TX_SETIMAGE1_I0   (0x8C << 24)
 
#define GX_BP_REGISTERS_TX_SETIMAGE2_I0   (0x90 << 24)
 
#define GX_BP_REGISTERS_TX_SETIMAGE3_I0   (0x94 << 24)
 
#define GX_BP_REGISTERS_TX_SETTLUT_0   (0x98 << 24)
 
#define GX_BP_REGISTERS_TEV0_COLOR_ENV   (0xC0 << 24)
 
#define GX_BP_REGISTERS_TEV0_ALPHA_ENV   (0xC1 << 24)
 
#define GX_BP_REGISTERS_TEV_REGISTERL_0   (0xE0 << 24)
 
#define GX_BP_REGISTERS_TEV_REGISTERH_0   (0xE1 << 24)
 
#define GX_CP_REGISTERS_MTXIDX_A   0x30
 
#define GX_CP_REGISTERS_MTXIDX_B   0x40
 
#define GX_CP_REGISTER_VCD_LOW   0x50
 
#define GX_CP_REGISTER_VCD_HIGH   0x60
 
#define GX_CP_REGISTER_VAT_A   0x70
 
#define GX_CP_REGISTER_VAT_B   0x80
 
#define GX_CP_REGISTER_VAT_C   0x90
 
#define GX_WPAR_CP_LOAD(address, value)
 
#define GX_WPAR_XF_LOAD(address, words)
 
#define GX_WPAR_BP_LOAD(value)
 
#define gx_end()
 End drawing primatives.
 

Enumerations

enum  gx_vtxattr_data_t { GX_VTXATTR_DATA_DISABLED , GX_VTXATTR_DATA_DIRECT , GX_VTXATTR_DATA_INDEX8 , GX_VTXATTR_DATA_INDEX16 }
 
enum  gx_vtxdesc_t {
  GX_VTXDESC_POSNORM_INDEX , GX_VTXDESC_TEXCOORDMTX0 , GX_VTXDESC_TEXCOORDMTX1 , GX_VTXDESC_TEXCOORDMTX2 ,
  GX_VTXDESC_TEXCOORDMTX3 , GX_VTXDESC_TEXCOORDMTX4 , GX_VTXDESC_TEXCOORDMTX5 , GX_VTXDESC_TEXCOORDMTX6 ,
  GX_VTXDESC_TEXCOORDMTX7 , GX_VTXDESC_POSITION , GX_VTXDESC_NORMAL , GX_VTXDESC_NORMAL_NBT ,
  GX_VTXDESC_COLOR0 , GX_VTXDESC_COLOR1 , GX_VTXDESC_TEXCOORD0 , GX_VTXDESC_TEXCOORD1 ,
  GX_VTXDESC_TEXCOORD2 , GX_VTXDESC_TEXCOORD3 , GX_VTXDESC_TEXCOORD4 , GX_VTXDESC_TEXCOORD5 ,
  GX_VTXDESC_TEXCOORD6 , GX_VTXDESC_TEXCOORD7
}
 
enum  gx_vtxattr_component_t {
  GX_VTXATTR_POS_XY = 0 , GX_VTXATTR_POS_XYZ = 1 , GX_VTXATTR_RGB = 0 , GX_VTXATTR_RGBA = 1 ,
  GX_VTXATTR_NRM_XYZ = 0 , GX_VTXATTR_NRM_NBT = 1 , GX_VTXATTR_NRM_NBT3 = 3 , GX_VTXATTR_TEX_S = 0 ,
  GX_VTXATTR_TEX_ST = 1
}
 
enum  gx_vtxattr_component_format_t {
  GX_VTXATTR_U8 = 0 , GX_VTXATTR_S8 , GX_VTXATTR_U16 , GX_VTXATTR_S16 ,
  GX_VTXATTR_F32 , GX_VTXATTR_RGB565 = 0 , GX_VTXATTR_RGB8 , GX_VTXATTR_RGBX8 ,
  GX_VTXATTR_RGBA4 , GX_VTXATTR_RGBA6 , GX_VTXATTR_RGBA8
}
 
enum  gx_primitive_t {
  GX_LINES = 0xA8 , GX_LINESTRIP = 0xB0 , GX_POINTS = 0xB8 , GX_QUADS = 0x80 ,
  GX_TRIANGLE_FAN = 0xA0 , GX_TRIANGLES = 0x90 , GX_TRIANGLE_STRIP = 0x98
}
 
enum  gx_compare_t {
  GX_COMPARE_NEVER , GX_COMPARE_LESS , GX_COMPARE_EQUAL , GX_COMPARE_LESS_EQUAL ,
  GX_COMPARE_GREATER , GX_COMPARE_NOT_EQUAL , GX_COMPARE_GREATER_EQUAL , GX_COMPARE_ALWAYS
}
 
enum  gx_pixel_format_t {
  GX_PIXEL_FORMAT_RGB8_Z24 , GX_PIXEL_FORMAT_RGBA6_Z24 , GX_PIXEL_FORMAT_RGB565_Z16 , GX_PIXEL_FORMAT_Z24 ,
  GX_PIXEL_FORMAT_Y8 , GX_PIXEL_FORMAT_U8 , GX_PIXEL_FORMAT_V8 , GX_PIXEL_FORMAT_YUV420
}
 
enum  gx_z_format_t { GX_Z_FORMAT_LINEAR , GX_Z_FORMAT_NEAR , GX_Z_FORMAT_MID , GX_Z_FORMAT_FAR }
 
enum  gx_clamp_mode_t { GX_CLAMP_MODE_NONE , GX_CLAMP_MODE_TOP , GX_CLAMP_MODE_BOTTOM , GX_CLAMP_MODE_TOP_BOTTOM }
 
enum  gx_gamma_t { GX_GAMMA_1_0 , GX_GAMMA_1_7 , GX_GAMMA_2_2 }
 
enum  gx_line_mode_t { GX_LINE_MODE_PROGRESSIVE , GX_LINE_MODE_EVEN = 2 , GX_LINE_MODE_ODD }
 
enum  gx_texture_id_t {
  GX_TEXTURE_ID_0 , GX_TEXTURE_ID_1 , GX_TEXTURE_ID_2 , GX_TEXTURE_ID_3 ,
  GX_TEXTURE_ID_4 , GX_TEXTURE_ID_5 , GX_TEXTURE_ID_6 , GX_TEXTURE_ID_7
}
 
enum  gx_texture_format_t {
  GX_TEXTURE_FORMAT_I4 , GX_TEXTURE_FORMAT_I8 , GX_TEXTURE_FORMAT_IA4 , GX_TEXTURE_FORMAT_IA8 ,
  GX_TEXTURE_FORMAT_RGB565 , GX_TEXTURE_FORMAT_RGB5A3 , GX_TEXTURE_FORMAT_RGBA8 , GX_TEXTURE_FORMAT_C4 = 8 ,
  GX_TEXTURE_FORMAT_C8 , GX_TEXTURE_FORMAT_C14X2 , GX_TEXTURE_FORMAT_CMP = 14
}
 
enum  gx_texture_wrap_t { GX_WRAP_CLAMP , GX_WRAP_REPEAT , GX_WRAP_MIRROR }
 
enum  gx_texture_min_filter {
  GX_TEXTURE_MIN_FILTER_NEAR , GX_TEXTURE_MIN_FILTER_NEAR_MIP , GX_TEXTURE_MIN_FILTER_NEAR_MIP_LINEAR , GX_TEXTURE_MIN_FILTER_LINEAR = 4 ,
  GX_TEXTURE_MIN_FILTER_LINEAR_MIP_NEAR , GX_TEXTURE_MIN_FILTER_LINEAR_MIP_LINEAR
}
 

Functions

void gx_initialize (const gx_fifo_t *fifo, const video_profile_t *video_profile)
 Initializes the graphics.
 
void gx_initialize_state ()
 Initializes the graphics state.
 
void gx_initialize_video (const video_profile_t *video_profile)
 Initializes all the video settings from a video profile.
 
void gx_fifo_initialize (gx_fifo_t *fifo, void *fifo_buffer, uint32_t fifo_buffer_size)
 Creates the fifo data structure.
 
void gx_fifo_set (const gx_fifo_t *fifo)
 Sets the current FIFO.
 
void gx_fifo_get (gx_fifo_t *fifo)
 Gets the current FIFO.
 
void gx_flush ()
 Flushes all commands to the command processor.
 
uint32_t gx_efb_peak (uint32_t x, uint32_t y)
 Grabs a pixel from the embedded frame buffer.
 
void gx_vtxdesc_clear ()
 Clears out all vertex descriptions.
 
void gx_vtxdesc_set (gx_vtxdesc_t desc, gx_vtxattr_data_t type)
 Sets a vertex description.
 
void gx_vtxfmtattr_clear (uint8_t attribute_index)
 Clears out a vertex attribute format.
 
void gx_vtxfmtattr_set (uint8_t attribute_index, gx_vtxdesc_t attribute, gx_vtxattr_component_t component, gx_vtxattr_component_format_t fmt, uint8_t fraction)
 Sets the format of a vertex attribute.
 
void gx_begin (gx_primitive_t primitive, uint8_t attribute, uint16_t count)
 Begin drawing primatives.
 
void gx_draw_done ()
 Call to send end current drawing session. Then wait.
 
void gx_set_render_thread (TaskHandle_t task)
 Sets the current render thread for suspension.
 
void gx_set_clear_color (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 Sets the background color when copying framebuffers.
 
void gx_set_clear_z (uint32_t z)
 Sets the z value the frame buffer is cleared with.
 
void gx_set_copy_y_scale (float y_scale)
 Sets the scale of the EFB to the XFB's Y.
 
void gx_set_scissor_rectangle (uint32_t x, uint32_t y, uint32_t width, uint32_t height)
 Sets the scissor rectangle.
 
void gx_set_scissor_offset (int32_t x, int32_t y)
 Offsets the scissor rectangle.
 
void gx_set_copy_window (uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t xfb_width)
 Sets the window to of the EFB into the XFB.
 
void gx_set_clamp_mode (gx_clamp_mode_t mode)
 Set the clamp mode when copying from EFB to XFB.
 
void gx_set_gamma (gx_gamma_t gamma)
 Sets the gamma value when copying from EFB to XFB.
 
void gx_set_line_mode (gx_line_mode_t line_mode)
 Sets the what lines are copied from EFB to XFB.
 
void gx_set_copy_filter (const uint8_t pattern[12][2], const uint8_t filter[7])
 Sets the interpolation filters used when copying the frame buffer into external frame buffers of differing resolutions.
 
void gx_set_z_mode (bool enable_compare, gx_compare_t compare, bool enable_update)
 Determins how Z values will be treated.
 
void gx_set_color_update (bool update_color, bool update_alpha)
 Enables updating the color when rendering into the EFB.
 
void gx_enable_z_precheck (bool enable)
 Enables / Disables checking Z before or after texturing.
 
void gx_set_pixel_format (gx_pixel_format_t pixels_format, gx_z_format_t z_format)
 Sets the format of pixels in the EFB.
 
void gx_copy_framebuffer (framebuffer_t *framebuffer, bool clear)
 Copys the internal framebuffer to the external frame buffer.
 
void gx_initialize_texture (gx_texture_t *texture, const void *data, gx_texture_format_t format, int width, int height, gx_texture_wrap_t s_wrap, gx_texture_wrap_t t_wrap, bool mipmap)
 Initializes a texture object for use.
 
void gx_flash_texture (gx_texture_map_t map, const gx_texture_t *texture)
 Flashes a texture configuration onto the BP.
 

Detailed Description

Manages graphics on the system.

Manages graphics on the system. Provides a interface to create and send commands to hardware, and configure the hardware for rendering.

Author
Samuel Fitzsimons (rainbain)
Date
2025 @license MIT (see LICENSE file)

Macro Definition Documentation

◆ gx_end

#define gx_end ( )

End drawing primatives.

This does nothing, its what you see in things like OpenGL so its included for similarity to such implementations. Also means it can be expanded if it turns out to be needed at some point.

◆ GX_WPAR_BP_LOAD

#define GX_WPAR_BP_LOAD ( value)
Value:
GX_WPAR_U8 = GX_WPAR_OPCODE_LOAD_BP; /* Load BP Command */ \
GX_WPAR_U32 = value; /* Combined 8 bit address and 24 bit value. */

◆ GX_WPAR_CP_LOAD

#define GX_WPAR_CP_LOAD ( address,
value )
Value:
GX_WPAR_U8 = GX_WPAR_OPCODE_LOAD_CP; /* Load CP Command */ \
GX_WPAR_U8 = address; /* Register Address */ \
GX_WPAR_U32 = value; /* Register Value */

◆ GX_WPAR_OPCODE_PRIMITIVE

#define GX_WPAR_OPCODE_PRIMITIVE ( type,
format )
Value:
(((uint8_t)type) | format)

◆ GX_WPAR_XF_LOAD

#define GX_WPAR_XF_LOAD ( address,
words )
Value:
GX_WPAR_U8 = GX_WPAR_OPCODE_LOAD_XF; /* Load XF Command */ \
GX_WPAR_U16 = (words) - 1; /* Load N-1 32 bit values */ \
GX_WPAR_U16 = address; /* Register Address */

Function Documentation

◆ gx_begin()

void gx_begin ( gx_primitive_t primitive,
uint8_t attribute,
uint16_t count )
extern

Begin drawing primatives.

Signals to the GPU to expect primitive data in coming messages. Also flushes GPU state changes.

Parameters
primitiveType of 3D primitive to draw.
attributeVertex attribute to use, values 0-7.
countVertex count. Up to 65535

◆ gx_copy_framebuffer()

void gx_copy_framebuffer ( framebuffer_t * framebuffer,
bool clear )
extern

Copys the internal framebuffer to the external frame buffer.

Copys the internal framebuffer to the external frame buffer. This is usually called during vblank to copy the frame buffer to display the next frame. vsync avoiding the need for double buffering.

Parameters
framebufferPointer to frame buffer. Needs to be 32 byte aligned.
clearClear the internal frame buffer during the copy.

◆ gx_draw_done()

void gx_draw_done ( )
extern

Call to send end current drawing session. Then wait.

This will signal to the BP that drawing is done, flush it, then sleep the current thread until its done

◆ gx_efb_peak()

uint32_t gx_efb_peak ( uint32_t x,
uint32_t y )
extern

Grabs a pixel from the embedded frame buffer.

Grabs a pixel from the embedded frame buffer. This is useful for debugging.

I don't recommend using it too much, the emulators do not like this. And it usually needs to be enabled for it to work in emulator.

◆ gx_enable_z_precheck()

void gx_enable_z_precheck ( bool enable)
extern

Enables / Disables checking Z before or after texturing.

Used to turn off early checking of Z before texturing. Checking Z before texturing allows you to quickly discard the fragment and save bandwidth.

But if the TEV stages or whatever discard the fragment, the Z buffer, during the compare, will be falsy updated when the fragment is discard.

So if your scene contains these. You will need to disable this. Its on by default.

Parameters
enableIf true, Z values are checked before texturing.

◆ gx_fifo_get()

void gx_fifo_get ( gx_fifo_t * fifo)
extern

Gets the current FIFO.

Gets the current fifo from hardware. Useful to check up on the CP.

Parameters
fifoWrites to fifo data into this.

◆ gx_fifo_initialize()

void gx_fifo_initialize ( gx_fifo_t * fifo,
void * fifo_buffer,
uint32_t fifo_buffer_size )
extern

Creates the fifo data structure.

Creates an empty vertex descriptor.

Creates a simple fifo data structure to set in the CP.

Parameters
fifoThe fifo to setup
fifo_bufferBuffer to put data into. 32 byte aligned
fifo_buffer_sizeSize of the buffer. 32 byte aligned

Creates the fifo data structure.

Creates a simple fifo data structure to set in the CP.

Parameters
fifoThe fifo to setup
fifo_bufferBuffer to put data into. 32 byte aligned
fifo_buffer_sizeSize of the buffer. 32 byte aligned

◆ gx_fifo_set()

void gx_fifo_set ( const gx_fifo_t * fifo)
extern

Sets the current FIFO.

Sets the current FIFO the CP will read from. CP is hopefully disabled when you do this.

gx_initialize calls this

Parameters
fifoThe fifo to set

◆ gx_flash_texture()

void gx_flash_texture ( gx_texture_map_t map,
const gx_texture_t * texture )
extern

Flashes a texture configuration onto the BP.

Sets up a texture for drawing by configuring the registers.

Its data wont be loaded into memory at this point, just that future draws with it will begin loading this new data.

Parameters
mapThe texture channel to load into. 1-8
textureThe texture register data.

◆ gx_flush()

void gx_flush ( )
extern

Flushes all commands to the command processor.

This inserts 32 NOP commands into the write gather pipeline to make sure that any commands at the end of the FIFO or display list get sent, since it only reads them in 32 byte burst.

This does not wait for command completion, it simply confirms commands before it will not be lost.

◆ gx_initialize()

void gx_initialize ( const gx_fifo_t * fifo,
const video_profile_t * video_profile )
extern

Initializes the graphics.

Puts the system graphics into a default state ready for rendering.

Takes a 32 byte aligned FIFO to hold commands. Hardware automatically fills it and cycles back through it, but write commands too fast and its possible to overflow it.

Parameters
fifoFifo to use.
video_profileVideo profile to use.

◆ gx_initialize_state()

void gx_initialize_state ( )
extern

Initializes the graphics state.

This function, called by gx_initialize, configures the hardware into GX's default state. That includes all the TEV stages and stuff like that.

It does not force the pipeline into a known state if somethings gone horribly wrong. Its just a bunch of calls to make the hardware into a pretty state.

This does not initialize some of the video settings. Use initialize video for that.

◆ gx_initialize_texture()

void gx_initialize_texture ( gx_texture_t * texture,
const void * data,
gx_texture_format_t format,
int width,
int height,
gx_texture_wrap_t s_wrap,
gx_texture_wrap_t t_wrap,
bool mipmap )
extern

Initializes a texture object for use.

Initializes a texture object to be loaded whenever needed. This does not actually allocate or contain the image data. Make sure to keep that safe. No, it just holds the state of the registers needed in order to draw that texture.

Parameters
textureThe texture object to setup
dataImage data of the format
formatTexture Format
widthWidth of the texture
heightHeight of the texture
s_wrapS Wrap (X values)
t_wrapT Wrap (Y values)
mipmapEnabling Mipmapping

◆ gx_initialize_video()

void gx_initialize_video ( const video_profile_t * video_profile)
extern

Initializes all the video settings from a video profile.

This function, usually following gx_initialize_state, can take a video profile and configure all the EFB and XFB copy registers to match your video profile.

◆ gx_set_clamp_mode()

void gx_set_clamp_mode ( gx_clamp_mode_t mode)
extern

Set the clamp mode when copying from EFB to XFB.

Defaults to clamping the top and bottom of the framebuffer.

Parameters
mode

◆ gx_set_clear_color()

void gx_set_clear_color ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a )
extern

Sets the background color when copying framebuffers.

As the framebuffer is copied, it clears the EFB back with these colors and Z value.

Parameters
rRed Channel
gGreen Channel
bBlue Channel
aAlpha Channel

◆ gx_set_clear_z()

void gx_set_clear_z ( uint32_t z)
extern

Sets the z value the frame buffer is cleared with.

As the frame buffer gets copied, it is cleared with this.

Parameters
zZ value, usually the max of 0xFFFFFF (24 bits)

◆ gx_set_color_update()

void gx_set_color_update ( bool update_color,
bool update_alpha )
extern

Enables updating the color when rendering into the EFB.

Parameters
update_colorUpdate the color values
update_alphaUpdate the alpha values

◆ gx_set_copy_filter()

void gx_set_copy_filter ( const uint8_t pattern[12][2],
const uint8_t filter[7] )
extern

Sets the interpolation filters used when copying the frame buffer into external frame buffers of differing resolutions.

This is a grid of values that determines how pixels are sampled when copying frame buffer.

For normal video modes you dont need to touch this.

For the X,Y pattern, Each one is between 0-12. The middle of the pixel is 6 (ish). These are for 3x MSAA generation.

filter is the array of ceoffenents between 0 and 63. Thats a Q0:6 fixed point format. And they should sum to 1 to keep normal brightness

The first 2 values are the top row. Then the next 3 are the middle row Last 2 are the bottom row.

Standard deflikering pattern is 0.25, 0.5, 0.25.

Parameters
patternPixel position for the filter.
filterCeoffenents for the filter.

◆ gx_set_copy_window()

void gx_set_copy_window ( uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
uint32_t xfb_width )
extern

Sets the window to of the EFB into the XFB.

Sets the window, or region, of the EFB to copy from.

Parameters
xBegining / Left of the EFB Window
yBegining / Top of the EFB Window
widthWidth of the window EFB
heightHeight of the Window EGB
xfb_widthWidth of the XFB

◆ gx_set_copy_y_scale()

void gx_set_copy_y_scale ( float y_scale)
extern

Sets the scale of the EFB to the XFB's Y.

Scales the image on the y axis to the size of the XFB

Parameters
scaleUsually xfb height / efb height

◆ gx_set_gamma()

void gx_set_gamma ( gx_gamma_t gamma)
extern

Sets the gamma value when copying from EFB to XFB.

Defaults to 1.0

Parameters
gammaThe gamma value from the enum.

◆ gx_set_line_mode()

void gx_set_line_mode ( gx_line_mode_t line_mode)
extern

Sets the what lines are copied from EFB to XFB.

Used to determine if all lines, or if even and odd lines are copied from EFB to XFB.

It defaults to progressive, aka, all lines.

◆ gx_set_pixel_format()

void gx_set_pixel_format ( gx_pixel_format_t pixels_format,
gx_z_format_t z_format )
extern

Sets the format of pixels in the EFB.

Sets the format of the pixels in the EFB.

Also lets you control z compression and such.

I will need to comment more on the effects of antialiasing since some modes use it, some dont.

◆ gx_set_render_thread()

void gx_set_render_thread ( TaskHandle_t task)
extern

Sets the current render thread for suspension.

When the GX FIFO is too full, it will suspend the graphics thread and resume it once it clears out a bit.

gx_initialize sets this to the current thread. If you plan to call GX functions outside the thread to called gx_initialize. You may want to set it here.

You can also set it to null and bypass this functionality.

Parameters
taskHandle to the task.

◆ gx_set_scissor_offset()

void gx_set_scissor_offset ( int32_t x,
int32_t y )
extern

Offsets the scissor rectangle.

Allows the scissor rectangle to be moved around the screen.

Values range from -342 to 382 and are even.

Parameters
xX offset of the window
yY offset of the window.

◆ gx_set_scissor_rectangle()

void gx_set_scissor_rectangle ( uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height )
extern

Sets the scissor rectangle.

Defines the rectangle things will be culled in.

Should be set to the viewport size by default.

Values range from 0 to 2047 gx_set_scissor_offset can be used to further expand this.

Parameters
xBegining / Left of the Window
yBegining / Top of the Window
widthWidth of thw window
heightHeight of the Window

◆ gx_set_z_mode()

void gx_set_z_mode ( bool enable_compare,
gx_compare_t compare,
bool enable_update )
extern

Determins how Z values will be treated.

Parameters
enable_compareCompare Z values? Or just pass all values
compareFunction to compare them with
enable_updateUpdate Z values of pixels? Or keep the previous.

◆ gx_vtxdesc_clear()

void gx_vtxdesc_clear ( )
extern

Clears out all vertex descriptions.

Turns off all vertex description parts in the VCD.

Enable them with gx_vtxdesc_set.

Guarantees it will be flushed to a valid state on the next draw call.

Called by gx_initialize()

◆ gx_vtxdesc_set()

void gx_vtxdesc_set ( gx_vtxdesc_t desc,
gx_vtxattr_data_t type )
extern

Sets a vertex description.

Sets the source of vertex data the attributes will use.

Note, only positions, normals, colors, and texture coords support indexed types, the remaining will only be enabled or disabled.

There can only be 1 vertex description, but 8 vertex attributes.

Requires a vertex data cache flushed before use of new format.

Parameters
descVertex description to enable.
typeType of vertex data for it.

◆ gx_vtxfmtattr_clear()

void gx_vtxfmtattr_clear ( uint8_t attribute_index)
extern

Clears out a vertex attribute format.

Clears out a vertex attribute format.

Set with gx_vtxfmtattr_set.

Called by gx_initialize()

Guarantees it will be flushed to a valid state on the next draw call.

Parameters
attribute_indexThe vertex attribute table to use, 0-7.

◆ gx_vtxfmtattr_set()

void gx_vtxfmtattr_set ( uint8_t attribute_index,
gx_vtxdesc_t attribute,
gx_vtxattr_component_t component,
gx_vtxattr_component_format_t fmt,
uint8_t fraction )
extern

Sets the format of a vertex attribute.

Sets the data format that vertex attributes are.

This will get updated in the VAT table of the GPU.

Parameters
attributeThe vertex attribute table to use, 0-7. Can switch between groups of vertex formats.
componentThe component, like is it XY, or XYZ. RGB or RGBA
fmtFormat of the component, Is it RGBA8888, or like, U16 position data, or float
fractionNumber of fractional bits in fixed point values. That is, inititer formats like S16, will be divided by 2^fraction. 0-31