Add vid_scalemode support to GL framebuffer

This commit is contained in:
Magnus Norddahl 2017-02-09 02:56:00 +01:00
parent 2e6c4eeab9
commit c3702ae9e7
9 changed files with 65 additions and 24 deletions

View File

@ -74,6 +74,7 @@
#include "gl/dynlights/gl_lightbuffer.h"
EXTERN_CVAR(Int, screenblocks)
EXTERN_CVAR(Int, vid_scalemode)
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
@ -300,7 +301,7 @@ void FGLRenderer::SetOutputViewport(GL_IRECT *bounds)
mSceneViewport.height = height;
// Scale viewports to fit letterbox
if ((gl_scale_viewport && !framebuffer->IsFullscreen()) || !FGLRenderBuffers::IsEnabled())
if ((gl_scale_viewport && !framebuffer->IsFullscreen() && vid_scalemode == 0) || !FGLRenderBuffers::IsEnabled())
{
mScreenViewport.width = mOutputLetterbox.width;
mScreenViewport.height = mOutputLetterbox.height;

View File

@ -55,6 +55,7 @@
EXTERN_CVAR (Float, vid_brightness)
EXTERN_CVAR (Float, vid_contrast)
EXTERN_CVAR (Bool, vid_vsync)
EXTERN_CVAR(Int, vid_scalemode)
CVAR(Bool, gl_aalines, false, CVAR_ARCHIVE)
@ -63,6 +64,8 @@ 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)
{
@ -180,18 +183,15 @@ void OpenGLFrameBuffer::Update()
Unlock();
CheckBench();
if (!IsFullscreen())
int clientWidth = ViewportScaledWidth(IsFullscreen() ? VideoWidth : GetClientWidth());
int clientHeight = ViewportScaledHeight(IsFullscreen() ? VideoHeight : GetClientHeight());
if (clientWidth > 0 && clientHeight > 0 && (Width != clientWidth || Height != clientHeight))
{
int clientWidth = GetClientWidth();
int clientHeight = GetClientHeight();
if (clientWidth > 0 && clientHeight > 0 && (Width != clientWidth || Height != clientHeight))
{
// Do not call Resize here because it's only for software canvases
Pitch = Width = clientWidth;
Height = clientHeight;
V_OutputResized(Width, Height);
GLRenderer->mVBO->OutputResized(Width, Height);
}
// Do not call Resize here because it's only for software canvases
Pitch = Width = clientWidth;
Height = clientHeight;
V_OutputResized(Width, Height);
GLRenderer->mVBO->OutputResized(Width, Height);
}
GLRenderer->SetOutputViewport(nullptr);

View File

@ -123,6 +123,37 @@ CUSTOM_CVAR (Bool, vid_tft, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
}
}
CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
if (self < 0 || self > 3)
{
self = 0;
}
}
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);
}
}
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);
}
}
//=============================================================================
//

View File

@ -151,8 +151,8 @@ CUSTOM_CVAR(Bool, fullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
extern int NewWidth, NewHeight, NewBits, DisplayBits;
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
setmodeneeded = true;
}

View File

@ -334,8 +334,8 @@ CUSTOM_CVAR(Bool, swtruecolor, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITC
CUSTOM_CVAR (Bool, fullscreen, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
setmodeneeded = true;
}
@ -349,8 +349,8 @@ CUSTOM_CVAR (Float, vid_winscale, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
else if (Video)
{
Video->SetWindowedScale (self);
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
setmodeneeded = true;
}

View File

@ -434,8 +434,8 @@ CUSTOM_CVAR(Bool, swtruecolor, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITC
CUSTOM_CVAR (Bool, fullscreen, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
{
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
setmodeneeded = true;
}
@ -449,8 +449,8 @@ CUSTOM_CVAR (Float, vid_winscale, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
else if (Video)
{
Video->SetWindowedScale (self);
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
//setmodeneeded = true; // This CVAR doesn't do anything and only causes problems!
}

View File

@ -1260,8 +1260,8 @@ void Win32GLFrameBuffer::NewRefreshRate ()
if (m_Fullscreen)
{
setmodeneeded = true;
NewWidth = screen->GetWidth();
NewHeight = screen->GetHeight();
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
NewBits = DisplayBits;
}
}

View File

@ -2191,6 +2191,7 @@ VIDMNU_HIDPI = "Retina/HiDPI support";
VIDMNU_ASPECTRATIO = "Aspect ratio";
VIDMNU_FORCEASPECT = "Force aspect ratio";
VIDMNU_5X4ASPECTRATIO = "Enable 5:4 aspect ratio";
VIDMNU_SCALEMODE = "Resolution scale";
VIDMNU_ENTERTEXT = "Press ENTER to set mode";
VIDMNU_TESTTEXT1 = "T to test mode for 5 seconds";
VIDMNU_TESTTEXT2 = "Please wait 5 seconds...";

View File

@ -1849,6 +1849,13 @@ OptionValue RatiosTFT
6.0, "21:9"
-1, "$OPTVAL_ALL"
}
OptionValue ScaleModes
{
0, "$OPTVAL_OFF"
1, "320x200"
2, "640x400"
3, "0.5x"
}
OptionMenu VideoModeMenu protected
{
@ -1862,6 +1869,7 @@ OptionMenu VideoModeMenu protected
Option "$VIDMNU_ASPECTRATIO", "menu_screenratios", "Ratios"
Option "$VIDMNU_FORCEASPECT", "vid_aspect", "ForceRatios"
Option "$VIDMNU_5X4ASPECTRATIO", "vid_tft", "YesNo"
Option "$VIDMNU_SCALEMODE", "vid_scalemode", "ScaleModes"
StaticText " "
ScreenResolution "res_0"
ScreenResolution "res_1"