all repos — mgba @ b532a214cdffde7ad45989ac1418bf5b28e2a9aa

mGBA Game Boy Advance Emulator

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