Switch: Allow switching between CPU and GPU renderers without reloading
Vicki Pfau vi@endrift.com
Fri, 26 Mar 2021 21:47:35 -0700
2 files changed,
29 insertions(+),
14 deletions(-)
M
CHANGES
→
CHANGES
@@ -155,6 +155,7 @@ - Qt: Use relative paths in portable mode when applicable (fixes mgba.io/i/838)
- Qt: Better initial shortcut editor column sizes - SDL: Fall back to sw blit if OpenGL init fails - Switch: Optimize font rendering (fixes mgba.io/i/2078) + - Switch: Allow switching between CPU and GPU renderers without reloading - Util: Reset vector size on deinit - VFS: Change semantics of VFile.sync on mapped files (fixes mgba.io/i/1730)
M
src/platform/switch/main.c
→
src/platform/switch/main.c
@@ -248,6 +248,19 @@ *y = state.touches[0].y;
return GUI_CURSOR_DOWN; } +static void _updateRenderer(struct mGUIRunner* runner, bool gl) { + if (gl) { + runner->core->setVideoGLTex(runner->core, tex); + usePbo = false; + } else { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + runner->core->setVideoBuffer(runner->core, frameBuffer, 256); + usePbo = true; + } +} + static void _setup(struct mGUIRunner* runner) { _mapKey(&runner->core->inputMap, AUTO_INPUT, HidNpadButton_A, GBA_KEY_A); _mapKey(&runner->core->inputMap, AUTO_INPUT, HidNpadButton_B, GBA_KEY_B);@@ -260,17 +273,11 @@ _mapKey(&runner->core->inputMap, AUTO_INPUT, HidNpadButton_Right, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, AUTO_INPUT, HidNpadButton_L, GBA_KEY_L); _mapKey(&runner->core->inputMap, AUTO_INPUT, HidNpadButton_R, GBA_KEY_R); - int fakeBool; - if (mCoreConfigGetIntValue(&runner->config, "hwaccelVideo", &fakeBool) && fakeBool && runner->core->supportsFeature(runner->core, mCORE_FEATURE_OPENGL)) { - runner->core->setVideoGLTex(runner->core, tex); - usePbo = false; - } else { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - runner->core->setVideoBuffer(runner->core, frameBuffer, 256); - usePbo = true; + int fakeBool = false; + if (runner->core->supportsFeature(runner->core, mCORE_FEATURE_OPENGL)) { + mCoreConfigGetIntValue(&runner->config, "hwaccelVideo", &fakeBool); } + _updateRenderer(runner, fakeBool); runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d); runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation);@@ -323,9 +330,16 @@ }
} } - int scale; - if (mCoreConfigGetUIntValue(&runner->config, "videoScale", &scale)) { - runner->core->reloadConfigOption(runner->core, "videoScale", &runner->config); + if (runner->core->supportsFeature(runner->core, mCORE_FEATURE_OPENGL)) { + if (mCoreConfigGetIntValue(&runner->config, "hwaccelVideo", &fakeBool) && fakeBool == usePbo) { + _updateRenderer(runner, fakeBool); + runner->core->reloadConfigOption(runner->core, "hwaccelVideo", &runner->config); + } + + unsigned scale; + if (mCoreConfigGetUIntValue(&runner->config, "videoScale", &scale)) { + runner->core->reloadConfigOption(runner->core, "videoScale", &runner->config); + } } rumble.up = 0;@@ -889,7 +903,7 @@ },
.nStates = 16 }, { - .title = "GPU-accelerated renderer (requires game reload)", + .title = "GPU-accelerated renderer", .data = "hwaccelVideo", .submenu = 0, .state = 0,