shithub: cstory

Download patch

ref: 5c1012aa8e72d1b51ae8bdfc29691dc9ff37a736
parent: f2c0f94e429f6fae58f3e99b2cff07c6f8688b9a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Sep 18 17:21:28 EDT 2020

Fix upscaled framebuffer skipping

Skipping it an 1x is wrong: it should only be skipped if the window
is an integer multiple of the framebuffer size

--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -1075,14 +1075,6 @@
 		upscaled_framebuffer_surface = NULL;
 	}
 
-	if (upscale_factor != 1)
-	{
-		upscaled_framebuffer_surface = CreateSurface(upscaled_framebuffer_width, upscaled_framebuffer_height * upscale_factor, true);
-
-		if (upscaled_framebuffer_surface == NULL)
-			Backend_PrintError("Couldn't regenerate upscaled framebuffer");
-	}
-
 	// Create rect that forces 4:3 no matter what size the window is
 	if (width * upscaled_framebuffer_height >= upscaled_framebuffer_width * height) // Fancy way to do `if (width / height >= upscaled_framebuffer->width / upscaled_framebuffer->height)` without floats
 	{
@@ -1102,4 +1094,12 @@
 
 	window_surface.width = width;
 	window_surface.height = height;
+
+	if ((window_rect.right - window_rect.left) % framebuffer_surface->width != 0 || (window_rect.bottom - window_rect.top) % framebuffer_surface->height != 0)
+	{
+		upscaled_framebuffer_surface = CreateSurface(upscaled_framebuffer_width, upscaled_framebuffer_height * upscale_factor, true);
+
+		if (upscaled_framebuffer_surface == NULL)
+			Backend_PrintError("Couldn't regenerate upscaled framebuffer");
+	}
 }
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -430,18 +430,6 @@
 		upscaled_framebuffer.texture = NULL;
 	}
 
-	if (upscale_factor != 1)
-	{
-		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
-		upscaled_framebuffer.texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, upscaled_framebuffer.width, upscaled_framebuffer.height);
-		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
-
-		if (upscaled_framebuffer.texture == NULL)
-			Backend_PrintError("Couldn't regenerate upscaled framebuffer");
-
-		SDL_SetTextureBlendMode(upscaled_framebuffer.texture, SDL_BLENDMODE_NONE);
-	}
-
 	// Create rect that forces 4:3 no matter what size the window is
 	if (width * upscaled_framebuffer.height >= upscaled_framebuffer.width * height) // Fancy way to do `if (width / height >= upscaled_framebuffer.width / upscaled_framebuffer.height)` without floats
 	{
@@ -456,4 +444,16 @@
 
 	window_rect.x = (width - window_rect.w) / 2;
 	window_rect.y = (height - window_rect.h) / 2;
+
+	if (window_rect.w % framebuffer.width != 0 || window_rect.h % framebuffer.height != 0)
+	{
+		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+		upscaled_framebuffer.texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, upscaled_framebuffer.width, upscaled_framebuffer.height);
+		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
+
+		if (upscaled_framebuffer.texture == NULL)
+			Backend_PrintError("Couldn't regenerate upscaled framebuffer");
+
+		SDL_SetTextureBlendMode(upscaled_framebuffer.texture, SDL_BLENDMODE_NONE);
+	}
 }