diff --git a/src/platform/sdl/egl-sdl.c b/src/platform/sdl/egl-sdl.c index 54d7c0725..fd50c4245 100644 --- a/src/platform/sdl/egl-sdl.c +++ b/src/platform/sdl/egl-sdl.c @@ -130,6 +130,10 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render SDL_Event event; while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { glViewport(0, 0, 240, 160); glClear(GL_COLOR_BUFFER_BIT); @@ -145,10 +149,6 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render eglSwapBuffers(renderer->display, renderer->surface); } GBASyncWaitFrameEnd(&context->sync); - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); - } } } diff --git a/src/platform/sdl/gl-sdl.c b/src/platform/sdl/gl-sdl.c index 61ccc67d4..e7a770b8e 100644 --- a/src/platform/sdl/gl-sdl.c +++ b/src/platform/sdl/gl-sdl.c @@ -83,6 +83,18 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render glLoadIdentity(); glOrtho(0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 0, 0, 1); while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); +#if SDL_VERSION_ATLEAST(2, 0, 0) + // Event handling can change the size of the screen + if (renderer->events.windowUpdated) { + SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); + glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); + renderer->events.windowUpdated = 0; + } +#endif + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { glBindTexture(GL_TEXTURE_2D, renderer->tex); #ifdef COLOR_16_BIT @@ -105,18 +117,6 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render #else SDL_GL_SwapBuffers(); #endif - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); -#if SDL_VERSION_ATLEAST(2, 0, 0) - // Event handling can change the size of the screen - if (renderer->events.windowUpdated) { - SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); - glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); - renderer->events.windowUpdated = 0; - } -#endif - } } } diff --git a/src/platform/sdl/sw-sdl.c b/src/platform/sdl/sw-sdl.c index 25074ab03..d5b20bf97 100644 --- a/src/platform/sdl/sw-sdl.c +++ b/src/platform/sdl/sw-sdl.c @@ -60,6 +60,10 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render #endif while (context->state < THREAD_EXITING) { + while (SDL_PollEvent(&event)) { + GBASDLHandleEvent(context, &renderer->events, &event); + } + if (GBASyncWaitFrameStart(&context->sync, context->frameskip)) { #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_UnlockTexture(renderer->tex); @@ -88,10 +92,6 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render #endif } GBASyncWaitFrameEnd(&context->sync); - - while (SDL_PollEvent(&event)) { - GBASDLHandleEvent(context, &renderer->events, &event); - } } }