diff --git a/src/r_videoscale.cpp b/src/r_videoscale.cpp index c666f08cc5..230006ed8d 100644 --- a/src/r_videoscale.cpp +++ b/src/r_videoscale.cpp @@ -25,9 +25,38 @@ #include "c_dispatch.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; } @@ -35,53 +64,22 @@ CUSTOM_CVAR (Int, vid_scalemode, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) bool ViewportLinearScale() { - switch(vid_scalemode) - { - default: return false; - case 4: - case 5: - case 6: return true; - } + return vidscale::vScaleTable[vid_scalemode].isLinear; } 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; - case 6: return 1280; - } + return vidscale::vScaleTable[vid_scalemode].GetScaledWidth(width); } 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; - case 6: return 800; - } + return vidscale::vScaleTable[vid_scalemode].GetScaledHeight(height); } bool ViewportIsScaled43() { - switch (vid_scalemode) - { - default: return false; - case 1: - case 2: - case 6: return true; - } + return vidscale::vScaleTable[vid_scalemode].isScaled43; } + diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index b95d538524..59c7946cb3 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1861,10 +1861,10 @@ OptionValue ScaleModes 0, "$OPTVAL_OFF" 1, "320x200" 2, "640x400" - 3, "0.5x" - 4, "0.75x" - 5, "2x SSAA" - 6, "1280x800" + 3, "1280x800" + 8, "0.5x" + 9, "0.75x" + 10, "2x SSAA" } OptionMenu VideoModeMenu protected