ref: 8602b236e3ac074033877e4cfe472a6f945f5c4f
parent: 546fc01da819c76655da407b74699f8c77da998b
author: laamaa <jonne.kokkonen@gmail.com>
date: Thu Apr 24 05:41:57 EDT 2025
use 2 pass scaling by default, check intermediate texture size before recreation
--- a/src/config.c
+++ b/src/config.c
@@ -29,7 +29,7 @@
}
c.init_fullscreen = 0; // default fullscreen state at load
- c.integer_scaling = 1; // use integer scaling for the user interface
+ c.integer_scaling = 0; // use integer scaling for the user interface
c.idle_ms = 10; // default to high performance
c.wait_for_device = 1; // default to exit if device disconnected
c.wait_packets = 256; // amount of empty command queue reads before assuming device disconnected
--- a/src/main.c
+++ b/src/main.c
@@ -18,6 +18,11 @@
#include "gamepads.h"
#include "render.h"
+// On MacOS TARGET_OS_IOS is defined as 0, so make sure that it's consistent on other platforms as well
+#ifndef TARGET_OS_IOS
+#define TARGET_OS_IOS 0
+#endif
+
static void do_wait_for_device(struct app_context *ctx) {static Uint64 ticks_poll_device = 0;
static int screensaver_initialized = 0;
@@ -87,13 +92,11 @@
}
config_params_s conf = config_initialize(*config_filename);
+
if (TARGET_OS_IOS == 0) {// It's not possible to edit the config on iOS, so let's go with the defaults
config_read(&conf);
- } else {- // Use integer scaling on iOS
- conf.integer_scaling = 0;
- }
+ }
return conf;
}
--- a/src/render.c
+++ b/src/render.c
@@ -37,6 +37,7 @@
static int texture_width = 320;
static int texture_height = 240;
+static int hd_texture_width, hd_texture_height = 0;
static int screensaver_initialized = 0;
@@ -49,7 +50,6 @@
// Creates an intermediate texture dynamically based on window size
static void create_hd_texture() {- SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "Creating HD texture");
int window_width, window_height;
// Get the current window size
@@ -60,14 +60,21 @@
if (scale_factor < 1) {scale_factor = 1; // Ensure at least 1x scaling
}
- SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "HD texture scale factor: %d", scale_factor);
// Calculate the HD texture size
- const int hd_texture_width = texture_width * scale_factor;
- const int hd_texture_height = texture_height * scale_factor;
- SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "HD texture size: %dx%d", hd_texture_width,
- hd_texture_height);
+ const int new_hd_texture_width = texture_width * scale_factor;
+ const int new_hd_texture_height = texture_height * scale_factor;
+ if (hd_texture != NULL && new_hd_texture_width == hd_texture_width && new_hd_texture_height == hd_texture_height) {+ // Texture exists and there is no change in the size, carry on
+ return;
+ }
+ hd_texture_width = new_hd_texture_width;
+ hd_texture_height = new_hd_texture_height;
+
+ SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "Creating HD texture, scale factor: %d, size: %dx%d", scale_factor,
+ hd_texture_width, hd_texture_height);
+
// Destroy any existing HD texture
if (hd_texture != NULL) {SDL_DestroyTexture(hd_texture);
@@ -530,8 +537,7 @@
} else {// Fullscreen scaling: use an intermediate texture with the highest possible integer size factor
if (hd_texture != NULL) {- SDL_DestroyTexture(hd_texture);
- create_hd_texture();
+ create_hd_texture(); // Recreate hd texture if necessary
}
// SDL forces black borders in letterbox mode, so in HD mode the texture scaling is manual
SDL_SetRenderLogicalPresentation(rend, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED);
--
⑨