#pragma once //#define GL_TRACK #include #include #include #ifdef GL_TRACK #include #endif #if __APPLE__ #include "TargetConditionals.h" #if TARGET_OS_IPHONE #include #include #elif TARGET_IPHONE_SIMULATOR #include #include #elif TARGET_OS_MAC #include #include #else #error Unsupported Apple platform #endif #elif __ANDROID__ || MBGL_USE_GLES2 #define GL_GLEXT_PROTOTYPES #include #include #else #define GL_GLEXT_PROTOTYPES #include #include #endif namespace mbgl { namespace gl { #ifdef GL_TRACK typedef void (*GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); template void mbx_trapExtension(const char *name, Args... args); void mbx_trapExtension(const char *); void mbx_trapExtension(const char *, GLint, const char *); void mbx_trapExtension(const char *, GLsizei, GLuint *); void mbx_trapExtension(const char *, GLsizei, const GLuint *); void mbx_trapExtension(const char *, GLenum, GLenum, GLenum, GLsizei, const GLuint *, GLboolean); void mbx_trapExtension(const char *, GLenum, GLuint, GLsizei, const GLchar *); void mbx_trapExtension(const char *, GLDEBUGPROC, const void *); void mbx_trapExtension(const char *, GLuint, GLuint, GLuint, GLuint, GLint, const char *, const void*); void mbx_trapExtension(const char *name, GLuint array); #endif struct Error : ::std::runtime_error { Error(GLenum err, const std::string &msg) : ::std::runtime_error(msg), code(err) {}; const GLenum code; }; void checkError(const char *cmd, const char *file, int line); #ifndef NDEBUG #define MBGL_CHECK_ERROR(cmd) ([&]() { struct __MBGL_C_E { ~__MBGL_C_E() { ::mbgl::gl::checkError(#cmd, __FILE__, __LINE__); } } __MBGL_C_E; return cmd; }()) #else #define MBGL_CHECK_ERROR(cmd) (cmd) #endif class ExtensionFunctionBase { public: static std::vector& functions(); typedef std::pair Probe; std::vector probes; void (*ptr)(); #ifdef GL_TRACK const char *foundName; #endif }; template class ExtensionFunction; template class ExtensionFunction : protected ExtensionFunctionBase { public: ExtensionFunction(std::initializer_list probes_) { probes = probes_; ExtensionFunctionBase::functions().push_back(this); } explicit operator bool() const { return ptr; } R operator()(Args... args) const { #ifdef GL_TRACK mbx_trapExtension(foundName, args...); #endif return (*reinterpret_cast(ptr))(std::forward(args)...); } }; using glProc = void (*)(); void InitializeExtensions(glProc (*getProcAddress)(const char *)); extern ExtensionFunction BindVertexArray; extern ExtensionFunction DeleteVertexArrays; extern ExtensionFunction GenVertexArrays; } // namespace gl } // namespace mbgl #ifdef GL_ES_VERSION_2_0 #define glClearDepth glClearDepthf #define glDepthRange glDepthRangef #endif #ifdef GL_TRACK #define glBindTexture mbx_glBindTexture #define glDeleteTexture mbx_glDeleteTexture #define glTexImage2D mbx_glTexImage2D #define glClear mbx_glClear #define glShaderSource mbx_glShaderSource #define glBufferData mbx_glBufferData #define glBindBuffer mbx_glBindBuffer #define glDeleteBuffers mbx_glDeleteBuffers void mbx_glDeleteBuffers(GLsizei n, const GLuint * buffers); void mbx_glBindBuffer(GLenum target, GLuint buffer); void mbx_glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); void mbx_glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length); void mbx_glClear(GLbitfield mask); void mbx_glBindTexture( GLenum target, GLuint texture); void mbx_glDeleteTextures(GLsizei n, const GLuint * textures); void mbx_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data); #endif