SDL: Ability to lock aspect ratio

This commit is contained in:
Jeffrey Pfau 2015-03-16 00:10:59 -07:00
parent 0b38dd1289
commit c04ca093e1
2 changed files with 23 additions and 4 deletions

View File

@ -28,6 +28,7 @@ Features:
- Debugger: Add CLI function for writing a register - Debugger: Add CLI function for writing a register
- Libretro core for use with RetroArch and other front-ends - Libretro core for use with RetroArch and other front-ends
- Controller profiles for setting different bindings for different controllers - Controller profiles for setting different bindings for different controllers
- Ability to lock aspect ratio
Bugfixes: Bugfixes:
- ARM7: Extend prefetch by one stage - ARM7: Extend prefetch by one stage
- GBA Audio: Support 16-bit writes to FIFO audio - GBA Audio: Support 16-bit writes to FIFO audio

View File

@ -29,6 +29,26 @@ static const GLint _glTexCoords[] = {
}; };
#endif #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) { bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
#ifndef COLOR_16_BIT #ifndef COLOR_16_BIT
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@ -86,9 +106,7 @@ bool GBASDLInit(struct SDLSoftwareRenderer* renderer) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
#endif #endif
_doViewport(renderer->viewportWidth, renderer->viewportHeight, renderer);
glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight);
return true; return true;
} }
@ -110,7 +128,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
// Event handling can change the size of the screen // Event handling can change the size of the screen
if (renderer->events.windowUpdated) { if (renderer->events.windowUpdated) {
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); 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; renderer->events.windowUpdated = 0;
} }
#endif #endif