all repos — mgba @ d312aa2c7ab1681a6eb6dbf9591d95720f0b7753

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
 8void GBASDLGLCommonSwap(struct VideoBackend* context) {
 9	struct SDLSoftwareRenderer* renderer = (struct SDLSoftwareRenderer*) context->user;
10#if SDL_VERSION_ATLEAST(2, 0, 0)
11	SDL_GL_SwapWindow(renderer->window);
12#else
13	UNUSED(renderer);
14	SDL_GL_SwapBuffers();
15#endif
16}
17
18void GBASDLGLCommonInit(struct SDLSoftwareRenderer* renderer) {
19#ifndef COLOR_16_BIT
20	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
21	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
22	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
23#else
24	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
25#ifdef COLOR_5_6_5
26	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
27#else
28	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
29#endif
30	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
31#endif
32
33#if SDL_VERSION_ATLEAST(2, 0, 0)
34	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));
35	renderer->glCtx = SDL_GL_CreateContext(renderer->window);
36	SDL_GL_SetSwapInterval(1);
37	SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
38	renderer->player.window = renderer->window;
39#else
40	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
41#ifdef COLOR_16_BIT
42	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL);
43#else
44	SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL);
45#endif
46#endif
47}