include/mgba/internal/gba/renderers/gl.h (view raw)
1/* Copyright (c) 2013-2019 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#ifndef VIDEO_GL_H
7#define VIDEO_GL_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/core.h>
14#include <mgba/gba/interface.h>
15#include <mgba/internal/gba/io.h>
16#include <mgba/internal/gba/renderers/common.h>
17#include <mgba/internal/gba/video.h>
18
19#ifdef USE_EPOXY
20#include <epoxy/gl.h>
21#elif defined(BUILD_GL)
22#ifdef __APPLE__
23#include <OpenGL/gl3.h>
24#else
25#define GL_GLEXT_PROTOTYPES
26#include <GL/gl.h>
27#include <GL/glext.h>
28#endif
29#else
30#include <GLES2/gl2.h>
31#endif
32
33struct GBAVideoGLAffine {
34 int16_t dx;
35 int16_t dmx;
36 int16_t dy;
37 int16_t dmy;
38 int32_t sx;
39 int32_t sy;
40};
41
42struct GBAVideoGLBackground {
43 GLuint fbo;
44 GLuint tex;
45 GLuint flags;
46
47 unsigned index;
48 int enabled;
49 unsigned priority;
50 uint32_t charBase;
51 int mosaic;
52 int multipalette;
53 uint32_t screenBase;
54 int overflow;
55 int size;
56 int target1;
57 int target2;
58 uint16_t x;
59 uint16_t y;
60 int32_t refx;
61 int32_t refy;
62
63 struct GBAVideoGLAffine affine[4];
64};
65
66enum {
67 GBA_GL_FBO_OBJ = 0,
68 GBA_GL_FBO_COMPOSITE = 1,
69 GBA_GL_FBO_OUTPUT = 2,
70
71 GBA_GL_TEX_OBJ_COLOR = 0,
72 GBA_GL_TEX_OBJ_FLAGS = 1,
73 GBA_GL_TEX_COMPOSITE_COLOR = 2,
74 GBA_GL_TEX_COMPOSITE_FLAGS = 3,
75 GBA_GL_TEX_COMPOSITE_OLD_COLOR = 4,
76 GBA_GL_TEX_COMPOSITE_OLD_FLAGS = 5,
77};
78
79struct GBAVideoGLRenderer {
80 struct GBAVideoRenderer d;
81
82 struct GBAVideoGLBackground bg[4];
83
84 int oamMax;
85 bool oamDirty;
86 struct GBAVideoRendererSprite sprites[128];
87
88 GLuint fbo[3];
89 GLuint layers[6];
90
91 GLuint outputTex;
92
93 GLuint paletteTex;
94 bool paletteDirty;
95
96 GLuint vramTex;
97 unsigned vramDirty;
98
99 GLuint bgProgram[6];
100 GLuint objProgram[2];
101
102 GLuint compositeProgram;
103 GLuint finalizeProgram;
104
105 GBARegisterDISPCNT dispcnt;
106
107 unsigned target1Obj;
108 unsigned target1Bd;
109 unsigned target2Obj;
110 unsigned target2Bd;
111 enum GBAVideoBlendEffect blendEffect;
112 uint16_t blda;
113 uint16_t bldb;
114 uint16_t bldy;
115
116 GBAMosaicControl mosaic;
117
118 int firstAffine;
119
120 int scale;
121};
122
123void GBAVideoGLRendererCreate(struct GBAVideoGLRenderer* renderer);
124
125CXX_GUARD_END
126
127#endif