all repos — mgba @ 60ec3e0e9926da9a10771f164f5040359f077872

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