diff options
28 files changed, 102 insertions, 193 deletions
diff --git a/platform/android/core-files.json b/platform/android/core-files.json index c1dc9e8429..f2bc43e9a3 100644 --- a/platform/android/core-files.json +++ b/platform/android/core-files.json @@ -81,6 +81,7 @@ "platform/android/src/style/value.cpp", "platform/android/src/text/collator.cpp", "platform/android/src/text/local_glyph_rasterizer.cpp", + "platform/android/src/gl.cpp", "platform/android/src/thread.cpp", "platform/android/src/timer.cpp", "platform/android/src/unaccent.cpp", diff --git a/platform/ios/core-files.json b/platform/ios/core-files.json index 18a8ed5b86..868ff61e14 100644 --- a/platform/ios/core-files.json +++ b/platform/ios/core-files.json @@ -2,6 +2,7 @@ "//": "This file can be edited manually and is the canonical source.", "sources": [ "platform/darwin/src/collator.mm", + "platform/darwin/src/gl.cpp", "platform/darwin/src/headless_backend_eagl.mm", "platform/darwin/src/image.mm", "platform/darwin/src/local_glyph_rasterizer.mm", diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 1df501a84e..2e70d609f4 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -41,6 +41,9 @@ macro(mbgl_platform_core) endif() target_sources(mbgl-core + # GL + PRIVATE platform/linux/src/gl.cpp + # Misc PRIVATE platform/default/src/mbgl/util/logging_stderr.cpp PRIVATE platform/default/src/mbgl/util/string_stdlib.cpp diff --git a/platform/macos/core-files.json b/platform/macos/core-files.json index bfc63d5027..54fd1117a0 100644 --- a/platform/macos/core-files.json +++ b/platform/macos/core-files.json @@ -2,6 +2,7 @@ "//": "This file can be edited manually and is the canonical source.", "sources": [ "platform/darwin/src/collator.mm", + "platform/darwin/src/gl.cpp", "platform/darwin/src/image.mm", "platform/darwin/src/local_glyph_rasterizer.mm", "platform/darwin/src/logging_nslog.mm", diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake index 68b32b9eb9..9249f846e8 100644 --- a/platform/qt/config.cmake +++ b/platform/qt/config.cmake @@ -6,9 +6,9 @@ macro(mbgl_platform_core) ) target_include_directories(mbgl-core - PUBLIC platform/default/include PRIVATE platform/qt PRIVATE platform/qt/include + PUBLIC platform/default/include ) target_link_libraries(mbgl-core PRIVATE diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index e651b8c0c7..853a5110e7 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -38,6 +38,7 @@ set(MBGL_QT_CORE_FILES PRIVATE platform/qt/src/timer.cpp PRIVATE platform/qt/src/timer_impl.hpp PRIVATE platform/qt/src/utf.cpp + PRIVATE platform/qt/src/gl.cpp PRIVATE platform/default/src/mbgl/text/collator.cpp PRIVATE platform/default/src/mbgl/text/unaccent.cpp diff --git a/src/core-files.json b/src/core-files.json index 51e48eae76..e4affde17c 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -23,7 +23,7 @@ "src/mbgl/gl/debugging.cpp", "src/mbgl/gl/debugging_extension.cpp", "src/mbgl/gl/depth_mode.cpp", - "src/mbgl/gl/gl.cpp", + "src/mbgl/gl/gl_functions.cpp", "src/mbgl/gl/object.cpp", "src/mbgl/gl/stencil_mode.cpp", "src/mbgl/gl/uniform.cpp", @@ -315,6 +315,8 @@ "mbgl/actor/message.hpp": "include/mbgl/actor/message.hpp", "mbgl/actor/scheduler.hpp": "include/mbgl/actor/scheduler.hpp", "mbgl/annotation/annotation.hpp": "include/mbgl/annotation/annotation.hpp", + "mbgl/gl/gl_defines.hpp": "include/mbgl/gl/gl_defines.hpp", + "mbgl/gl/gl_function_pointers.hpp": "include/mbgl/gl/gl_function_pointers.hpp", "mbgl/layermanager/background_layer_factory.hpp": "include/mbgl/layermanager/background_layer_factory.hpp", "mbgl/layermanager/circle_layer_factory.hpp": "include/mbgl/layermanager/circle_layer_factory.hpp", "mbgl/layermanager/custom_layer_factory.hpp": "include/mbgl/layermanager/custom_layer_factory.hpp", @@ -336,6 +338,7 @@ "mbgl/math/log2.hpp": "include/mbgl/math/log2.hpp", "mbgl/math/minmax.hpp": "include/mbgl/math/minmax.hpp", "mbgl/math/wrap.hpp": "include/mbgl/math/wrap.hpp", + "mbgl/platform/gl.hpp": "include/mbgl/platform/gl.hpp", "mbgl/renderer/backend_scope.hpp": "include/mbgl/renderer/backend_scope.hpp", "mbgl/renderer/mode.hpp": "include/mbgl/renderer/mode.hpp", "mbgl/renderer/query.hpp": "include/mbgl/renderer/query.hpp", @@ -507,7 +510,7 @@ "mbgl/gl/extension.hpp": "src/mbgl/gl/extension.hpp", "mbgl/gl/features.hpp": "src/mbgl/gl/features.hpp", "mbgl/gl/framebuffer.hpp": "src/mbgl/gl/framebuffer.hpp", - "mbgl/gl/gl.hpp": "src/mbgl/gl/gl.hpp", + "mbgl/gl/gl_functions.hpp": "src/mbgl/gl/gl_functions.hpp", "mbgl/gl/index_buffer.hpp": "src/mbgl/gl/index_buffer.hpp", "mbgl/gl/object.hpp": "src/mbgl/gl/object.hpp", "mbgl/gl/primitives.hpp": "src/mbgl/gl/primitives.hpp", diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index b2d05fe665..fc002c624d 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -1,6 +1,5 @@ #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/context.hpp> -#include <mbgl/gl/gl.hpp> namespace mbgl { namespace gl { @@ -13,7 +12,7 @@ void bindAttributeLocation(Context& context, ProgramID id, AttributeLocation loc // an OpenGL error). This means we'll see rendering errors, and possibly slow rendering due // to unbound attributes. } else { - MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); + MBGL_CHECK_ERROR(GLFunctions::glBindAttribLocation(id, location, name)); } } @@ -21,10 +20,10 @@ std::set<std::string> getActiveAttributes(ProgramID id) { std::set<std::string> activeAttributes; GLint attributeCount; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount)); + MBGL_CHECK_ERROR(GLFunctions::glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount)); GLint maxAttributeLength; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength)); + MBGL_CHECK_ERROR(GLFunctions::glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength)); std::string attributeName; attributeName.resize(maxAttributeLength); @@ -34,7 +33,7 @@ std::set<std::string> getActiveAttributes(ProgramID id) { GLenum type; for (int32_t i = 0; i < attributeCount; i++) { - MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0])); + MBGL_CHECK_ERROR(GLFunctions::glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0])); activeAttributes.emplace(std::string(attributeName, 0, actualLength)); } diff --git a/src/mbgl/gl/color_mode.cpp b/src/mbgl/gl/color_mode.cpp index e838c8e2ff..c4b01188f4 100644 --- a/src/mbgl/gl/color_mode.cpp +++ b/src/mbgl/gl/color_mode.cpp @@ -1,5 +1,5 @@ #include <mbgl/gl/color_mode.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> #include <mbgl/util/traits.hpp> namespace mbgl { diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 18ab38e684..a5f5d9a86f 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -1,5 +1,4 @@ #include <mbgl/gl/context.hpp> -#include <mbgl/gl/gl.hpp> #include <mbgl/gl/debugging_extension.hpp> #include <mbgl/gl/vertex_array_extension.hpp> #include <mbgl/gl/program_binary_extension.hpp> @@ -427,7 +426,7 @@ void Context::drawPixels(const Size size, const void* data, TextureFormat format namespace { void checkFramebuffer() { - GLenum status = MBGL_CHECK_ERROR(glCheckFramebufferStatus(GL_FRAMEBUFFER)); + GLenum status = MBGL_CHECK_ERROR(GLFunctions::glCheckFramebufferStatus(GL_FRAMEBUFFER)); if (status != GL_FRAMEBUFFER_COMPLETE) { switch (status) { case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: @@ -458,12 +457,12 @@ void checkFramebuffer() { void bindDepthStencilRenderbuffer( const Renderbuffer<RenderbufferType::DepthStencil>& depthStencil) { #ifdef GL_DEPTH_STENCIL_ATTACHMENT - MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, + MBGL_CHECK_ERROR(GLFunctions::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil.renderbuffer)); #else - MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, + MBGL_CHECK_ERROR(GLFunctions::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencil.renderbuffer)); - MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, + MBGL_CHECK_ERROR(GLFunctions::glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencil.renderbuffer)); #endif } diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index bd682f44da..25167e453a 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/gl/features.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/gl/object.hpp> #include <mbgl/gl/state.hpp> #include <mbgl/gl/value.hpp> @@ -36,7 +37,7 @@ class Debugging; class ProgramBinary; } // namespace extension -class Context { +class Context : private GLFunctions { public: Context(); ~Context(); diff --git a/src/mbgl/gl/cull_face_mode.cpp b/src/mbgl/gl/cull_face_mode.cpp index 42729aeea7..99e61f98d5 100644 --- a/src/mbgl/gl/cull_face_mode.cpp +++ b/src/mbgl/gl/cull_face_mode.cpp @@ -1,5 +1,5 @@ #include <mbgl/gl/cull_face_mode.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> #include <mbgl/util/traits.hpp> namespace mbgl { diff --git a/src/mbgl/gl/debugging_extension.hpp b/src/mbgl/gl/debugging_extension.hpp index 5657bbde88..8acdd67e3e 100644 --- a/src/mbgl/gl/debugging_extension.hpp +++ b/src/mbgl/gl/debugging_extension.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gl/extension.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_functions.hpp> #define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 #define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 diff --git a/src/mbgl/gl/depth_mode.cpp b/src/mbgl/gl/depth_mode.cpp index 21af75a391..fedb45aeb2 100644 --- a/src/mbgl/gl/depth_mode.cpp +++ b/src/mbgl/gl/depth_mode.cpp @@ -1,5 +1,5 @@ #include <mbgl/gl/depth_mode.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> #include <mbgl/util/traits.hpp> namespace mbgl { diff --git a/src/mbgl/gl/gl.cpp b/src/mbgl/gl/gl.cpp deleted file mode 100644 index bd6d7b192d..0000000000 --- a/src/mbgl/gl/gl.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include <mbgl/gl/gl.hpp> -#include <mbgl/util/string.hpp> -#include <mbgl/util/util.hpp> - -namespace mbgl { -namespace gl { - -namespace { - -MBGL_CONSTEXPR const char* stringFromError(GLenum err) { - switch (err) { - case GL_INVALID_ENUM: - return "GL_INVALID_ENUM"; - - case GL_INVALID_VALUE: - return "GL_INVALID_VALUE"; - - case GL_INVALID_OPERATION: - return "GL_INVALID_OPERATION"; - - case GL_INVALID_FRAMEBUFFER_OPERATION: - return "GL_INVALID_FRAMEBUFFER_OPERATION"; - - case GL_OUT_OF_MEMORY: - return "GL_OUT_OF_MEMORY"; - -#ifdef GL_TABLE_TOO_LARGE - case GL_TABLE_TOO_LARGE: - return "GL_TABLE_TOO_LARGE"; -#endif - -#ifdef GL_STACK_OVERFLOW - case GL_STACK_OVERFLOW: - return "GL_STACK_OVERFLOW"; -#endif - -#ifdef GL_STACK_UNDERFLOW - case GL_STACK_UNDERFLOW: - return "GL_STACK_UNDERFLOW"; -#endif - -#ifdef GL_CONTEXT_LOST - case GL_CONTEXT_LOST: - return "GL_CONTEXT_LOST"; -#endif - - default: - return "GL_UNKNOWN"; - } -} - -} // namespace - -void checkError(const char* cmd, const char* file, int line) { -// fprintf(stderr, "cmd: %s\n", cmd); - GLenum err = GL_NO_ERROR; - if ((err = glGetError()) != GL_NO_ERROR) { - std::string message = std::string(cmd) + ": Error " + stringFromError(err); - - // Check for further errors - while ((err = glGetError()) != GL_NO_ERROR) { - message += ", "; - message += stringFromError(err); - } - - throw Error(message + " at " + file + ":" + util::toString(line)); - } -} - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/gl.hpp b/src/mbgl/gl/gl.hpp deleted file mode 100644 index 976b7d2f74..0000000000 --- a/src/mbgl/gl/gl.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mbgl/gl/gl_impl.hpp> - -#include <stdexcept> -#include <limits> - -namespace mbgl { -namespace gl { - -struct Error : std::runtime_error { - using std::runtime_error::runtime_error; -}; - -void checkError(const char *cmd, const char *file, int line); - -#ifndef NDEBUG -#define MBGL_CHECK_ERROR(cmd) ([&]() { struct __MBGL_C_E { ~__MBGL_C_E() noexcept(false) { ::mbgl::gl::checkError(#cmd, __FILE__, __LINE__); } } __MBGL_C_E; return cmd; }()) -#else -#define MBGL_CHECK_ERROR(cmd) (cmd) -#endif - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/program_binary_extension.hpp b/src/mbgl/gl/program_binary_extension.hpp index a4aa1eeefc..ef3229ccbd 100644 --- a/src/mbgl/gl/program_binary_extension.hpp +++ b/src/mbgl/gl/program_binary_extension.hpp @@ -2,7 +2,7 @@ #include <mbgl/gl/features.hpp> #include <mbgl/gl/extension.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> #if MBGL_HAS_BINARY_PROGRAMS diff --git a/src/mbgl/gl/stencil_mode.cpp b/src/mbgl/gl/stencil_mode.cpp index 6858d6d106..3d92d8c996 100644 --- a/src/mbgl/gl/stencil_mode.cpp +++ b/src/mbgl/gl/stencil_mode.cpp @@ -1,5 +1,5 @@ #include <mbgl/gl/stencil_mode.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> #include <mbgl/util/traits.hpp> namespace mbgl { diff --git a/src/mbgl/gl/uniform.cpp b/src/mbgl/gl/uniform.cpp index 3d8a8d53d9..e469b77da6 100644 --- a/src/mbgl/gl/uniform.cpp +++ b/src/mbgl/gl/uniform.cpp @@ -1,5 +1,5 @@ #include <mbgl/gl/uniform.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/size.hpp> #include <mbgl/util/convert.hpp> @@ -10,47 +10,47 @@ namespace mbgl { namespace gl { UniformLocation uniformLocation(ProgramID id, const char* name) { - return MBGL_CHECK_ERROR(glGetUniformLocation(id, name)); + return MBGL_CHECK_ERROR(GLFunctions::glGetUniformLocation(id, name)); } template <> void bindUniform<float>(UniformLocation location, const float& t) { - MBGL_CHECK_ERROR(glUniform1f(location, t)); + MBGL_CHECK_ERROR(GLFunctions::glUniform1f(location, t)); } template <> void bindUniform<int32_t>(UniformLocation location, const int32_t& t) { - MBGL_CHECK_ERROR(glUniform1i(location, t)); + MBGL_CHECK_ERROR(GLFunctions::glUniform1i(location, t)); } template <> void bindUniform<std::array<float, 2>>(UniformLocation location, const std::array<float, 2>& t) { - MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data())); + MBGL_CHECK_ERROR(GLFunctions::glUniform2fv(location, 1, t.data())); } template <> void bindUniform<std::array<float, 3>>(UniformLocation location, const std::array<float, 3>& t) { - MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data())); + MBGL_CHECK_ERROR(GLFunctions::glUniform3fv(location, 1, t.data())); } template <> void bindUniform<std::array<float, 4>>(UniformLocation location, const std::array<float, 4>& t) { - MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data())); + MBGL_CHECK_ERROR(GLFunctions::glUniform4fv(location, 1, t.data())); } template <> void bindUniform<std::array<double, 4>>(UniformLocation location, const std::array<double, 4>& t) { - MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, util::convert<float>(t).data())); + MBGL_CHECK_ERROR(GLFunctions::glUniformMatrix2fv(location, 1, GL_FALSE, util::convert<float>(t).data())); } template <> void bindUniform<std::array<double, 9>>(UniformLocation location, const std::array<double, 9>& t) { - MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, util::convert<float>(t).data())); + MBGL_CHECK_ERROR(GLFunctions::glUniformMatrix3fv(location, 1, GL_FALSE, util::convert<float>(t).data())); } template <> void bindUniform<std::array<double, 16>>(UniformLocation location, const std::array<double, 16>& t) { - MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, util::convert<float>(t).data())); + MBGL_CHECK_ERROR(GLFunctions::glUniformMatrix4fv(location, 1, GL_FALSE, util::convert<float>(t).data())); } @@ -93,16 +93,15 @@ ActiveUniforms activeUniforms(ProgramID id) { GLint count; GLint maxLength; - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count)); - MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); + MBGL_CHECK_ERROR(GLFunctions::glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count)); + MBGL_CHECK_ERROR(GLFunctions::glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); auto name = std::make_unique<GLchar[]>(maxLength); GLsizei length; GLint size; GLenum type; for (GLint index = 0; index < count; index++) { - MBGL_CHECK_ERROR( - glGetActiveUniform(id, index, maxLength, &length, &size, &type, name.get())); + MBGL_CHECK_ERROR(GLFunctions::glGetActiveUniform(id, index, maxLength, &length, &size, &type, name.get())); active.emplace( std::string{ name.get(), static_cast<size_t>(length) }, ActiveUniform{ static_cast<size_t>(size), static_cast<UniformDataType>(type) }); diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index 581acd0358..523ad2ae45 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -1,5 +1,4 @@ #include <mbgl/gl/value.hpp> -#include <mbgl/gl/gl.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/gl/vertex_array_extension.hpp> @@ -10,11 +9,7 @@ namespace value { const constexpr ClearDepth::Type ClearDepth::Default; void ClearDepth::Set(const Type& value) { -#if MBGL_USE_GLES2 MBGL_CHECK_ERROR(glClearDepthf(value)); -#else - MBGL_CHECK_ERROR(glClearDepth(value)); -#endif } ClearDepth::Type ClearDepth::Get() { @@ -130,11 +125,7 @@ StencilOp::Type StencilOp::Get() { const constexpr DepthRange::Type DepthRange::Default; void DepthRange::Set(const Type& value) { -#if MBGL_USE_GLES2 MBGL_CHECK_ERROR(glDepthRangef(value.min, value.max)); -#else - MBGL_CHECK_ERROR(glDepthRange(value.min, value.max)); -#endif } DepthRange::Type DepthRange::Get() { diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 25f22aa038..3dd8a4130a 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -2,6 +2,7 @@ #include <mbgl/gl/types.hpp> #include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gl/color_mode.hpp> #include <mbgl/gl/cull_face_mode.hpp> @@ -17,49 +18,49 @@ class Context; namespace value { -struct ClearDepth { +struct ClearDepth : private GLFunctions { using Type = float; static const constexpr Type Default = 1; static void Set(const Type&); static Type Get(); }; -struct ClearColor { +struct ClearColor : private GLFunctions { using Type = Color; static const Type Default; static void Set(const Type&); static Type Get(); }; -struct ClearStencil { +struct ClearStencil : private GLFunctions { using Type = int32_t; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct StencilMask { +struct StencilMask : private GLFunctions { using Type = uint32_t; static const constexpr Type Default = ~0u; static void Set(const Type&); static Type Get(); }; -struct DepthMask { +struct DepthMask : private GLFunctions { using Type = bool; static const constexpr Type Default = true; static void Set(const Type&); static Type Get(); }; -struct ColorMask { +struct ColorMask : private GLFunctions { using Type = ColorMode::Mask; static const constexpr Type Default = { true, true, true, true }; static void Set(const Type&); static Type Get(); }; -struct StencilFunc { +struct StencilFunc : private GLFunctions { struct Type { uint32_t func; int32_t ref; @@ -74,14 +75,14 @@ constexpr bool operator!=(const StencilFunc::Type& a, const StencilFunc::Type& b return a.func != b.func || a.ref != b.ref || a.mask != b.mask; } -struct StencilTest { +struct StencilTest : private GLFunctions { using Type = bool; static const constexpr Type Default = false; static void Set(const Type&); static Type Get(); }; -struct StencilOp { +struct StencilOp : private GLFunctions { struct Type { StencilMode::Op sfail; StencilMode::Op dpfail; @@ -96,42 +97,42 @@ constexpr bool operator!=(const StencilOp::Type& a, const StencilOp::Type& b) { return a.sfail != b.sfail || a.dpfail != b.dpfail || a.dppass != b.dppass; } -struct DepthRange { +struct DepthRange : private GLFunctions { using Type = Range<float>; static const constexpr Type Default = { 0, 1 }; static void Set(const Type&); static Type Get(); }; -struct DepthTest { +struct DepthTest : private GLFunctions { using Type = bool; static const constexpr Type Default = false; static void Set(const Type&); static Type Get(); }; -struct DepthFunc { +struct DepthFunc : private GLFunctions { using Type = DepthMode::Function; static const constexpr Type Default = DepthMode::Less; static void Set(const Type&); static Type Get(); }; -struct Blend { +struct Blend : private GLFunctions { using Type = bool; static const constexpr Type Default = true; static void Set(const Type&); static Type Get(); }; -struct BlendEquation { +struct BlendEquation : private GLFunctions { using Type = ColorMode::BlendEquation; static const constexpr Type Default = ColorMode::BlendEquation::Add; static void Set(const Type&); static Type Get(); }; -struct BlendFunc { +struct BlendFunc : private GLFunctions { struct Type { ColorMode::BlendFactor sfactor; ColorMode::BlendFactor dfactor; @@ -145,35 +146,35 @@ constexpr bool operator!=(const BlendFunc::Type& a, const BlendFunc::Type& b) { return a.sfactor != b.sfactor || a.dfactor != b.dfactor; } -struct BlendColor { +struct BlendColor : private GLFunctions { using Type = Color; static const Type Default; static void Set(const Type&); static Type Get(); }; -struct Program { +struct Program : private GLFunctions { using Type = gl::ProgramID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct LineWidth { +struct LineWidth : private GLFunctions { using Type = float; static const constexpr Type Default = 1; static void Set(const Type&); static Type Get(); }; -struct ActiveTextureUnit { +struct ActiveTextureUnit : private GLFunctions { using Type = TextureUnit; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct Viewport { +struct Viewport : private GLFunctions { struct Type { int32_t x; int32_t y; @@ -184,7 +185,7 @@ struct Viewport { static Type Get(); }; -struct ScissorTest { +struct ScissorTest : private GLFunctions { using Type = bool; static const constexpr Type Default = false; static void Set(const Type&); @@ -199,83 +200,83 @@ constexpr bool operator==(const Viewport::Type& a, const Viewport::Type& b) { return !(a != b); } -struct BindFramebuffer { +struct BindFramebuffer : private GLFunctions { using Type = FramebufferID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct BindRenderbuffer { +struct BindRenderbuffer : private GLFunctions { using Type = RenderbufferID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct CullFace { +struct CullFace : private GLFunctions { using Type = CullFaceMode::CullFace; static const constexpr Type Default = CullFaceMode::Disable; static void Set(const Type&); static Type Get(); }; -struct CullFaceSide { +struct CullFaceSide : private GLFunctions { using Type = CullFaceMode::CullFaceSide; static const constexpr Type Default = CullFaceMode::Back; static void Set(const Type&); static Type Get(); }; -struct FrontFace { +struct FrontFace : private GLFunctions { using Type = CullFaceMode::FrontFace; static const constexpr Type Default = CullFaceMode::CounterClockwise; static void Set(const Type&); static Type Get(); }; -struct BindTexture { +struct BindTexture : private GLFunctions { using Type = gl::TextureID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct BindVertexBuffer { +struct BindVertexBuffer : private GLFunctions { using Type = gl::BufferID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct BindElementBuffer { +struct BindElementBuffer : private GLFunctions { using Type = gl::BufferID; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); }; -struct BindVertexArray { +struct BindVertexArray : private GLFunctions { using Type = gl::VertexArrayID; static const constexpr Type Default = 0; static void Set(const Type&, const Context&); static Type Get(const Context&); }; -struct VertexAttribute { +struct VertexAttribute : private GLFunctions { using Type = optional<gl::AttributeBinding>; static const Type Default; static void Set(const Type&, Context&, AttributeLocation); }; -struct PixelStorePack { +struct PixelStorePack : private GLFunctions { using Type = PixelStorageType; static const constexpr Type Default = { 4 }; static void Set(const Type&); static Type Get(); }; -struct PixelStoreUnpack { +struct PixelStoreUnpack : private GLFunctions { using Type = PixelStorageType; static const constexpr Type Default = { 4 }; static void Set(const Type&); @@ -284,14 +285,14 @@ struct PixelStoreUnpack { #if not MBGL_USE_GLES2 -struct PointSize { +struct PointSize : private GLFunctions { using Type = float; static const constexpr Type Default = 1; static void Set(const Type&); static Type Get(); }; -struct PixelZoom { +struct PixelZoom : private GLFunctions { struct Type { float xfactor; float yfactor; @@ -305,7 +306,7 @@ constexpr bool operator!=(const PixelZoom::Type& a, const PixelZoom::Type& b) { return a.xfactor != b.xfactor || a.yfactor != b.yfactor; } -struct RasterPos { +struct RasterPos : private GLFunctions { struct Type { double x; double y; @@ -321,7 +322,7 @@ constexpr bool operator!=(const RasterPos::Type& a, const RasterPos::Type& b) { return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w; } -struct PixelTransferDepth { +struct PixelTransferDepth : private GLFunctions { struct Type { float scale; float bias; @@ -335,7 +336,7 @@ constexpr bool operator!=(const PixelTransferDepth::Type& a, const PixelTransfer return a.scale != b.scale || a.bias != b.bias; } -struct PixelTransferStencil { +struct PixelTransferStencil : private GLFunctions { struct Type { int32_t shift; int32_t offset; diff --git a/src/mbgl/gl/vertex_array.cpp b/src/mbgl/gl/vertex_array.cpp index d552a8292e..0892c3b08b 100644 --- a/src/mbgl/gl/vertex_array.cpp +++ b/src/mbgl/gl/vertex_array.cpp @@ -1,6 +1,5 @@ #include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/context.hpp> -#include <mbgl/gl/gl.hpp> namespace mbgl { namespace gl { diff --git a/src/mbgl/gl/vertex_array_extension.hpp b/src/mbgl/gl/vertex_array_extension.hpp index 707a20e6f0..ef3b6f3694 100644 --- a/src/mbgl/gl/vertex_array_extension.hpp +++ b/src/mbgl/gl/vertex_array_extension.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gl/extension.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_defines.hpp> namespace mbgl { namespace gl { diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index 9e65830faf..8a7a263e80 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -3,9 +3,9 @@ #include <mbgl/renderer/backend_scope.hpp> #include <mbgl/renderer/renderer_backend.hpp> #include <mbgl/renderer/bucket.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/style/layers/custom_layer_impl.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/gl/gl.hpp> #include <mbgl/util/mat4.hpp> namespace mbgl { @@ -15,7 +15,7 @@ using namespace style; RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl) : RenderLayer(std::move(_impl)), host(impl().host) { assert(BackendScope::exists()); - host->initialize(); + MBGL_CHECK_ERROR(host->initialize()); } RenderCustomLayer::~RenderCustomLayer() { @@ -23,7 +23,7 @@ RenderCustomLayer::~RenderCustomLayer() { if (contextDestroyed) { host->contextLost(); } else { - host->deinitialize(); + MBGL_CHECK_ERROR(host->deinitialize()); } } diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp index 83d1543a0a..51d026e30d 100644 --- a/test/api/custom_geometry_source.test.cpp +++ b/test/api/custom_geometry_source.test.cpp @@ -1,6 +1,5 @@ #include <mbgl/test/util.hpp> -#include <mbgl/gl/gl.hpp> #include <mbgl/map/map.hpp> #include <mbgl/util/shared_thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index a94cf122bf..c60012dbb2 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -1,6 +1,6 @@ #include <mbgl/test/util.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/map/map.hpp> #include <mbgl/util/default_thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> @@ -34,7 +34,7 @@ void main() { // layer implementation because it is intended to reflect how someone using custom layers // might actually write their own implementation. -class TestLayer : public mbgl::style::CustomLayerHost { +class TestLayer : public mbgl::style::CustomLayerHost, private mbgl::gl::GLFunctions { public: void initialize() { program = MBGL_CHECK_ERROR(glCreateProgram()); diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp index 3818544021..940e05fe5a 100644 --- a/test/gl/context.test.cpp +++ b/test/gl/context.test.cpp @@ -1,6 +1,6 @@ #include <mbgl/test/util.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/map/map.hpp> #include <mbgl/util/default_thread_pool.hpp> @@ -36,7 +36,7 @@ void main() { } )MBGL_SHADER"; -struct Shader { +struct Shader : private mbgl::gl::GLFunctions { Shader(const GLchar* vertex, const GLchar* fragment) { program = MBGL_CHECK_ERROR(glCreateProgram()); vertexShader = MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)); @@ -65,7 +65,7 @@ struct Shader { GLuint a_pos = 0; }; -struct Buffer { +struct Buffer : private mbgl::gl::GLFunctions { Buffer(std::vector<GLfloat> data) { MBGL_CHECK_ERROR(glGenBuffers(1, &buffer)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, buffer)); @@ -80,7 +80,10 @@ struct Buffer { GLuint buffer = 0; }; -TEST(GLContextMode, Shared) { +class GLContextModeTest : public ::testing::Test, protected mbgl::gl::GLFunctions { +}; + +TEST_F(GLContextModeTest, Shared) { util::RunLoop loop; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index 09c940c4c3..bacd5d804f 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -1,6 +1,6 @@ #include <mbgl/test/util.hpp> -#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_functions.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/gl/headless_backend.hpp> #include <mbgl/renderer/backend_scope.hpp> @@ -9,7 +9,10 @@ using namespace mbgl; -TEST(OffscreenTexture, EmptyRed) { +class OffscreenTextureTest : public ::testing::Test, protected mbgl::gl::GLFunctions { +}; + +TEST_F(OffscreenTextureTest, EmptyRed) { HeadlessBackend backend({ 512, 256 }); BackendScope scope { backend }; @@ -26,7 +29,7 @@ TEST(OffscreenTexture, EmptyRed) { test::checkImage("test/fixtures/offscreen_texture/empty-red", image, 0, 0); } -struct Shader { +struct Shader : private mbgl::gl::GLFunctions { Shader(const GLchar* vertex, const GLchar* fragment) { program = MBGL_CHECK_ERROR(glCreateProgram()); vertexShader = MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)); @@ -55,7 +58,7 @@ struct Shader { GLuint a_pos = 0; }; -struct Buffer { +struct Buffer : private mbgl::gl::GLFunctions { Buffer(std::vector<GLfloat> data) { MBGL_CHECK_ERROR(glGenBuffers(1, &buffer)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, buffer)); @@ -71,7 +74,7 @@ struct Buffer { }; -TEST(OffscreenTexture, RenderToTexture) { +TEST_F(OffscreenTextureTest, RenderToTexture) { HeadlessBackend backend({ 512, 256 }); BackendScope scope { backend }; auto& context = backend.getContext(); |