libdragon
Loading...
Searching...
No Matches
rdpq_mode.h
Go to the documentation of this file.
1
91#ifndef LIBDRAGON_RDPQ_MODE_H
92#define LIBDRAGON_RDPQ_MODE_H
93
94#include "rdpq.h"
95#include <stdint.h>
96
97#ifdef __cplusplus
98extern "C" {
99#endif
100
102// Internal helpers, not part of the public API
103inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val);
105
119void rdpq_mode_push(void);
120
128void rdpq_mode_pop(void);
129
138
200typedef enum rdpq_dither_s {
205
210
215
221
225typedef enum rdpq_tlut_s {
230
235 switch (format) {
236 case FMT_CI4:
237 case FMT_CI8:
238 return TLUT_RGBA16;
239 default:
240 return TLUT_NONE;
241 }
242}
243
254
258typedef enum rdpq_antialias_s {
263
264
286void rdpq_set_mode_standard(void);
287
288
301inline void rdpq_set_mode_fill(color_t color) {
302 extern void __rdpq_set_mode_fill(void);
304 rdpq_set_fill_color(color);
305}
306
329void rdpq_set_mode_copy(bool transparency);
330
347void rdpq_set_mode_yuv(bool bilinear);
348
390{
391 // Just enable/disable SOM_AA_ENABLE. The RSP will then update the render mode
392 // which would trigger different other bits in SOM depending on the current mode.
393 __rdpq_mode_change_som(SOM_AA_ENABLE | SOMX_AA_REDUCED,
394 (mode ? SOM_AA_ENABLE : 0) | (mode == AA_REDUCED ? SOMX_AA_REDUCED : 0));
395}
396
468 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
469 extern void __rdpq_fixup_mode4(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3);
470
471 if (comb & RDPQ_COMBINER_2PASS)
472 __rdpq_fixup_mode(RDPQ_CMD_SET_COMBINE_MODE_2PASS,
473 (comb >> 32) & 0x00FFFFFF,
474 comb & 0xFFFFFFFF);
475 else {
476 rdpq_combiner_t comb1_mask = RDPQ_COMB1_MASK;
477 if (((comb >> 0 ) & 7) == 1) comb1_mask ^= 1ull << 0;
478 if (((comb >> 3 ) & 7) == 1) comb1_mask ^= 1ull << 3;
479 if (((comb >> 6 ) & 7) == 1) comb1_mask ^= 1ull << 6;
480 if (((comb >> 18) & 7) == 1) comb1_mask ^= 1ull << 18;
481 if (((comb >> 21) & 7) == 1) comb1_mask ^= 1ull << 21;
482 if (((comb >> 24) & 7) == 1) comb1_mask ^= 1ull << 24;
483 if (((comb >> 32) & 31) == 1) comb1_mask ^= 1ull << 32;
484 if (((comb >> 37) & 15) == 1) comb1_mask ^= 1ull << 37;
485
486 __rdpq_fixup_mode4(RDPQ_CMD_SET_COMBINE_MODE_1PASS,
487 (comb >> 32) & 0x00FFFFFF,
488 comb & 0xFFFFFFFF,
489 (comb1_mask >> 32) & 0x00FFFFFF,
490 comb1_mask & 0xFFFFFFFF);
491 }
492}
493
501#define RDPQ_BLENDER_MULTIPLY RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
502
523#define RDPQ_BLENDER_MULTIPLY_CONST RDPQ_BLENDER((IN_RGB, FOG_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
524
533#define RDPQ_BLENDER_ADDITIVE RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, ONE))
534
602 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
603 if (blend) blend |= SOM_BLENDING;
604 __rdpq_fixup_mode(RDPQ_CMD_SET_BLENDING_MODE, 0, blend);
605}
606
649 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
650 if (fog) fog |= SOM_BLENDING;
651 if (fog) assertf((fog & SOMX_BLEND_2PASS) == 0, "Fogging cannot be used with two-pass blending formulas");
652 __rdpq_mode_change_som(SOMX_FOG, fog ? SOMX_FOG : 0);
653 __rdpq_fixup_mode(RDPQ_CMD_SET_FOG_MODE, 0, fog);
654}
655
671 __rdpq_mode_change_som(
673}
674
696inline void rdpq_mode_alphacompare(int threshold) {
697 if (threshold == 0) {
698 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, 0);
699 } else if (threshold > 0) {
700 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_THRESHOLD);
701 rdpq_set_blend_color(RGBA32(0,0,0,(uint8_t)threshold));
702 } else {
703 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_NOISE);
704 }
705}
706
722inline void rdpq_mode_zbuf(bool compare, bool update) {
723 __rdpq_mode_change_som(
725 (compare ? SOM_Z_COMPARE : 0) |
726 (update ? SOM_Z_WRITE : 0)
727 );
728}
729
747inline void rdpq_mode_zoverride(bool enable, float z, int16_t deltaz) {
748 if (enable) rdpq_set_prim_depth_raw(z * 0x7FFF, deltaz);
749 __rdpq_mode_change_som(
751 );
752}
753
754
768inline void rdpq_mode_tlut(rdpq_tlut_t tlut) {
769 // This assert is useful to catch the common mistake of rdpq_mode_tlut(true)
770 assertf(tlut == TLUT_NONE || tlut == TLUT_RGBA16 || tlut == TLUT_IA16, "invalid TLUT type");
771 __rdpq_mode_change_som(SOM_TLUT_MASK, (uint64_t)tlut << SOM_TLUT_SHIFT);
772}
773
787 __rdpq_mode_change_som(SOM_SAMPLE_MASK, (uint64_t)filt << SOM_SAMPLE_SHIFT);
788}
789
816inline void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels) {
817 if (mode == MIPMAP_NONE)
818 num_levels = 0;
819 if (num_levels)
820 num_levels -= 1;
822 ((uint64_t)mode << 32) | ((uint64_t)num_levels << SOMX_NUMLODS_SHIFT));
823};
824
837inline void rdpq_mode_persp(bool perspective)
838{
839 __rdpq_mode_change_som(SOM_TEXTURE_PERSP, perspective ? SOM_TEXTURE_PERSP : 0);
840}
841
872void rdpq_mode_begin(void);
873
881void rdpq_mode_end(void);
882
883/********************************************************************
884 * Internal functions (not part of public API)
885 ********************************************************************/
886
888inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val)
889{
890 // This is identical to #rdpq_change_other_modes_raw, but we also
891 // set bit 1<<15 in the first word. That flag tells the RSP code
892 // to recalculate the render mode, in addition to flipping the bits.
893 // #rdpq_change_other_modes_raw instead just changes the bits as
894 // you would expect from a raw API.
895 extern void __rdpq_fixup_mode3(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2);
896 if (mask >> 32)
897 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 0 | (1<<15), ~(mask >> 32), val >> 32);
898 if ((uint32_t)mask)
899 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 4 | (1<<15), ~(uint32_t)mask, (uint32_t)val);
900}
902
903
904#ifdef __cplusplus
905}
906#endif
907
908#endif
#define RGBA32(rx, gx, bx, ax)
Create a color_t from the R,G,B,A components in the RGBA32 range (0-255).
Definition graphics.h:74
Generic color structure.
Definition graphics.h:52
void rdpq_set_prim_depth_raw(uint16_t primitive_z, int16_t primitive_delta_z)
Set a fixed Z value to be used instead of a per-pixel value (RDP command; SET_PRIM_DEPTH)
Definition rdpq.h:464
void rdpq_set_fill_color(color_t color)
Enqueue a SET_FILL_COLOR RDP command.
Definition rdpq.h:837
void rdpq_set_blend_color(color_t color)
Set the RDP BLEND blender register.
Definition rdpq.h:917
RDP Command queue.
#define SOM_TEXTURE_DETAIL
Texture: enable "detail".
Definition rdpq_macros.h:529
#define SOM_TEXTURE_SHARPEN
Texture: enable "sharpen".
Definition rdpq_macros.h:530
#define SOM_TLUT_MASK
TLUT mask.
Definition rdpq_macros.h:537
#define SOMX_LOD_INTERPOLATE
RDPQ special state: mimap interpolation (aka trilinear) requested.
Definition rdpq_macros.h:571
#define SOM_Z_WRITE
Activate Z-buffer write.
Definition rdpq_macros.h:594
#define SOM_TLUT_SHIFT
TLUT mask shift.
Definition rdpq_macros.h:538
#define SOM_ALPHACOMPARE_THRESHOLD
Alpha Compare: use blend alpha as threshold.
Definition rdpq_macros.h:606
#define SOM_RGBDITHER_MASK
RGB Dithering mask.
Definition rdpq_macros.h:558
#define SOM_ALPHADITHER_MASK
Alpha Dithering mask.
Definition rdpq_macros.h:565
#define SOM_TEXTURE_LOD
Texture: enable LODs.
Definition rdpq_macros.h:531
#define RDPQ_COMB1_MASK
Combiner: mask to isolate settings related to cycle 1.
Definition rdpq_macros.h:259
#define SOM_TEXTURE_PERSP
Texture: enable perspective correction.
Definition rdpq_macros.h:528
uint64_t rdpq_combiner_t
A combiner formula, created by RDPQ_COMBINER1 or RDPQ_COMBINER2.
Definition rdpq_macros.h:18
#define SOMX_BLEND_2PASS
RDPQ special state: record that the blender is made of 2 passes.
Definition rdpq_macros.h:577
#define SOM_RGBDITHER_NONE
RGB Dithering: none.
Definition rdpq_macros.h:557
#define SOM_SAMPLE_SHIFT
Texture sampling mask shift.
Definition rdpq_macros.h:544
#define SOM_AA_ENABLE
Enable anti-alias.
Definition rdpq_macros.h:612
#define SOM_ALPHADITHER_SHIFT
Alpha Dithering mask shift.
Definition rdpq_macros.h:566
#define SOM_Z_COMPARE
Activate Z-buffer compare.
Definition rdpq_macros.h:597
#define SOMX_AA_REDUCED
RDPQ special state: reduced antialiasing is enabled.
Definition rdpq_macros.h:570
#define SOM_SAMPLE_MEDIAN
Texture sampling: mid-texel average (2x2)
Definition rdpq_macros.h:542
#define SOM_ALPHADITHER_NONE
Alpha Dithering: none.
Definition rdpq_macros.h:564
#define SOM_ALPHACOMPARE_NOISE
Alpha Compare: use noise as threshold.
Definition rdpq_macros.h:607
#define SOM_ALPHADITHER_INVERT
Alpha Dithering: invert pattern compared to RG.
Definition rdpq_macros.h:562
#define SOM_SAMPLE_BILINEAR
Texture sampling: bilinear interpolation (2x2)
Definition rdpq_macros.h:541
#define SOMX_FOG
RDPQ special state: fogging is enabled.
Definition rdpq_macros.h:568
#define SOM_ZSOURCE_PRIM
Z-source: fixed value.
Definition rdpq_macros.h:601
#define SOM_BLENDING
Activate blending for all pixels.
Definition rdpq_macros.h:579
#define SOM_SAMPLE_POINT
Texture sampling: point sampling (1x1)
Definition rdpq_macros.h:540
#define SOM_ALPHACOMPARE_MASK
Alpha Compare mask.
Definition rdpq_macros.h:608
#define SOM_ALPHADITHER_NOISE
Alpha Dithering: noise.
Definition rdpq_macros.h:563
#define SOM_ALPHADITHER_SAME
Alpha Dithering: same as RGB.
Definition rdpq_macros.h:561
#define SOMX_NUMLODS_MASK
Rdpq extension: number of LODs.
Definition rdpq_macros.h:516
uint32_t rdpq_blender_t
A blender formula, created by RDPQ_BLENDER or RDPQ_BLENDER2.
Definition rdpq_macros.h:20
#define SOM_RGBDITHER_SQUARE
RGB Dithering: square filter.
Definition rdpq_macros.h:554
#define SOM_SAMPLE_MASK
Texture sampling mask.
Definition rdpq_macros.h:543
#define RDPQ_COMBINER_2PASS
Flag to mark the combiner as requiring two passes.
Definition rdpq_macros.h:272
#define SOM_RGBDITHER_BAYER
RGB Dithering: bayer filter.
Definition rdpq_macros.h:555
#define SOM_RGBDITHER_NOISE
RGB Dithering: noise.
Definition rdpq_macros.h:556
#define SOMX_NUMLODS_SHIFT
Rdpq extension: number of LODs shift.
Definition rdpq_macros.h:517
void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1)
Write a fixup that changes the current render mode (8-byte command)
Definition rdpq_mode.c:29
void __rdpq_fixup_mode3(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2)
Write a fixup that changes the current render mode (12-byte command)
Definition rdpq_mode.c:37
void __rdpq_fixup_mode4(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3)
Write a fixup that changes the current render mode (16-byte command)
Definition rdpq_mode.c:46
void __rdpq_set_mode_fill(void)
Like rdpq_set_mode_fill, but without fill color configuration.
Definition rdpq_mode.c:75
void rdpq_mode_push(void)
Push the current render mode into the stack.
Definition rdpq_mode.c:62
rdpq_tlut_t rdpq_tlut_from_format(tex_format_t format)
Converts the specified texture format to the TLUT mode that is needed to draw a texture of this forma...
Definition rdpq_mode.h:234
void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels)
Activate mip-mapping.
Definition rdpq_mode.h:816
rdpq_antialias_t
Types of antialiasing supported by RDP.
Definition rdpq_mode.h:258
@ AA_STANDARD
Standard antialiasing.
Definition rdpq_mode.h:260
@ AA_REDUCED
Reduced antialiasing.
Definition rdpq_mode.h:261
@ AA_NONE
No antialiasing.
Definition rdpq_mode.h:259
void rdpq_mode_persp(bool perspective)
Activate perspective correction for textures.
Definition rdpq_mode.h:837
void rdpq_mode_blender(rdpq_blender_t blend)
Configure the formula to use for blending.
Definition rdpq_mode.h:601
void rdpq_set_mode_yuv(bool bilinear)
Reset render mode to YUV mode.
Definition rdpq_mode.c:112
void rdpq_mode_fog(rdpq_blender_t fog)
Enable or disable fog.
Definition rdpq_mode.h:648
void rdpq_mode_combiner(rdpq_combiner_t comb)
Configure the color combiner.
Definition rdpq_mode.h:467
rdpq_filter_t
Texture filtering types.
Definition rdpq_mode.h:133
@ FILTER_POINT
Point filtering (aka nearest)
Definition rdpq_mode.h:134
@ FILTER_BILINEAR
Bilinear filtering.
Definition rdpq_mode.h:135
@ FILTER_MEDIAN
Median filtering.
Definition rdpq_mode.h:136
void rdpq_set_mode_copy(bool transparency)
Reset render mode to COPY type.
Definition rdpq_mode.c:84
void rdpq_mode_antialias(rdpq_antialias_t mode)
Activate antialiasing.
Definition rdpq_mode.h:389
void rdpq_mode_dithering(rdpq_dither_t dither)
Change dithering mode.
Definition rdpq_mode.h:670
void rdpq_set_mode_fill(color_t color)
Reset render mode to FILL type.
Definition rdpq_mode.h:301
void rdpq_mode_zbuf(bool compare, bool update)
Activate z-buffer usage.
Definition rdpq_mode.h:722
rdpq_dither_t
Dithering configuration.
Definition rdpq_mode.h:200
@ DITHER_BAYER_BAYER
Dithering: RGB=Bayer, Alpha=Bayer.
Definition rdpq_mode.h:206
@ DITHER_SQUARE_NOISE
Dithering: RGB=Square, Alpha=Noise.
Definition rdpq_mode.h:203
@ DITHER_BAYER_NONE
Dithering: RGB=Bayer, Alpha=None.
Definition rdpq_mode.h:209
@ DITHER_BAYER_NOISE
Dithering: RGB=Bayer, Alpha=Noise.
Definition rdpq_mode.h:208
@ DITHER_SQUARE_SQUARE
Dithering: RGB=Square, Alpha=Square.
Definition rdpq_mode.h:201
@ DITHER_NOISE_NOISE
Dithering: RGB=Noise, Alpha=Noise.
Definition rdpq_mode.h:213
@ DITHER_NONE_NONE
Dithering: RGB=None, Alpha=None.
Definition rdpq_mode.h:219
@ DITHER_NOISE_INVSQUARE
Dithering: RGB=Noise, Alpha=InvSquare.
Definition rdpq_mode.h:212
@ DITHER_NOISE_NONE
Dithering: RGB=Noise, Alpha=None.
Definition rdpq_mode.h:214
@ DITHER_NONE_INVBAYER
Dithering: RGB=None, Alpha=InvBayer.
Definition rdpq_mode.h:217
@ DITHER_BAYER_INVBAYER
Dithering: RGB=Bayer, Alpha=InvBayer.
Definition rdpq_mode.h:207
@ DITHER_SQUARE_NONE
Dithering: RGB=Square, Alpha=None.
Definition rdpq_mode.h:204
@ DITHER_SQUARE_INVSQUARE
Dithering: RGB=Square, Alpha=InvSquare.
Definition rdpq_mode.h:202
@ DITHER_NONE_NOISE
Dithering: RGB=None, Alpha=Noise.
Definition rdpq_mode.h:218
@ DITHER_NOISE_SQUARE
Dithering: RGB=Noise, Alpha=Square.
Definition rdpq_mode.h:211
@ DITHER_NONE_BAYER
Dithering: RGB=None, Alpha=Bayer.
Definition rdpq_mode.h:216
void rdpq_mode_filter(rdpq_filter_t filt)
Activate texture filtering.
Definition rdpq_mode.h:786
void rdpq_mode_begin(void)
Start a batch of RDP mode changes.
Definition rdpq_mode.c:134
void rdpq_mode_zoverride(bool enable, float z, int16_t deltaz)
Set a fixed override of Z value.
Definition rdpq_mode.h:747
void rdpq_set_mode_standard(void)
Reset render mode to standard.
Definition rdpq_mode.c:93
void rdpq_mode_end(void)
Finish a batch of RDP mode changes.
Definition rdpq_mode.c:144
void rdpq_mode_pop(void)
Pop the current render mode from the stack.
Definition rdpq_mode.c:69
void rdpq_mode_alphacompare(int threshold)
Activate alpha compare feature.
Definition rdpq_mode.h:696
void rdpq_mode_tlut(rdpq_tlut_t tlut)
Activate palette lookup during drawing.
Definition rdpq_mode.h:768
rdpq_mipmap_t
Types of mipmap supported by RDP.
Definition rdpq_mode.h:247
@ MIPMAP_NEAREST
Choose the nearest mipmap level.
Definition rdpq_mode.h:249
@ MIPMAP_INTERPOLATE
Interpolate between the two nearest mipmap levels (also known as "trilinear")
Definition rdpq_mode.h:250
@ MIPMAP_NONE
Mipmap disabled.
Definition rdpq_mode.h:248
@ MIPMAP_INTERPOLATE_DETAIL
Interpolate between the two nearest mipmap levels (also known as "trilinear") with detail texture ena...
Definition rdpq_mode.h:252
@ MIPMAP_INTERPOLATE_SHARPEN
Interpolate between the two nearest mipmap levels (also known as "trilinear") with sharpening enabled...
Definition rdpq_mode.h:251
rdpq_tlut_t
Types of palettes supported by RDP.
Definition rdpq_mode.h:225
@ TLUT_RGBA16
Palette made of FMT_RGBA16 colors.
Definition rdpq_mode.h:227
@ TLUT_IA16
Palette made of FMT_IA16 colors.
Definition rdpq_mode.h:228
@ TLUT_NONE
No palette.
Definition rdpq_mode.h:226
tex_format_t
Pixel format enum.
Definition surface.h:103
@ FMT_CI8
Format CI8: color index 8-bit (paletted, 1 index per byte)
Definition surface.h:110
@ FMT_CI4
Format CI4: color index 4-bit (paletted, 2 indices per byte)
Definition surface.h:109