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 GLuint ui;
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 GLuint uivec2[2];
36 GLuint uivec3[3];
37 GLuint uivec4[4];
38 GLfloat fmat2x2[4];
39 GLfloat fmat2x3[6];
40 GLfloat fmat2x4[8];
41 GLfloat fmat3x2[6];
42 GLfloat fmat3x3[9];
43 GLfloat fmat3x4[12];
44 GLfloat fmat4x2[8];
45 GLfloat fmat4x3[12];
46 GLfloat fmat4x4[16];
47};
48
49struct GBAGLES2Uniform {
50 const char* name;
51 GLenum type;
52 union GBAGLES2UniformValue value;
53 GLuint location;
54};
55
56struct GBAGLES2Shader {
57 unsigned width;
58 unsigned height;
59 bool filter;
60 bool blend;
61 GLuint tex;
62 GLuint fbo;
63 GLuint fragmentShader;
64 GLuint vertexShader;
65 GLuint program;
66 GLuint texLocation;
67 GLuint positionLocation;
68
69 struct GBAGLES2Uniform* uniforms;
70 size_t nUniforms;
71};
72
73struct GBAGLES2Context {
74 struct VideoBackend d;
75
76 GLuint tex;
77 GLuint texLocation;
78 GLuint positionLocation;
79
80 struct GBAGLES2Shader initialShader;
81 struct GBAGLES2Shader finalShader;
82
83 struct GBAGLES2Shader* shaders;
84 size_t nShaders;
85};
86
87struct GBAGLES2ShaderMetadata {
88 const char* name;
89 const char* author;
90 const char* description;
91};
92
93void GBAGLES2ContextCreate(struct GBAGLES2Context*);
94
95void GBAGLES2ShaderInit(struct GBAGLES2Shader*, const char* vs, const char* fs, int width, int height, struct GBAGLES2Uniform* uniforms, size_t nUniforms);
96void GBAGLES2ShaderDeinit(struct GBAGLES2Shader*);
97void GBAGLES2ShaderAttach(struct GBAGLES2Context*, struct GBAGLES2Shader*, size_t nShaders);
98void GBAGLES2ShaderDetach(struct GBAGLES2Context*);
99
100struct VDir;
101bool GBAGLES2ShaderLoad(struct GBAGLES2Shader**, size_t* nShaders, struct GBAGLES2ShaderMetadata*, struct VDir*);
102void GBAGLES2ShaderFree(struct GBAGLES2Shader*, size_t nShaders);
103
104#endif