libdragon
Loading...
Searching...
No Matches
rdpq_mode.h
Go to the documentation of this file.
1
89#ifndef LIBDRAGON_RDPQ_MODE_H
90#define LIBDRAGON_RDPQ_MODE_H
91
92#include "rdpq.h"
93#include <stdint.h>
94
95#ifdef __cplusplus
96extern "C" {
97#endif
98
100// Internal helpers, not part of the public API
101inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val);
103
117void rdpq_mode_push(void);
118
126void rdpq_mode_pop(void);
127
136
198typedef enum rdpq_dither_s {
203
208
213
219
223typedef enum rdpq_tlut_s {
228
233 switch (format) {
234 case FMT_CI4:
235 case FMT_CI8:
236 return TLUT_RGBA16;
237 default:
238 return TLUT_NONE;
239 }
240}
241
252
256typedef enum rdpq_antialias_s {
261
262
284void rdpq_set_mode_standard(void);
285
286
299inline void rdpq_set_mode_fill(color_t color) {
300 extern void __rdpq_set_mode_fill(void);
302 rdpq_set_fill_color(color);
303}
304
327void rdpq_set_mode_copy(bool transparency);
328
345void rdpq_set_mode_yuv(bool bilinear);
346
388{
389 // Just enable/disable SOM_AA_ENABLE. The RSP will then update the render mode
390 // which would trigger different other bits in SOM depending on the current mode.
391 __rdpq_mode_change_som(SOM_AA_ENABLE | SOMX_AA_REDUCED,
392 (mode ? SOM_AA_ENABLE : 0) | (mode == AA_REDUCED ? SOMX_AA_REDUCED : 0));
393}
394
466 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
467 extern void __rdpq_fixup_mode4(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3);
468
469 if (comb & RDPQ_COMBINER_2PASS)
470 __rdpq_fixup_mode(RDPQ_CMD_SET_COMBINE_MODE_2PASS,
471 (comb >> 32) & 0x00FFFFFF,
472 comb & 0xFFFFFFFF);
473 else {
474 rdpq_combiner_t comb1_mask = RDPQ_COMB1_MASK;
475 if (((comb >> 0 ) & 7) == 1) comb1_mask ^= 1ull << 0;
476 if (((comb >> 3 ) & 7) == 1) comb1_mask ^= 1ull << 3;
477 if (((comb >> 6 ) & 7) == 1) comb1_mask ^= 1ull << 6;
478 if (((comb >> 18) & 7) == 1) comb1_mask ^= 1ull << 18;
479 if (((comb >> 21) & 7) == 1) comb1_mask ^= 1ull << 21;
480 if (((comb >> 24) & 7) == 1) comb1_mask ^= 1ull << 24;
481 if (((comb >> 32) & 31) == 1) comb1_mask ^= 1ull << 32;
482 if (((comb >> 37) & 15) == 1) comb1_mask ^= 1ull << 37;
483
484 __rdpq_fixup_mode4(RDPQ_CMD_SET_COMBINE_MODE_1PASS,
485 (comb >> 32) & 0x00FFFFFF,
486 comb & 0xFFFFFFFF,
487 (comb1_mask >> 32) & 0x00FFFFFF,
488 comb1_mask & 0xFFFFFFFF);
489 }
490}
491
499#define RDPQ_BLENDER_MULTIPLY RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
500
521#define RDPQ_BLENDER_MULTIPLY_CONST RDPQ_BLENDER((IN_RGB, FOG_ALPHA, MEMORY_RGB, INV_MUX_ALPHA))
522
531#define RDPQ_BLENDER_ADDITIVE RDPQ_BLENDER((IN_RGB, IN_ALPHA, MEMORY_RGB, ONE))
532
600 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
601 if (blend) blend |= SOM_BLENDING;
602 __rdpq_fixup_mode(RDPQ_CMD_SET_BLENDING_MODE, 0, blend);
603}
604
607#define RDPQ_FOG_STANDARD RDPQ_BLENDER((IN_RGB, SHADE_ALPHA, FOG_RGB, INV_MUX_ALPHA))
608
651 extern void __rdpq_fixup_mode(uint32_t cmd_id, uint32_t w0, uint32_t w1);
652 if (fog) fog |= SOM_BLENDING;
653 if (fog) assertf((fog & SOMX_BLEND_2PASS) == 0, "Fogging cannot be used with two-pass blending formulas");
654 __rdpq_mode_change_som(SOMX_FOG, fog ? SOMX_FOG : 0);
655 __rdpq_fixup_mode(RDPQ_CMD_SET_FOG_MODE, 0, fog);
656}
657
673 __rdpq_mode_change_som(
675}
676
698inline void rdpq_mode_alphacompare(int threshold) {
699 if (threshold == 0) {
700 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, 0);
701 } else if (threshold > 0) {
702 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_THRESHOLD);
703 rdpq_set_blend_color(RGBA32(0,0,0,(uint8_t)threshold));
704 } else {
705 __rdpq_mode_change_som(SOM_ALPHACOMPARE_MASK, SOM_ALPHACOMPARE_NOISE);
706 }
707}
708
724inline void rdpq_mode_zbuf(bool compare, bool update) {
725 __rdpq_mode_change_som(
727 (compare ? SOM_Z_COMPARE : 0) |
728 (update ? SOM_Z_WRITE : 0)
729 );
730}
731
749inline void rdpq_mode_zoverride(bool enable, float z, int16_t deltaz) {
750 if (enable) rdpq_set_prim_depth_raw(z * 0x7FFF, deltaz);
751 __rdpq_mode_change_som(
753 );
754}
755
756
770inline void rdpq_mode_tlut(rdpq_tlut_t tlut) {
771 // This assert is useful to catch the common mistake of rdpq_mode_tlut(true)
772 assertf(tlut == TLUT_NONE || tlut == TLUT_RGBA16 || tlut == TLUT_IA16, "invalid TLUT type");
773 __rdpq_mode_change_som(SOM_TLUT_MASK, (uint64_t)tlut << SOM_TLUT_SHIFT);
774}
775
789 __rdpq_mode_change_som(SOM_SAMPLE_MASK, (uint64_t)filt << SOM_SAMPLE_SHIFT);
790}
791
808inline void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels) {
809 if (mode == MIPMAP_NONE)
810 num_levels = 0;
811 if (num_levels)
812 num_levels -= 1;
814 ((uint64_t)mode << 32) | ((uint64_t)num_levels << SOMX_NUMLODS_SHIFT));
815};
816
829inline void rdpq_mode_persp(bool perspective)
830{
831 __rdpq_mode_change_som(SOM_TEXTURE_PERSP, perspective ? SOM_TEXTURE_PERSP : 0);
832}
833
864void rdpq_mode_begin(void);
865
873void rdpq_mode_end(void);
874
875/********************************************************************
876 * Internal functions (not part of public API)
877 ********************************************************************/
878
880inline void __rdpq_mode_change_som(uint64_t mask, uint64_t val)
881{
882 // This is identical to #rdpq_change_other_modes_raw, but we also
883 // set bit 1<<15 in the first word. That flag tells the RSP code
884 // to recalculate the render mode, in addition to flipping the bits.
885 // #rdpq_change_other_modes_raw instead just changes the bits as
886 // you would expect from a raw API.
887 extern void __rdpq_fixup_mode3(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t w2);
888 if (mask >> 32)
889 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 0 | (1<<15), ~(mask >> 32), val >> 32);
890 if ((uint32_t)mask)
891 __rdpq_fixup_mode3(RDPQ_CMD_MODIFY_OTHER_MODES, 4 | (1<<15), ~(uint32_t)mask, (uint32_t)val);
892}
894
895
896#ifdef __cplusplus
897}
898#endif
899
900#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:232
void rdpq_mode_mipmap(rdpq_mipmap_t mode, int num_levels)
Activate mip-mapping.
Definition rdpq_mode.h:808
rdpq_antialias_t
Types of antialiasing supported by RDP.
Definition rdpq_mode.h:256
@ AA_STANDARD
Standard antialiasing.
Definition rdpq_mode.h:258
@ AA_REDUCED
Reduced antialiasing.
Definition rdpq_mode.h:259
@ AA_NONE
No antialiasing.
Definition rdpq_mode.h:257
void rdpq_mode_persp(bool perspective)
Activate perspective correction for textures.
Definition rdpq_mode.h:829
void rdpq_mode_blender(rdpq_blender_t blend)
Configure the formula to use for blending.
Definition rdpq_mode.h:599
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:650
void rdpq_mode_combiner(rdpq_combiner_t comb)
Configure the color combiner.
Definition rdpq_mode.h:465
rdpq_filter_t
Texture filtering types.
Definition rdpq_mode.h:131
@ FILTER_POINT
Point filtering (aka nearest)
Definition rdpq_mode.h:132
@ FILTER_BILINEAR
Bilinear filtering.
Definition rdpq_mode.h:133
@ FILTER_MEDIAN
Median filtering.
Definition rdpq_mode.h:134
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:387
void rdpq_mode_dithering(rdpq_dither_t dither)
Change dithering mode.
Definition rdpq_mode.h:672
void rdpq_set_mode_fill(color_t color)
Reset render mode to FILL type.
Definition rdpq_mode.h:299
void rdpq_mode_zbuf(bool compare, bool update)
Activate z-buffer usage.
Definition rdpq_mode.h:724
rdpq_dither_t
Dithering configuration.
Definition rdpq_mode.h:198
@ DITHER_BAYER_BAYER
Dithering: RGB=Bayer, Alpha=Bayer.
Definition rdpq_mode.h:204
@ DITHER_SQUARE_NOISE
Dithering: RGB=Square, Alpha=Noise.
Definition rdpq_mode.h:201
@ DITHER_BAYER_NONE
Dithering: RGB=Bayer, Alpha=None.
Definition rdpq_mode.h:207
@ DITHER_BAYER_NOISE
Dithering: RGB=Bayer, Alpha=Noise.
Definition rdpq_mode.h:206
@ DITHER_SQUARE_SQUARE
Dithering: RGB=Square, Alpha=Square.
Definition rdpq_mode.h:199
@ DITHER_NOISE_NOISE
Dithering: RGB=Noise, Alpha=Noise.
Definition rdpq_mode.h:211
@ DITHER_NONE_NONE
Dithering: RGB=None, Alpha=None.
Definition rdpq_mode.h:217
@ DITHER_NOISE_INVSQUARE
Dithering: RGB=Noise, Alpha=InvSquare.
Definition rdpq_mode.h:210
@ DITHER_NOISE_NONE
Dithering: RGB=Noise, Alpha=None.
Definition rdpq_mode.h:212
@ DITHER_NONE_INVBAYER
Dithering: RGB=None, Alpha=InvBayer.
Definition rdpq_mode.h:215
@ DITHER_BAYER_INVBAYER
Dithering: RGB=Bayer, Alpha=InvBayer.
Definition rdpq_mode.h:205
@ DITHER_SQUARE_NONE
Dithering: RGB=Square, Alpha=None.
Definition rdpq_mode.h:202
@ DITHER_SQUARE_INVSQUARE
Dithering: RGB=Square, Alpha=InvSquare.
Definition rdpq_mode.h:200
@ DITHER_NONE_NOISE
Dithering: RGB=None, Alpha=Noise.
Definition rdpq_mode.h:216
@ DITHER_NOISE_SQUARE
Dithering: RGB=Noise, Alpha=Square.
Definition rdpq_mode.h:209
@ DITHER_NONE_BAYER
Dithering: RGB=None, Alpha=Bayer.
Definition rdpq_mode.h:214
void rdpq_mode_filter(rdpq_filter_t filt)
Activate texture filtering.
Definition rdpq_mode.h:788
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:749
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:698
void rdpq_mode_tlut(rdpq_tlut_t tlut)
Activate palette lookup during drawing.
Definition rdpq_mode.h:770
rdpq_mipmap_t
Types of mipmap supported by RDP.
Definition rdpq_mode.h:245
@ MIPMAP_NEAREST
Choose the nearest mipmap level.
Definition rdpq_mode.h:247
@ MIPMAP_INTERPOLATE
Interpolate between the two nearest mipmap levels (also known as "trilinear")
Definition rdpq_mode.h:248
@ MIPMAP_NONE
Mipmap disabled.
Definition rdpq_mode.h:246
@ MIPMAP_INTERPOLATE_DETAIL
Interpolate between the two nearest mipmap levels (also known as "trilinear") with detail texture ena...
Definition rdpq_mode.h:250
@ MIPMAP_INTERPOLATE_SHARPEN
Interpolate between the two nearest mipmap levels (also known as "trilinear") with sharpening enabled...
Definition rdpq_mode.h:249
rdpq_tlut_t
Types of palettes supported by RDP.
Definition rdpq_mode.h:223
@ TLUT_RGBA16
Palette made of FMT_RGBA16 colors.
Definition rdpq_mode.h:225
@ TLUT_IA16
Palette made of FMT_IA16 colors.
Definition rdpq_mode.h:226
@ TLUT_NONE
No palette.
Definition rdpq_mode.h:224
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