shithub: choc

Download patch

ref: f48bc14086eeeacc5f3bab4361d7302f019baca5
parent: 98b86be284c0d4a1a18f8b3aa9f652b779e441ea
author: Mike Swanson <mikeonthecomputer@gmail.com>
date: Sat Mar 31 07:55:10 EDT 2018

video: allow setting linear filtering via config file

Suggested by @vanfanel in #1009, nearest filtering can produce poor
results in low resolutions.  Now, in the extra config file, scaling_filter
can be set to "linear" which normally results in Blur-O-Vision, but
might be desirable in low resolutions.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -104,6 +104,10 @@
 
 char *window_position = "center";
 
+// Scaling filter applied
+
+char *scaling_filter = "nearest";
+
 // SDL display number on which to run.
 
 int video_display = 0;
@@ -1290,11 +1294,20 @@
         SDL_DestroyTexture(texture);
     }
 
-    // Set the scaling quality for rendering the intermediate texture into
-    // the upscaled texture to "nearest", which is gritty and pixelated and
-    // resembles software scaling pretty well.
+    // Set the scaling quality for rendering and immediate texture.
+    // Defaults to "nearest", which is gritty and pixelated and resembles
+    // software scaling pretty well.  "linear" can be set as an alternative,
+    // which may give better results at low resolutions.
 
-    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
+    if (!strcmp(scaling_filter, "linear"))
+    {
+        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+    }
+    else
+    {
+        scaling_filter = "nearest";
+        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
+    }
 
     // Create the intermediate texture that the RGBA surface gets loaded into.
     // The SDL_TEXTUREACCESS_STREAMING flag means that this texture's content
@@ -1456,6 +1469,7 @@
     M_BindIntVariable("grabmouse",                 &grabmouse);
     M_BindStringVariable("video_driver",           &video_driver);
     M_BindStringVariable("window_position",        &window_position);
+    M_BindStringVariable("scaling_filter",         &scaling_filter);
     M_BindIntVariable("usegamma",                  &usegamma);
     M_BindIntVariable("png_screenshots",           &png_screenshots);
 }
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -86,6 +86,7 @@
 extern int usegamma;
 extern pixel_t *I_VideoBuffer;
 
+extern char *scaling_filter;
 extern int screen_width;
 extern int screen_height;
 extern int fullscreen;
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -706,6 +706,16 @@
     CONFIG_VARIABLE_STRING(window_position),
 
     //!
+    //
+    // Scaling filter to use, accepted values are "nearest" (default)
+    // and "linear" - nearest gives a crisper display, but linear
+    // might produce more pleasing results at low resolutions
+    // (sub-640x480).
+    //
+
+    CONFIG_VARIABLE_STRING(scaling_filter),
+
+    //!
     // If non-zero, the game will run in full screen mode.  If zero,
     // the game will run in a window.
     //
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -65,6 +65,7 @@
 
 static char *video_driver = "";
 static char *window_position = "";
+static char *scaling_filter = "nearest";
 static int aspect_ratio_correct = 1;
 static int integer_scaling = 0;
 static int vga_porch_flash = 0;
@@ -261,6 +262,7 @@
     M_BindIntVariable("startup_delay",             &startup_delay);
     M_BindStringVariable("video_driver",           &video_driver);
     M_BindStringVariable("window_position",        &window_position);
+    M_BindStringVariable("scaling_filter",         &scaling_filter);
     M_BindIntVariable("usegamma",                  &usegamma);
     M_BindIntVariable("png_screenshots",           &png_screenshots);
     M_BindIntVariable("vga_porch_flash",           &vga_porch_flash);