all repos — mgba @ de61a4aea4a618f24af3478fd8a241bae095e7bb

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