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#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#ifdef USE_EPOXY
14#include <epoxy/gl.h>
15#elif defined(BUILD_GL)
16#ifdef __APPLE__
17#include <OpenGL/gl3.h>
18#else
19#define GL_GLEXT_PROTOTYPES
20#include <GL/gl.h>
21#include <GL/glext.h>
22#endif
23#else
24#include <GLES2/gl2.h>
25#endif
26
27#include "platform/video-backend.h"
28
29union mGLES2UniformValue {
30 GLfloat f;
31 GLint i;
32 GLboolean b;
33 GLfloat fvec2[2];
34 GLfloat fvec3[3];
35 GLfloat fvec4[4];
36 GLint ivec2[2];
37 GLint ivec3[3];
38 GLint ivec4[4];
39 GLboolean bvec2[2];
40 GLboolean bvec3[3];
41 GLboolean bvec4[4];
42 GLfloat fmat2x2[4];
43 GLfloat fmat3x3[9];
44 GLfloat fmat4x4[16];
45};
46
47struct mGLES2Uniform {
48 const char* name;
49 GLenum type;
50 union mGLES2UniformValue value;
51 GLuint location;
52 union mGLES2UniformValue min;
53 union mGLES2UniformValue max;
54 const char* readableName;
55};
56
57struct mGLES2Shader {
58 int width;
59 int height;
60 bool integerScaling;
61 bool filter;
62 bool blend;
63 bool dirty;
64 GLuint tex;
65 GLuint fbo;
66 GLuint vao;
67 GLuint fragmentShader;
68 GLuint vertexShader;
69 GLuint program;
70 GLuint texLocation;
71 GLuint texSizeLocation;
72 GLuint positionLocation;
73
74 struct mGLES2Uniform* uniforms;
75 size_t nUniforms;
76};
77
78struct mGLES2Context {
79 struct VideoBackend d;
80
81 GLuint tex;
82 GLuint vbo;
83
84 struct mGLES2Shader initialShader;
85 struct mGLES2Shader finalShader;
86 struct mGLES2Shader interframeShader;
87
88 struct mGLES2Shader* shaders;
89 size_t nShaders;
90};
91
92void mGLES2ContextCreate(struct mGLES2Context*);
93
94void mGLES2ShaderInit(struct mGLES2Shader*, const char* vs, const char* fs, int width, int height, bool integerScaling, struct mGLES2Uniform* uniforms, size_t nUniforms);
95void mGLES2ShaderDeinit(struct mGLES2Shader*);
96void mGLES2ShaderAttach(struct mGLES2Context*, struct mGLES2Shader*, size_t nShaders);
97void mGLES2ShaderDetach(struct mGLES2Context*);
98
99struct VDir;
100bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*);
101void mGLES2ShaderFree(struct VideoShader*);
102
103CXX_GUARD_END
104
105#endif