Tiny3D
Loading...
Searching...
No Matches
tpx.h File Reference
#include <libdragon.h>
#include <t3d/t3dmath.h>
Include dependency graph for tpx.h:

Go to the source code of this file.

Data Structures

struct  TPXInitParams
 
struct  __attribute__
 

Typedefs

typedef TPXParticleS8 TPXParticle
 

Enumerations

enum  TPXCmd {
  TPX_CMD_SYNC_T3D = 0x0 , TPX_CMD_DRAW_COLOR = 0x1 , TPX_CMD_MATRIX_STACK = 0x2 , TPX_CMD_SET_DMEM = 0x3 ,
  TPX_CMD_DRAW_TEXTURE = 0x4
}
 

Functions

 aligned (16))) TPXParticleS8
 
 aligned (8))) TPXParticleS16
 
void tpx_init (TPXInitParams params)
 Initializes the tinyPX library.
 
void tpx_state_from_t3d ()
 
void tpx_state_set_scale (float scaleX, float scaleY)
 
void tpx_state_set_base_size (uint16_t baseSize)
 
void tpx_state_set_tex_params (int16_t offsetX, uint16_t mirrorPoint)
 
void tpx_particle_draw_s8 (TPXParticleS8 *particles, uint32_t count)
 
static void tpx_particle_draw (TPXParticleS8 *particles, uint32_t count)
 
void tpx_particle_draw_s16 (TPXParticleS16 *particles, uint32_t count)
 
void tpx_particle_draw_tex_s8 (TPXParticleS8 *particles, uint32_t count)
 
static void tpx_particle_draw_tex (TPXParticleS8 *particles, uint32_t count)
 
void tpx_particle_draw_tex_s16 (TPXParticleS16 *particles, uint32_t count)
 
void tpx_matrix_set (const T3DMat4FP *mat, bool doMultiply)
 
void tpx_matrix_push (const T3DMat4FP *mat)
 
void tpx_matrix_pop (int count)
 
void tpx_matrix_push_pos (int count)
 
static int8_t * tpx_buffer_s8_get_pos (TPXParticleS8 pt[], int idx)
 
static int8_t * tpx_buffer_get_pos (TPXParticleS8 pt[], int idx)
 
static int8_t * tpx_buffer_s8_get_size (TPXParticleS8 pt[], int idx)
 
static int8_t * tpx_buffer_get_size (TPXParticleS8 pt[], int idx)
 
static uint32_t * tpx_buffer_s8_get_color (TPXParticleS8 pt[], int idx)
 
static uint32_t * tpx_buffer_get_color (TPXParticleS8 pt[], int idx)
 
static uint8_t * tpx_buffer_s8_get_rgba (TPXParticleS8 pt[], int idx)
 
static uint8_t * tpx_buffer_get_rgba (TPXParticleS8 pt[], int idx)
 
static int16_t * tpx_buffer_s16_get_pos (TPXParticleS16 pt[], int idx)
 
static int8_t * tpx_buffer_s16_get_size (TPXParticleS16 pt[], int idx)
 
static uint8_t * tpx_buffer_s16_get_rgba (TPXParticleS16 pt[], int idx)
 
static uint8_t * tpx_buffer_s16_get_tex_offset (TPXParticleS16 pt[], int idx)
 
void tpx_buffer_s8_swap (TPXParticleS8 pt[], uint32_t idxA, uint32_t idxB)
 
static void tpx_buffer_swap (TPXParticleS8 pt[], uint32_t idxA, uint32_t idxB)
 
void tpx_buffer_s16_swap (TPXParticleS16 pt[], uint32_t idxA, uint32_t idxB)
 
void tpx_buffer_s8_copy (TPXParticleS8 pt[], uint32_t idxDst, uint32_t idxSrc)
 
static void tpx_buffer_copy (TPXParticleS8 pt[], uint32_t idxDst, uint32_t idxSrc)
 
void tpx_buffer_s16_copy (TPXParticleS16 pt[], uint32_t idxDst, uint32_t idxSrc)
 
void tpx_destroy ()
 

Variables

uint32_t TPX_RSP_ID
 

Detailed Description

Typedef Documentation

◆ TPXParticle

typedef TPXParticleS8 TPXParticle
Deprecated
Use 'TPXParticleS8' instead.

Function Documentation

◆ tpx_buffer_s16_copy()

void tpx_buffer_s16_copy ( TPXParticleS16 pt[],
uint32_t idxDst,
uint32_t idxSrc )

Copies a particle into another place in a buffer This will overwrite the destination particle and keep the source particle unchanged.

Parameters
ptbuffer to copy particles in
idxDstdestination index
idxSrcsource index

◆ tpx_buffer_s16_get_pos()

static int16_t * tpx_buffer_s16_get_pos ( TPXParticleS16 pt[],
int idx )
inlinestatic

Returns the pointer to a position of a particle in a buffer

Parameters
vertparticle buffer
idxparticle index

◆ tpx_buffer_s16_get_rgba()

static uint8_t * tpx_buffer_s16_get_rgba ( TPXParticleS16 pt[],
int idx )
inlinestatic

Returns the pointer to the color (as a u32) of a particle in a buffer

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s16_get_size()

static int8_t * tpx_buffer_s16_get_size ( TPXParticleS16 pt[],
int idx )
inlinestatic

Returns the pointer to the size of a particle in a buffer

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s16_get_tex_offset()

static uint8_t * tpx_buffer_s16_get_tex_offset ( TPXParticleS16 pt[],
int idx )
inlinestatic

Returns the pointer to the texture offset in the buffer. This is only present in the 16bit buffer, in the 8bit version this stored in alpha channel.

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s16_swap()

void tpx_buffer_s16_swap ( TPXParticleS16 pt[],
uint32_t idxA,
uint32_t idxB )

Swaps two particles in a buffer

Parameters
ptbuffer to swap particles in
idxAindex of the first particle
idxBindex of the second particle

◆ tpx_buffer_s8_copy()

void tpx_buffer_s8_copy ( TPXParticleS8 pt[],
uint32_t idxDst,
uint32_t idxSrc )

Copies a particle into another place in a buffer This will overwrite the destination particle and keep the source particle unchanged.

Parameters
ptbuffer to copy particles in
idxDstdestination index
idxSrcsource index

◆ tpx_buffer_s8_get_color()

static uint32_t * tpx_buffer_s8_get_color ( TPXParticleS8 pt[],
int idx )
inlinestatic

Returns the pointer to the color (as a u32) of a particle in a buffer

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s8_get_pos()

static int8_t * tpx_buffer_s8_get_pos ( TPXParticleS8 pt[],
int idx )
inlinestatic

Returns the pointer to a position of a particle in a buffer

Parameters
vertparticle buffer
idxparticle index

◆ tpx_buffer_s8_get_rgba()

static uint8_t * tpx_buffer_s8_get_rgba ( TPXParticleS8 pt[],
int idx )
inlinestatic

Returns the pointer to the color (as a u8[4]) of a particle in a buffer

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s8_get_size()

static int8_t * tpx_buffer_s8_get_size ( TPXParticleS8 pt[],
int idx )
inlinestatic

Returns the pointer to the size of a particle in a buffer

Parameters
ptparticle buffer
idxparticle index

◆ tpx_buffer_s8_swap()

void tpx_buffer_s8_swap ( TPXParticleS8 pt[],
uint32_t idxA,
uint32_t idxB )

Swaps two particles in a buffer

Parameters
ptbuffer to swap particles in
idxAindex of the first particle
idxBindex of the second particle

◆ tpx_destroy()

void tpx_destroy ( )

Destroys the tinyPX library and frees all resources

◆ tpx_init()

void tpx_init ( TPXInitParams params)

Initializes the tinyPX library.

Parameters
paramssettings to configure the library

◆ tpx_matrix_pop()

void tpx_matrix_pop ( int count)

Pops the current matrix from the stack.

Parameters
counthow many matrices to pop

◆ tpx_matrix_push()

void tpx_matrix_push ( const T3DMat4FP * mat)

Multiplies a matrix with the current stack position, then pushes it onto the stack.

Parameters
mataddress to load matrix from

◆ tpx_matrix_push_pos()

void tpx_matrix_push_pos ( int count)

Moves the stack pos. without changing a matrix or causing re-calculations. This should only be used in preparation for 'tpx_matrix_set' calls.

E.g. instead of multiple push/pop combis, use:

  • 'tpx_matrix_push_pos(1)' once
  • then multiple 'tpx_matrix_set'
  • finish with 'tpx_matrix_pop'

This is the most efficient way to set multiple matrices at the same level.

Parameters
countrelative change (matrix count), should usually be 1

◆ tpx_matrix_set()

void tpx_matrix_set ( const T3DMat4FP * mat,
bool doMultiply )

Directly loads a matrix, overwriting the current stack position.

With 'doMultiply' set to false, this lets you completely replace the current matrix. With 'doMultiply' set to true, it serves as a faster version of a pop+push combination.

Parameters
mataddress to load matrix from
doMultiplyif true, the matrix will be multiplied with the previous stack entry

◆ tpx_particle_draw_s16()

void tpx_particle_draw_s16 ( TPXParticleS16 * particles,
uint32_t count )

Draws a given amount of particles (16bit position precision). 16bit Precision gives you larger range but comes with slightly more memory and runtime cost. Whenever possible use the 8bit version instead. It is most useful if you need to cover large ranges, e.g. when using it for billboards in scene.

In contrast to triangles in t3d, this works in a single command. So load, transform and draw happens in one go.

Parameters
particlespointer to the particle data
countnumber of particles to draw

◆ tpx_particle_draw_s8()

void tpx_particle_draw_s8 ( TPXParticleS8 * particles,
uint32_t count )

Draws a given amount of particles (8bit position precision). In contrast to triangles in t3d, this works in a single command. So load, transform and draw happens in one go.

Parameters
particlespointer to the particle data
countnumber of particles to draw

◆ tpx_particle_draw_tex_s16()

void tpx_particle_draw_tex_s16 ( TPXParticleS16 * particles,
uint32_t count )

Draws a given amount of particles (16bit position precision). 16bit Precision gives you larger range but comes with slightly more memory and runtime cost. Whenever possible use the 8bit version instead. It is most useful if you need to cover large ranges, e.g. when using it for billboards in scene.

Note: this expects that you already setup textures. It will also always use TILE0 for the rect-commands. A per-particle texture offset can be set in 'texOffsetA'/'texOffsetB'.

Parameters
particlespointer to the particle data
countnumber of particles to draw

◆ tpx_particle_draw_tex_s8()

void tpx_particle_draw_tex_s8 ( TPXParticleS8 * particles,
uint32_t count )

Draws a given amount of particles with a texture. In contrast to triangles in t3d, this works in a single command. So load, transform and draw happens in one go.

Note: this expects that you already setup textures. It will also always use TILE0 for the rect-commands. The colors alpha channel acts as a texture offset.

Parameters
particlespointer to the particle data
countnumber of particles to draw

◆ tpx_state_from_t3d()

void tpx_state_from_t3d ( )

T3D and TPX have separate states and ucodes. This function copies the relevant T3D state to TPX.

Settings that are copied:

  • Screen size
  • Current MVP matrix
  • W-normalization factor

◆ tpx_state_set_base_size()

void tpx_state_set_base_size ( uint16_t baseSize)

Sets a global base size from which all particles are scaled. This values can later only be scaled down, not up. By default it is set to 128, which should be good enough for most cases. If you notices particles are way too small or large, you can change this value. This may happen if you use large or very small screen sizes, or unusual near/far values.

Parameters
baseSizeunit-less base size, def.: 128

◆ tpx_state_set_scale()

void tpx_state_set_scale ( float scaleX,
float scaleY )

Sets a global scaling factor applied to all particles Note that you can only scale down, not up.

Parameters
scaleXhorizontal scaling factor, range: 0.0 - 1.0
scaleYvertical scaling factor, range: 0.0 - 1.0

◆ tpx_state_set_tex_params()

void tpx_state_set_tex_params ( int16_t offsetX,
uint16_t mirrorPoint )

Sets global params for textured particles. Those can be used to animate particles over time. NOTE: Check out the '19_particles_tex' example for more info.

Parameters
offsetXbase-offset UV offset in 1/4th pixels.
This refers to the 8x8px base size irrespective of the actual texture size.
mirrorPointpoint where the texture should be mirrored
This is in amount of sections of the 8x8px base size.
So if you want to repeat after 32px set it to 4.
If you want no mirroring, set it to 0.