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 GLuint tex;
64 GLuint fbo;
65 GLuint fragmentShader;
66 GLuint vertexShader;
67 GLuint program;
68 GLuint texLocation;
69 GLuint texSizeLocation;
70 GLuint positionLocation;
71
72 struct mGLES2Uniform* uniforms;
73 size_t nUniforms;
74};
75
76struct mGLES2Context {
77 struct VideoBackend d;
78
79 GLuint tex;
80 GLuint texLocation;
81 GLuint positionLocation;
82
83 struct mGLES2Shader initialShader;
84 struct mGLES2Shader finalShader;
85
86 struct mGLES2Shader* shaders;
87 size_t nShaders;
88};
89
90void mGLES2ContextCreate(struct mGLES2Context*);
91
92void mGLES2ShaderInit(struct mGLES2Shader*, const char* vs, const char* fs, int width, int height, bool integerScaling, struct mGLES2Uniform* uniforms, size_t nUniforms);
93void mGLES2ShaderDeinit(struct mGLES2Shader*);
94void mGLES2ShaderAttach(struct mGLES2Context*, struct mGLES2Shader*, size_t nShaders);
95void mGLES2ShaderDetach(struct mGLES2Context*);
96
97struct VDir;
98bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*);
99void mGLES2ShaderFree(struct VideoShader*);
100
101CXX_GUARD_END
102
103#endif