libdragon
|
Interface to the hardware sprite/triangle rasterizer (RDP). More...
Files | |
file | rdp.c |
(Deprecated) Old RDP library | |
file | rdp.h |
RDP: Hardware Display Interface. | |
Data Structures | |
struct | sprite_cache |
Cached sprite structure. More... | |
Macros | |
#define | DP_START ((volatile uint32_t*)0xA4100000) |
DP start register. | |
#define | DP_END ((volatile uint32_t*)0xA4100004) |
DP end register. | |
#define | DP_CURRENT ((volatile uint32_t*)0xA4100008) |
DP current register. | |
#define | DP_STATUS ((volatile uint32_t*)0xA410000C) |
DP status register. | |
#define | DP_CLOCK ((volatile uint32_t*)0xA4100010) |
DP clock counter. | |
#define | DP_BUSY ((volatile uint32_t*)0xA4100014) |
DP command buffer busy. | |
#define | DP_PIPE_BUSY ((volatile uint32_t*)0xA4100018) |
DP pipe busy. | |
#define | DP_TMEM_BUSY ((volatile uint32_t*)0xA410001C) |
DP tmem busy. | |
#define | DP_STATUS_DMEM_DMA (1 << 0) |
DP is using DMEM DMA. | |
#define | DP_STATUS_FREEZE (1 << 1) |
DP is frozen. | |
#define | DP_STATUS_FLUSH (1 << 2) |
DP is flushed. | |
#define | DP_STATUS_GCLK_ALIVE (1 << 3) |
DP GCLK is alive. | |
#define | DP_STATUS_TMEM_BUSY (1 << 4) |
DP TMEM is busy. | |
#define | DP_STATUS_PIPE_BUSY (1 << 5) |
DP pipeline is busy. | |
#define | DP_STATUS_BUSY (1 << 6) |
DP command unit is busy. | |
#define | DP_STATUS_BUFFER_READY (1 << 7) |
DP command buffer is ready. | |
#define | DP_STATUS_DMA_BUSY (1 << 8) |
DP DMA is busy. | |
#define | DP_STATUS_END_VALID (1 << 9) |
DP command end register is valid. | |
#define | DP_STATUS_START_VALID (1 << 10) |
DP command start register is valid. | |
#define | DP_WSTATUS_RESET_XBUS_DMEM_DMA (1<<0) |
DP_STATUS write mask: clear DP_STATUS_DMEM_DMA bit. | |
#define | DP_WSTATUS_SET_XBUS_DMEM_DMA (1<<1) |
DP_STATUS write mask: set DP_STATUS_DMEM_DMA bit. | |
#define | DP_WSTATUS_RESET_FREEZE (1<<2) |
DP_STATUS write mask: clear DP_STATUS_FREEZE bit. | |
#define | DP_WSTATUS_SET_FREEZE (1<<3) |
DP_STATUS write mask: set DP_STATUS_FREEZE bit. | |
#define | DP_WSTATUS_RESET_FLUSH (1<<4) |
DP_STATUS write mask: clear DP_STATUS_FLUSH bit. | |
#define | DP_WSTATUS_SET_FLUSH (1<<5) |
DP_STATUS write mask: set DP_STATUS_FLUSH bit. | |
#define | DP_WSTATUS_RESET_TMEM_COUNTER (1<<6) |
DP_STATUS write mask: clear TMEM counter. | |
#define | DP_WSTATUS_RESET_PIPE_COUNTER (1<<7) |
DP_STATUS write mask: clear PIPE counter. | |
#define | DP_WSTATUS_RESET_CMD_COUNTER (1<<8) |
DP_STATUS write mask: clear CMD counter. | |
#define | DP_WSTATUS_RESET_CLOCK_COUNTER (1<<9) |
DP_STATUS write mask: clear CLOCK counter. | |
Enumerations | |
enum | mirror_t { MIRROR_DISABLED , MIRROR_X , MIRROR_Y , MIRROR_XY } |
Mirror settings for textures. More... | |
enum | flush_t { FLUSH_STRATEGY_NONE , FLUSH_STRATEGY_AUTOMATIC } |
Caching strategy for loaded textures. More... | |
Functions | |
uint32_t | rdp_load_texture (uint32_t texslot, uint32_t texloc, mirror_t mirror, sprite_t *sprite) |
Load a sprite into RDP TMEM. | |
uint32_t | rdp_load_texture_stride (uint32_t texslot, uint32_t texloc, mirror_t mirror, sprite_t *sprite, int offset) |
Load part of a sprite into RDP TMEM. | |
void | rdp_draw_textured_rectangle_scaled (uint32_t texslot, int tx, int ty, int bx, int by, double x_scale, double y_scale, mirror_t mirror) |
Draw a textured rectangle with a scaled texture. | |
void | rdp_draw_textured_rectangle (uint32_t texslot, int tx, int ty, int bx, int by, mirror_t mirror) |
Draw a textured rectangle. | |
void | rdp_draw_sprite (uint32_t texslot, int x, int y, mirror_t mirror) |
Draw a texture to the screen as a sprite. | |
void | rdp_draw_sprite_scaled (uint32_t texslot, int x, int y, double x_scale, double y_scale, mirror_t mirror) |
Draw a texture to the screen as a scaled sprite. | |
void | rdp_set_blend_color (uint32_t color) |
Set the blend draw color for subsequent filled primitive operations. | |
void | rdp_draw_filled_triangle (float x1, float y1, float x2, float y2, float x3, float y3) |
Draw a filled triangle. | |
void | rdp_set_texture_flush (flush_t flush) |
Set the flush strategy for texture loads. | |
Interface to the hardware sprite/triangle rasterizer (RDP).
This module contains an old API to draw using the RDP. The API was not extensible enough and in general did not provide a good enough foundation for RDP programming. So it has been deprecated in favor of the new RDPQ API, which is much more flexible.
All RDP functions are now implemented as wrappers of the RDPQ API. They continue to work just like before, but there will be no further work on them. Also, most of them are explicitly marked as deprecated, and will generate a warning at compile time. The warning suggests the alternative RDPQ API to use instead. In most cases, the change should be straightforward.
Functions not explicitly marked as deprecated do not have a direct equivalent in RDPQ API yet.
struct sprite_cache |
Cached sprite structure.
enum mirror_t |
enum flush_t |
Load a sprite into RDP TMEM.
[in] | texslot | The RDP texture slot to load this sprite into (0-7) |
[in] | texloc | The RDP TMEM offset to place the texture at |
[in] | mirror | Whether the sprite should be mirrored when displaying past boundaries |
[in] | sprite | Pointer to sprite structure to load the texture from |
uint32_t rdp_load_texture_stride | ( | uint32_t | texslot, |
uint32_t | texloc, | ||
mirror_t | mirror, | ||
sprite_t * | sprite, | ||
int | offset | ||
) |
Load part of a sprite into RDP TMEM.
Given a sprite with vertical and horizontal slices defined, this function will load the slice specified in offset into texture memory. This is usefl for treating a large sprite as a tilemap.
Given a sprite with 3 horizontal slices and two vertical slices, the offsets are as follows:
*---*---*---* | 0 | 1 | 2 | *---*---*---* | 3 | 4 | 5 | *---*---*---*
[in] | texslot | The RDP texture slot to load this sprite into (0-7) |
[in] | texloc | The RDP TMEM offset to place the texture at |
[in] | mirror | Whether the sprite should be mirrored when displaying past boundaries |
[in] | sprite | Pointer to sprite structure to load the texture from |
[in] | offset | Offset of the particular slice to load into RDP TMEM. |
void rdp_draw_textured_rectangle_scaled | ( | uint32_t | texslot, |
int | tx, | ||
int | ty, | ||
int | bx, | ||
int | by, | ||
double | x_scale, | ||
double | y_scale, | ||
mirror_t | mirror | ||
) |
Draw a textured rectangle with a scaled texture.
Given an already loaded texture, this function will draw a rectangle textured with the loaded texture at a scale other than 1. This allows rectangles to be drawn with stretched or squashed textures. If the rectangle is larger than the texture after scaling, it will be tiled or mirrored based on the mirror setting given in the load texture command.
Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.
[in] | texslot | The texture slot that the texture was previously loaded into (0-7) |
[in] | tx | The pixel X location of the top left of the rectangle |
[in] | ty | The pixel Y location of the top left of the rectangle |
[in] | bx | The pixel X location of the bottom right of the rectangle |
[in] | by | The pixel Y location of the bottom right of the rectangle |
[in] | x_scale | Horizontal scaling factor |
[in] | y_scale | Vertical scaling factor |
[in] | mirror | Whether the texture should be mirrored |
void rdp_draw_textured_rectangle | ( | uint32_t | texslot, |
int | tx, | ||
int | ty, | ||
int | bx, | ||
int | by, | ||
mirror_t | mirror | ||
) |
Draw a textured rectangle.
Given an already loaded texture, this function will draw a rectangle textured with the loaded texture. If the rectangle is larger than the texture, it will be tiled or mirrored based on the* mirror setting given in the load texture command.
Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.
[in] | texslot | The texture slot that the texture was previously loaded into (0-7) |
[in] | tx | The pixel X location of the top left of the rectangle |
[in] | ty | The pixel Y location of the top left of the rectangle |
[in] | bx | The pixel X location of the bottom right of the rectangle |
[in] | by | The pixel Y location of the bottom right of the rectangle |
[in] | mirror | Whether the texture should be mirrored |
void rdp_draw_sprite | ( | uint32_t | texslot, |
int | x, | ||
int | y, | ||
mirror_t | mirror | ||
) |
Draw a texture to the screen as a sprite.
Given an already loaded texture, this function will draw a rectangle textured with the loaded texture.
Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.
[in] | texslot | The texture slot that the texture was previously loaded into (0-7) |
[in] | x | The pixel X location of the top left of the sprite |
[in] | y | The pixel Y location of the top left of the sprite |
[in] | mirror | Whether the texture should be mirrored |
void rdp_draw_sprite_scaled | ( | uint32_t | texslot, |
int | x, | ||
int | y, | ||
double | x_scale, | ||
double | y_scale, | ||
mirror_t | mirror | ||
) |
Draw a texture to the screen as a scaled sprite.
Given an already loaded texture, this function will draw a rectangle textured with the loaded texture.
Before using this command to draw a textured rectangle, use rdpq_set_mode_copy (or the deprecated rdp_enable_texture_copy) to set the RDP up in texture copy mode.
[in] | texslot | The texture slot that the texture was previously loaded into (0-7) |
[in] | x | The pixel X location of the top left of the sprite |
[in] | y | The pixel Y location of the top left of the sprite |
[in] | x_scale | Horizontal scaling factor |
[in] | y_scale | Vertical scaling factor |
[in] | mirror | Whether the texture should be mirrored |
void rdp_set_blend_color | ( | uint32_t | color | ) |
Set the blend draw color for subsequent filled primitive operations.
This function sets the color of all rdp_draw_filled_triangle operations that follow.
[in] | color | Color to draw primitives in |
void rdp_draw_filled_triangle | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
float | x3, | ||
float | y3 | ||
) |
Draw a filled triangle.
Given a color set with rdp_set_blend_color, this will draw a filled triangle to the screen. Vertex order is not important.
Before calling this function, make sure that the RDP is set to blend mode by calling rdp_enable_blend_fill.
[in] | x1 | Pixel X1 location of triangle |
[in] | y1 | Pixel Y1 location of triangle |
[in] | x2 | Pixel X2 location of triangle |
[in] | y2 | Pixel Y2 location of triangle |
[in] | x3 | Pixel X3 location of triangle |
[in] | y3 | Pixel Y3 location of triangle |
void rdp_set_texture_flush | ( | flush_t | flush | ) |
Set the flush strategy for texture loads.
If textures are guaranteed to be in uncached RDRAM or the cache is flushed before calling load operations, the RDP can be told to skip flushing the cache. This affords a good speedup. However, if you are changing textures in memory on the fly or otherwise do not want to deal with cache coherency, set the cache strategy to automatic to have the RDP flush cache before texture loads.
[in] | flush | The cache strategy, either FLUSH_STRATEGY_NONE or FLUSH_STRATEGY_AUTOMATIC. |