From 30087f7cd7d64dde75c4f6e67ece85f333eaa929 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Thu, 27 Jul 2017 03:05:01 -0400 Subject: [PATCH] - cleaned up the video scale mode code a bit, in order to increase future flexibility. --- src/CMakeLists.txt | 1 + src/gl/renderer/gl_postprocess.cpp | 3 +- src/gl/renderer/gl_renderer.cpp | 4 +- src/gl/system/gl_framebuffer.cpp | 3 +- src/gl/system/gl_swframebuffer.cpp | 9 +--- src/menu/videomenu.cpp | 41 +--------------- src/r_videoscale.cpp | 77 ++++++++++++++++++++++++++++++ src/r_videoscale.h | 31 ++++++++++++ src/v_video.cpp | 4 +- 9 files changed, 118 insertions(+), 55 deletions(-) create mode 100644 src/r_videoscale.cpp create mode 100644 src/r_videoscale.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1861d93f..1c5192a4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -944,6 +944,7 @@ set (PCH_SOURCES portal.cpp r_utility.cpp r_sky.cpp + r_videoscale.cpp s_advsound.cpp s_environment.cpp s_playlist.cpp diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index bf054db6d..cea7cbb3f 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -65,6 +65,7 @@ #include "gl/shaders/gl_postprocessshader.h" #include "gl/renderer/gl_2ddrawer.h" #include "gl/stereo3d/gl_stereo3d.h" +#include "r_videoscale.h" //========================================================================== // @@ -153,8 +154,6 @@ EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Float, vid_saturation) EXTERN_CVAR(Int, gl_satformula) -bool ViewportLinearScale(); - void FGLRenderer::RenderScreenQuad() { mVBO->BindVBO(); diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 4951d4905..6795c9864 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -78,6 +78,8 @@ EXTERN_CVAR(Int, vid_scalemode) CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE); +bool ViewportIsScaled43(); + //=========================================================================== // // Renderer interface @@ -283,7 +285,7 @@ void FGLRenderer::SetOutputViewport(GL_IRECT *bounds) int screenWidth = framebuffer->GetWidth(); int screenHeight = framebuffer->GetHeight(); float scaleX, scaleY; - if (vid_scalemode == 1 || vid_scalemode == 2) + if (ViewportIsScaled43()) { scaleX = MIN(clientWidth / (float)screenWidth, clientHeight / (screenHeight * 1.2f)); scaleY = scaleX * 1.2f; diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index ba08acaf2..73b81bd2c 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -51,6 +51,7 @@ #include "gl/gl_functions.h" #include "gl/renderer/gl_2ddrawer.h" #include "gl_debug.h" +#include "r_videoscale.h" EXTERN_CVAR (Float, vid_brightness) EXTERN_CVAR (Float, vid_contrast) @@ -64,8 +65,6 @@ FGLRenderer *GLRenderer; void gl_LoadExtensions(); void gl_PrintStartupLog(); void gl_SetupMenu(); -int ViewportScaledWidth(int width); -int ViewportScaledHeight(int height); CUSTOM_CVAR(Int, vid_hwgamma, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 5d90b7725..dd552f6df 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -68,6 +68,7 @@ #include "gl/utility/gl_templates.h" #include "gl/gl_functions.h" #include "gl_debug.h" +#include "r_videoscale.h" #include "swrenderer/scene/r_light.h" @@ -93,9 +94,6 @@ EXTERN_CVAR(Bool, vid_vsync) EXTERN_CVAR(Float, transsouls) EXTERN_CVAR(Int, vid_refreshrate) EXTERN_CVAR(Bool, gl_legacy_mode) -EXTERN_CVAR(Int, vid_scalemode) - -bool ViewportLinearScale(); #ifdef WIN32 extern cycle_t BlitCycles; @@ -104,9 +102,6 @@ extern cycle_t BlitCycles; void gl_LoadExtensions(); void gl_PrintStartupLog(); -int ViewportScaledWidth(int width); -int ViewportScaledHeight(int height); - #ifndef WIN32 // This has to be in this file because system headers conflict Doom headers DFrameBuffer *CreateGLSWFrameBuffer(int width, int height, bool bgra, bool fullscreen) @@ -729,7 +724,7 @@ void OpenGLSWFrameBuffer::Present() glViewport(0, 0, clientWidth, clientHeight); float scaleX, scaleY; - if (vid_scalemode == 1 || vid_scalemode == 2) + if (ViewportIsScaled43()) { scaleX = MIN(clientWidth / (float)Width, clientHeight / (Height * 1.2f)); scaleY = scaleX * 1.2f; diff --git a/src/menu/videomenu.cpp b/src/menu/videomenu.cpp index dcf594f96..7d434843b 100644 --- a/src/menu/videomenu.cpp +++ b/src/menu/videomenu.cpp @@ -54,6 +54,7 @@ #include "sbar.h" #include "hardware.h" #include "vm.h" +#include "r_videoscale.h" /*======================================= * @@ -123,46 +124,6 @@ CUSTOM_CVAR (Bool, vid_tft, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) } } -CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -{ - if (self < 0 || self > 5) - { - self = 0; - } -} - -bool ViewportLinearScale() -{ - return vid_scalemode == 4 || vid_scalemode == 5; -} - -int ViewportScaledWidth(int width) -{ - switch (vid_scalemode) - { - default: - case 0: return width; - case 1: return 320; - case 2: return 640; - case 3: return (int)roundf(width * 0.5f); - case 4: return (int)roundf(width * 0.75f); - case 5: return width * 2; - } -} - -int ViewportScaledHeight(int height) -{ - switch (vid_scalemode) - { - default: - case 0: return height; - case 1: return 200; - case 2: return 400; - case 3: return (int)roundf(height * 0.5f); - case 4: return (int)roundf(height * 0.75f); - case 5: return height * 2; - } -} //============================================================================= // diff --git a/src/r_videoscale.cpp b/src/r_videoscale.cpp new file mode 100644 index 000000000..d602062ae --- /dev/null +++ b/src/r_videoscale.cpp @@ -0,0 +1,77 @@ +// +//--------------------------------------------------------------------------- +// +// Copyright(C) 2017 Magnus Norddahl +// Copyright(C) 2017 Rachael Alexanderson +// All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//-------------------------------------------------------------------------- +// + +#include "c_dispatch.h" +#include "c_cvars.h" + +CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +{ + if (self < 0 || self > 5) + { + self = 0; + } +} + +bool ViewportLinearScale() +{ + return vid_scalemode == 4 || vid_scalemode == 5; +} + +int ViewportScaledWidth(int width) +{ + switch (vid_scalemode) + { + default: + case 0: return width; + case 1: return 320; + case 2: return 640; + case 3: return (int)roundf(width * 0.5f); + case 4: return (int)roundf(width * 0.75f); + case 5: return width * 2; + } +} + +int ViewportScaledHeight(int height) +{ + switch (vid_scalemode) + { + default: + case 0: return height; + case 1: return 200; + case 2: return 400; + case 3: return (int)roundf(height * 0.5f); + case 4: return (int)roundf(height * 0.75f); + case 5: return height * 2; + } +} + +bool ViewportIsScaled43() +{ + switch (vid_scalemode) + { + default: return false; + case 1: + case 2: return true; + } +} + diff --git a/src/r_videoscale.h b/src/r_videoscale.h new file mode 100644 index 000000000..002fc7c38 --- /dev/null +++ b/src/r_videoscale.h @@ -0,0 +1,31 @@ +// +//--------------------------------------------------------------------------- +// +// Copyright(C) 2017 Magnus Norddahl +// Copyright(C) 2017 Rachael Alexanderson +// All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//-------------------------------------------------------------------------- +// + +#ifndef __VIDEOSCALE_H__ +#define __VIDEOSCALE_H__ +EXTERN_CVAR (Int, vid_scalemode) +bool ViewportLinearScale(); +int ViewportScaledWidth(int width); +int ViewportScaledHeight(int height); +bool ViewportIsScaled43(); +#endif //__VIDEOSCALE_H__ \ No newline at end of file diff --git a/src/v_video.cpp b/src/v_video.cpp index 24fbab68f..182abde17 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -83,14 +83,12 @@ #include "menu/menu.h" #include "r_data/voxels.h" #include "vm.h" +#include "r_videoscale.h" EXTERN_CVAR(Bool, r_blendmethod) int active_con_scale(); -int ViewportScaledWidth(int width); -int ViewportScaledHeight(int height); - FRenderer *Renderer; EXTERN_CVAR (Bool, swtruecolor)