Tiny3D
Loading...
Searching...
No Matches
tpx.h
Go to the documentation of this file.
1
6#ifndef TINYPX_PTX_H
7#define TINYPX_PTX_H
8
9#include <libdragon.h>
10#include <t3d/t3dmath.h>
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17extern uint32_t TPX_RSP_ID;
18
19// RSP commands, must match with the commands defined in `rsp/rsp_tinypx.rspl`
20enum TPXCmd {
21 TPX_CMD_SYNC_T3D = 0x0,
22 TPX_CMD_DRAW_COLOR = 0x1,
23 TPX_CMD_MATRIX_STACK = 0x2,
24 TPX_CMD_SET_DMEM = 0x3,
25 TPX_CMD_DRAW_TEXTURE = 0x4,
26 // = 0x5,
27 // = 0x6,
28 // = 0x7,
29 // = 0x8,
30 // = 0x9,
31 // = 0xA,
32 // = 0xB,
33 // = 0xC,
34 // = 0xD,
35 // = 0xE,
36 // = 0xF,
37};
38
39typedef struct {
40 // Internal matrix stack size, must be at least 2.
41 // If set two zero, 4 will be used by default.
42 int matrixStackSize;
44
45typedef struct {
46 int8_t posA[3];
47 int8_t sizeA;
48 int8_t posB[3];
49 int8_t sizeB;
50 uint8_t colorA[4];
51 uint8_t colorB[4];
52} __attribute__((packed, aligned(16))) TPXParticleS8;
53
54static_assert(sizeof(TPXParticleS8) == 16, "TPXParticleS8 size mismatch");
55
59[[deprecated("Use 'TPXParticleS8' instead")]] typedef TPXParticleS8 TPXParticle;
60
61typedef struct {
62 int16_t posA[3];
63 int8_t sizeA;
64 uint8_t texOffsetA;
65 int16_t posB[3];
66 int8_t sizeB;
67 uint8_t texOffsetB;
68 uint8_t colorA[4];
69 uint8_t colorB[4];
70} __attribute__((packed, aligned(8))) TPXParticleS16;
71
72static_assert(sizeof(TPXParticleS16) == 24, "TPXParticle16 size mismatch");
73
78void tpx_init(TPXInitParams params);
79
90
97void tpx_state_set_scale(float scaleX, float scaleY);
98
107void tpx_state_set_base_size(uint16_t baseSize);
108
121void tpx_state_set_tex_params(int16_t offsetX, uint16_t mirrorPoint);
122
130void tpx_particle_draw_s8(TPXParticleS8 *particles, uint32_t count);
131
132[[deprecated("Use 'tpx_particle_draw_s8' instead")]]
133inline static void tpx_particle_draw(TPXParticleS8 *particles, uint32_t count) {
134 return tpx_particle_draw_s8(particles, count);
135}
136
148void tpx_particle_draw_s16(TPXParticleS16 *particles, uint32_t count);
149
162void tpx_particle_draw_tex_s8(TPXParticleS8 *particles, uint32_t count);
163
164[[deprecated("Use 'tpx_particle_draw_tex_s8' instead")]]
165inline static void tpx_particle_draw_tex(TPXParticleS8 *particles, uint32_t count) {
166 return tpx_particle_draw_tex_s8(particles, count);
167}
168
182void tpx_particle_draw_tex_s16(TPXParticleS16 *particles, uint32_t count);
183
193void tpx_matrix_set(const T3DMat4FP *mat, bool doMultiply);
194
199void tpx_matrix_push(const T3DMat4FP *mat);
200
205void tpx_matrix_pop(int count);
206
219void tpx_matrix_push_pos(int count);
220
226static inline int8_t* tpx_buffer_s8_get_pos(TPXParticleS8 pt[], int idx) {
227 return (idx & 1) ? pt[idx/2].posB : pt[idx/2].posA;
228}
229
230[[deprecated("Use 'tpx_buffer_s8_get_pos' instead")]]
231static inline int8_t* tpx_buffer_get_pos(TPXParticleS8 pt[], int idx) {
232 return tpx_buffer_s8_get_pos(pt, idx);
233}
234
240static inline int8_t* tpx_buffer_s8_get_size(TPXParticleS8 pt[], int idx) {
241 return (idx & 1) ? &pt[idx/2].sizeB : &pt[idx/2].sizeA;
242}
243
244[[deprecated("Use 'tpx_buffer_s8_get_size' instead")]]
245static inline int8_t* tpx_buffer_get_size(TPXParticleS8 pt[], int idx) {
246 return tpx_buffer_s8_get_size(pt, idx);
247}
248
254static inline uint32_t* tpx_buffer_s8_get_color(TPXParticleS8 pt[], int idx) {
255 return (idx & 1) ? (uint32_t*)&pt[idx/2].colorB : (uint32_t*)&pt[idx/2].colorA;
256}
257
258[[deprecated("Use 'tpx_buffer_s8_get_color' instead")]]
259static inline uint32_t* tpx_buffer_get_color(TPXParticleS8 pt[], int idx) {
260 return tpx_buffer_s8_get_color(pt, idx);
261}
262
268static inline uint8_t* tpx_buffer_s8_get_rgba(TPXParticleS8 pt[], int idx) {
269 return (idx & 1) ? pt[idx/2].colorB : pt[idx/2].colorA;
270}
271
272[[deprecated("Use 'tpx_buffer_s8_get_rgba' instead")]]
273static inline uint8_t* tpx_buffer_get_rgba(TPXParticleS8 pt[], int idx) {
274 return tpx_buffer_s8_get_rgba(pt, idx);
275}
276
282static inline int16_t* tpx_buffer_s16_get_pos(TPXParticleS16 pt[], int idx) {
283 return (idx & 1) ? pt[idx/2].posB : pt[idx/2].posA;
284}
285
291static inline int8_t* tpx_buffer_s16_get_size(TPXParticleS16 pt[], int idx) {
292 return (idx & 1) ? &pt[idx/2].sizeB : &pt[idx/2].sizeA;
293}
294
300static inline uint8_t* tpx_buffer_s16_get_rgba(TPXParticleS16 pt[], int idx) {
301 return (idx & 1) ? pt[idx/2].colorB : pt[idx/2].colorA;
302}
303
310static inline uint8_t* tpx_buffer_s16_get_tex_offset(TPXParticleS16 pt[], int idx) {
311 return (idx & 1) ? &pt[idx/2].texOffsetA : &pt[idx/2].texOffsetB;
312}
313
320void tpx_buffer_s8_swap(TPXParticleS8 pt[], uint32_t idxA, uint32_t idxB);
321
322[[deprecated("Use 'tpx_buffer_s8_swap' instead")]]
323static inline void tpx_buffer_swap(TPXParticleS8 pt[], uint32_t idxA, uint32_t idxB) {
324 tpx_buffer_s8_swap(pt, idxA, idxB);
325}
326
333void tpx_buffer_s16_swap(TPXParticleS16 pt[], uint32_t idxA, uint32_t idxB);
334
342void tpx_buffer_s8_copy(TPXParticleS8 pt[], uint32_t idxDst, uint32_t idxSrc);
343
344[[deprecated("Use 'tpx_buffer_s8_copy' instead")]]
345static inline void tpx_buffer_copy(TPXParticleS8 pt[], uint32_t idxDst, uint32_t idxSrc) {
346 tpx_buffer_s8_copy(pt, idxDst, idxSrc);
347}
348
356void tpx_buffer_s16_copy(TPXParticleS16 pt[], uint32_t idxDst, uint32_t idxSrc);
357
361void tpx_destroy();
362
363#ifdef __cplusplus
364}
365#endif
366
367#endif // TINYPX_PTX_H
Definition tpx.h:39
__attribute__((deprecated)) void t3d_debug_print_init()
Initializes the debug print system, make sure to have 'font.ia4.png' in your FS.
void tpx_state_set_base_size(uint16_t baseSize)
Definition tpx.c:69
static uint8_t * tpx_buffer_s16_get_tex_offset(TPXParticleS16 pt[], int idx)
Definition tpx.h:310
void tpx_init(TPXInitParams params)
Initializes the tinyPX library.
Definition tpx.c:21
void tpx_buffer_s16_swap(TPXParticleS16 pt[], uint32_t idxA, uint32_t idxB)
Definition tpx.c:167
void tpx_particle_draw_tex_s16(TPXParticleS16 *particles, uint32_t count)
Definition tpx.c:126
void tpx_state_set_tex_params(int16_t offsetX, uint16_t mirrorPoint)
Definition tpx.c:73
static int8_t * tpx_buffer_s8_get_size(TPXParticleS8 pt[], int idx)
Definition tpx.h:240
void tpx_destroy()
Definition tpx.c:200
static uint8_t * tpx_buffer_s8_get_rgba(TPXParticleS8 pt[], int idx)
Definition tpx.h:268
void tpx_matrix_push_pos(int count)
Definition tpx.c:151
static uint8_t * tpx_buffer_s16_get_rgba(TPXParticleS16 pt[], int idx)
Definition tpx.h:300
static int8_t * tpx_buffer_s8_get_pos(TPXParticleS8 pt[], int idx)
Definition tpx.h:226
void tpx_particle_draw_s8(TPXParticleS8 *particles, uint32_t count)
Definition tpx.c:114
void tpx_matrix_set(const T3DMat4FP *mat, bool doMultiply)
Definition tpx.c:138
void tpx_buffer_s8_swap(TPXParticleS8 pt[], uint32_t idxA, uint32_t idxB)
Definition tpx.c:156
static int16_t * tpx_buffer_s16_get_pos(TPXParticleS16 pt[], int idx)
Definition tpx.h:282
void tpx_matrix_pop(int count)
Definition tpx.c:146
static uint32_t * tpx_buffer_s8_get_color(TPXParticleS8 pt[], int idx)
Definition tpx.h:254
void tpx_matrix_push(const T3DMat4FP *mat)
Definition tpx.c:142
void tpx_state_from_t3d()
Definition tpx.c:48
void tpx_buffer_s8_copy(TPXParticleS8 pt[], uint32_t idxDst, uint32_t idxSrc)
void tpx_state_set_scale(float scaleX, float scaleY)
Definition tpx.c:63
void tpx_particle_draw_tex_s8(TPXParticleS8 *particles, uint32_t count)
Definition tpx.c:122
static int8_t * tpx_buffer_s16_get_size(TPXParticleS16 pt[], int idx)
Definition tpx.h:291
void tpx_buffer_s16_copy(TPXParticleS16 pt[], uint32_t idxDst, uint32_t idxSrc)
Definition tpx.c:189
void tpx_particle_draw_s16(TPXParticleS16 *particles, uint32_t count)
Definition tpx.c:118
TPXParticleS8 TPXParticle
Definition tpx.h:59