all repos — mgba @ 3889fd4d3f893b9a2445cea2057dbd23c997bf3c

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#else
42	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
43#ifdef COLOR_16_BIT
44	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen));
45#else
46	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen));
47#endif
48#endif
49}