all repos — mgba @ 86cf8a90a35bd1b210aa21e8252164dc6f9928c2

mGBA Game Boy Advance Emulator

src/platform/sdl/gl-common.c (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "main.h"
 7
 8#include <mgba/core/version.h>
 9
10void mSDLGLCommonSwap(struct VideoBackend* context) {
11	struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user;
12#if SDL_VERSION_ATLEAST(2, 0, 0)
13	SDL_GL_SwapWindow(renderer->window);
14#else
15	UNUSED(renderer);
16	SDL_GL_SwapBuffers();
17#endif
18}
19
20void mSDLGLCommonInit(struct mSDLRenderer* renderer) {
21#ifndef COLOR_16_BIT
22	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
23	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
24	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
25#else
26	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
27#ifdef COLOR_5_6_5
28	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
29#else
30	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
31#endif
32	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
33#endif
34
35#if SDL_VERSION_ATLEAST(2, 0, 0)
36	renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
37	renderer->glCtx = SDL_GL_CreateContext(renderer->window);
38	SDL_GL_SetSwapInterval(1);
39	SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
40	renderer->player.window = renderer->window;
41	if (renderer->lockIntegerScaling) {
42		SDL_SetWindowMinimumSize(renderer->window, renderer->width, renderer->height);
43	}
44#else
45	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
46#ifdef COLOR_16_BIT
47	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen));
48#else
49	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen));
50#endif
51#endif
52}