diff --git a/src/gba/gui/gui-runner.c b/src/gba/gui/gui-runner.c index a0751d41c..5a604fa60 100644 --- a/src/gba/gui/gui-runner.c +++ b/src/gba/gui/gui-runner.c @@ -258,7 +258,13 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) { runner->params.drawStart(); runner->drawFrame(runner, false); if (drawFps) { + if (runner->params.guiPrepare) { + runner->params.guiPrepare(); + } GUIFontPrintf(runner->params.font, 0, GUIFontHeight(runner->params.font), GUI_TEXT_LEFT, 0x7FFFFFFF, "%.2f fps", runner->fps); + if (runner->params.guiPrepare) { + runner->params.guiFinish(); + } } runner->params.drawEnd(); diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 1b76515e1..b3b198569 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -48,6 +48,7 @@ static int16_t* audioLeft = 0; static int16_t* audioRight = 0; static size_t audioPos = 0; static struct ctrTexture gbaOutputTexture; +static bool guiDrawn; extern bool allocateRomBuffer(void); @@ -60,16 +61,46 @@ static void _drawStart(void) { } else { ctrSetViewportSize(400, 240); } + guiDrawn = false; } static void _drawEnd(void) { + if (!guiDrawn) { + int screen = screenMode < SM_PA_TOP ? GFX_BOTTOM : GFX_TOP; + u16 width = 0, height = 0; + + void* outputFramebuffer = gfxGetFramebuffer(screen, GFX_LEFT, &height, &width); + ctrGpuEndFrame(outputFramebuffer, width, height); + } + gfxSwapBuffersGpu(); + gspWaitForEvent(GSPEVENT_VBlank0, false); +} + +static void _guiPrepare(void) { int screen = screenMode < SM_PA_TOP ? GFX_BOTTOM : GFX_TOP; + if (screen == GFX_BOTTOM) { + return; + } + u16 width = 0, height = 0; void* outputFramebuffer = gfxGetFramebuffer(screen, GFX_LEFT, &height, &width); ctrGpuEndFrame(outputFramebuffer, width, height); - gfxSwapBuffersGpu(); - gspWaitForEvent(GSPEVENT_VBlank0, false); + guiDrawn = true; + + ctrGpuBeginFrame(); + ctrSetViewportSize(320, 240); +} + +static void _guiFinish(void) { + int screen = screenMode < SM_PA_TOP ? GFX_BOTTOM : GFX_TOP; + if (screen == GFX_BOTTOM) { + return; + } + + u16 width = 0, height = 0; + void* outputFramebuffer = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &height, &width); + ctrGpuEndFrame(outputFramebuffer, width, height); } static void _setup(struct GBAGUIRunner* runner) { @@ -403,7 +434,7 @@ int main() { font, "/", _drawStart, _drawEnd, _pollInput, _pollCursor, - 0, 0, + _guiPrepare, _guiFinish, GUI_PARAMS_TRAIL },