mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 23:34:37 +01:00
Add smooth nearest neighbor scaling
This commit implements smooth nearest neighbor scaling, this scaling method looks sharper than linear scaling and not deformed like NN scaling.
This commit is contained in:
committed by
Michał Janiszewski
parent
9bc9e20778
commit
b66df2d6db
@@ -497,6 +497,10 @@ public:
|
||||
{
|
||||
_scaleQuality = 0;
|
||||
}
|
||||
if (_scaleQuality == 3)
|
||||
{
|
||||
_scaleQuality = 1;
|
||||
}
|
||||
snprintf(scaleQualityBuffer, sizeof(scaleQualityBuffer), "%u", _scaleQuality);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ private:
|
||||
SDL_Window * _window = nullptr;
|
||||
SDL_Renderer * _sdlRenderer = nullptr;
|
||||
SDL_Texture * _screenTexture = nullptr;
|
||||
SDL_Texture * _scaledScreenTexture = nullptr;
|
||||
SDL_PixelFormat * _screenTextureFormat = nullptr;
|
||||
uint32 _paletteHWMapped[256] = { 0 };
|
||||
#ifdef __ENABLE_LIGHTFX__
|
||||
@@ -53,6 +54,8 @@ private:
|
||||
bool _pausedBeforeOverlay = false;
|
||||
|
||||
std::vector<uint32> _dirtyVisualsTime;
|
||||
|
||||
bool smoothNN = false;
|
||||
|
||||
public:
|
||||
explicit HardwareDisplayDrawingEngine(IUiContext * uiContext)
|
||||
@@ -98,7 +101,40 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
_screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
sint32 scaleQuality = gConfigGeneral.scale_quality;
|
||||
if (gConfigGeneral.use_nn_at_integer_scales &&
|
||||
gConfigGeneral.window_scale == std::floor(gConfigGeneral.window_scale))
|
||||
{
|
||||
scaleQuality = 0;
|
||||
}
|
||||
if (scaleQuality == 3)
|
||||
{
|
||||
scaleQuality = 1;
|
||||
smoothNN = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
smoothNN = false;
|
||||
}
|
||||
|
||||
if (smoothNN)
|
||||
{
|
||||
SDL_DestroyTexture(_scaledScreenTexture);
|
||||
|
||||
char scaleQualityBuffer[4];
|
||||
snprintf(scaleQualityBuffer, sizeof(scaleQualityBuffer), "%u", scaleQuality);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
|
||||
_screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaleQualityBuffer);
|
||||
|
||||
uint32 scale = std::ceil(gConfigGeneral.window_scale);
|
||||
_scaledScreenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_TARGET,
|
||||
width * scale, height * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
_screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING,width, height);
|
||||
}
|
||||
|
||||
uint32 format;
|
||||
SDL_QueryTexture(_screenTexture, &format, 0, 0, 0);
|
||||
@@ -175,7 +211,18 @@ private:
|
||||
{
|
||||
CopyBitsToTexture(_screenTexture, _bits, (sint32)_width, (sint32)_height, _paletteHWMapped);
|
||||
}
|
||||
SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr);
|
||||
if (smoothNN)
|
||||
{
|
||||
SDL_SetRenderTarget(_sdlRenderer, _scaledScreenTexture);
|
||||
SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr);
|
||||
|
||||
SDL_SetRenderTarget(_sdlRenderer, nullptr);
|
||||
SDL_RenderCopy(_sdlRenderer, _scaledScreenTexture, nullptr, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (gShowDirtyVisuals)
|
||||
{
|
||||
|
||||
@@ -385,6 +385,7 @@ static const rct_string_id window_options_scale_quality_names[] = {
|
||||
STR_SCALING_QUALITY_NN,
|
||||
STR_SCALING_QUALITY_LINEAR,
|
||||
STR_SCALING_QUALITY_ANISOTROPIC,
|
||||
STR_SCALING_QUALITY_SMOOTH_NN
|
||||
};
|
||||
|
||||
static const rct_string_id window_options_fullscreen_mode_names[] = {
|
||||
@@ -1022,11 +1023,13 @@ static void window_options_mousedown(rct_window *w, rct_widgetindex widgetIndex,
|
||||
gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL;
|
||||
gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL;
|
||||
gDropdownItemsFormat[2] = STR_DROPDOWN_MENU_LABEL;
|
||||
gDropdownItemsFormat[3] = STR_DROPDOWN_MENU_LABEL;
|
||||
gDropdownItemsArgs[0] = STR_SCALING_QUALITY_NN;
|
||||
gDropdownItemsArgs[1] = STR_SCALING_QUALITY_LINEAR;
|
||||
gDropdownItemsArgs[2] = STR_SCALING_QUALITY_ANISOTROPIC;
|
||||
gDropdownItemsArgs[3] = STR_SCALING_QUALITY_SMOOTH_NN;
|
||||
|
||||
window_options_show_dropdown(w, widget, 3);
|
||||
window_options_show_dropdown(w, widget, 4);
|
||||
|
||||
dropdown_set_checked(gConfigGeneral.scale_quality, true);
|
||||
break;
|
||||
|
||||
@@ -3814,6 +3814,8 @@ enum {
|
||||
STR_CONSOLE = 6157,
|
||||
|
||||
STR_FAILED_TO_LOAD_IMCOMPATIBLE_RCTC_FLAG = 6158,
|
||||
|
||||
STR_SCALING_QUALITY_SMOOTH_NN = 6159,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
STR_COUNT = 32768
|
||||
|
||||
Reference in New Issue
Block a user