libdragon
Loading...
Searching...
No Matches
rdpq_tex.h
Go to the documentation of this file.
1
8#ifndef LIBDRAGON_RDPQ_TEX_H
9#define LIBDRAGON_RDPQ_TEX_H
10
11#include "rdpq.h"
12#include <stdint.h>
13
15typedef struct surface_s surface_t;
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
24#define MIRROR_REPEAT true
26#define MIRROR_NONE false
28#define REPEAT_INFINITE 2048
29
40typedef struct rdpq_texparms_s {
42 int palette;
43
44 struct {
45 float translate;
46 int scale_log;
47
48 float repeats;
49 bool mirror;
50 } s, t; // S/T directions of texture parameters
51
53
54// Multi-pass optimized texture loader
55// Not part of the public API yet
57enum tex_load_mode {
58 TEX_LOAD_UNKNOWN,
59 TEX_LOAD_TILE,
60 TEX_LOAD_BLOCK,
61};
62
63typedef struct tex_loader_s {
64 const surface_t *tex;
65 tex_format_t fmt;
66 rdpq_tile_t tile;
67 const rdpq_texparms_t *texparms;
68 rdpq_tileparms_t tileparms;
69 struct {
70 int width, height;
71 int num_texels, tmem_pitch;
72 int block_max_lines;
73 bool can_load_block;
74 int s0fx, t0fx, s1fx, t1fx;
75 } rect;
76 int tmem_addr;
77 enum tex_load_mode load_mode;
78 void (*load_block)(struct tex_loader_s *tload, int s0, int t0, int s1, int t1);
79 void (*load_tile)(struct tex_loader_s *tload, int s0, int t0, int s1, int t1);
80} tex_loader_t;
81tex_loader_t tex_loader_init(rdpq_tile_t tile, const surface_t *tex);
82int tex_loader_load(tex_loader_t *tload, int s0, int t0, int s1, int t1);
83void tex_loader_set_tmem_addr(tex_loader_t *tload, int tmem_addr);
84int tex_loader_calc_max_height(tex_loader_t *tload, int s0, int s1);
86
87
119int rdpq_tex_upload(rdpq_tile_t tile, const surface_t *tex, const rdpq_texparms_t *parms);
120
184int rdpq_tex_upload_sub(rdpq_tile_t tile, const surface_t *tex, const rdpq_texparms_t *parms, int s0, int t0, int s1, int t1);
185
199void rdpq_tex_upload_tlut(uint16_t *tlut, int color_idx, int num_colors);
200
233int rdpq_tex_reuse_sub(rdpq_tile_t tile, const rdpq_texparms_t *parms, int s0, int t0, int s1, int t1);
234
252int rdpq_tex_reuse(rdpq_tile_t tile, const rdpq_texparms_t *parms);
253
276void rdpq_tex_multi_begin(void);
277
278
289int rdpq_tex_multi_end(void);
290
291
303typedef struct rdpq_blitparms_s {
305 int s0;
306 int t0;
307 int width;
308 int height;
309 bool flip_x;
310 bool flip_y;
311
312 int cx;
313 int cy;
314 float scale_x;
315 float scale_y;
316 float theta;
317
318 // FIXME: replace this with CPU tracking of filtering mode?
320
321 // FIXME: remove this?
322 int nx;
323 int ny;
325
403void rdpq_tex_blit(const surface_t *surf, float x0, float y0, const rdpq_blitparms_t *parms);
404
406__attribute__((deprecated("use rdpq_tex_upload instead")))
407static inline int rdpq_tex_load(rdpq_tile_t tile, surface_t *tex, const rdpq_texparms_t *parms) {
408 return rdpq_tex_upload(tile, tex, parms);
409}
410__attribute__((deprecated("use rdpq_tex_upload_sub instead")))
411static inline int rdpq_tex_load_sub(rdpq_tile_t tile, surface_t *tex, const rdpq_texparms_t *parms, int s0, int t0, int s1, int t1) {
412 return rdpq_tex_upload_sub(tile, tex, parms, s0, t0, s1, t1);
413}
414__attribute__((deprecated("use rdpq_tex_upload_tlut instead")))
415static inline void rdpq_tex_load_tlut(uint16_t *tlut, int color_idx, int num_colors) {
416 return rdpq_tex_upload_tlut(tlut, color_idx, num_colors);
417}
419
420#ifdef __cplusplus
421}
422#endif
423
424#endif
RDP Command queue.
rdpq_tile_t
Tile descriptors.
Definition rdpq.h:250
Tile parameters for rdpq_set_tile.
Definition rdpq.h:272
int rdpq_tex_upload_sub(rdpq_tile_t tile, const surface_t *tex, const rdpq_texparms_t *parms, int s0, int t0, int s1, int t1)
Load a portion of texture into TMEM.
Definition rdpq_tex.c:369
int rdpq_tex_reuse_sub(rdpq_tile_t tile, const rdpq_texparms_t *parms, int s0, int t0, int s1, int t1)
Reuse a portion of the previously uploaded texture to TMEM.
Definition rdpq_tex.c:412
int s0
Source sub-rect top-left X coordinate.
Definition rdpq_tex.h:305
void rdpq_tex_upload_tlut(uint16_t *tlut, int color_idx, int num_colors)
Load one or more palettes into TMEM.
Definition rdpq_tex.c:689
void rdpq_tex_blit(const surface_t *surf, float x0, float y0, const rdpq_blitparms_t *parms)
Blit a surface to the active framebuffer.
Definition rdpq_tex.c:684
float scale_x
Horizontal scale factor to apply to the surface. If 0, no scaling is performed (the same as 1....
Definition rdpq_tex.h:314
float theta
Rotation angle in radians.
Definition rdpq_tex.h:316
int height
Source sub-rect height. If 0, the height of the surface is used.
Definition rdpq_tex.h:308
int rdpq_tex_multi_end(void)
Finish a multi-texture upload.
Definition rdpq_tex.c:712
int cx
Transformation center (aka "hotspot") X coordinate, relative to (s0, t0). Used for all transformation...
Definition rdpq_tex.h:312
int nx
Texture horizontal repeat count. If 0, no repetition is performed (the same as 1)
Definition rdpq_tex.h:322
int tmem_addr
TMEM address where to load the texture (default: 0)
Definition rdpq_tex.h:41
float scale_y
Vertical scale factor to apply to the surface. If 0, no scaling is performed (the same as 1....
Definition rdpq_tex.h:315
int width
Source sub-rect width. If 0, the width of the surface is used.
Definition rdpq_tex.h:307
bool flip_y
Flip vertically. If true, the source sub-rect is treated as vertically flipped (so flipping is perfor...
Definition rdpq_tex.h:310
int ny
Texture vertical repeat count. If 0, no repetition is performed (the same as 1)
Definition rdpq_tex.h:323
int rdpq_tex_upload(rdpq_tile_t tile, const surface_t *tex, const rdpq_texparms_t *parms)
Load a texture into TMEM.
Definition rdpq_tex.c:407
bool filtering
True if texture filtering is enabled (activates workaround for filtering artifacts when splitting tex...
Definition rdpq_tex.h:319
int t0
Source sub-rect top-left Y coordinate.
Definition rdpq_tex.h:306
void rdpq_tex_multi_begin(void)
Begin a multi-texture upload.
Definition rdpq_tex.c:700
int palette
Palette number where TLUT is stored (used only for CI4 textures)
Definition rdpq_tex.h:42
int cy
Transformation center (aka "hotspot") X coordinate, relative to (s0, t0). Used for all transformation...
Definition rdpq_tex.h:313
int rdpq_tex_reuse(rdpq_tile_t tile, const rdpq_texparms_t *parms)
Reuse the previously uploaded texture to TMEM.
Definition rdpq_tex.c:453
rdpq_tile_t tile
Base tile descriptor to use (default: TILE_0); notice that two tiles will often be used to do the upl...
Definition rdpq_tex.h:304
bool flip_x
Flip horizontally. If true, the source sub-rect is treated as horizontally flipped (so flipping is pe...
Definition rdpq_tex.h:309
Blitting parameters for rdpq_tex_blit.
Definition rdpq_tex.h:303
Texture sampling parameters for rdpq_tex_upload.
Definition rdpq_tex.h:40
tex_format_t
Pixel format enum.
Definition surface.h:105
A surface buffer for graphics.
Definition surface.h:140