all repos — mgba @ 453791d28987558d3d2eb3d4facc829b84ab8257

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
113	GBA_GL_WIN_DISPCNT = 2,
114	GBA_GL_WIN_BLEND,
115	GBA_GL_WIN_FLAGS,
116	GBA_GL_WIN_WIN0,
117	GBA_GL_WIN_WIN1,
118
119	GBA_GL_FINALIZE_SCALE = 2,
120	GBA_GL_FINALIZE_LAYERS,
121	GBA_GL_FINALIZE_FLAGS,
122	GBA_GL_FINALIZE_WINDOW,
123	GBA_GL_FINALIZE_BACKDROP,
124	GBA_GL_FINALIZE_BACKDROPFLAGS,
125
126	GBA_GL_UNIFORM_MAX = 12
127};
128
129struct GBAVideoGLShader {
130	GLuint program;
131	GLuint vao;
132	GLuint uniforms[GBA_GL_UNIFORM_MAX];
133};
134
135struct GBAVideoGLRenderer {
136	struct GBAVideoRenderer d;
137
138	uint32_t* temporaryBuffer;
139
140	struct GBAVideoGLBackground bg[4];
141
142	int oamMax;
143	bool oamDirty;
144	struct GBAVideoRendererSprite sprites[128];
145
146	GLuint fbo[GBA_GL_FBO_MAX];
147	GLuint layers[GBA_GL_TEX_MAX];
148	GLuint vbo;
149
150	GLuint outputTex;
151
152	GLint shadowPalette[512];
153	bool paletteDirty;
154
155	GLuint vramTex;
156	unsigned vramDirty;
157
158	uint16_t shadowRegs[0x30];
159	uint64_t regsDirty;
160
161	struct GBAVideoGLShader bgShader[6];
162	struct GBAVideoGLShader objShader[3];
163	struct GBAVideoGLShader windowShader;
164	struct GBAVideoGLShader finalizeShader;
165
166	GBARegisterDISPCNT dispcnt;
167
168	unsigned target1Obj;
169	unsigned target1Bd;
170	unsigned target2Obj;
171	unsigned target2Bd;
172	enum GBAVideoBlendEffect blendEffect;
173	uint16_t blda;
174	uint16_t bldb;
175	uint16_t bldy;
176
177	GBAMosaicControl mosaic;
178
179	struct GBAVideoGLWindowN {
180		struct GBAVideoWindowRegion h;
181		struct GBAVideoWindowRegion v;
182		GBAWindowControl control;
183	} winN[2];
184
185	GLint winNHistory[2][GBA_VIDEO_VERTICAL_PIXELS * 4];
186
187	GBAWindowControl winout;
188	GBAWindowControl objwin;
189
190	int firstAffine;
191	int firstY;
192
193	int scale;
194};
195
196void GBAVideoGLRendererCreate(struct GBAVideoGLRenderer* renderer);
197void GBAVideoGLRendererSetScale(struct GBAVideoGLRenderer* renderer, int scale);
198
199#endif
200
201CXX_GUARD_END
202
203#endif