all repos — mgba @ c04ca093e17a6b2bbb66833b811a7473fa388aa8

mGBA Game Boy Advance Emulator

SDL: Ability to lock aspect ratio
Jeffrey Pfau jeffrey@endrift.com
Mon, 16 Mar 2015 00:10:59 -0700
commit

c04ca093e17a6b2bbb66833b811a7473fa388aa8

parent

0b38dd1289427bd77f0cadaa52aeeaf6d2c2fd94

2 files changed, 23 insertions(+), 4 deletions(-)

jump to
M CHANGESCHANGES

@@ -28,6 +28,7 @@ - Runtime configurable audio driver

- Debugger: Add CLI function for writing a register - Libretro core for use with RetroArch and other front-ends - Controller profiles for setting different bindings for different controllers + - Ability to lock aspect ratio Bugfixes: - ARM7: Extend prefetch by one stage - GBA Audio: Support 16-bit writes to FIFO audio
M src/platform/sdl/gl-sdl.csrc/platform/sdl/gl-sdl.c

@@ -29,6 +29,26 @@ 0, 1

}; #endif +static void _doViewport(int w, int h, struct SDLSoftwareRenderer* renderer) { + int drawW = w; + int drawH = h; + if (renderer->lockAspectRatio) { + if (w * 2 > h * 3) { + drawW = h * 3 / 2; + } else if (w * 2 < h * 3) { + drawH = w * 2 / 3; + } + } + glViewport((w - drawW) / 2, (h - drawH) / 2, drawW, drawH); + glClear(GL_COLOR_BUFFER_BIT); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_GL_SwapWindow(renderer->window); +#else + SDL_GL_SwapBuffers(); +#endif + glClear(GL_COLOR_BUFFER_BIT); +} + bool GBASDLInit(struct SDLSoftwareRenderer* renderer) { #ifndef COLOR_16_BIT SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);

@@ -86,9 +106,7 @@ #else

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); #endif - - glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight); - + _doViewport(renderer->viewportWidth, renderer->viewportHeight, renderer); return true; }

@@ -110,7 +128,7 @@ #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); + _doViewport(renderer->viewportWidth, renderer->viewportHeight, renderer); renderer->events.windowUpdated = 0; } #endif