libdragon
Loading...
Searching...
No Matches
rdpq_mode.h
Go to the documentation of this file.
1
92#ifndef LIBDRAGON_RDPQ_MODE_H
93#define LIBDRAGON_RDPQ_MODE_H
94
95#include "rdpq.h"
96#include <stdint.h>
97
98#ifdef __cplusplus
99extern "C" {
100#endif
101
103// Internal helpers, not part of the public API
104inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val);
106
120void rdpq_mode_push(void);
121
129void rdpq_mode_pop(void);
130
139
201typedef enum rdpq_dither_s {
206
211
216
222
226typedef enum rdpq_tlut_s {
231
236 switch (format) {
237 case FMT_CI4:
238 case FMT_CI8:
239 return TLUT_RGBA16;
240 default:
241 return TLUT_NONE;
242 }
243}
244
255
259typedef enum rdpq_antialias_s {
264
265
287void rdpq_set_mode_standard(void);
288
289
302inline void rdpq_set_mode_fill(color_t color) {
303 extern void __rdpq_set_mode_fill(void);
305 rdpq_set_fill_color(color);
306}
307
330void rdpq_set_mode_copy(bool transparency);
331
348void rdpq_set_mode_yuv(bool bilinear);
349
391{
392 // Just enable/disable SOM_AA_ENABLE. The RSP will then update the render mode
393 // which would trigger different other bits in SOM depending on the current mode.
394 __rdpq_mode_change_som(SOM_AA_ENABLE | SOMX_AA_REDUCED,
395 (mode ? SOM_AA_ENABLE : 0) | (mode == AA_REDUCED ? SOMX_AA_REDUCED : 0));
396}
397
469 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
470 extern void __rdpq_fixup_mode4(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3);
471
472 if (comb & RDPQ_COMBINER_2PASS)
473 __rdpq_fixup_mode(RDPQ_CMD_SET_COMBINE_MODE_2PASS,
474 (comb >> 32) & 0x00FFFFFF,
475 comb & 0xFFFFFFFF);
476 else {
477 rdpq_combiner_t comb1_mask = RDPQ_COMB1_MASK;
478 if (((comb >> 0 ) & 7) == 1) comb1_mask ^= 1ull << 0;
479 if (((comb >> 3 ) & 7) == 1) comb1_mask ^= 1ull << 3;
480 if (((comb >> 6 ) & 7) == 1) comb1_mask ^= 1ull << 6;
481 if (((comb >> 18) & 7) == 1) comb1_mask ^= 1ull << 18;
482 if (((comb >> 21) & 7) == 1) comb1_mask ^= 1ull << 21;
483 if (((comb >> 24) & 7) == 1) comb1_mask ^= 1ull << 24;
484 if (((comb >> 32) & 31) == 1) comb1_mask ^= 1ull << 32;
485 if (((comb >> 37) & 15) == 1) comb1_mask ^= 1ull << 37;
486
487 __rdpq_fixup_mode4(RDPQ_CMD_SET_COMBINE_MODE_1PASS,
488 (comb >> 32) & 0x00FFFFFF,
489 comb & 0xFFFFFFFF,
490 (comb1_mask >> 32) & 0x00FFFFFF,
491 comb1_mask & 0xFFFFFFFF);
492 }
493}
494
502#define RDPQ_BLENDER_MULTIPLY RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
503
524#define RDPQ_BLENDER_MULTIPLY_CONST RDPQ_BLENDER((IN_RGB, FOG_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
525
534#define RDPQ_BLENDER_ADDITIVE RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, ONE))
535
603 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
604 if (blend) blend |= SOM_BLENDING;
605 __rdpq_fixup_mode(RDPQ_CMD_SET_BLENDING_MODE, 0, blend);
606}
607
650 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
651 if (fog) fog |= SOM_BLENDING;
652 if (fog) assertf((fog & SOMX_BLEND_2PASS) == 0, "Fogging cannot be used with two-pass blending formulas");
653 __rdpq_mode_change_som(SOMX_FOG, fog ? SOMX_FOG : 0);
654 __rdpq_fixup_mode(RDPQ_CMD_SET_FOG_MODE, 0, fog);
655}
656
672 __rdpq_mode_change_som(
674}
675
697inline void rdpq_mode_alphacompare(int threshold) {
698 if (threshold == 0) {
699 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, 0);
700 } else if (threshold > 0) {
701 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_THRESHOLD);
702 rdpq_set_blend_color(RGBA32(0,0,0,(uint8_t)threshold));
703 } else {
704 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_NOISE);
705 }
706}
707
723inline void rdpq_mode_zbuf(bool compare, bool update) {
724 __rdpq_mode_change_som(
726 (compare ? SOM_Z_COMPARE : 0) |
727 (update ? SOM_Z_WRITE : 0)
728 );
729}
730
748inline void rdpq_mode_zoverride(bool enable, float z, int16_t deltaz) {
749 if (enable) rdpq_set_prim_depth_raw(z * 0x7FFF, deltaz);
750 __rdpq_mode_change_som(
752 );
753}
754
755
769inline void rdpq_mode_tlut(rdpq_tlut_t tlut) {
770 // This assert is useful to catch the common mistake of rdpq_mode_tlut(true)
771 assertf(tlut == TLUT_NONE || tlut == TLUT_RGBA16 || tlut == TLUT_IA16, "invalid TLUT type");
772 __rdpq_mode_change_som(SOM_TLUT_MASK, (uint64_t)tlut << SOM_TLUT_SHIFT);
773}
774
788 __rdpq_mode_change_som(SOM_SAMPLE_MASK, (uint64_t)filt << SOM_SAMPLE_SHIFT);
789}
790
817inline void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels) {
818 if (mode == MIPMAP_NONE)
819 num_levels = 0;
820 if (num_levels)
821 num_levels -= 1;
823 ((uint64_t)mode << 32) | ((uint64_t)num_levels << SOMX_NUMLODS_SHIFT));
824};
825
838inline void rdpq_mode_persp(bool perspective)
839{
840 __rdpq_mode_change_som(SOM_TEXTURE_PERSP, perspective ? SOM_TEXTURE_PERSP : 0);
841}
842
873void rdpq_mode_begin(void);
874
882void rdpq_mode_end(void);
883
884/********************************************************************
885 * Internal functions (not part of public API)
886 ********************************************************************/
887
889inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val)
890{
891 // This is identical to #rdpq_change_other_modes_raw, but we also
892 // set bit 1<<15 in the first word. That flag tells the RSP code
893 // to recalculate the render mode, in addition to flipping the bits.
894 // #rdpq_change_other_modes_raw instead just changes the bits as
895 // you would expect from a raw API.
896 extern void __rdpq_fixup_mode3(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2);
897 if (mask >> 32)
898 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 0 | (1<<15), ~(mask >> 32), val >> 32);
899 if ((uint32_t)mask)
900 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 4 | (1<<15), ~(uint32_t)mask, (uint32_t)val);
901}
903
904
905#ifdef __cplusplus
906}
907#endif
908
909#endif
#define assertf(expr, msg,...)
assertf() is like assert() with an attached printf().
Definition debug.h:196
#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:76
Generic color structure.
Definition graphics.h:54
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:465
void rdpq_set_fill_color(color_t color)
Enqueue a SET_FILL_COLOR RDP command.
Definition rdpq.h:838
void rdpq_set_blend_color(color_t color)
Set the RDP BLEND blender register.
Definition rdpq.h:918
RDP Command queue.
#define SOM_TEXTURE_DETAIL
Texture: enable "detail".
Definition rdpq_macros.h:530
#define SOM_TEXTURE_SHARPEN
Texture: enable "sharpen".
Definition rdpq_macros.h:531
#define SOM_TLUT_MASK
TLUT mask.
Definition rdpq_macros.h:538
#define SOMX_LOD_INTERPOLATE
RDPQ special state: mimap interpolation (aka trilinear) requested.
Definition rdpq_macros.h:572
#define SOM_Z_WRITE
Activate Z-buffer write.
Definition rdpq_macros.h:595
#define SOM_TLUT_SHIFT
TLUT mask shift.
Definition rdpq_macros.h:539
#define SOM_ALPHACOMPARE_THRESHOLD
Alpha Compare: use blend alpha as threshold.
Definition rdpq_macros.h:607
#define SOM_RGBDITHER_MASK
RGB Dithering mask.
Definition rdpq_macros.h:559
#define SOM_ALPHADITHER_MASK
Alpha Dithering mask.
Definition rdpq_macros.h:566
#define SOM_TEXTURE_LOD
Texture: enable LODs.
Definition rdpq_macros.h:532
#define RDPQ_COMB1_MASK
Combiner: mask to isolate settings related to cycle 1.
Definition rdpq_macros.h:260
#define SOM_TEXTURE_PERSP
Texture: enable perspective correction.
Definition rdpq_macros.h:529
uint64_t rdpq_combiner_t
A combiner formula, created by RDPQ_COMBINER1 or RDPQ_COMBINER2.
Definition rdpq_macros.h:19
#define SOMX_BLEND_2PASS
RDPQ special state: record that the blender is made of 2 passes.
Definition rdpq_macros.h:578
#define SOM_RGBDITHER_NONE
RGB Dithering: none.
Definition rdpq_macros.h:558
#define SOM_SAMPLE_SHIFT
Texture sampling mask shift.
Definition rdpq_macros.h:545
#define SOM_AA_ENABLE
Enable anti-alias.
Definition rdpq_macros.h:613
#define SOM_ALPHADITHER_SHIFT
Alpha Dithering mask shift.
Definition rdpq_macros.h:567
#define SOM_Z_COMPARE
Activate Z-buffer compare.
Definition rdpq_macros.h:598
#define SOMX_AA_REDUCED
RDPQ special state: reduced antialiasing is enabled.
Definition rdpq_macros.h:571
#define SOM_SAMPLE_MEDIAN
Texture sampling: mid-texel average (2x2)
Definition rdpq_macros.h:543
#define SOM_ALPHADITHER_NONE
Alpha Dithering: none.
Definition rdpq_macros.h:565
#define SOM_ALPHACOMPARE_NOISE
Alpha Compare: use noise as threshold.
Definition rdpq_macros.h:608
#define SOM_ALPHADITHER_INVERT
Alpha Dithering: invert pattern compared to RG.
Definition rdpq_macros.h:563
#define SOM_SAMPLE_BILINEAR
Texture sampling: bilinear interpolation (2x2)
Definition rdpq_macros.h:542
#define SOMX_FOG
RDPQ special state: fogging is enabled.
Definition rdpq_macros.h:569
#define SOM_ZSOURCE_PRIM
Z-source: fixed value.
Definition rdpq_macros.h:602
#define SOM_BLENDING
Activate blending for all pixels.
Definition rdpq_macros.h:580
#define SOM_SAMPLE_POINT
Texture sampling: point sampling (1x1)
Definition rdpq_macros.h:541
#define SOM_ALPHACOMPARE_MASK
Alpha Compare mask.
Definition rdpq_macros.h:609
#define SOM_ALPHADITHER_NOISE
Alpha Dithering: noise.
Definition rdpq_macros.h:564
#define SOM_ALPHADITHER_SAME
Alpha Dithering: same as RGB.
Definition rdpq_macros.h:562
#define SOMX_NUMLODS_MASK
Rdpq extension: number of LODs.
Definition rdpq_macros.h:517
uint32_t rdpq_blender_t
A blender formula, created by RDPQ_BLENDER or RDPQ_BLENDER2.
Definition rdpq_macros.h:21
#define SOM_RGBDITHER_SQUARE
RGB Dithering: square filter.
Definition rdpq_macros.h:555
#define SOM_SAMPLE_MASK
Texture sampling mask.
Definition rdpq_macros.h:544
#define RDPQ_COMBINER_2PASS
Flag to mark the combiner as requiring two passes.
Definition rdpq_macros.h:273
#define SOM_RGBDITHER_BAYER
RGB Dithering: bayer filter.
Definition rdpq_macros.h:556
#define SOM_RGBDITHER_NOISE
RGB Dithering: noise.
Definition rdpq_macros.h:557
#define SOMX_NUMLODS_SHIFT
Rdpq extension: number of LODs shift.
Definition rdpq_macros.h:518
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:30
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:38
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:47
void __rdpq_set_mode_fill(void)
Like rdpq_set_mode_fill, but without fill color configuration.
Definition rdpq_mode.c:79
void rdpq_mode_push(void)
Push the current render mode into the stack.
Definition rdpq_mode.c:63
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:235
void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels)
Activate mip-mapping.
Definition rdpq_mode.h:817
rdpq_antialias_t
Types of antialiasing supported by RDP.
Definition rdpq_mode.h:259
@ AA_STANDARD
Standard antialiasing.
Definition rdpq_mode.h:261
@ AA_REDUCED
Reduced antialiasing.
Definition rdpq_mode.h:262
@ AA_NONE
No antialiasing.
Definition rdpq_mode.h:260
void rdpq_mode_persp(bool perspective)
Activate perspective correction for textures.
Definition rdpq_mode.h:838
void rdpq_mode_blender(rdpq_blender_t blend)
Configure the formula to use for blending.
Definition rdpq_mode.h:602
void rdpq_set_mode_yuv(bool bilinear)
Reset render mode to YUV mode.
Definition rdpq_mode.c:116
void rdpq_mode_fog(rdpq_blender_t fog)
Enable or disable fog.
Definition rdpq_mode.h:649
void rdpq_mode_combiner(rdpq_combiner_t comb)
Configure the color combiner.
Definition rdpq_mode.h:468
rdpq_filter_t
Texture filtering types.
Definition rdpq_mode.h:134
@ FILTER_POINT
Point filtering (aka nearest)
Definition rdpq_mode.h:135
@ FILTER_BILINEAR
Bilinear filtering.
Definition rdpq_mode.h:136
@ FILTER_MEDIAN
Median filtering.
Definition rdpq_mode.h:137
void rdpq_set_mode_copy(bool transparency)
Reset render mode to COPY type.
Definition rdpq_mode.c:88
void rdpq_mode_antialias(rdpq_antialias_t mode)
Activate antialiasing.
Definition rdpq_mode.h:390
void rdpq_mode_dithering(rdpq_dither_t dither)
Change dithering mode.
Definition rdpq_mode.h:671
void rdpq_set_mode_fill(color_t color)
Reset render mode to FILL type.
Definition rdpq_mode.h:302
void rdpq_mode_zbuf(bool compare, bool update)
Activate z-buffer usage.
Definition rdpq_mode.h:723
rdpq_dither_t
Dithering configuration.
Definition rdpq_mode.h:201
@ DITHER_BAYER_BAYER
Dithering: RGB=Bayer, Alpha=Bayer.
Definition rdpq_mode.h:207
@ DITHER_SQUARE_NOISE
Dithering: RGB=Square, Alpha=Noise.
Definition rdpq_mode.h:204
@ DITHER_BAYER_NONE
Dithering: RGB=Bayer, Alpha=None.
Definition rdpq_mode.h:210
@ DITHER_BAYER_NOISE
Dithering: RGB=Bayer, Alpha=Noise.
Definition rdpq_mode.h:209
@ DITHER_SQUARE_SQUARE
Dithering: RGB=Square, Alpha=Square.
Definition rdpq_mode.h:202
@ DITHER_NOISE_NOISE
Dithering: RGB=Noise, Alpha=Noise.
Definition rdpq_mode.h:214
@ DITHER_NONE_NONE
Dithering: RGB=None, Alpha=None.
Definition rdpq_mode.h:220
@ DITHER_NOISE_INVSQUARE
Dithering: RGB=Noise, Alpha=InvSquare.
Definition rdpq_mode.h:213
@ DITHER_NOISE_NONE
Dithering: RGB=Noise, Alpha=None.
Definition rdpq_mode.h:215
@ DITHER_NONE_INVBAYER
Dithering: RGB=None, Alpha=InvBayer.
Definition rdpq_mode.h:218
@ DITHER_BAYER_INVBAYER
Dithering: RGB=Bayer, Alpha=InvBayer.
Definition rdpq_mode.h:208
@ DITHER_SQUARE_NONE
Dithering: RGB=Square, Alpha=None.
Definition rdpq_mode.h:205
@ DITHER_SQUARE_INVSQUARE
Dithering: RGB=Square, Alpha=InvSquare.
Definition rdpq_mode.h:203
@ DITHER_NONE_NOISE
Dithering: RGB=None, Alpha=Noise.
Definition rdpq_mode.h:219
@ DITHER_NOISE_SQUARE
Dithering: RGB=Noise, Alpha=Square.
Definition rdpq_mode.h:212
@ DITHER_NONE_BAYER
Dithering: RGB=None, Alpha=Bayer.
Definition rdpq_mode.h:217
void rdpq_mode_filter(rdpq_filter_t filt)
Activate texture filtering.
Definition rdpq_mode.h:787
void rdpq_mode_begin(void)
Start a batch of RDP mode changes.
Definition rdpq_mode.c:138
void rdpq_mode_zoverride(bool enable, float z, int16_t deltaz)
Set a fixed override of Z value.
Definition rdpq_mode.h:748
void rdpq_set_mode_standard(void)
Reset render mode to standard.
Definition rdpq_mode.c:97
void rdpq_mode_end(void)
Finish a batch of RDP mode changes.
Definition rdpq_mode.c:148
void rdpq_mode_pop(void)
Pop the current render mode from the stack.
Definition rdpq_mode.c:70
void rdpq_mode_alphacompare(int threshold)
Activate alpha compare feature.
Definition rdpq_mode.h:697
void rdpq_mode_tlut(rdpq_tlut_t tlut)
Activate palette lookup during drawing.
Definition rdpq_mode.h:769
rdpq_mipmap_t
Types of mipmap supported by RDP.
Definition rdpq_mode.h:248
@ MIPMAP_NEAREST
Choose the nearest mipmap level.
Definition rdpq_mode.h:250
@ MIPMAP_INTERPOLATE
Interpolate between the two nearest mipmap levels (also known as "trilinear")
Definition rdpq_mode.h:251
@ MIPMAP_NONE
Mipmap disabled.
Definition rdpq_mode.h:249
@ MIPMAP_INTERPOLATE_DETAIL
Interpolate between the two nearest mipmap levels (also known as "trilinear") with detail texture ena...
Definition rdpq_mode.h:253
@ MIPMAP_INTERPOLATE_SHARPEN
Interpolate between the two nearest mipmap levels (also known as "trilinear") with sharpening enabled...
Definition rdpq_mode.h:252
rdpq_tlut_t
Types of palettes supported by RDP.
Definition rdpq_mode.h:226
@ TLUT_RGBA16
Palette made of FMT_RGBA16 colors.
Definition rdpq_mode.h:228
@ TLUT_IA16
Palette made of FMT_IA16 colors.
Definition rdpq_mode.h:229
@ TLUT_NONE
No palette.
Definition rdpq_mode.h:227
tex_format_t
Pixel format enum.
Definition surface.h:105
@ FMT_CI8
Format CI8: color index 8-bit (paletted, 1 index per byte)
Definition surface.h:112
@ FMT_CI4
Format CI4: color index 4-bit (paletted, 2 indices per byte)
Definition surface.h:111