Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamped display antialiasing options into filters #408

Merged
merged 18 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/audioplayer/audioplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ int main(void) {
debug_init_isviewer();
debug_init_usblog();

display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE);
display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, FILTERS_RESAMPLE);
dfs_init(DFS_DEFAULT_LOCATION);

char sbuf[1024];
Expand Down
2 changes: 1 addition & 1 deletion examples/customfont/customfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int main(void)
{
/* Initialize peripherals */
display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE );
dfs_init( DFS_DEFAULT_LOCATION );
rdp_init();
controller_init();
Expand Down
2 changes: 1 addition & 1 deletion examples/loadspritefromsd/loadspritefromsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void load_sprite(int id) {

int main(void) {
/* Initialize peripherals */
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE);
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE);
dfs_init(DFS_DEFAULT_LOCATION);
controller_init();

Expand Down
2 changes: 1 addition & 1 deletion examples/mixertest/mixertest.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(void) {
debug_init_usblog();
debug_init_isviewer();
controller_init();
display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE);
display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, FILTERS_RESAMPLE);

int ret = dfs_init(DFS_DEFAULT_LOCATION);
assert(ret == DFS_ESUCCESS);
Expand Down
2 changes: 1 addition & 1 deletion examples/rtctest/rtctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void update_joystick_directions( void )

int main(void)
{
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
controller_init();
timer_init();

Expand Down
2 changes: 1 addition & 1 deletion examples/spritemap/spritemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(void)
int mode = 0;

/* Initialize peripherals */
display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE );
dfs_init( DFS_DEFAULT_LOCATION );
rdp_init();
controller_init();
Expand Down
10 changes: 5 additions & 5 deletions examples/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sprite_t *read_sprite( const char * const spritename )
int main(void)
{
/* Initialize peripherals */
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
dfs_init( DFS_DEFAULT_LOCATION );
controller_init();

Expand Down Expand Up @@ -127,31 +127,31 @@ int main(void)
display_close();

res = RESOLUTION_640x480;
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
}

if( keys.c[0].down )
{
display_close();

res = RESOLUTION_320x240;
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
}

if( keys.c[0].left )
{
display_close();

bit = DEPTH_16_BPP;
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
}

if( keys.c[0].right )
{
display_close();

bit = DEPTH_32_BPP;
display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( res, bit, 2, GAMMA_NONE, FILTERS_RESAMPLE );
}
}
}
4 changes: 2 additions & 2 deletions examples/vtest/vtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void delay(int cnt)
void init_n64(void)
{
/* Initialize peripherals */
display_init( RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE );

register_VI_handler(vblCallback);

Expand Down Expand Up @@ -203,7 +203,7 @@ int main(void)
res++;
res %= 6;
display_close();
display_init(mode[res], DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE);
display_init(mode[res], DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE);
}
}

Expand Down
82 changes: 66 additions & 16 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,76 @@ typedef enum
/** @brief Valid gamma correction settings */
typedef enum
{
/** @brief Uncorrected gamma */
/** @brief Uncorrected gamma, should be used by default and with assets built by libdragon tools */
GAMMA_NONE,
/** @brief Corrected gamma */
/** @brief Corrected gamma, should be used on a 32-bit framebuffer
* only when assets have been produced in linear color space and accurate blending is important */
GAMMA_CORRECT,
/** @brief Corrected gamma with hardware dither */
/** @brief Corrected gamma with hardware dithered output */
GAMMA_CORRECT_DITHER
} gamma_t;

/** @brief Valid antialiasing settings */
/** @brief Valid display filter options.
*
* Libdragon uses preconfigured options for enabling certain
* combinations of Video Interface filters due to a large number of wrong/invalid configurations
* with very strict conditions, and to simplify the options for the user.
*
* Like for example antialiasing requiring resampling; dedithering not working with
* resampling, unless always fetching; always enabling divot filter under AA etc.
*
* The options below provide all possible configurations that are deemed useful in development. */
typedef enum
{
/** @brief No anti-aliasing */
ANTIALIAS_OFF,
/** @brief Resampling anti-aliasing */
ANTIALIAS_RESAMPLE,
/** @brief Anti-aliasing and resampling with fetch-on-need */
ANTIALIAS_RESAMPLE_FETCH_NEEDED,
/** @brief Anti-aliasing and resampling with fetch-always */
ANTIALIAS_RESAMPLE_FETCH_ALWAYS
} antialias_t;
/** @brief All display filters are disabled */
FILTERS_DISABLED,
/** @brief Resize the output image with a bilinear filter.
* In general, VI is in charge of resizing the framebuffer to fit the TV resolution
* (which is always NTSC 640x480 or PAL 640x512).
* This option enables a bilinear interpolation that can be used during this resize. */
FILTERS_RESAMPLE,
/** @brief Reconstruct a 32-bit output from dithered 16-bit framebuffer. */
FILTERS_DEDITHER,
/** @brief Resize the output image with a bilinear filter (see #FILTERS_RESAMPLE).
* Add a video interface anti-aliasing pass with a divot filter.
* To be able to see correct anti-aliased output, this display filter must be enabled,
* along with anti-aliased rendering of surfaces. */
FILTERS_RESAMPLE_ANTIALIAS,
/** @brief Resize the output image with a bilinear filter (see #FILTERS_RESAMPLE).
* Add a video interface anti-aliasing pass with a divot filter (see #FILTERS_RESAMPLE_ANTIALIAS).
* Reconstruct a 32-bit output from dithered 16-bit framebuffer. */
FILTERS_RESAMPLE_ANTIALIAS_DEDITHER
} filter_options_t;

///@cond
/**
* @brief Display anti-aliasing options (DEPRECATED: Use #filter_options_t instead)
*
* @see #filter_options_t
*/
typedef filter_options_t antialias_t;
/** @brief Display no anti-aliasing (DEPRECATED: Use #FILTERS_DISABLED instead)
*
* @see #filter_options_t
*/
#define ANTIALIAS_OFF FILTERS_DISABLED
/** @brief Display resampling anti-aliasing (DEPRECATED: Use #FILTERS_RESAMPLE instead)
*
* @see #filter_options_t
*/
#define ANTIALIAS_RESAMPLE FILTERS_RESAMPLE
/** @brief Display anti-aliasing and resampling with fetch-on-need (DEPRECATED: Use #FILTERS_RESAMPLE_ANTIALIAS instead)
*
* @see #filter_options_t
*/
#define ANTIALIAS_RESAMPLE_FETCH_NEEDED FILTERS_RESAMPLE_ANTIALIAS
/** @brief Display anti-aliasing and resampling with fetch-always (DEPRECATED: Use #FILTERS_RESAMPLE_ANTIALIAS_DEDITHER instead)
*
* @see #filter_options_t
*/
#define ANTIALIAS_RESAMPLE_FETCH_ALWAYS FILTERS_RESAMPLE_ANTIALIAS_DEDITHER

///@endcond

/**
* @brief Display context (DEPRECATED: Use #surface_t instead)
Expand Down Expand Up @@ -139,10 +189,10 @@ extern "C" {
* so that slowdowns don't impact too much.
* @param[in] gamma
* The requested gamma setting
* @param[in] aa
* The requested anti-aliasing setting
* @param[in] filters
* The requested display filtering options, see #filter_options_t
*/
void display_init( resolution_t res, bitdepth_t bit, uint32_t num_buffers, gamma_t gamma, antialias_t aa );
void display_init( resolution_t res, bitdepth_t bit, uint32_t num_buffers, gamma_t gamma, filter_options_t filters );

/**
* @brief Close the display
Expand Down
2 changes: 1 addition & 1 deletion src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void console_init()
{
/* In case they initialized the display already */
display_close();
display_init( RESOLUTION_640x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
display_init( RESOLUTION_640x240, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE );

render_buffer = malloc(CONSOLE_SIZE);

Expand Down
Loading