shithub: cstory

Download patch

ref: 56b96ed432dc2e90d4cb57013f52069e82833319
parent: 53e96486ce016d3bc511035e1f5ad5733bcc7247
author: Clownacy <[email protected]>
date: Mon Sep 14 06:36:35 EDT 2020

Only use an upscaled framebuffer if we have to

--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -140,11 +140,14 @@
 
 void RenderBackend_DrawScreen(void)
 {
-	if (SDL_SetRenderTarget(renderer, upscaled_framebuffer.texture) < 0)
-		Backend_PrintError("Couldn't set upscaled framebuffer as the current rendering target: %s", SDL_GetError());
+	if (upscaled_framebuffer.texture != NULL)
+	{
+		if (SDL_SetRenderTarget(renderer, upscaled_framebuffer.texture) < 0)
+			Backend_PrintError("Couldn't set upscaled framebuffer as the current rendering target: %s", SDL_GetError());
 
-	if (SDL_RenderCopy(renderer, framebuffer.texture, NULL, NULL) < 0)
-		Backend_PrintError("Failed to copy framebuffer texture to upscaled framebuffer: %s", SDL_GetError());
+		if (SDL_RenderCopy(renderer, framebuffer.texture, NULL, NULL) < 0)
+			Backend_PrintError("Failed to copy framebuffer texture to upscaled framebuffer: %s", SDL_GetError());
+	}
 
 	if (SDL_SetRenderTarget(renderer, NULL) < 0)
 		Backend_PrintError("Couldn't set default render target as the current rendering target: %s", SDL_GetError());
@@ -154,7 +157,7 @@
 
 	SDL_RenderClear(renderer);
 
-	if (SDL_RenderCopy(renderer, upscaled_framebuffer.texture, NULL, &upscaled_framebuffer_rect) < 0)
+	if (SDL_RenderCopy(renderer, upscaled_framebuffer.texture != NULL ? upscaled_framebuffer.texture : framebuffer.texture, NULL, &upscaled_framebuffer_rect) < 0)
 		Backend_PrintError("Failed to copy upscaled framebuffer texture to default render target: %s", SDL_GetError());
 
 	SDL_RenderPresent(renderer);
@@ -443,16 +446,22 @@
 	upscaled_framebuffer.height = framebuffer.height * upscale_factor;
 
 	if (upscaled_framebuffer.texture != NULL)
+	{
 		SDL_DestroyTexture(upscaled_framebuffer.texture);
+		upscaled_framebuffer.texture = NULL;
+	}
 
-	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 (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");
+		if (upscaled_framebuffer.texture == NULL)
+			Backend_PrintError("Couldn't regenerate upscaled framebuffer");
 
-	SDL_SetTextureBlendMode(upscaled_framebuffer.texture, SDL_BLENDMODE_NONE);
+		SDL_SetTextureBlendMode(upscaled_framebuffer.texture, SDL_BLENDMODE_NONE);
+	}
 
 	// Create rect that forces 4:3 no matter what size the window is
 	float window_ratio = (float)width / height;