From dd7e422bde762063efded268abc8f14b06821e03 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 17 Nov 2018 14:48:03 -0800 Subject: [PATCH] Switch: Screen stretching options --- CHANGES | 1 + src/platform/switch/main.c | 64 +++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 18bb402f1..21b1e3f51 100644 --- a/CHANGES +++ b/CHANGES @@ -114,6 +114,7 @@ Features: - Qt: Separate fast forward volume control (fixes mgba.io/i/846, mgba.io/i/1143) - Switch: Rumble support - Switch: Rotation support + - Switch: Screen stretching options - Qt: State file load/save menu options - Windows installer - Tile viewer now has adjustable width diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index 6c1018712..c8d2fbd3d 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -92,6 +92,13 @@ static unsigned framecap = 10; static u32 vibrationDeviceHandles[4]; static HidVibrationValue vibrationStop = { .freq_low = 160.f, .freq_high = 320.f }; +static enum ScreenMode { + SM_PA, + SM_AF, + SM_SF, + SM_MAX +} screenMode = SM_PA; + static bool initEgl() { s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!s_display) { @@ -238,6 +245,11 @@ static void _setup(struct mGUIRunner* runner) { runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d); runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation); runner->core->setAVStream(runner->core, &stream); + + unsigned mode; + if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { + screenMode = mode; + } } static void _gameLoaded(struct mGUIRunner* runner) { @@ -249,6 +261,11 @@ static void _gameLoaded(struct mGUIRunner* runner) { mCoreConfigGetUIntValue(&runner->config, "fastForwardCap", &framecap); + unsigned mode; + if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { + screenMode = mode; + } + rumble.up = 0; rumble.down = 0; } @@ -270,11 +287,26 @@ static void _drawTex(struct mGUIRunner* runner, unsigned width, unsigned height, glBindVertexArray(vao); float aspectX = width / (float) runner->params.width; float aspectY = height / (float) runner->params.height; - float max; - if (aspectX > aspectY) { - max = floor(1.0 / aspectX); - } else { - max = floor(1.0 / aspectY); + float max = 1.f; + switch (screenMode) { + case SM_PA: + if (aspectX > aspectY) { + max = floor(1.0 / aspectX); + } else { + max = floor(1.0 / aspectY); + } + break; + case SM_AF: + if (aspectX > aspectY) { + max = 1.0 / aspectX; + } else { + max = 1.0 / aspectY; + } + break; + case SM_SF: + aspectX = 1.0; + aspectY = 1.0; + break; } aspectX *= max; @@ -354,6 +386,12 @@ static uint16_t _pollGameInput(struct mGUIRunner* runner) { return _pollInput(&runner->core->inputMap); } +static void _incrementScreenMode(struct mGUIRunner* runner) { + UNUSED(runner); + screenMode = (screenMode + 1) % SM_MAX; + mCoreConfigSetUIntValue(&runner->config, "screenMode", screenMode); +} + static void _setFrameLimiter(struct mGUIRunner* runner, bool limit) { UNUSED(runner); if (!frameLimiter && limit) { @@ -607,6 +645,18 @@ int main(int argc, char* argv[]) { { .id = 0 } }, .configExtra = (struct GUIMenuItem[]) { + { + .title = "Screen mode", + .data = "screenMode", + .submenu = 0, + .state = SM_PA, + .validStates = (const char*[]) { + "Pixel-Accurate", + "Aspect-Ratio Fit", + "Stretched", + }, + .nStates = 3 + }, { .title = "Fast forward cap", .data = "fastForwardCap", @@ -637,7 +687,7 @@ int main(int argc, char* argv[]) { .nStates = 15 }, }, - .nConfigExtra = 1, + .nConfigExtra = 2, .setup = _setup, .teardown = NULL, .gameLoaded = _gameLoaded, @@ -647,7 +697,7 @@ int main(int argc, char* argv[]) { .drawScreenshot = _drawScreenshot, .paused = _gameUnloaded, .unpaused = _gameLoaded, - .incrementScreenMode = NULL, + .incrementScreenMode = _incrementScreenMode, .setFrameLimiter = _setFrameLimiter, .pollGameInput = _pollGameInput, .running = _running