mirror of
https://github.com/diasurgical/DevilutionX.git
synced 2026-10-11 22:29:54 +00:00
SDL3: Fix nearest-neighbor scaling
For some reason, setting the scaling on just `texture` still results in bluriness. However, setting the default scaling mode on the renderer fixes it. Also, does a few more things the SDL3 way.
This commit is contained in:
committed by
Anders Jenbo
parent
db9404dcf6
commit
705a007c22
+4
-18
@@ -242,29 +242,15 @@ void RenderPresent()
|
||||
|
||||
#ifndef USE_SDL1
|
||||
if (renderer != nullptr) {
|
||||
#ifdef USE_SDL3
|
||||
if (!SDL_UpdateTexture(texture.get(), nullptr, surface->pixels, surface->pitch)) ErrSdl();
|
||||
#else
|
||||
if (SDL_UpdateTexture(texture.get(), nullptr, surface->pixels, surface->pitch) <= -1) ErrSdl();
|
||||
#endif
|
||||
|
||||
// Clear buffer to avoid artifacts in case the window was resized
|
||||
// TODO only do this if window was resized
|
||||
#ifdef USE_SDL3
|
||||
if (!SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255)) ErrSdl();
|
||||
#else
|
||||
if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) <= -1) ErrSdl();
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL3
|
||||
if (!SDL_RenderClear(renderer)) ErrSdl();
|
||||
#else
|
||||
if (SDL_RenderClear(renderer) <= -1) ErrSdl();
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL3
|
||||
if (!SDL_UpdateTexture(texture.get(), nullptr, surface->pixels, surface->pitch)) ErrSdl();
|
||||
if (!SDL_RenderTexture(renderer, texture.get(), nullptr, nullptr)) ErrSdl();
|
||||
#else
|
||||
if (SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) <= -1) ErrSdl();
|
||||
if (SDL_RenderClear(renderer) <= -1) ErrSdl();
|
||||
if (SDL_UpdateTexture(texture.get(), nullptr, surface->pixels, surface->pitch) <= -1) ErrSdl();
|
||||
if (SDL_RenderCopy(renderer, texture.get(), nullptr, nullptr) <= -1) ErrSdl();
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ bool SetHardwareCursorFromSurface(SDL_Surface *surface, HotpointPosition hotpoin
|
||||
size.width, size.height, scaledSize.width, scaledSize.height);
|
||||
#endif
|
||||
#ifdef USE_SDL3
|
||||
SDL_BlitSurfaceScaled(converted.get(), nullptr, scaledSurface.get(), nullptr, SDL_SCALEMODE_NEAREST);
|
||||
SDL_BlitSurfaceScaled(converted.get(), nullptr, scaledSurface.get(), nullptr, SDL_SCALEMODE_PIXELART);
|
||||
#else
|
||||
SDL_BlitScaled(converted.get(), nullptr, scaledSurface.get(), nullptr);
|
||||
#endif
|
||||
|
||||
+26
-15
@@ -432,19 +432,21 @@ void AdjustToScreenGeometry(Size windowSize)
|
||||
|
||||
float GetDpiScalingFactor()
|
||||
{
|
||||
#ifdef USE_SDL1
|
||||
return 1.0F;
|
||||
#else
|
||||
#ifdef USE_SDL3
|
||||
const float dispScale = SDL_GetWindowDisplayScale(ghMainWnd);
|
||||
if (dispScale == 0.0F) {
|
||||
LogError("SDL_GetWindowDisplayScale: {}", SDL_GetError());
|
||||
SDL_ClearError();
|
||||
return 1.0F;
|
||||
}
|
||||
return dispScale;
|
||||
#elif !defined(USE_SDL1)
|
||||
if (renderer == nullptr)
|
||||
return 1.0F;
|
||||
|
||||
int renderWidth;
|
||||
int renderHeight;
|
||||
#ifdef USE_SDL3
|
||||
SDL_GetCurrentRenderOutputSize(renderer, &renderWidth, &renderHeight);
|
||||
#else
|
||||
SDL_GetRendererOutputSize(renderer, &renderWidth, &renderHeight);
|
||||
#endif
|
||||
|
||||
int windowWidth;
|
||||
int windowHeight;
|
||||
@@ -454,6 +456,8 @@ float GetDpiScalingFactor()
|
||||
const float vhfactor = static_cast<float>(renderHeight) / windowHeight;
|
||||
|
||||
return std::min(hfactor, vhfactor);
|
||||
#else
|
||||
return 1.0F;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -616,7 +620,11 @@ bool SpawnWindow(const char *lpWindowName)
|
||||
}
|
||||
|
||||
#ifdef USE_SDL3
|
||||
ghMainWnd = SDL_CreateWindow(lpWindowName, windowSize.width, windowSize.height, flags);
|
||||
if (*GetOptions().Graphics.upscale) {
|
||||
if (!SDL_CreateWindowAndRenderer(lpWindowName, windowSize.width, windowSize.height, flags, &ghMainWnd, &renderer)) ErrSdl();
|
||||
} else {
|
||||
ghMainWnd = SDL_CreateWindow(lpWindowName, windowSize.width, windowSize.height, flags);
|
||||
}
|
||||
#else
|
||||
ghMainWnd = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowSize.width, windowSize.height, flags);
|
||||
#endif
|
||||
@@ -687,14 +695,17 @@ void ReinitializeTexture()
|
||||
if (renderer == nullptr)
|
||||
return;
|
||||
|
||||
auto quality = StrCat(static_cast<int>(*GetOptions().Graphics.scaleQuality));
|
||||
|
||||
#ifdef USE_SDL3
|
||||
texture = SDLWrap::CreateTexture(renderer, DEVILUTIONX_DISPLAY_TEXTURE_FORMAT, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight);
|
||||
if (quality == "nearest") {
|
||||
SDL_SetTextureScaleMode(texture.get(), SDL_SCALEMODE_NEAREST);
|
||||
if (!SDL_SetDefaultTextureScaleMode(renderer,
|
||||
*GetOptions().Graphics.scaleQuality == ScalingQuality::NearestPixel
|
||||
? SDL_SCALEMODE_PIXELART
|
||||
: SDL_SCALEMODE_LINEAR)) {
|
||||
Log("SDL_SetDefaultTextureScaleMode: {}", SDL_GetError());
|
||||
SDL_ClearError();
|
||||
}
|
||||
texture = SDLWrap::CreateTexture(renderer, DEVILUTIONX_DISPLAY_TEXTURE_FORMAT, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight);
|
||||
#else
|
||||
auto quality = StrCat(static_cast<int>(*GetOptions().Graphics.scaleQuality));
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.c_str());
|
||||
texture = SDLWrap::CreateTexture(renderer, DEVILUTIONX_DISPLAY_TEXTURE_FORMAT, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight);
|
||||
#endif
|
||||
@@ -756,8 +767,6 @@ void ReinitializeRenderer()
|
||||
SDL_RenderSetVSync(renderer, *GetOptions().Graphics.frameRateControl == FrameRateControl::VerticalSync ? 1 : 0);
|
||||
#endif
|
||||
|
||||
ReinitializeTexture();
|
||||
|
||||
#ifdef USE_SDL3
|
||||
if (!SDL_SetRenderLogicalPresentation(renderer, gnScreenWidth, gnScreenHeight,
|
||||
*GetOptions().Graphics.integerScaling
|
||||
@@ -775,6 +784,8 @@ void ReinitializeRenderer()
|
||||
}
|
||||
#endif
|
||||
|
||||
ReinitializeTexture();
|
||||
|
||||
#ifdef USE_SDL3
|
||||
RendererTextureSurface = SDLSurfaceUniquePtr { SDL_CreateSurface(gnScreenWidth, gnScreenHeight, texture->format) };
|
||||
if (RendererTextureSurface == nullptr) ErrSdl();
|
||||
|
||||
@@ -236,7 +236,7 @@ inline const SDL_GamepadDeviceEvent &SDLC_EventGamepadDevice(const SDL_Event &ev
|
||||
|
||||
#define SDLC_SURFACE_BITSPERPIXEL(surface) surface->format->BitsPerPixel
|
||||
|
||||
inline bool SDLC_PushEvent(SDL_Event *event) { return SDL_PushEvent(event) == 0; }
|
||||
inline bool SDLC_PushEvent(SDL_Event *event) { return SDL_PushEvent(event) == 1; }
|
||||
|
||||
inline
|
||||
#ifdef USE_SDL1
|
||||
|
||||
Reference in New Issue
Block a user