Switch: Allow switching between CPU and GPU renderers without reloading

This commit is contained in:
Vicki Pfau 2021-03-26 21:47:35 -07:00
parent 47d70582c0
commit 853c64b326
2 changed files with 29 additions and 14 deletions

View File

@ -155,6 +155,7 @@ Misc:
- 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)

View File

@ -248,6 +248,19 @@ static enum GUICursorState _pollCursor(unsigned* x, unsigned* 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 @@ static void _setup(struct mGUIRunner* runner) {
_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,10 +330,17 @@ static void _gameLoaded(struct mGUIRunner* runner) {
}
}
int scale;
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;
rumble.down = 0;
@ -889,7 +903,7 @@ int main(int argc, char* argv[]) {
.nStates = 16
},
{
.title = "GPU-accelerated renderer (requires game reload)",
.title = "GPU-accelerated renderer",
.data = "hwaccelVideo",
.submenu = 0,
.state = 0,