SDL: Fix changing screen size when using OpenGL ES 2

This commit is contained in:
Cameron Cawley 2018-01-29 17:29:19 +00:00 committed by endrift
parent 4f8fe384b3
commit eafd265ab6
4 changed files with 20 additions and 9 deletions

View File

@ -7,6 +7,13 @@
#include <mgba/core/version.h> #include <mgba/core/version.h>
void mSDLGLDoViewport(int w, int h, struct VideoBackend* v) {
v->resized(v, w, h);
v->clear(v);
v->swap(v);
v->clear(v);
}
void mSDLGLCommonSwap(struct VideoBackend* context) { void mSDLGLCommonSwap(struct VideoBackend* context) {
struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user; struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)

View File

@ -12,6 +12,7 @@ CXX_GUARD_START
#include "main.h" #include "main.h"
void mSDLGLDoViewport(int w, int h, struct VideoBackend* v);
void mSDLGLCommonSwap(struct VideoBackend* context); void mSDLGLCommonSwap(struct VideoBackend* context);
void mSDLGLCommonInit(struct mSDLRenderer* renderer); void mSDLGLCommonInit(struct mSDLRenderer* renderer);

View File

@ -13,13 +13,6 @@
#include "platform/opengl/gl.h" #include "platform/opengl/gl.h"
static void _doViewport(int w, int h, struct VideoBackend* v) {
v->resized(v, w, h);
v->clear(v);
v->swap(v);
v->clear(v);
}
static bool mSDLGLInit(struct mSDLRenderer* renderer); static bool mSDLGLInit(struct mSDLRenderer* renderer);
static void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user); static void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user);
static void mSDLGLDeinit(struct mSDLRenderer* renderer); static void mSDLGLDeinit(struct mSDLRenderer* renderer);
@ -47,7 +40,7 @@ bool mSDLGLInit(struct mSDLRenderer* renderer) {
renderer->gl.d.init(&renderer->gl.d, 0); renderer->gl.d.init(&renderer->gl.d, 0);
renderer->gl.d.setDimensions(&renderer->gl.d, renderer->width, renderer->height); renderer->gl.d.setDimensions(&renderer->gl.d, renderer->width, renderer->height);
_doViewport(renderer->viewportWidth, renderer->viewportHeight, &renderer->gl.d); mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, &renderer->gl.d);
return true; return true;
} }
@ -63,7 +56,7 @@ void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user) {
// Event handling can change the size of the screen // Event handling can change the size of the screen
if (renderer->player.windowUpdated) { if (renderer->player.windowUpdated) {
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
_doViewport(renderer->viewportWidth, renderer->viewportHeight, v); mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, v);
renderer->player.windowUpdated = 0; renderer->player.windowUpdated = 0;
} }
#endif #endif

View File

@ -115,6 +115,8 @@ bool mSDLGLES2Init(struct mSDLRenderer* renderer) {
renderer->gl2.d.swap = mSDLGLCommonSwap; renderer->gl2.d.swap = mSDLGLCommonSwap;
renderer->gl2.d.init(&renderer->gl2.d, 0); renderer->gl2.d.init(&renderer->gl2.d, 0);
renderer->gl2.d.setDimensions(&renderer->gl2.d, renderer->width, renderer->height); renderer->gl2.d.setDimensions(&renderer->gl2.d, renderer->width, renderer->height);
mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, &renderer->gl2.d);
return true; return true;
} }
@ -126,6 +128,14 @@ void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user) {
while (mCoreThreadIsActive(context)) { while (mCoreThreadIsActive(context)) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
mSDLHandleEvent(context, &renderer->player, &event); mSDLHandleEvent(context, &renderer->player, &event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
// Event handling can change the size of the screen
if (renderer->player.windowUpdated) {
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, v);
renderer->player.windowUpdated = 0;
}
#endif
} }
if (mCoreSyncWaitFrameStart(&context->impl->sync)) { if (mCoreSyncWaitFrameStart(&context->impl->sync)) {