summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-05 15:19:32 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-08 20:04:31 +0200
commitc9056ded897ad81fed4f2d7c486242019f8437a6 (patch)
tree450ce28b45c30805503571c3a9fbb5a8d464945e
parent7acaa3b467552e952354b17bd39b913a02a90167 (diff)
downloadqtlocation-mapboxgl-c9056ded897ad81fed4f2d7c486242019f8437a6.tar.gz
[core] Abstract the OpenGL implementation
The platform will be responsible to load the OpenGL implementation and give the function pointers to Mapbox GL Core. The platform might load OpenGL by linking against some OpenGL implementation, load it dynamically, etc. It doesn't matter as long as it is a valid implementation. Also adds the `::platform` namespace where all the missing symbols and interfaces expected to be implemented by the platforms will live.
-rw-r--r--include/mbgl/gl/gl_defines.hpp197
-rw-r--r--include/mbgl/gl/gl_function_pointers.hpp308
-rw-r--r--include/mbgl/platform/gl.hpp20
-rw-r--r--src/mbgl/gl/gl_functions.cpp333
-rw-r--r--src/mbgl/gl/gl_functions.hpp189
5 files changed, 1047 insertions, 0 deletions
diff --git a/include/mbgl/gl/gl_defines.hpp b/include/mbgl/gl/gl_defines.hpp
new file mode 100644
index 0000000000..6e4fa5a09e
--- /dev/null
+++ b/include/mbgl/gl/gl_defines.hpp
@@ -0,0 +1,197 @@
+#pragma once
+
+#include <cstddef>
+
+using GLbitfield = unsigned int;
+using GLboolean = unsigned char;
+using GLchar = char;
+using GLdouble = double;
+using GLenum = unsigned int;
+using GLfloat = float;
+using GLint = int;
+using GLsizei = int;
+using GLubyte = unsigned char;
+using GLuint = unsigned int;
+using GLvoid = void;
+
+#if defined(_WINDOWS)
+using GLintptr = long long;
+using GLsizeiptr = long long;
+#else
+using GLintptr = long;
+using GLsizeiptr = long;
+#endif
+
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ALPHA 0x1906
+#define GL_ALWAYS 0x0207
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_BACK 0x0405
+#define GL_BLEND 0x0BE2
+#define GL_BLEND_COLOR 0x8005
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_EQUATION_RGB 0x8009
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_BYTE 0x1400
+#define GL_CCW 0x0901
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_CULL_FACE 0x0B44
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_CW 0x0900
+#define GL_DECR 0x1E03
+#define GL_DECR_WRAP 0x8508
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_TEST 0x0B71
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DONT_CARE 0x1100
+#define GL_DST_ALPHA 0x0304
+#define GL_DST_COLOR 0x0306
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_EQUAL 0x0202
+#define GL_EXTENSIONS 0x1F03
+#define GL_FALSE 0
+#define GL_FLOAT 0x1406
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+#define GL_FRONT 0x0404
+#define GL_FRONT_AND_BACK 0x0408
+#define GL_FRONT_FACE 0x0B46
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_GEQUAL 0x0206
+#define GL_GREATER 0x0204
+#define GL_INCR 0x1E02
+#define GL_INCR_WRAP 0x8507
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_INT 0x1404
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+#define GL_INVALID_OPERATION 0x0502
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVERT 0x150A
+#define GL_KEEP 0x1E00
+#define GL_LEQUAL 0x0203
+#define GL_LESS 0x0201
+#define GL_LINEAR 0x2601
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_LINE_LOOP 0x0002
+#define GL_LINES 0x0001
+#define GL_LINE_STRIP 0x0003
+#define GL_LINE_WIDTH 0x0B21
+#define GL_LINK_STATUS 0x8B82
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_NEAREST 0x2600
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_NEVER 0x0200
+#define GL_NO_ERROR 0
+#define GL_NOTEQUAL 0x0205
+#define GL_ONE 1
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_OUT_OF_MEMORY 0x0505
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_POINTS 0x0000
+#define GL_RENDERBUFFER 0x8D41
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_RENDERER 0x1F01
+#define GL_REPEAT 0x2901
+#define GL_REPLACE 0x1E01
+#define GL_RGBA 0x1908
+#define GL_RGBA8_OES 0x8058
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SCISSOR_TEST 0x0C11
+#define GL_SHORT 0x1402
+#define GL_SRC_ALPHA 0x0302
+#define GL_SRC_ALPHA_SATURATE 0x0308
+#define GL_SRC_COLOR 0x0300
+#define GL_STATIC_DRAW 0x88E4
+#define GL_STENCIL_ATTACHMENT 0x8D20
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_TEST 0x0B90
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STREAM_DRAW 0x88E0
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+#define GL_TRIANGLE_FAN 0x0006
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRUE 1
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_UNSIGNED_INT 0x1405
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_VIEWPORT 0x0BA2
+#define GL_ZERO 0
+
+#ifndef MBGL_USE_GLES2
+#define GL_CURRENT_RASTER_POSITION 0x0B07
+#define GL_DEPTH24_STENCIL8 0x88F0
+#define GL_DEPTH_BIAS 0x0D1F
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_DEPTH_SCALE 0x0D1E
+#define GL_INDEX_OFFSET 0x0D13
+#define GL_INDEX_SHIFT 0x0D12
+#define GL_LUMINANCE 0x1909
+#define GL_POINT_SIZE 0x0B11
+#define GL_RGBA8 0x8058
+#define GL_ZOOM_X 0x0D16
+#define GL_ZOOM_Y 0x0D17
+#endif \ No newline at end of file
diff --git a/include/mbgl/gl/gl_function_pointers.hpp b/include/mbgl/gl/gl_function_pointers.hpp
new file mode 100644
index 0000000000..267ae413fc
--- /dev/null
+++ b/include/mbgl/gl/gl_function_pointers.hpp
@@ -0,0 +1,308 @@
+#pragma once
+
+#include <mbgl/gl/gl_defines.hpp>
+
+namespace mbgl {
+namespace gl {
+
+/**
+ * @brief Holds pointers to OpenGL ES 2.0 functions.
+ */
+struct GLFunctionPointers {
+ /// Pointer to glActiveTexture OpenGL function.
+ void (*glActiveTexture)(GLenum);
+ /// Pointer to glAttachShader OpenGL function.
+ void (*glAttachShader)(GLuint, GLuint);
+ /// Pointer to glBindAttribLocation OpenGL function.
+ void (*glBindAttribLocation)(GLuint, GLuint, const GLchar *);
+ /// Pointer to glBindBuffer OpenGL function.
+ void (*glBindBuffer)(GLenum, GLuint);
+ /// Pointer to glBindFramebuffer OpenGL function.
+ void (*glBindFramebuffer)(GLenum, GLuint);
+ /// Pointer to glBindRenderbuffer OpenGL function.
+ void (*glBindRenderbuffer)(GLenum, GLuint);
+ /// Pointer to glBindTexture OpenGL function.
+ void (*glBindTexture)(GLenum, GLuint);
+ /// Pointer to glBlendColor OpenGL function.
+ void (*glBlendColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glBlendEquation OpenGL function.
+ void (*glBlendEquation)(GLenum);
+ /// Pointer to glBlendEquationSeparate OpenGL function.
+ void (*glBlendEquationSeparate)(GLenum, GLenum);
+ /// Pointer to glBlendFunc OpenGL function.
+ void (*glBlendFunc)(GLenum, GLenum);
+ /// Pointer to glBlendFuncSeparate OpenGL function.
+ void (*glBlendFuncSeparate)(GLenum, GLenum, GLenum, GLenum);
+ /// Pointer to glBufferData OpenGL function.
+ void (*glBufferData)(GLenum, GLsizeiptr, const void *, GLenum);
+ /// Pointer to glBufferSubData OpenGL function.
+ void (*glBufferSubData)(GLenum, GLintptr, GLsizeiptr, const void *);
+ /// Pointer to glCheckFramebufferStatus OpenGL function.
+ GLenum (*glCheckFramebufferStatus)(GLenum);
+ /// Pointer to glClear OpenGL function.
+ void (*glClear)(GLbitfield);
+ /// Pointer to glClearColor OpenGL function.
+ void (*glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glClearDepthf OpenGL function.
+ void (*glClearDepthf)(GLfloat);
+ /// Pointer to glClearStencil OpenGL function.
+ void (*glClearStencil)(GLint);
+ /// Pointer to glColorMask OpenGL function.
+ void (*glColorMask)(GLboolean, GLboolean, GLboolean, GLboolean);
+ /// Pointer to glCompileShader OpenGL function.
+ void (*glCompileShader)(GLuint);
+ /// Pointer to glCompressedTexImage2D OpenGL function.
+ void (*glCompressedTexImage2D)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const void *);
+ /// Pointer to glCompressedTexSubImage2D OpenGL function.
+ void (*glCompressedTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const void *);
+ /// Pointer to glCopyTexImage2D OpenGL function.
+ void (*glCopyTexImage2D)(GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint);
+ /// Pointer to glCopyTexSubImage2D OpenGL function.
+ void (*glCopyTexSubImage2D)(GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei);
+ /// Pointer to glCreateProgram OpenGL function.
+ GLuint (*glCreateProgram)();
+ /// Pointer to glCreateShader OpenGL function.
+ GLuint (*glCreateShader)(GLenum);
+ /// Pointer to glCullFace OpenGL function.
+ void (*glCullFace)(GLenum);
+ /// Pointer to glDeleteBuffers OpenGL function.
+ void (*glDeleteBuffers)(GLsizei, const GLuint *);
+ /// Pointer to glDeleteFramebuffers OpenGL function.
+ void (*glDeleteFramebuffers)(GLsizei, const GLuint *);
+ /// Pointer to glDeleteProgram OpenGL function.
+ void (*glDeleteProgram)(GLuint);
+ /// Pointer to glDeleteRenderbuffers OpenGL function.
+ void (*glDeleteRenderbuffers)(GLsizei, const GLuint *);
+ /// Pointer to glDeleteShader OpenGL function.
+ void (*glDeleteShader)(GLuint);
+ /// Pointer to glDeleteTextures OpenGL function.
+ void (*glDeleteTextures)(GLsizei, const GLuint *);
+ /// Pointer to glDepthFunc OpenGL function.
+ void (*glDepthFunc)(GLenum);
+ /// Pointer to glDepthMask OpenGL function.
+ void (*glDepthMask)(GLboolean);
+ /// Pointer to glDepthRangef OpenGL function.
+ void (*glDepthRangef)(GLfloat, GLfloat);
+ /// Pointer to glDetachShader OpenGL function.
+ void (*glDetachShader)(GLuint, GLuint);
+ /// Pointer to glDisable OpenGL function.
+ void (*glDisable)(GLenum);
+ /// Pointer to glDisableVertexAttribArray OpenGL function.
+ void (*glDisableVertexAttribArray)(GLuint);
+ /// Pointer to glDrawArrays OpenGL function.
+ void (*glDrawArrays)(GLenum, GLint, GLsizei);
+ /// Pointer to glDrawElements OpenGL function.
+ void (*glDrawElements)(GLenum, GLsizei, GLenum, const void *);
+ /// Pointer to glEnable OpenGL function.
+ void (*glEnable)(GLenum);
+ /// Pointer to glEnableVertexAttribArray OpenGL function.
+ void (*glEnableVertexAttribArray)(GLuint);
+ /// Pointer to glFinish OpenGL function.
+ void (*glFinish)();
+ /// Pointer to glFlush OpenGL function.
+ void (*glFlush)();
+ /// Pointer to glFramebufferRenderbuffer OpenGL function.
+ void (*glFramebufferRenderbuffer)(GLenum, GLenum, GLenum, GLuint);
+ /// Pointer to glFramebufferTexture2D OpenGL function.
+ void (*glFramebufferTexture2D)(GLenum, GLenum, GLenum, GLuint, GLint);
+ /// Pointer to glFrontFace OpenGL function.
+ void (*glFrontFace)(GLenum);
+ /// Pointer to glGenBuffers OpenGL function.
+ void (*glGenBuffers)(GLsizei, GLuint *);
+ /// Pointer to glGenerateMipmap OpenGL function.
+ void (*glGenerateMipmap)(GLenum);
+ /// Pointer to glGenFramebuffers OpenGL function.
+ void (*glGenFramebuffers)(GLsizei, GLuint *);
+ /// Pointer to glGenRenderbuffers OpenGL function.
+ void (*glGenRenderbuffers)(GLsizei, GLuint *);
+ /// Pointer to glGenTextures OpenGL function.
+ void (*glGenTextures)(GLsizei, GLuint *);
+ /// Pointer to glGetActiveAttrib OpenGL function.
+ void (*glGetActiveAttrib)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+ /// Pointer to glGetActiveUniform OpenGL function.
+ void (*glGetActiveUniform)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+ /// Pointer to glGetAttachedShaders OpenGL function.
+ void (*glGetAttachedShaders)(GLuint, GLsizei, GLsizei *, GLuint *);
+ /// Pointer to glGetAttribLocation OpenGL function.
+ GLint (*glGetAttribLocation)(GLuint, const GLchar *);
+ /// Pointer to glGetBooleanv OpenGL function.
+ void (*glGetBooleanv)(GLenum, GLboolean *);
+ /// Pointer to glGetBufferParameteriv OpenGL function.
+ void (*glGetBufferParameteriv)(GLenum, GLenum, GLint *);
+ /// Pointer to glGetError OpenGL function.
+ GLenum (*glGetError)();
+ /// Pointer to glGetFloatv OpenGL function.
+ void (*glGetFloatv)(GLenum, GLfloat *);
+ /// Pointer to glGetFramebufferAttachmentParameteriv OpenGL function.
+ void (*glGetFramebufferAttachmentParameteriv)(GLenum, GLenum, GLenum, GLint *);
+ /// Pointer to glGetIntegerv OpenGL function.
+ void (*glGetIntegerv)(GLenum, GLint *);
+ /// Pointer to glGetProgramInfoLog OpenGL function.
+ void (*glGetProgramInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+ /// Pointer to glGetProgramiv OpenGL function.
+ void (*glGetProgramiv)(GLuint, GLenum, GLint *);
+ /// Pointer to glGetRenderbufferParameteriv OpenGL function.
+ void (*glGetRenderbufferParameteriv)(GLenum, GLenum, GLint *);
+ /// Pointer to glGetShaderInfoLog OpenGL function.
+ void (*glGetShaderInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+ /// Pointer to glGetShaderiv OpenGL function.
+ void (*glGetShaderiv)(GLuint, GLenum, GLint *);
+ /// Pointer to glGetShaderSource OpenGL function.
+ void (*glGetShaderSource)(GLuint, GLsizei, GLsizei *, GLchar *);
+ /// Pointer to glGetString OpenGL function.
+ const GLubyte *(*glGetString)(GLenum);
+ /// Pointer to glGetTexParameterfv OpenGL function.
+ void (*glGetTexParameterfv)(GLenum, GLenum, GLfloat *);
+ /// Pointer to glGetTexParameteriv OpenGL function.
+ void (*glGetTexParameteriv)(GLenum, GLenum, GLint *);
+ /// Pointer to glGetUniformfv OpenGL function.
+ void (*glGetUniformfv)(GLuint, GLint, GLfloat *);
+ /// Pointer to glGetUniformiv OpenGL function.
+ void (*glGetUniformiv)(GLuint, GLint, GLint *);
+ /// Pointer to glGetUniformLocation OpenGL function.
+ GLint (*glGetUniformLocation)(GLuint, const GLchar *);
+ /// Pointer to glGetVertexAttribfv OpenGL function.
+ void (*glGetVertexAttribfv)(GLuint, GLenum, GLfloat *);
+ /// Pointer to glGetVertexAttribiv OpenGL function.
+ void (*glGetVertexAttribiv)(GLuint, GLenum, GLint *);
+ /// Pointer to glGetVertexAttribPointerv OpenGL function.
+ void (*glGetVertexAttribPointerv)(GLuint, GLenum, void **);
+ /// Pointer to glHint OpenGL function.
+ void (*glHint)(GLenum, GLenum);
+ /// Pointer to glIsBuffer OpenGL function.
+ GLboolean (*glIsBuffer)(GLuint);
+ /// Pointer to glIsEnabled OpenGL function.
+ GLboolean (*glIsEnabled)(GLenum);
+ /// Pointer to glIsFramebuffer OpenGL function.
+ GLboolean (*glIsFramebuffer)(GLuint);
+ /// Pointer to glIsProgram OpenGL function.
+ GLboolean (*glIsProgram)(GLuint);
+ /// Pointer to glIsRenderbuffer OpenGL function.
+ GLboolean (*glIsRenderbuffer)(GLuint);
+ /// Pointer to glIsShader OpenGL function.
+ GLboolean (*glIsShader)(GLuint);
+ /// Pointer to glIsTexture OpenGL function.
+ GLboolean (*glIsTexture)(GLuint);
+ /// Pointer to glLineWidth OpenGL function.
+ void (*glLineWidth)(GLfloat);
+ /// Pointer to glLinkProgram OpenGL function.
+ void (*glLinkProgram)(GLuint);
+ /// Pointer to glPixelStorei OpenGL function.
+ void (*glPixelStorei)(GLenum, GLint);
+ /// Pointer to glPolygonOffset OpenGL function.
+ void (*glPolygonOffset)(GLfloat, GLfloat);
+ /// Pointer to glReadPixels OpenGL function.
+ void (*glReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *);
+ /// Pointer to glRenderbufferStorage OpenGL function.
+ void (*glRenderbufferStorage)(GLenum, GLenum, GLsizei, GLsizei);
+ /// Pointer to glSampleCoverage OpenGL function.
+ void (*glSampleCoverage)(GLfloat, GLboolean);
+ /// Pointer to glScissor OpenGL function.
+ void (*glScissor)(GLint, GLint, GLsizei, GLsizei);
+ /// Pointer to glShaderSource OpenGL function.
+ void (*glShaderSource)(GLuint, GLsizei, const GLchar * const*, const GLint *);
+ /// Pointer to glStencilFunc OpenGL function.
+ void (*glStencilFunc)(GLenum, GLint, GLuint);
+ /// Pointer to glStencilFuncSeparate OpenGL function.
+ void (*glStencilFuncSeparate)(GLenum, GLenum, GLint, GLuint);
+ /// Pointer to glStencilMask OpenGL function.
+ void (*glStencilMask)(GLuint);
+ /// Pointer to glStencilMaskSeparate OpenGL function.
+ void (*glStencilMaskSeparate)(GLenum, GLuint);
+ /// Pointer to glStencilOp OpenGL function.
+ void (*glStencilOp)(GLenum, GLenum, GLenum);
+ /// Pointer to glStencilOpSeparate OpenGL function.
+ void (*glStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum);
+ /// Pointer to glTexImage2D OpenGL function.
+ void (*glTexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *);
+ /// Pointer to glTexParameterf OpenGL function.
+ void (*glTexParameterf)(GLenum, GLenum, GLfloat);
+ /// Pointer to glTexParameterfv OpenGL function.
+ void (*glTexParameterfv)(GLenum, GLenum, const GLfloat *);
+ /// Pointer to glTexParameteri OpenGL function.
+ void (*glTexParameteri)(GLenum, GLenum, GLint);
+ /// Pointer to glTexParameteriv OpenGL function.
+ void (*glTexParameteriv)(GLenum, GLenum, const GLint *);
+ /// Pointer to glTexSubImage2D OpenGL function.
+ void (*glTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const void *);
+ /// Pointer to glUniform1f OpenGL function.
+ void (*glUniform1f)(GLint, GLfloat);
+ /// Pointer to glUniform1fv OpenGL function.
+ void (*glUniform1fv)(GLint, GLsizei, const GLfloat *);
+ /// Pointer to glUniform1i OpenGL function.
+ void (*glUniform1i)(GLint, GLint);
+ /// Pointer to glUniform1iv OpenGL function.
+ void (*glUniform1iv)(GLint, GLsizei, const GLint *);
+ /// Pointer to glUniform2f OpenGL function.
+ void (*glUniform2f)(GLint, GLfloat, GLfloat);
+ /// Pointer to glUniform2fv OpenGL function.
+ void (*glUniform2fv)(GLint, GLsizei, const GLfloat *);
+ /// Pointer to glUniform2i OpenGL function.
+ void (*glUniform2i)(GLint, GLint, GLint);
+ /// Pointer to glUniform2iv OpenGL function.
+ void (*glUniform2iv)(GLint, GLsizei, const GLint *);
+ /// Pointer to glUniform3f OpenGL function.
+ void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glUniform3fv OpenGL function.
+ void (*glUniform3fv)(GLint, GLsizei, const GLfloat *);
+ /// Pointer to glUniform3i OpenGL function.
+ void (*glUniform3i)(GLint, GLint, GLint, GLint);
+ /// Pointer to glUniform3iv OpenGL function.
+ void (*glUniform3iv)(GLint, GLsizei, const GLint *);
+ /// Pointer to glUniform4f OpenGL function.
+ void (*glUniform4f)(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glUniform4fv OpenGL function.
+ void (*glUniform4fv)(GLint, GLsizei, const GLfloat *);
+ /// Pointer to glUniform4i OpenGL function.
+ void (*glUniform4i)(GLint, GLint, GLint, GLint, GLint);
+ /// Pointer to glUniform4iv OpenGL function.
+ void (*glUniform4iv)(GLint, GLsizei, const GLint *);
+ /// Pointer to glUniformMatrix2fv OpenGL function.
+ void (*glUniformMatrix2fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ /// Pointer to glUniformMatrix3fv OpenGL function.
+ void (*glUniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ /// Pointer to glUniformMatrix4fv OpenGL function.
+ void (*glUniformMatrix4fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ /// Pointer to glUseProgram OpenGL function.
+ void (*glUseProgram)(GLuint);
+ /// Pointer to glValidateProgram OpenGL function.
+ void (*glValidateProgram)(GLuint);
+ /// Pointer to glVertexAttrib1f OpenGL function.
+ void (*glVertexAttrib1f)(GLuint, GLfloat);
+ /// Pointer to glVertexAttrib1fv OpenGL function.
+ void (*glVertexAttrib1fv)(GLuint, const GLfloat *);
+ /// Pointer to glVertexAttrib2f OpenGL function.
+ void (*glVertexAttrib2f)(GLuint, GLfloat, GLfloat);
+ /// Pointer to glVertexAttrib2fv OpenGL function.
+ void (*glVertexAttrib2fv)(GLuint, const GLfloat *);
+ /// Pointer to glVertexAttrib3f OpenGL function.
+ void (*glVertexAttrib3f)(GLuint, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glVertexAttrib3fv OpenGL function.
+ void (*glVertexAttrib3fv)(GLuint, const GLfloat *);
+ /// Pointer to glVertexAttrib4f OpenGL function.
+ void (*glVertexAttrib4f)(GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
+ /// Pointer to glVertexAttrib4fv OpenGL function.
+ void (*glVertexAttrib4fv)(GLuint, const GLfloat *);
+ /// Pointer to glVertexAttribPointer OpenGL function.
+ void (*glVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, const void *);
+ /// Pointer to glViewport OpenGL function.
+ void (*glViewport)(GLint, GLint, GLsizei, GLsizei);
+
+#ifndef MBGL_USE_GLES2
+ /// Pointer to glDrawPixels OpenGL function.
+ void (*glDrawPixels)(GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
+ /// Pointer to glGetDoublev OpenGL function.
+ void (*glGetDoublev)(GLenum, GLdouble *);
+ /// Pointer to glPixelTransferf OpenGL function.
+ void (*glPixelTransferf)(GLenum, GLfloat);
+ /// Pointer to glPixelZoom OpenGL function.
+ void (*glPixelZoom)(GLfloat, GLfloat);
+ /// Pointer to glPointSize OpenGL function.
+ void (*glPointSize)(GLfloat);
+ /// Pointer to glRasterPos4d OpenGL function.
+ void (*glRasterPos4d)(GLdouble, GLdouble, GLdouble, GLdouble);
+#endif
+};
+
+} // namespace gl
+} // namespace mbgl \ No newline at end of file
diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp
new file mode 100644
index 0000000000..b42628a671
--- /dev/null
+++ b/include/mbgl/platform/gl.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <mbgl/gl/gl_function_pointers.hpp>
+
+namespace mbgl {
+namespace platform {
+
+/**
+ * @brief Get the global table of OpenGL ES 2.0 function pointers. Mapbox GL
+ * Native will make no assumptions on how the table is created. Platforms
+ * can dynamically load OpenGL, link against an OpenGL implementation or
+ * even use a software rendering implementation, as long as it behaves as
+ * expected and the table is valid during the lifecycle of the application.
+ *
+ * @return Table of OpenGL ES 2.0 function pointers.
+ */
+gl::GLFunctionPointers getGLFunctionPointers();
+
+} // namespace platform
+} // namespace mbgl
diff --git a/src/mbgl/gl/gl_functions.cpp b/src/mbgl/gl/gl_functions.cpp
new file mode 100644
index 0000000000..45f50c1251
--- /dev/null
+++ b/src/mbgl/gl/gl_functions.cpp
@@ -0,0 +1,333 @@
+#include <mbgl/gl/gl_functions.hpp>
+
+#include <mbgl/platform/gl.hpp>
+#include <mbgl/util/logging.hpp>
+
+#include <mutex>
+
+namespace mbgl {
+namespace gl {
+
+void (*GLFunctions::glActiveTexture)(GLenum);
+void (*GLFunctions::glAttachShader)(GLuint, GLuint);
+void (*GLFunctions::glBindAttribLocation)(GLuint, GLuint, const GLchar *);
+void (*GLFunctions::glBindBuffer)(GLenum, GLuint);
+void (*GLFunctions::glBindFramebuffer)(GLenum, GLuint);
+void (*GLFunctions::glBindRenderbuffer)(GLenum, GLuint);
+void (*GLFunctions::glBindTexture)(GLenum, GLuint);
+void (*GLFunctions::glBlendColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glBlendEquation)(GLenum);
+void (*GLFunctions::glBlendEquationSeparate)(GLenum, GLenum);
+void (*GLFunctions::glBlendFunc)(GLenum, GLenum);
+void (*GLFunctions::glBlendFuncSeparate)(GLenum, GLenum, GLenum, GLenum);
+void (*GLFunctions::glBufferData)(GLenum, GLsizeiptr, const void *, GLenum);
+void (*GLFunctions::glBufferSubData)(GLenum, GLintptr, GLsizeiptr, const void *);
+GLenum (*GLFunctions::glCheckFramebufferStatus)(GLenum);
+void (*GLFunctions::glClear)(GLbitfield);
+void (*GLFunctions::glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glClearDepthf)(GLfloat);
+void (*GLFunctions::glClearStencil)(GLint);
+void (*GLFunctions::glColorMask)(GLboolean, GLboolean, GLboolean, GLboolean);
+void (*GLFunctions::glCompileShader)(GLuint);
+void (*GLFunctions::glCompressedTexImage2D)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const void *);
+void (*GLFunctions::glCompressedTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const void *);
+void (*GLFunctions::glCopyTexImage2D)(GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint);
+void (*GLFunctions::glCopyTexSubImage2D)(GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei);
+GLuint (*GLFunctions::glCreateProgram)();
+GLuint (*GLFunctions::glCreateShader)(GLenum);
+void (*GLFunctions::glCullFace)(GLenum);
+void (*GLFunctions::glDeleteBuffers)(GLsizei, const GLuint *);
+void (*GLFunctions::glDeleteFramebuffers)(GLsizei, const GLuint *);
+void (*GLFunctions::glDeleteProgram)(GLuint);
+void (*GLFunctions::glDeleteRenderbuffers)(GLsizei, const GLuint *);
+void (*GLFunctions::glDeleteShader)(GLuint);
+void (*GLFunctions::glDeleteTextures)(GLsizei, const GLuint *);
+void (*GLFunctions::glDepthFunc)(GLenum);
+void (*GLFunctions::glDepthMask)(GLboolean);
+void (*GLFunctions::glDepthRangef)(GLfloat, GLfloat);
+void (*GLFunctions::glDetachShader)(GLuint, GLuint);
+void (*GLFunctions::glDisable)(GLenum);
+void (*GLFunctions::glDisableVertexAttribArray)(GLuint);
+void (*GLFunctions::glDrawArrays)(GLenum, GLint, GLsizei);
+void (*GLFunctions::glDrawElements)(GLenum, GLsizei, GLenum, const void *);
+void (*GLFunctions::glEnable)(GLenum);
+void (*GLFunctions::glEnableVertexAttribArray)(GLuint);
+void (*GLFunctions::glFinish)();
+void (*GLFunctions::glFlush)();
+void (*GLFunctions::glFramebufferRenderbuffer)(GLenum, GLenum, GLenum, GLuint);
+void (*GLFunctions::glFramebufferTexture2D)(GLenum, GLenum, GLenum, GLuint, GLint);
+void (*GLFunctions::glFrontFace)(GLenum);
+void (*GLFunctions::glGenBuffers)(GLsizei, GLuint *);
+void (*GLFunctions::glGenerateMipmap)(GLenum);
+void (*GLFunctions::glGenFramebuffers)(GLsizei, GLuint *);
+void (*GLFunctions::glGenRenderbuffers)(GLsizei, GLuint *);
+void (*GLFunctions::glGenTextures)(GLsizei, GLuint *);
+void (*GLFunctions::glGetActiveAttrib)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+void (*GLFunctions::glGetActiveUniform)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+void (*GLFunctions::glGetAttachedShaders)(GLuint, GLsizei, GLsizei *, GLuint *);
+GLint (*GLFunctions::glGetAttribLocation)(GLuint, const GLchar *);
+void (*GLFunctions::glGetBooleanv)(GLenum, GLboolean *);
+void (*GLFunctions::glGetBufferParameteriv)(GLenum, GLenum, GLint *);
+GLenum (*GLFunctions::glGetError)();
+void (*GLFunctions::glGetFloatv)(GLenum, GLfloat *);
+void (*GLFunctions::glGetFramebufferAttachmentParameteriv)(GLenum, GLenum, GLenum, GLint *);
+void (*GLFunctions::glGetIntegerv)(GLenum, GLint *);
+void (*GLFunctions::glGetProgramInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+void (*GLFunctions::glGetProgramiv)(GLuint, GLenum, GLint *);
+void (*GLFunctions::glGetRenderbufferParameteriv)(GLenum, GLenum, GLint *);
+void (*GLFunctions::glGetShaderInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+void (*GLFunctions::glGetShaderiv)(GLuint, GLenum, GLint *);
+void (*GLFunctions::glGetShaderSource)(GLuint, GLsizei, GLsizei *, GLchar *);
+const GLubyte *(*GLFunctions::glGetString)(GLenum);
+void (*GLFunctions::glGetTexParameterfv)(GLenum, GLenum, GLfloat *);
+void (*GLFunctions::glGetTexParameteriv)(GLenum, GLenum, GLint *);
+void (*GLFunctions::glGetUniformfv)(GLuint, GLint, GLfloat *);
+void (*GLFunctions::glGetUniformiv)(GLuint, GLint, GLint *);
+GLint (*GLFunctions::glGetUniformLocation)(GLuint, const GLchar *);
+void (*GLFunctions::glGetVertexAttribfv)(GLuint, GLenum, GLfloat *);
+void (*GLFunctions::glGetVertexAttribiv)(GLuint, GLenum, GLint *);
+void (*GLFunctions::glGetVertexAttribPointerv)(GLuint, GLenum, void **);
+void (*GLFunctions::glHint)(GLenum, GLenum);
+GLboolean (*GLFunctions::glIsBuffer)(GLuint);
+GLboolean (*GLFunctions::glIsEnabled)(GLenum);
+GLboolean (*GLFunctions::glIsFramebuffer)(GLuint);
+GLboolean (*GLFunctions::glIsProgram)(GLuint);
+GLboolean (*GLFunctions::glIsRenderbuffer)(GLuint);
+GLboolean (*GLFunctions::glIsShader)(GLuint);
+GLboolean (*GLFunctions::glIsTexture)(GLuint);
+void (*GLFunctions::glLineWidth)(GLfloat);
+void (*GLFunctions::glLinkProgram)(GLuint);
+void (*GLFunctions::glPixelStorei)(GLenum, GLint);
+void (*GLFunctions::glPolygonOffset)(GLfloat, GLfloat);
+void (*GLFunctions::glReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *);
+void (*GLFunctions::glRenderbufferStorage)(GLenum, GLenum, GLsizei, GLsizei);
+void (*GLFunctions::glSampleCoverage)(GLfloat, GLboolean);
+void (*GLFunctions::glScissor)(GLint, GLint, GLsizei, GLsizei);
+void (*GLFunctions::glShaderSource)(GLuint, GLsizei, const GLchar * const*, const GLint *);
+void (*GLFunctions::glStencilFunc)(GLenum, GLint, GLuint);
+void (*GLFunctions::glStencilFuncSeparate)(GLenum, GLenum, GLint, GLuint);
+void (*GLFunctions::glStencilMask)(GLuint);
+void (*GLFunctions::glStencilMaskSeparate)(GLenum, GLuint);
+void (*GLFunctions::glStencilOp)(GLenum, GLenum, GLenum);
+void (*GLFunctions::glStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum);
+void (*GLFunctions::glTexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *);
+void (*GLFunctions::glTexParameterf)(GLenum, GLenum, GLfloat);
+void (*GLFunctions::glTexParameterfv)(GLenum, GLenum, const GLfloat *);
+void (*GLFunctions::glTexParameteri)(GLenum, GLenum, GLint);
+void (*GLFunctions::glTexParameteriv)(GLenum, GLenum, const GLint *);
+void (*GLFunctions::glTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const void *);
+void (*GLFunctions::glUniform1f)(GLint, GLfloat);
+void (*GLFunctions::glUniform1fv)(GLint, GLsizei, const GLfloat *);
+void (*GLFunctions::glUniform1i)(GLint, GLint);
+void (*GLFunctions::glUniform1iv)(GLint, GLsizei, const GLint *);
+void (*GLFunctions::glUniform2f)(GLint, GLfloat, GLfloat);
+void (*GLFunctions::glUniform2fv)(GLint, GLsizei, const GLfloat *);
+void (*GLFunctions::glUniform2i)(GLint, GLint, GLint);
+void (*GLFunctions::glUniform2iv)(GLint, GLsizei, const GLint *);
+void (*GLFunctions::glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glUniform3fv)(GLint, GLsizei, const GLfloat *);
+void (*GLFunctions::glUniform3i)(GLint, GLint, GLint, GLint);
+void (*GLFunctions::glUniform3iv)(GLint, GLsizei, const GLint *);
+void (*GLFunctions::glUniform4f)(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glUniform4fv)(GLint, GLsizei, const GLfloat *);
+void (*GLFunctions::glUniform4i)(GLint, GLint, GLint, GLint, GLint);
+void (*GLFunctions::glUniform4iv)(GLint, GLsizei, const GLint *);
+void (*GLFunctions::glUniformMatrix2fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+void (*GLFunctions::glUniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+void (*GLFunctions::glUniformMatrix4fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+void (*GLFunctions::glUseProgram)(GLuint);
+void (*GLFunctions::glValidateProgram)(GLuint);
+void (*GLFunctions::glVertexAttrib1f)(GLuint, GLfloat);
+void (*GLFunctions::glVertexAttrib1fv)(GLuint, const GLfloat *);
+void (*GLFunctions::glVertexAttrib2f)(GLuint, GLfloat, GLfloat);
+void (*GLFunctions::glVertexAttrib2fv)(GLuint, const GLfloat *);
+void (*GLFunctions::glVertexAttrib3f)(GLuint, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glVertexAttrib3fv)(GLuint, const GLfloat *);
+void (*GLFunctions::glVertexAttrib4f)(GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
+void (*GLFunctions::glVertexAttrib4fv)(GLuint, const GLfloat *);
+void (*GLFunctions::glVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, const void *);
+void (*GLFunctions::glViewport)(GLint, GLint, GLsizei, GLsizei);
+
+#ifndef MBGL_USE_GLES2
+void (*GLFunctions::glDrawPixels)(GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
+void (*GLFunctions::glGetDoublev)(GLenum, GLdouble *);
+void (*GLFunctions::glPixelTransferf)(GLenum, GLfloat);
+void (*GLFunctions::glPixelZoom)(GLfloat, GLfloat);
+void (*GLFunctions::glPointSize)(GLfloat);
+void (*GLFunctions::glRasterPos4d)(GLdouble, GLdouble, GLdouble, GLdouble);
+#endif
+
+void GLFunctions::init() {
+ static std::mutex mutex;
+ std::lock_guard<std::mutex> lock(mutex);
+
+ if (glActiveTexture) {
+ return;
+ }
+
+ auto fps = platform::getGLFunctionPointers();
+
+ glActiveTexture = fps.glActiveTexture;
+ glAttachShader = fps.glAttachShader;
+ glBindAttribLocation = fps.glBindAttribLocation;
+ glBindBuffer = fps.glBindBuffer;
+ glBindFramebuffer = fps.glBindFramebuffer;
+ glBindRenderbuffer = fps.glBindRenderbuffer;
+ glBindTexture = fps.glBindTexture;
+ glBlendColor = fps.glBlendColor;
+ glBlendEquation = fps.glBlendEquation;
+ glBlendEquationSeparate = fps.glBlendEquationSeparate;
+ glBlendFunc = fps.glBlendFunc;
+ glBlendFuncSeparate = fps.glBlendFuncSeparate;
+ glBufferData = fps.glBufferData;
+ glBufferSubData = fps.glBufferSubData;
+ glCheckFramebufferStatus = fps.glCheckFramebufferStatus;
+ glClear = fps.glClear;
+ glClearColor = fps.glClearColor;
+ glClearDepthf = fps.glClearDepthf;
+ glClearStencil = fps.glClearStencil;
+ glColorMask = fps.glColorMask;
+ glCompileShader = fps.glCompileShader;
+ glCompressedTexImage2D = fps.glCompressedTexImage2D;
+ glCompressedTexSubImage2D = fps.glCompressedTexSubImage2D;
+ glCopyTexImage2D = fps.glCopyTexImage2D;
+ glCopyTexSubImage2D = fps.glCopyTexSubImage2D;
+ glCreateProgram = fps.glCreateProgram;
+ glCreateShader = fps.glCreateShader;
+ glCullFace = fps.glCullFace;
+ glDeleteBuffers = fps.glDeleteBuffers;
+ glDeleteFramebuffers = fps.glDeleteFramebuffers;
+ glDeleteProgram = fps.glDeleteProgram;
+ glDeleteRenderbuffers = fps.glDeleteRenderbuffers;
+ glDeleteShader = fps.glDeleteShader;
+ glDeleteTextures = fps.glDeleteTextures;
+ glDepthFunc = fps.glDepthFunc;
+ glDepthMask = fps.glDepthMask;
+ glDepthRangef = fps.glDepthRangef;
+ glDetachShader = fps.glDetachShader;
+ glDisable = fps.glDisable;
+ glDisableVertexAttribArray = fps.glDisableVertexAttribArray;
+ glDrawArrays = fps.glDrawArrays;
+ glDrawElements = fps.glDrawElements;
+ glEnable = fps.glEnable;
+ glEnableVertexAttribArray = fps.glEnableVertexAttribArray;
+ glFinish = fps.glFinish;
+ glFlush = fps.glFlush;
+ glFramebufferRenderbuffer = fps.glFramebufferRenderbuffer;
+ glFramebufferTexture2D = fps.glFramebufferTexture2D;
+ glFrontFace = fps.glFrontFace;
+ glGenBuffers = fps.glGenBuffers;
+ glGenerateMipmap = fps.glGenerateMipmap;
+ glGenFramebuffers = fps.glGenFramebuffers;
+ glGenRenderbuffers = fps.glGenRenderbuffers;
+ glGenTextures = fps.glGenTextures;
+ glGetActiveAttrib = fps.glGetActiveAttrib;
+ glGetActiveUniform = fps.glGetActiveUniform;
+ glGetAttachedShaders = fps.glGetAttachedShaders;
+ glGetAttribLocation = fps.glGetAttribLocation;
+ glGetBooleanv = fps.glGetBooleanv;
+ glGetBufferParameteriv = fps.glGetBufferParameteriv;
+ glGetError = fps.glGetError;
+ glGetFloatv = fps.glGetFloatv;
+ glGetFramebufferAttachmentParameteriv = fps.glGetFramebufferAttachmentParameteriv;
+ glGetIntegerv = fps.glGetIntegerv;
+ glGetProgramInfoLog = fps.glGetProgramInfoLog;
+ glGetProgramiv = fps.glGetProgramiv;
+ glGetRenderbufferParameteriv = fps.glGetRenderbufferParameteriv;
+ glGetShaderInfoLog = fps.glGetShaderInfoLog;
+ glGetShaderiv = fps.glGetShaderiv;
+ glGetShaderSource = fps.glGetShaderSource;
+ glGetString = fps.glGetString;
+ glGetTexParameterfv = fps.glGetTexParameterfv;
+ glGetTexParameteriv = fps.glGetTexParameteriv;
+ glGetUniformfv = fps.glGetUniformfv;
+ glGetUniformiv = fps.glGetUniformiv;
+ glGetUniformLocation = fps.glGetUniformLocation;
+ glGetVertexAttribfv = fps.glGetVertexAttribfv;
+ glGetVertexAttribiv = fps.glGetVertexAttribiv;
+ glGetVertexAttribPointerv = fps.glGetVertexAttribPointerv;
+ glHint = fps.glHint;
+ glIsBuffer = fps.glIsBuffer;
+ glIsEnabled = fps.glIsEnabled;
+ glIsFramebuffer = fps.glIsFramebuffer;
+ glIsProgram = fps.glIsProgram;
+ glIsRenderbuffer = fps.glIsRenderbuffer;
+ glIsShader = fps.glIsShader;
+ glIsTexture = fps.glIsTexture;
+ glLineWidth = fps.glLineWidth;
+ glLinkProgram = fps.glLinkProgram;
+ glPixelStorei = fps.glPixelStorei;
+ glPolygonOffset = fps.glPolygonOffset;
+ glReadPixels = fps.glReadPixels;
+ glRenderbufferStorage = fps.glRenderbufferStorage;
+ glSampleCoverage = fps.glSampleCoverage;
+ glScissor = fps.glScissor;
+ glShaderSource = fps.glShaderSource;
+ glStencilFunc = fps.glStencilFunc;
+ glStencilFuncSeparate = fps.glStencilFuncSeparate;
+ glStencilMask = fps.glStencilMask;
+ glStencilMaskSeparate = fps.glStencilMaskSeparate;
+ glStencilOp = fps.glStencilOp;
+ glStencilOpSeparate = fps.glStencilOpSeparate;
+ glTexImage2D = fps.glTexImage2D;
+ glTexParameterf = fps.glTexParameterf;
+ glTexParameterfv = fps.glTexParameterfv;
+ glTexParameteri = fps.glTexParameteri;
+ glTexParameteriv = fps.glTexParameteriv;
+ glTexSubImage2D = fps.glTexSubImage2D;
+ glUniform1f = fps.glUniform1f;
+ glUniform1fv = fps.glUniform1fv;
+ glUniform1i = fps.glUniform1i;
+ glUniform1iv = fps.glUniform1iv;
+ glUniform2f = fps.glUniform2f;
+ glUniform2fv = fps.glUniform2fv;
+ glUniform2i = fps.glUniform2i;
+ glUniform2iv = fps.glUniform2iv;
+ glUniform3f = fps.glUniform3f;
+ glUniform3fv = fps.glUniform3fv;
+ glUniform3i = fps.glUniform3i;
+ glUniform3iv = fps.glUniform3iv;
+ glUniform4f = fps.glUniform4f;
+ glUniform4fv = fps.glUniform4fv;
+ glUniform4i = fps.glUniform4i;
+ glUniform4iv = fps.glUniform4iv;
+ glUniformMatrix2fv = fps.glUniformMatrix2fv;
+ glUniformMatrix3fv = fps.glUniformMatrix3fv;
+ glUniformMatrix4fv = fps.glUniformMatrix4fv;
+ glUseProgram = fps.glUseProgram;
+ glValidateProgram = fps.glValidateProgram;
+ glVertexAttrib1f = fps.glVertexAttrib1f;
+ glVertexAttrib1fv = fps.glVertexAttrib1fv;
+ glVertexAttrib2f = fps.glVertexAttrib2f;
+ glVertexAttrib2fv = fps.glVertexAttrib2fv;
+ glVertexAttrib3f = fps.glVertexAttrib3f;
+ glVertexAttrib3fv = fps.glVertexAttrib3fv;
+ glVertexAttrib4f = fps.glVertexAttrib4f;
+ glVertexAttrib4fv = fps.glVertexAttrib4fv;
+ glVertexAttribPointer = fps.glVertexAttribPointer;
+ glViewport = fps.glViewport;
+
+#ifndef MBGL_USE_GLES2
+ glDrawPixels = fps.glDrawPixels;
+ glGetDoublev = fps.glGetDoublev;
+ glPixelTransferf = fps.glPixelTransferf;
+ glPixelZoom = fps.glPixelZoom;
+ glPointSize = fps.glPointSize;
+ glRasterPos4d = fps.glRasterPos4d;
+#endif
+}
+
+#ifndef NDEBUG
+void GLFunctions::checkError(const char* cmd, const char* file, int line) {
+ if (GLenum err = glGetError()) {
+ Log::Warning(Event::OpenGL, "Error %d: %s - %s:%d", err, cmd, file, line);
+ }
+}
+#endif
+
+GLFunctions::GLFunctions() {
+ init();
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/gl_functions.hpp b/src/mbgl/gl/gl_functions.hpp
new file mode 100644
index 0000000000..10cea41de1
--- /dev/null
+++ b/src/mbgl/gl/gl_functions.hpp
@@ -0,0 +1,189 @@
+#pragma once
+
+#include <mbgl/gl/gl_defines.hpp>
+
+namespace mbgl {
+namespace gl {
+
+/**
+ * @brief Holds pointers to OpenGL ES 2.0 functions. Mapbox GL Native
+ * will only use OpenGL through this abstraction to make sure no assumption
+ * is made on how OpenGL is loaded by the platform and what OpenGL
+ * implementation is provided, as long as it is compatible with ES 2.0.
+ *
+ * Heavily inspired by QOpenGLFunctions, the recommend way of using this
+ * class is by protected/private inheritance, otherwise, the user of
+ * this class needs to make sure to explicitly call Init() at lest once
+ * during the application lifecycle.
+ */
+struct GLFunctions {
+public:
+ /// Load the function pointers from the platform.
+ static void init();
+
+#ifndef NDEBUG
+ /// Check for GL errors and print on the console.
+ static void checkError(const char *cmd, const char *file, int line);
+#endif
+
+ static void (*glActiveTexture)(GLenum);
+ static void (*glAttachShader)(GLuint, GLuint);
+ static void (*glBindAttribLocation)(GLuint, GLuint, const GLchar *);
+ static void (*glBindBuffer)(GLenum, GLuint);
+ static void (*glBindFramebuffer)(GLenum, GLuint);
+ static void (*glBindRenderbuffer)(GLenum, GLuint);
+ static void (*glBindTexture)(GLenum, GLuint);
+ static void (*glBlendColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+ static void (*glBlendEquation)(GLenum);
+ static void (*glBlendEquationSeparate)(GLenum, GLenum);
+ static void (*glBlendFunc)(GLenum, GLenum);
+ static void (*glBlendFuncSeparate)(GLenum, GLenum, GLenum, GLenum);
+ static void (*glBufferData)(GLenum, GLsizeiptr, const void *, GLenum);
+ static void (*glBufferSubData)(GLenum, GLintptr, GLsizeiptr, const void *);
+ static GLenum (*glCheckFramebufferStatus)(GLenum);
+ static void (*glClear)(GLbitfield);
+ static void (*glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat);
+ static void (*glClearDepthf)(GLfloat);
+ static void (*glClearStencil)(GLint);
+ static void (*glColorMask)(GLboolean, GLboolean, GLboolean, GLboolean);
+ static void (*glCompileShader)(GLuint);
+ static void (*glCompressedTexImage2D)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const void *);
+ static void (*glCompressedTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const void *);
+ static void (*glCopyTexImage2D)(GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint);
+ static void (*glCopyTexSubImage2D)(GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei);
+ static GLuint (*glCreateProgram)();
+ static GLuint (*glCreateShader)(GLenum);
+ static void (*glCullFace)(GLenum);
+ static void (*glDeleteBuffers)(GLsizei, const GLuint *);
+ static void (*glDeleteFramebuffers)(GLsizei, const GLuint *);
+ static void (*glDeleteProgram)(GLuint);
+ static void (*glDeleteRenderbuffers)(GLsizei, const GLuint *);
+ static void (*glDeleteShader)(GLuint);
+ static void (*glDeleteTextures)(GLsizei, const GLuint *);
+ static void (*glDepthFunc)(GLenum);
+ static void (*glDepthMask)(GLboolean);
+ static void (*glDepthRangef)(GLfloat, GLfloat);
+ static void (*glDetachShader)(GLuint, GLuint);
+ static void (*glDisable)(GLenum);
+ static void (*glDisableVertexAttribArray)(GLuint);
+ static void (*glDrawArrays)(GLenum, GLint, GLsizei);
+ static void (*glDrawElements)(GLenum, GLsizei, GLenum, const void *);
+ static void (*glEnable)(GLenum);
+ static void (*glEnableVertexAttribArray)(GLuint);
+ static void (*glFinish)();
+ static void (*glFlush)();
+ static void (*glFramebufferRenderbuffer)(GLenum, GLenum, GLenum, GLuint);
+ static void (*glFramebufferTexture2D)(GLenum, GLenum, GLenum, GLuint, GLint);
+ static void (*glFrontFace)(GLenum);
+ static void (*glGenBuffers)(GLsizei, GLuint *);
+ static void (*glGenerateMipmap)(GLenum);
+ static void (*glGenFramebuffers)(GLsizei, GLuint *);
+ static void (*glGenRenderbuffers)(GLsizei, GLuint *);
+ static void (*glGenTextures)(GLsizei, GLuint *);
+ static void (*glGetActiveAttrib)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+ static void (*glGetActiveUniform)(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *);
+ static void (*glGetAttachedShaders)(GLuint, GLsizei, GLsizei *, GLuint *);
+ static GLint (*glGetAttribLocation)(GLuint, const GLchar *);
+ static void (*glGetBooleanv)(GLenum, GLboolean *);
+ static void (*glGetBufferParameteriv)(GLenum, GLenum, GLint *);
+ static GLenum (*glGetError)();
+ static void (*glGetFloatv)(GLenum, GLfloat *);
+ static void (*glGetFramebufferAttachmentParameteriv)(GLenum, GLenum, GLenum, GLint *);
+ static void (*glGetIntegerv)(GLenum, GLint *);
+ static void (*glGetProgramInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+ static void (*glGetProgramiv)(GLuint, GLenum, GLint *);
+ static void (*glGetRenderbufferParameteriv)(GLenum, GLenum, GLint *);
+ static void (*glGetShaderInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+ static void (*glGetShaderiv)(GLuint, GLenum, GLint *);
+ static void (*glGetShaderSource)(GLuint, GLsizei, GLsizei *, GLchar *);
+ static const GLubyte *(*glGetString)(GLenum);
+ static void (*glGetTexParameterfv)(GLenum, GLenum, GLfloat *);
+ static void (*glGetTexParameteriv)(GLenum, GLenum, GLint *);
+ static void (*glGetUniformfv)(GLuint, GLint, GLfloat *);
+ static void (*glGetUniformiv)(GLuint, GLint, GLint *);
+ static GLint (*glGetUniformLocation)(GLuint, const GLchar *);
+ static void (*glGetVertexAttribfv)(GLuint, GLenum, GLfloat *);
+ static void (*glGetVertexAttribiv)(GLuint, GLenum, GLint *);
+ static void (*glGetVertexAttribPointerv)(GLuint, GLenum, void **);
+ static void (*glHint)(GLenum, GLenum);
+ static GLboolean (*glIsBuffer)(GLuint);
+ static GLboolean (*glIsEnabled)(GLenum);
+ static GLboolean (*glIsFramebuffer)(GLuint);
+ static GLboolean (*glIsProgram)(GLuint);
+ static GLboolean (*glIsRenderbuffer)(GLuint);
+ static GLboolean (*glIsShader)(GLuint);
+ static GLboolean (*glIsTexture)(GLuint);
+ static void (*glLineWidth)(GLfloat);
+ static void (*glLinkProgram)(GLuint);
+ static void (*glPixelStorei)(GLenum, GLint);
+ static void (*glPolygonOffset)(GLfloat, GLfloat);
+ static void (*glReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *);
+ static void (*glRenderbufferStorage)(GLenum, GLenum, GLsizei, GLsizei);
+ static void (*glSampleCoverage)(GLfloat, GLboolean);
+ static void (*glScissor)(GLint, GLint, GLsizei, GLsizei);
+ static void (*glShaderSource)(GLuint, GLsizei, const GLchar * const*, const GLint *);
+ static void (*glStencilFunc)(GLenum, GLint, GLuint);
+ static void (*glStencilFuncSeparate)(GLenum, GLenum, GLint, GLuint);
+ static void (*glStencilMask)(GLuint);
+ static void (*glStencilMaskSeparate)(GLenum, GLuint);
+ static void (*glStencilOp)(GLenum, GLenum, GLenum);
+ static void (*glStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum);
+ static void (*glTexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *);
+ static void (*glTexParameterf)(GLenum, GLenum, GLfloat);
+ static void (*glTexParameterfv)(GLenum, GLenum, const GLfloat *);
+ static void (*glTexParameteri)(GLenum, GLenum, GLint);
+ static void (*glTexParameteriv)(GLenum, GLenum, const GLint *);
+ static void (*glTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const void *);
+ static void (*glUniform1f)(GLint, GLfloat);
+ static void (*glUniform1fv)(GLint, GLsizei, const GLfloat *);
+ static void (*glUniform1i)(GLint, GLint);
+ static void (*glUniform1iv)(GLint, GLsizei, const GLint *);
+ static void (*glUniform2f)(GLint, GLfloat, GLfloat);
+ static void (*glUniform2fv)(GLint, GLsizei, const GLfloat *);
+ static void (*glUniform2i)(GLint, GLint, GLint);
+ static void (*glUniform2iv)(GLint, GLsizei, const GLint *);
+ static void (*glUniform3f)(GLint, GLfloat, GLfloat, GLfloat);
+ static void (*glUniform3fv)(GLint, GLsizei, const GLfloat *);
+ static void (*glUniform3i)(GLint, GLint, GLint, GLint);
+ static void (*glUniform3iv)(GLint, GLsizei, const GLint *);
+ static void (*glUniform4f)(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
+ static void (*glUniform4fv)(GLint, GLsizei, const GLfloat *);
+ static void (*glUniform4i)(GLint, GLint, GLint, GLint, GLint);
+ static void (*glUniform4iv)(GLint, GLsizei, const GLint *);
+ static void (*glUniformMatrix2fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ static void (*glUniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ static void (*glUniformMatrix4fv)(GLint, GLsizei, GLboolean, const GLfloat *);
+ static void (*glUseProgram)(GLuint);
+ static void (*glValidateProgram)(GLuint);
+ static void (*glVertexAttrib1f)(GLuint, GLfloat);
+ static void (*glVertexAttrib1fv)(GLuint, const GLfloat *);
+ static void (*glVertexAttrib2f)(GLuint, GLfloat, GLfloat);
+ static void (*glVertexAttrib2fv)(GLuint, const GLfloat *);
+ static void (*glVertexAttrib3f)(GLuint, GLfloat, GLfloat, GLfloat);
+ static void (*glVertexAttrib3fv)(GLuint, const GLfloat *);
+ static void (*glVertexAttrib4f)(GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
+ static void (*glVertexAttrib4fv)(GLuint, const GLfloat *);
+ static void (*glVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, const void *);
+ static void (*glViewport)(GLint, GLint, GLsizei, GLsizei);
+
+#ifndef MBGL_USE_GLES2
+ static void (*glDrawPixels)(GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
+ static void (*glGetDoublev)(GLenum, GLdouble *);
+ static void (*glPixelTransferf)(GLenum, GLfloat);
+ static void (*glPixelZoom)(GLfloat, GLfloat);
+ static void (*glPointSize)(GLfloat);
+ static void (*glRasterPos4d)(GLdouble, GLdouble, GLdouble, GLdouble);
+#endif
+
+protected:
+ GLFunctions();
+};
+
+#ifndef NDEBUG
+#define MBGL_CHECK_ERROR(cmd) ([&]() { struct __MBGL_CHECK_ERROR { ~__MBGL_CHECK_ERROR() noexcept(false) { mbgl::gl::GLFunctions::checkError(#cmd, __FILE__, __LINE__); } } __MBGL_CHECK_ERROR; return cmd; }())
+#else
+#define MBGL_CHECK_ERROR(cmd) (cmd)
+#endif
+
+} // namespace gl
+} // namespace mbgl \ No newline at end of file