all repos — mgba @ 43180dca1df957a9e82f08edbf02cd19b00248e8

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[4];
 66};
 67
 68enum {
 69	GBA_GL_FBO_OBJ = 0,
 70	GBA_GL_FBO_WINDOW = 1,
 71	GBA_GL_FBO_OUTPUT = 2,
 72	GBA_GL_FBO_MAX
 73};
 74
 75enum {
 76	GBA_GL_TEX_OBJ_COLOR = 0,
 77	GBA_GL_TEX_OBJ_FLAGS = 1,
 78	GBA_GL_TEX_WINDOW = 6,
 79	GBA_GL_TEX_MAX
 80};
 81
 82enum {
 83	GBA_GL_VS_LOC = 0,
 84	GBA_GL_VS_MAXPOS,
 85
 86	GBA_GL_BG_VRAM = 2,
 87	GBA_GL_BG_PALETTE,
 88	GBA_GL_BG_SCREENBASE,
 89	GBA_GL_BG_CHARBASE,
 90	GBA_GL_BG_SIZE,
 91	GBA_GL_BG_OFFSET,
 92	GBA_GL_BG_INFLAGS,
 93	GBA_GL_BG_TRANSFORM,
 94	GBA_GL_BG_RANGE,
 95
 96	GBA_GL_OBJ_VRAM = 2,
 97	GBA_GL_OBJ_PALETTE,
 98	GBA_GL_OBJ_CHARBASE,
 99	GBA_GL_OBJ_STRIDE,
100	GBA_GL_OBJ_LOCALPALETTE,
101	GBA_GL_OBJ_INFLAGS,
102	GBA_GL_OBJ_TRANSFORM,
103	GBA_GL_OBJ_DIMS,
104	GBA_GL_OBJ_OBJWIN,
105
106	GBA_GL_FINALIZE_SCALE = 2,
107	GBA_GL_FINALIZE_LAYERS,
108	GBA_GL_FINALIZE_FLAGS,
109	GBA_GL_FINALIZE_WINDOW,
110	GBA_GL_FINALIZE_BACKDROP,
111	GBA_GL_FINALIZE_BACKDROPFLAGS,
112
113	GBA_GL_UNIFORM_MAX = 12
114};
115
116struct GBAVideoGLShader {
117	GLuint program;
118	GLuint vao;
119	GLuint uniforms[GBA_GL_UNIFORM_MAX];
120};
121
122struct GBAVideoGLRenderer {
123	struct GBAVideoRenderer d;
124
125	uint32_t* temporaryBuffer;
126
127	struct GBAVideoGLBackground bg[4];
128
129	int oamMax;
130	bool oamDirty;
131	struct GBAVideoRendererSprite sprites[128];
132
133	GLuint fbo[GBA_GL_FBO_MAX];
134	GLuint layers[GBA_GL_TEX_MAX];
135	GLuint vbo;
136
137	GLuint outputTex;
138
139#ifdef BUILD_GLES3
140	uint16_t shadowPalette[512];
141#endif
142	GLuint paletteTex;
143	bool paletteDirty;
144
145	GLuint vramTex;
146	unsigned vramDirty;
147
148	struct GBAVideoGLShader bgShader[6];
149	struct GBAVideoGLShader objShader[2];
150	struct GBAVideoGLShader finalizeShader;
151
152	GBARegisterDISPCNT dispcnt;
153
154	unsigned target1Obj;
155	unsigned target1Bd;
156	unsigned target2Obj;
157	unsigned target2Bd;
158	enum GBAVideoBlendEffect blendEffect;
159	uint16_t blda;
160	uint16_t bldb;
161	uint16_t bldy;
162
163	GBAMosaicControl mosaic;
164
165	struct GBAVideoGLWindowN {
166		struct GBAVideoWindowRegion h[2];
167		struct GBAVideoWindowRegion v;
168		GBAWindowControl control;
169	} winN[2];
170
171	GBAWindowControl winout;
172	GBAWindowControl objwin;
173
174	int firstAffine;
175
176	int scale;
177};
178
179void GBAVideoGLRendererCreate(struct GBAVideoGLRenderer* renderer);
180
181#endif
182
183CXX_GUARD_END
184
185#endif