libdragon
Loading...
Searching...
No Matches
Functions
sprite.c File Reference

Functions

sprite_ext_t__sprite_ext (sprite_t *sprite)
 Access the sprite extended structure, or NULL if the structure does not exist.
 
bool __sprite_upgrade (sprite_t *sprite)
 Convert a sprite from the old format with implicit texture format.
 
sprite_tsprite_load_buf (void *buf, int sz)
 Load a sprite from a buffer.
 
sprite_tsprite_load (const char *fn)
 Load a sprite from a filesystem (eg: ROM)
 
void sprite_free (sprite_t *s)
 Deallocate a sprite.
 
surface_t sprite_get_pixels (sprite_t *sprite)
 Create a surface_t pointing to the full sprite contents.
 
surface_t sprite_get_lod_pixels (sprite_t *sprite, int num_level)
 Create a surface_t pointing to the contents of a LOD level.
 
surface_t sprite_get_detail_pixels (sprite_t *sprite, sprite_detail_t *info, rdpq_texparms_t *infoparms)
 Create a surface_t pointing to the contents of a detail texture.
 
uint16_t * sprite_get_palette (sprite_t *sprite)
 Access the sprite palette (if any)
 
surface_t sprite_get_tile (sprite_t *sprite, int h, int v)
 Return a surface_t pointing to a specific tile of the spritemap.
 
bool sprite_get_texparms (sprite_t *sprite, rdpq_texparms_t *parms)
 Get a copy of the RDP texparms, optionally stored within the sprite.
 
int sprite_get_lod_count (sprite_t *sprite)
 Return the number of LOD levels stored within the sprite (including the main image).
 
bool sprite_fits_tmem (sprite_t *sprite)
 Return true if the sprite fits in TMEM without splitting.
 
tex_format_t sprite_get_format (sprite_t *sprite)
 Get the sprite texture format.
 

Detailed Description

Author
Giovanni Bajo giova.nosp@m.nnib.nosp@m.ajo@g.nosp@m.mail.nosp@m..com
Dennis Heinze denni.nosp@m.sjp..nosp@m.heinz.nosp@m.e@gm.nosp@m.ail.c.nosp@m.om

Function Documentation

◆ sprite_load_buf()

sprite_t * sprite_load_buf ( void *  buf,
int  sz 
)

Load a sprite from a buffer.

This function loads a sprite from a buffer corresponding to sprite file data in memory. The function also performs any necessary processing to load the sprite file data.

sprite_load_buf functions in-place which means it does not allocate another buffer for the loaded sprite. So, sprite_free will not remove the sprite data from memory. This means that the input buffer must be freed manually after sprite_free is called.

Parameters
bufPointer to the sprite file data
szSize of the sprite file buffer
Returns
sprite_t* The loaded sprite

◆ sprite_load()

sprite_t * sprite_load ( const char *  fn)

Load a sprite from a filesystem (eg: ROM)

This function loads a full sprite from a filesystem. Notice that there is no streaming support, so the file is fully loaded into RDRAM, in its final uncompressed format.

sprite_load internally uses the asset API (asset_load), so the sprite file is transparently uncompressed if needed.

Parameters
fnFilename of the sprite, including filesystem specifier. For instance: "rom:/hero.sprite" to load from DFS.
Returns
sprite_t* The loaded sprite

◆ sprite_get_pixels()

surface_t sprite_get_pixels ( sprite_t sprite)

Create a surface_t pointing to the full sprite contents.

This function can be used to pass a full sprite to functions accepting a surface_t.

Notice that no memory allocations or copies are performed: the returned surface will point to the sprite contents.

Parameters
spriteThe sprite
Returns
The surface pointing to the sprite

◆ sprite_get_lod_pixels()

surface_t sprite_get_lod_pixels ( sprite_t sprite,
int  num_level 
)

Create a surface_t pointing to the contents of a LOD level.

This function can be used to access LOD images within a sprite file. It is useful for sprites created by mksprite containing multiple mipmap levels.

LOD levels are indexed from 1 upward. 0 refers to the main sprite, so calling sprite_get_lod_pixels(s, 0) is equivalent to sprite_get_pixels(s).

Notice that no memory allocations or copies are performed: the returned surface will point to the sprite contents.

Parameters
spriteThe sprite to access
num_levelThe number of LOD level. 0 is the main sprite.
Returns
surface_t The surface containing the data.

◆ sprite_get_detail_pixels()

surface_t sprite_get_detail_pixels ( sprite_t sprite,
sprite_detail_t info,
rdpq_texparms_t infoparms 
)

Create a surface_t pointing to the contents of a detail texture.

This function can be used to access detail texture within a sprite file. It is useful for sprites created by mksprite containing one.

If there isn't a detail texture, the returned surface is 0.

Additional detail information such as factor or texparms are accessible through the filled sprite_detail_t and rdpq_texparms_t structure. If you don't wish to use this information, pass NULL to the info argument(s).

Notice that no memory allocations or copies are performed: the returned surface will point to the sprite contents.

Parameters
spriteThe sprite to access
infoThe detail information struct to fill if needed
infoparmsThe detail texture sampling struct to fill if needed
Returns
surface_t The surface containing the data.

◆ sprite_get_palette()

uint16_t * sprite_get_palette ( sprite_t sprite)

Access the sprite palette (if any)

A sprite can also contain a palette, in case the sprite data is color-indexed (that is, the format is either FMT_CI4 or FMT_CI8).

This function returns a pointer to the raw palette data contained in the sprite.

Parameters
spriteThe sprite to access
Returns
A pointer to the palette data, or NULL if the sprite does not have a palette

◆ sprite_get_tile()

surface_t sprite_get_tile ( sprite_t sprite,
int  h,
int  v 
)

Return a surface_t pointing to a specific tile of the spritemap.

A sprite can be used as a spritemap, that is a collection of multiple smaller images of equal size, called "tiles". In this case, the number of tiles is stored in the members hslices and vslices of the sprite structure.

This function allows to get a surface that points to the specific sub-tile, so that it can accessed directly.

Parameters
spriteThe sprite used as spritemap
hHorizontal index of the tile to access
vVertical index of the tile to access
Returns
A surface pointing to the tile

◆ sprite_get_texparms()

bool sprite_get_texparms ( sprite_t sprite,
rdpq_texparms_t parms 
)

Get a copy of the RDP texparms, optionally stored within the sprite.

This function allows to obtain the RDP texparms structure stored within the sprite, if any. This structure is used by the RDP to set texture properties such as wrapping, mirroring, etc. It can be added to the sprite via the mksprite tool, using the --texparms option.

Parameters
spriteThe sprite to access
parmsThe texparms structure to fill
Returns
true if the sprite contain RDP texparms, false otherwise

◆ sprite_get_lod_count()

int sprite_get_lod_count ( sprite_t sprite)

Return the number of LOD levels stored within the sprite (including the main image).

Parameters
spriteThe sprite to access
Returns
The number of LOD levels

◆ sprite_fits_tmem()

bool sprite_fits_tmem ( sprite_t sprite)

Return true if the sprite fits in TMEM without splitting.

This function returns true if the sprite can be fully uploaded in TMEM (including all its LODs, detail texture and palettes).

When working on 3D graphics, each texture must fit into RDP TMEM (4 KiB), otherwise it cannot be used. All sprites that are meant to be used as textures should fit in TMEM.

In case of 2D graphics, it is more common to have images of arbitrary size. They can be drawn with rdpq_sprite_blit (accelerated) or graphics_draw_sprite (CPU) without specific limits (the RDP accelerated version does internally need to split the sprite in multiple parts, but that is indeed possible).

This function is mostly for debugging purposes, as it can help validating whether a sprite can be used as a texture or not.

Parameters
spriteThe sprite to access
Returns
True if the sprite fits TMEM, false otherwise

◆ sprite_get_format()

tex_format_t sprite_get_format ( sprite_t sprite)
externinline

Get the sprite texture format.

Parameters
spriteThe sprite
Returns
The texture format