Add option to enable SDL pixel art texture filter

Add a checkbox in display config to enable SDL_SCALEMODE_PIXELART when
it is available.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover
2025-09-18 00:40:34 +00:00
parent 6ec0ba0610
commit ab01be3373
7 changed files with 32 additions and 0 deletions

View File

@@ -76,6 +76,14 @@ option(ENABLE_LZMA "Enable LZMA archive support" ON)
if(ENABLE_SDL3)
set(CMAKE_C_FLAGS "-DENABLE_SDL3 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DENABLE_SDL3 ${CMAKE_CXX_FLAGS}")
include(CheckSymbolExists)
check_symbol_exists(SDL_SCALEMODE_PIXELART "SDL3/SDL.h" HAVE_SDL_SCALEMODE_PIXELART)
if(HAVE_SDL_SCALEMODE_PIXELART)
set(CMAKE_C_FLAGS "-DHAVE_SDL3_PIXELART ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DHAVE_SDL3_PIXELART ${CMAKE_CXX_FLAGS}")
endif()
endif()
if(DISABLE_OPENGL)

View File

@@ -151,6 +151,7 @@ std::array<Option, kNbOptions>& Option::All() {
struct OwnedOptions {
/// Display
bool bilinear = true;
bool sdl_pixel_art = false;
Filter filter = Filter::kNone;
wxString filter_plugin = wxEmptyString;
Interframe interframe = Interframe::kNone;
@@ -280,6 +281,7 @@ std::array<Option, kNbOptions>& Option::All() {
static std::array<Option, kNbOptions> g_all_opts = {
/// Display
Option(OptionID::kDispBilinear, &g_owned_opts.bilinear),
Option(OptionID::kDispSDLPixelArt, &g_owned_opts.sdl_pixel_art),
Option(OptionID::kDispFilter, &g_owned_opts.filter),
Option(OptionID::kDispFilterPlugin, &g_owned_opts.filter_plugin),
Option(OptionID::kDispIFB, &g_owned_opts.interframe),
@@ -427,6 +429,7 @@ namespace internal {
const std::array<OptionData, kNbOptions + 1> kAllOptionsData = {
/// Display
OptionData{"Display/Bilinear", "Bilinear", _("Use bilinear filter with 3d renderer")},
OptionData{"Display/SDLPixelArt", "SDLPixelArt", _("Use the SDL pixel art filter with an SDL renderer")},
OptionData{"Display/Filter", "", _("Full-screen filter to apply")},
OptionData{"Display/FilterPlugin", "", _("Filter plugin library")},
OptionData{"Display/IFB", "", _("Interframe blending function")},

View File

@@ -8,6 +8,7 @@ namespace config {
enum class OptionID {
/// Display
kDispBilinear = 0,
kDispSDLPixelArt,
kDispFilter,
kDispFilterPlugin,
kDispIFB,

View File

@@ -12,6 +12,7 @@ namespace config {
static constexpr std::array<Option::Type, kNbOptions> kOptionsTypes = {
/// Display
/*kDispBilinear*/ Option::Type::kBool,
/*kDispSDLPixelArt*/ Option::Type::kBool,
/*kDispFilter*/ Option::Type::kFilter,
/*kDispFilterPlugin*/ Option::Type::kString,
/*kDispIFB*/ Option::Type::kInterframe,

View File

@@ -386,6 +386,14 @@ DisplayConfig::DisplayConfig(wxWindow* parent)
sdlrenderer_selector_ = GetValidatedChild<wxChoice>("SDLRenderer");
sdlrenderer_selector_->SetValidator(SDLDevicesValidator());
#if !defined(ENABLE_SDL3) || !defined(HAVE_SDL3_PIXELART)
GetValidatedChild<wxCheckBox>("SDLPixelArt")->Hide();
#else
GetValidatedChild<wxCheckBox>("SDLPixelArt")
->SetValidator(
widgets::OptionBoolValidator(config::OptionID::kDispSDLPixelArt));
#endif
wxWindow* color_profile_srgb = GetValidatedChild("ColorProfileSRGB");
color_profile_srgb->SetValidator(
ColorCorrectionProfileValidator(config::ColorCorrectionProfile::kSRGB));

View File

@@ -2577,7 +2577,11 @@ SDL_TEXTUREACCESS_STREAMING, (width * scale), (height * scale));
// Set bilinear or nearest on the texture.
#ifdef ENABLE_SDL3
#ifdef HAVE_SDL3_PIXELART
SDL_SetTextureScaleMode(texture, OPTION(kDispSDLPixelArt) ? SDL_SCALEMODE_PIXELART : OPTION(kDispBilinear) ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST);
#else
SDL_SetTextureScaleMode(texture, OPTION(kDispBilinear) ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST);
#endif
#else
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, OPTION(kDispBilinear) ? "1" : "0");
#endif

View File

@@ -170,6 +170,13 @@
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="SDLPixelArt">
<label>SDL Pixel Art Filter</label>
</object>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
</object>
<cols>2</cols>
<growablecols>1</growablecols>
</object>