all repos — mgba @ ac9c2476953df4da60883ce825b7eac264a35348

mGBA Game Boy Advance Emulator

src/platform/opengl/gles2.h (view raw)

 1/* Copyright (c) 2013-2015 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 GLES2_H
 7#define GLES2_H
 8
 9#ifdef USE_EPOXY
10#include <epoxy/gl.h>
11#elif defined(BUILD_GL)
12#ifdef __APPLE__
13#include <OpenGL/gl3.h>
14#else
15#define GL_GLEXT_PROTOTYPES
16#include <GL/gl.h>
17#include <GL/glext.h>
18#endif
19#else
20#include <GLES2/gl2.h>
21#endif
22
23#include "platform/video-backend.h"
24
25union GBAGLES2UniformValue {
26	GLfloat f;
27	GLint i;
28	GLboolean b;
29	GLfloat fvec2[2];
30	GLfloat fvec3[3];
31	GLfloat fvec4[4];
32	GLint ivec2[2];
33	GLint ivec3[3];
34	GLint ivec4[4];
35	GLboolean bvec2[2];
36	GLboolean bvec3[3];
37	GLboolean bvec4[4];
38	GLfloat fmat2x2[4];
39	GLfloat fmat3x3[9];
40	GLfloat fmat4x4[16];
41};
42
43struct GBAGLES2Uniform {
44	const char* name;
45	GLenum type;
46	union GBAGLES2UniformValue value;
47	GLuint location;
48};
49
50struct GBAGLES2Shader {
51	unsigned width;
52	unsigned height;
53	bool filter;
54	bool blend;
55	GLuint tex;
56	GLuint fbo;
57	GLuint fragmentShader;
58	GLuint vertexShader;
59	GLuint program;
60	GLuint texLocation;
61	GLuint positionLocation;
62
63	struct GBAGLES2Uniform* uniforms;
64	size_t nUniforms;
65};
66
67struct GBAGLES2Context {
68	struct VideoBackend d;
69
70	GLuint tex;
71	GLuint texLocation;
72	GLuint positionLocation;
73
74	struct GBAGLES2Shader initialShader;
75	struct GBAGLES2Shader finalShader;
76
77	struct GBAGLES2Shader* shaders;
78	size_t nShaders;
79};
80
81struct GBAGLES2ShaderMetadata {
82	const char* name;
83	const char* author;
84	const char* description;
85};
86
87void GBAGLES2ContextCreate(struct GBAGLES2Context*);
88
89void GBAGLES2ShaderInit(struct GBAGLES2Shader*, const char* vs, const char* fs, int width, int height, struct GBAGLES2Uniform* uniforms, size_t nUniforms);
90void GBAGLES2ShaderDeinit(struct GBAGLES2Shader*);
91void GBAGLES2ShaderAttach(struct GBAGLES2Context*, struct GBAGLES2Shader*, size_t nShaders);
92void GBAGLES2ShaderDetach(struct GBAGLES2Context*);
93
94struct VDir;
95bool GBAGLES2ShaderLoad(struct GBAGLES2Shader**, size_t* nShaders, struct GBAGLES2ShaderMetadata*, struct VDir*);
96void GBAGLES2ShaderFree(struct GBAGLES2Shader*, size_t nShaders);
97
98#endif