- refactored r_videoscale.cpp to use a table.

- reordered vid_scalemode modes to be a little neater, having static modes and scalar modes separate, with a buffer in between so new modes can be added in the future without disrupting the current order.
This commit is contained in:
Rachael Alexanderson 2017-09-10 09:40:30 -04:00
parent 666198dec8
commit 86a66cd554
2 changed files with 40 additions and 42 deletions

View file

@ -25,9 +25,38 @@
#include "c_dispatch.h" #include "c_dispatch.h"
#include "c_cvars.h" #include "c_cvars.h"
CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) #define NUMSCALEMODES 11
namespace vidscale
{ {
if (self < 0 || self > 6) struct v_ScaleTable
{
bool isValid;
bool isLinear;
uint32_t(*GetScaledWidth)(uint32_t Width);
uint32_t(*GetScaledHeight)(uint32_t Height);
bool isScaled43;
};
v_ScaleTable vScaleTable[NUMSCALEMODES] =
{
// isValid, isLinear, GetScaledWidth(), GetScaledHeight(), isScaled43
{ true, false, [](uint32_t Width)->uint32_t { return Width; }, [](uint32_t Height)->uint32_t { return Height; }, false }, // 0 - Native
{ true, false, [](uint32_t Width)->uint32_t { return 320; }, [](uint32_t Height)->uint32_t { return 200; }, true }, // 1 - 320x200
{ true, true, [](uint32_t Width)->uint32_t { return 640; }, [](uint32_t Height)->uint32_t { return 400; }, true }, // 2 - 640x400
{ true, true, [](uint32_t Width)->uint32_t { return 1280; }, [](uint32_t Height)->uint32_t { return 800; }, true }, // 3 - 1280x800
{ false, false, nullptr, nullptr, false }, // 4
{ false, false, nullptr, nullptr, false }, // 5
{ false, false, nullptr, nullptr, false }, // 6
{ false, false, nullptr, nullptr, false }, // 7
{ true, false, [](uint32_t Width)->uint32_t { return Width / 2; }, [](uint32_t Height)->uint32_t { return Height / 2; }, false }, // 8 - Half-Res
{ true, true, [](uint32_t Width)->uint32_t { return Width * 0.75; }, [](uint32_t Height)->uint32_t { return Height * 0.75; }, false }, // 9 - Res * 0.75
{ true, true, [](uint32_t Width)->uint32_t { return Width * 2; }, [](uint32_t Height)->uint32_t { return Height * 2; }, false }, // 10 - SSAAx2
};
}
CUSTOM_CVAR(Int, vid_scalemode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0 || self >= NUMSCALEMODES || vidscale::vScaleTable[self].isValid == false)
{ {
self = 0; self = 0;
} }
@ -35,53 +64,22 @@ CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
bool ViewportLinearScale() bool ViewportLinearScale()
{ {
switch(vid_scalemode) return vidscale::vScaleTable[vid_scalemode].isLinear;
{
default: return false;
case 4:
case 5:
case 6: return true;
}
} }
int ViewportScaledWidth(int width) int ViewportScaledWidth(int width)
{ {
switch (vid_scalemode) return vidscale::vScaleTable[vid_scalemode].GetScaledWidth(width);
{
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;
case 6: return 1280;
}
} }
int ViewportScaledHeight(int height) int ViewportScaledHeight(int height)
{ {
switch (vid_scalemode) return vidscale::vScaleTable[vid_scalemode].GetScaledHeight(height);
{
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;
case 6: return 800;
}
} }
bool ViewportIsScaled43() bool ViewportIsScaled43()
{ {
switch (vid_scalemode) return vidscale::vScaleTable[vid_scalemode].isScaled43;
{
default: return false;
case 1:
case 2:
case 6: return true;
}
} }

View file

@ -1861,10 +1861,10 @@ OptionValue ScaleModes
0, "$OPTVAL_OFF" 0, "$OPTVAL_OFF"
1, "320x200" 1, "320x200"
2, "640x400" 2, "640x400"
3, "0.5x" 3, "1280x800"
4, "0.75x" 8, "0.5x"
5, "2x SSAA" 9, "0.75x"
6, "1280x800" 10, "2x SSAA"
} }
OptionMenu VideoModeMenu protected OptionMenu VideoModeMenu protected