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#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
20
21#ifdef USE_EPOXY
22#include <epoxy/gl.h>
23#elif defined(BUILD_GL)
24#ifdef __APPLE__
25#include <OpenGL/gl3.h>
26#else
27#define GL_GLEXT_PROTOTYPES
28#include <GL/gl.h>
29#include <GL/glext.h>
30#endif
31#else
32#include <GLES3/gl3.h>
33#endif
34
35struct GBAVideoGLAffine {
36 int16_t dx;
37 int16_t dmx;
38 int16_t dy;
39 int16_t dmy;
40 int32_t sx;
41 int32_t sy;
42};
43
44struct GBAVideoGLBackground {
45 GLuint fbo;
46 GLuint tex;
47 GLuint flags;
48 GLuint scanlineTex;
49
50 unsigned index;
51 int enabled;
52 unsigned priority;
53 uint32_t charBase;
54 int mosaic;
55 int multipalette;
56 uint32_t screenBase;
57 int overflow;
58 int size;
59 int target1;
60 int target2;
61 uint16_t x;
62 uint16_t y;
63 int32_t refx;
64 int32_t refy;
65
66 struct GBAVideoGLAffine affine;
67};
68
69enum {
70 GBA_GL_FBO_OBJ = 0,
71 GBA_GL_FBO_BACKDROP,
72 GBA_GL_FBO_WINDOW,
73 GBA_GL_FBO_OUTPUT,
74 GBA_GL_FBO_MAX
75};
76
77enum {
78 GBA_GL_TEX_OBJ_COLOR = 0,
79 GBA_GL_TEX_OBJ_FLAGS,
80 GBA_GL_TEX_OBJ_DEPTH,
81 GBA_GL_TEX_BACKDROP_COLOR,
82 GBA_GL_TEX_BACKDROP_FLAGS,
83 GBA_GL_TEX_WINDOW,
84 GBA_GL_TEX_AFFINE_2,
85 GBA_GL_TEX_AFFINE_3,
86 GBA_GL_TEX_MAX
87};
88
89enum {
90 GBA_GL_VS_LOC = 0,
91 GBA_GL_VS_MAXPOS,
92
93 GBA_GL_BG_VRAM = 2,
94 GBA_GL_BG_PALETTE,
95 GBA_GL_BG_SCREENBASE,
96 GBA_GL_BG_CHARBASE,
97 GBA_GL_BG_SIZE,
98 GBA_GL_BG_OFFSET,
99 GBA_GL_BG_INFLAGS,
100 GBA_GL_BG_TRANSFORM,
101 GBA_GL_BG_RANGE,
102 GBA_GL_BG_MOSAIC,
103
104 GBA_GL_OBJ_VRAM = 2,
105 GBA_GL_OBJ_PALETTE,
106 GBA_GL_OBJ_CHARBASE,
107 GBA_GL_OBJ_STRIDE,
108 GBA_GL_OBJ_LOCALPALETTE,
109 GBA_GL_OBJ_INFLAGS,
110 GBA_GL_OBJ_TRANSFORM,
111 GBA_GL_OBJ_DIMS,
112 GBA_GL_OBJ_OBJWIN,
113 GBA_GL_OBJ_MOSAIC,
114
115 GBA_GL_WIN_DISPCNT = 2,
116 GBA_GL_WIN_BLEND,
117 GBA_GL_WIN_FLAGS,
118 GBA_GL_WIN_WIN0,
119 GBA_GL_WIN_WIN1,
120
121 GBA_GL_FINALIZE_SCALE = 2,
122 GBA_GL_FINALIZE_LAYERS,
123 GBA_GL_FINALIZE_FLAGS,
124 GBA_GL_FINALIZE_WINDOW,
125 GBA_GL_FINALIZE_BACKDROP,
126 GBA_GL_FINALIZE_BACKDROPFLAGS,
127
128 GBA_GL_UNIFORM_MAX = 12
129};
130
131struct GBAVideoGLShader {
132 GLuint program;
133 GLuint vao;
134 GLuint uniforms[GBA_GL_UNIFORM_MAX];
135};
136
137struct GBAVideoGLRenderer {
138 struct GBAVideoRenderer d;
139
140 uint32_t* temporaryBuffer;
141
142 struct GBAVideoGLBackground bg[4];
143 struct GBAVideoGLAffine affine[2][GBA_VIDEO_VERTICAL_PIXELS];
144
145 int oamMax;
146 bool oamDirty;
147 struct GBAVideoRendererSprite sprites[128];
148
149 GLuint fbo[GBA_GL_FBO_MAX];
150 GLuint layers[GBA_GL_TEX_MAX];
151 GLuint vbo;
152
153 GLuint outputTex;
154
155 GLint shadowPalette[512];
156 bool paletteDirty;
157
158 GLuint vramTex;
159 unsigned vramDirty;
160
161 uint16_t shadowRegs[0x30];
162 uint64_t regsDirty;
163
164 struct GBAVideoGLShader bgShader[6];
165 struct GBAVideoGLShader objShader[2];
166 struct GBAVideoGLShader windowShader;
167 struct GBAVideoGLShader finalizeShader;
168
169 GBARegisterDISPCNT dispcnt;
170
171 unsigned target1Obj;
172 unsigned target1Bd;
173 unsigned target2Obj;
174 unsigned target2Bd;
175 enum GBAVideoBlendEffect blendEffect;
176 uint16_t blda;
177 uint16_t bldb;
178 uint16_t bldy;
179
180 GBAMosaicControl mosaic;
181
182 struct GBAVideoGLWindowN {
183 struct GBAVideoWindowRegion h;
184 struct GBAVideoWindowRegion v;
185 GBAWindowControl control;
186 } winN[2];
187
188 GLint winNHistory[2][GBA_VIDEO_VERTICAL_PIXELS * 4];
189
190 GBAWindowControl winout;
191 GBAWindowControl objwin;
192
193 int firstAffine;
194 int firstY;
195
196 int scale;
197};
198
199void GBAVideoGLRendererCreate(struct GBAVideoGLRenderer* renderer);
200
201#endif
202
203CXX_GUARD_END
204
205#endif