all repos — mgba @ 71379aac66f002e8bc87bc3bc936fbfc4b688b27

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 mSDLGLDoViewport(int w, int h, struct VideoBackend* v) {
11	v->resized(v, w, h);
12	v->clear(v);
13	v->swap(v);
14	v->clear(v);
15}
16
17void mSDLGLCommonSwap(struct VideoBackend* context) {
18	struct mSDLRenderer* renderer = (struct mSDLRenderer*) context->user;
19#if SDL_VERSION_ATLEAST(2, 0, 0)
20	SDL_GL_SwapWindow(renderer->window);
21#else
22	UNUSED(renderer);
23	SDL_GL_SwapBuffers();
24#endif
25}
26
27bool mSDLGLCommonInit(struct mSDLRenderer* renderer) {
28#ifndef COLOR_16_BIT
29	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
30	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
31	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
32#else
33	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
34#ifdef COLOR_5_6_5
35	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
36#else
37	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
38#endif
39	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
40#endif
41
42#if SDL_VERSION_ATLEAST(2, 0, 0)
43	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));
44	renderer->glCtx = NULL;//SDL_GL_CreateContext(renderer->window);
45	if (!renderer->glCtx) {
46		SDL_DestroyWindow(renderer->window);
47		return false;
48	}
49	SDL_GL_SetSwapInterval(1);
50	SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
51	renderer->player.window = renderer->window;
52	if (renderer->lockIntegerScaling) {
53		SDL_SetWindowMinimumSize(renderer->window, renderer->width, renderer->height);
54	}
55#else
56	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
57#ifdef COLOR_16_BIT
58	SDL_Surface* surface = SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->player.fullscreen));
59#else
60	SDL_Surface* surface = SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->player.fullscreen));
61#endif
62	if (!surface) {
63		return false;
64	}
65	SDL_WM_SetCaption(projectName, "");
66#endif
67	return true;
68}