foxygit / doom Log in
commit 8bc6097e992bfd4122614b9f9d63611b730e01ce
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun Feb 5 18:06:51 2017 -0500
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun Feb 5 18:06:51 2017 -0500

    video: Add config variable for texture pixel limit.

    We use an intermediate texture for scaling up the screen accurately and
    limit this to 1600x1200, but for very high resolution displays there can
    be some slight blurriness around pixels when they are examined closely.
    So provide the ability to override this and use even more memory if
    desired.

    Thanks to Linguica for the report. This fixes #859.
---
 src/i_video.c       | 30 ++++++++++++++++++++++++------
 src/m_config.c      |  8 ++++++++
 src/setup/display.c |  2 ++
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 97f97d23..26623e5f 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -114,6 +114,10 @@ int window_height = SCREENHEIGHT_4_3 * 2;

 int fullscreen_width = 0, fullscreen_height = 0;

+// Maximum number of pixels to use for intermediate scale buffer.
+
+static int max_scaling_buffer_pixels = 1600 * 1200;
+
 // Run in full screen mode?  (int type for config code)

 int fullscreen = true;
@@ -587,16 +591,29 @@ static void CreateUpscaledTexture(boolean force)
         h_upscale = 1;
     }

-    // Limit maximum texture dimensions to 1600x1200.
-    // It's really diminishing returns at this point.
+    // We limit the amount of texture memory used for the intermediate buffer.
+    // By default we limit to 1600x1200, which gives pretty good results, but
+    // we allow the user to override this and use more if they want to use
+    // even more (or less, if their graphics card can't handle it).

-    if (w_upscale * SCREENWIDTH > 1600)
+    if (max_scaling_buffer_pixels < SCREENWIDTH * SCREENHEIGHT)
     {
-        w_upscale = 1600 / SCREENWIDTH;
+        I_Error("CreateUpscaledTexture: max_scaling_buffer_pixels too small "
+                "to create a texture buffer: %d < %d",
+                max_scaling_buffer_pixels, SCREENWIDTH * SCREENHEIGHT);
     }
-    if (h_upscale * SCREENHEIGHT > 1200)
+
+    while (w_upscale * h_upscale * SCREENWIDTH * SCREENHEIGHT
+           > max_scaling_buffer_pixels)
     {
-        h_upscale = 1200 / SCREENHEIGHT;
+        if (w_upscale > h_upscale)
+        {
+            --w_upscale;
+        }
+        else
+        {
+            --h_upscale;
+        }
     }

     // Create a new texture only if the upscale factors have actually changed.
@@ -1334,6 +1351,7 @@ void I_BindVideoVariables(void)
     M_BindIntVariable("fullscreen_width",          &fullscreen_width);
     M_BindIntVariable("fullscreen_height",         &fullscreen_height);
     M_BindIntVariable("force_software_renderer",   &force_software_renderer);
+    M_BindIntVariable("max_scaling_buffer_pixels", &max_scaling_buffer_pixels);
     M_BindIntVariable("window_width",              &window_width);
     M_BindIntVariable("window_height",             &window_height);
     M_BindIntVariable("grabmouse",                 &grabmouse);
diff --git a/src/m_config.c b/src/m_config.c
index 718226bc..38e17ccf 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -763,6 +763,14 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(force_software_renderer),

+    //!
+    // Maximum number of pixels to use for intermediate scaling buffer.
+    // More pixels mean that the screen can be rendered more precisely,
+    // but there are diminishing returns on quality. The default limits
+    // to a 1600x1200 buffer.
+
+    CONFIG_VARIABLE_INT(max_scaling_buffer_pixels),
+
     //!
     // Number of milliseconds to wait on startup after the video mode
     // has been set, before the game will start.  This allows the
diff --git a/src/setup/display.c b/src/setup/display.c
index 79f799b4..2a007918 100644
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -71,6 +71,7 @@ static int fullscreen = 1;
 static int fullscreen_width = 0, fullscreen_height = 0;
 static int window_width = 640, window_height = 480;
 static int startup_delay = 1000;
+static int max_scaling_buffer_pixels = 1600 * 1200;
 static int usegamma = 0;

 int graphical_startup = 1;
@@ -260,6 +261,7 @@ void BindDisplayVariables(void)
     M_BindIntVariable("usegamma",                  &usegamma);
     M_BindIntVariable("png_screenshots",           &png_screenshots);
     M_BindIntVariable("force_software_renderer",   &force_software_renderer);
+    M_BindIntVariable("max_scaling_buffer_pixels", &max_scaling_buffer_pixels);

     if (gamemission == doom || gamemission == heretic
      || gamemission == strife)