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
27void 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 = SDL_GL_CreateContext(renderer->window);
45 SDL_GL_SetSwapInterval(1);
46 SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
47 renderer->player.window = renderer->window;
48 if (renderer->lockIntegerScaling) {
49 SDL_SetWindowMinimumSize(renderer->window, renderer->width, renderer->height);
50 }
51#else
52 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
53#ifdef COLOR_16_BIT
54 SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->fullscreen));
55#else
56 SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->fullscreen));
57#endif
58 SDL_WM_SetCaption(projectName, "");
59#endif
60}