summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/render.cpp2
-rw-r--r--cmake/test.cmake1
-rw-r--r--cmake/vendor.cmake2
-rw-r--r--include/mbgl/gfx/backend.hpp44
-rw-r--r--include/mbgl/gfx/renderer_backend.hpp5
-rw-r--r--include/mbgl/gl/renderer_backend.hpp3
-rwxr-xr-xplatform/android/src/android_renderer_backend.cpp2
-rw-r--r--platform/default/include/mbgl/gfx/headless_backend.hpp9
-rw-r--r--platform/default/src/mbgl/gfx/headless_frontend.cpp6
-rw-r--r--platform/default/src/mbgl/gl/headless_backend.cpp12
-rw-r--r--platform/glfw/glfw_backend.hpp7
-rw-r--r--platform/glfw/glfw_gl_backend.cpp12
-rw-r--r--platform/glfw/glfw_view.cpp9
-rw-r--r--platform/glfw/glfw_view.hpp2
-rw-r--r--platform/glfw/main.cpp2
-rw-r--r--platform/node/src/node_mapbox_gl_native.cpp13
-rwxr-xr-xscripts/generate-shaders.js4
-rw-r--r--src/core-files.json2
-rw-r--r--src/mbgl/gfx/context.hpp14
-rw-r--r--src/mbgl/gfx/context_impl.hpp23
-rw-r--r--src/mbgl/gfx/types.hpp4
-rw-r--r--src/mbgl/gl/context.cpp2
-rw-r--r--src/mbgl/gl/renderer_backend.cpp32
-rw-r--r--src/mbgl/programs/background_program.cpp4
-rw-r--r--src/mbgl/programs/circle_program.cpp3
-rw-r--r--src/mbgl/programs/clipping_mask_program.cpp3
-rw-r--r--src/mbgl/programs/collision_box_program.cpp4
-rw-r--r--src/mbgl/programs/debug_program.cpp3
-rw-r--r--src/mbgl/programs/fill_extrusion_program.cpp4
-rw-r--r--src/mbgl/programs/fill_program.cpp6
-rw-r--r--src/mbgl/programs/gl/background.cpp4
-rw-r--r--src/mbgl/programs/gl/background_pattern.cpp4
-rw-r--r--src/mbgl/programs/gl/circle.cpp4
-rw-r--r--src/mbgl/programs/gl/clipping_mask.cpp4
-rw-r--r--src/mbgl/programs/gl/collision_box.cpp4
-rw-r--r--src/mbgl/programs/gl/collision_circle.cpp4
-rw-r--r--src/mbgl/programs/gl/debug.cpp4
-rw-r--r--src/mbgl/programs/gl/fill.cpp4
-rw-r--r--src/mbgl/programs/gl/fill_extrusion.cpp4
-rw-r--r--src/mbgl/programs/gl/fill_extrusion_pattern.cpp4
-rw-r--r--src/mbgl/programs/gl/fill_outline.cpp4
-rw-r--r--src/mbgl/programs/gl/fill_outline_pattern.cpp4
-rw-r--r--src/mbgl/programs/gl/fill_pattern.cpp4
-rw-r--r--src/mbgl/programs/gl/heatmap.cpp4
-rw-r--r--src/mbgl/programs/gl/heatmap_texture.cpp4
-rw-r--r--src/mbgl/programs/gl/hillshade.cpp4
-rw-r--r--src/mbgl/programs/gl/hillshade_prepare.cpp4
-rw-r--r--src/mbgl/programs/gl/line.cpp4
-rw-r--r--src/mbgl/programs/gl/line_gradient.cpp4
-rw-r--r--src/mbgl/programs/gl/line_pattern.cpp4
-rw-r--r--src/mbgl/programs/gl/line_sdf.cpp4
-rw-r--r--src/mbgl/programs/gl/raster.cpp4
-rw-r--r--src/mbgl/programs/gl/symbol_icon.cpp4
-rw-r--r--src/mbgl/programs/gl/symbol_sdf_icon.cpp4
-rw-r--r--src/mbgl/programs/gl/symbol_sdf_text.cpp4
-rw-r--r--src/mbgl/programs/heatmap_program.cpp3
-rw-r--r--src/mbgl/programs/heatmap_texture_program.cpp3
-rw-r--r--src/mbgl/programs/hillshade_prepare_program.cpp3
-rw-r--r--src/mbgl/programs/hillshade_program.cpp3
-rw-r--r--src/mbgl/programs/line_program.cpp6
-rw-r--r--src/mbgl/programs/raster_program.cpp3
-rw-r--r--src/mbgl/programs/symbol_program.cpp5
-rw-r--r--test/api/custom_layer.test.cpp4
-rw-r--r--test/gl/context.test.cpp4
-rw-r--r--test/map/map.test.cpp4
-rw-r--r--test/src/mbgl/test/test.cpp9
-rw-r--r--test/util/offscreen_texture.test.cpp8
67 files changed, 216 insertions, 178 deletions
diff --git a/bin/render.cpp b/bin/render.cpp
index a29ecdf08a..85231c8cba 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -4,6 +4,7 @@
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/default_styles.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/headless_frontend.hpp>
#include <mbgl/style/style.hpp>
@@ -17,6 +18,7 @@ int main(int argc, char *argv[]) {
args::ArgumentParser argumentParser("Mapbox GL render tool");
args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {"help"});
+ args::ValueFlag<std::string> backendValue(argumentParser, "Backend", "Rendering backend", {"backend"});
args::ValueFlag<std::string> tokenValue(argumentParser, "key", "Mapbox access token", {'t', "token"});
args::ValueFlag<std::string> styleValue(argumentParser, "URL", "Map stylesheet", {'s', "style"});
args::ValueFlag<std::string> outputValue(argumentParser, "file", "Output file name", {'o', "output"});
diff --git a/cmake/test.cmake b/cmake/test.cmake
index 0614270089..16dc10f93d 100644
--- a/cmake/test.cmake
+++ b/cmake/test.cmake
@@ -26,6 +26,7 @@ target_include_directories(mbgl-test
target_link_libraries(mbgl-test PRIVATE
gtest
+ args
mbgl-core
shelf-pack-cpp
unique_resource
diff --git a/cmake/vendor.cmake b/cmake/vendor.cmake
index 7aac53e4cb..0b2deeb552 100644
--- a/cmake/vendor.cmake
+++ b/cmake/vendor.cmake
@@ -27,8 +27,8 @@ include(${CMAKE_SOURCE_DIR}/vendor/unique_resource.cmake)
include(${CMAKE_SOURCE_DIR}/vendor/variant.cmake)
include(${CMAKE_SOURCE_DIR}/vendor/vector-tile.cmake)
include(${CMAKE_SOURCE_DIR}/vendor/wagyu.cmake)
+include(${CMAKE_SOURCE_DIR}/vendor/args.cmake)
if(MBGL_PLATFORM STREQUAL "linux" OR MBGL_PLATFORM STREQUAL "macos")
- include(${CMAKE_SOURCE_DIR}/vendor/args.cmake)
include(${CMAKE_SOURCE_DIR}/vendor/glfw.cmake)
endif()
diff --git a/include/mbgl/gfx/backend.hpp b/include/mbgl/gfx/backend.hpp
new file mode 100644
index 0000000000..eed63dfcba
--- /dev/null
+++ b/include/mbgl/gfx/backend.hpp
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <cstdint>
+#include <cstdlib>
+#include <memory>
+
+namespace mbgl {
+namespace gfx {
+
+class Backend {
+public:
+ enum class Type : uint8_t {
+ OpenGL,
+ };
+
+ static constexpr Type DefaultType = Type::OpenGL;
+
+ static void SetType(const Type value) {
+ if (Value(value) != value) {
+ abort(); // SetType must be called prior to any GetType calls.
+ }
+ }
+
+ static Type GetType() {
+ return Value(DefaultType);
+ }
+
+ template <typename T, typename... Args>
+ static std::unique_ptr<T> Create(Args... args) {
+ return Create<Type::OpenGL, T, Args...>(std::forward<Args>(args)...);
+ }
+
+private:
+ template <Type, typename T, typename... Args>
+ static std::unique_ptr<T> Create(Args...);
+
+ static Type Value(Type value) {
+ static const Type type = value;
+ return type;
+ }
+};
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/include/mbgl/gfx/renderer_backend.hpp b/include/mbgl/gfx/renderer_backend.hpp
index 29f6b43a8f..aa76d7e502 100644
--- a/include/mbgl/gfx/renderer_backend.hpp
+++ b/include/mbgl/gfx/renderer_backend.hpp
@@ -30,6 +30,11 @@ public:
// Returns the device's context.
Context& getContext();
+ template <typename T>
+ T& getContext() {
+ return static_cast<T&>(getContext());
+ }
+
bool contextIsShared() const {
return contextMode == ContextMode::Shared;
}
diff --git a/include/mbgl/gl/renderer_backend.hpp b/include/mbgl/gl/renderer_backend.hpp
index ba87e4ce4f..cfa28ddaeb 100644
--- a/include/mbgl/gl/renderer_backend.hpp
+++ b/include/mbgl/gl/renderer_backend.hpp
@@ -17,9 +17,6 @@ public:
RendererBackend(gfx::ContextMode);
~RendererBackend() override;
- // Returns the backend's context which manages OpenGL state.
- Context& getGLContext();
-
// Called prior to rendering to update the internally assumed OpenGL state.
virtual void updateAssumedState() = 0;
diff --git a/platform/android/src/android_renderer_backend.cpp b/platform/android/src/android_renderer_backend.cpp
index 3fba0b83da..e2d0648385 100755
--- a/platform/android/src/android_renderer_backend.cpp
+++ b/platform/android/src/android_renderer_backend.cpp
@@ -59,7 +59,7 @@ void AndroidRendererBackend::updateAssumedState() {
void AndroidRendererBackend::markContextLost() {
if (context) {
- getGLContext().setCleanupOnDestruction(false);
+ getContext<gl::Context>().setCleanupOnDestruction(false);
}
}
diff --git a/platform/default/include/mbgl/gfx/headless_backend.hpp b/platform/default/include/mbgl/gfx/headless_backend.hpp
index de9283dcdf..325422323a 100644
--- a/platform/default/include/mbgl/gfx/headless_backend.hpp
+++ b/platform/default/include/mbgl/gfx/headless_backend.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/gfx/renderable.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/util/image.hpp>
@@ -15,8 +16,12 @@ namespace gfx {
class HeadlessBackend : public gfx::Renderable {
public:
// Factory.
- static std::unique_ptr<HeadlessBackend> make(Size = { 256, 256 }, gfx::ContextMode = gfx::ContextMode::Unique);
-
+ static std::unique_ptr<HeadlessBackend>
+ Create(const Size size = { 256, 256 },
+ const gfx::ContextMode contextMode = gfx::ContextMode::Unique) {
+ return Backend::Create<HeadlessBackend, Size, gfx::ContextMode>(size, contextMode);
+ }
+
virtual PremultipliedImage readStillImage() = 0;
virtual RendererBackend* getRendererBackend() = 0;
void setSize(Size);
diff --git a/platform/default/src/mbgl/gfx/headless_frontend.cpp b/platform/default/src/mbgl/gfx/headless_frontend.cpp
index 025abdd87a..0e97c40e49 100644
--- a/platform/default/src/mbgl/gfx/headless_frontend.cpp
+++ b/platform/default/src/mbgl/gfx/headless_frontend.cpp
@@ -23,9 +23,9 @@ HeadlessFrontend::HeadlessFrontend(Size size_,
const gfx::ContextMode contextMode,
const optional<std::string> localFontFamily)
: size(size_),
- pixelRatio(pixelRatio_),
- backend(gfx::HeadlessBackend::make( { static_cast<uint32_t>(size.width * pixelRatio),
- static_cast<uint32_t>(size.height * pixelRatio) }, contextMode)),
+ pixelRatio(pixelRatio_),
+ backend(gfx::HeadlessBackend::Create({ static_cast<uint32_t>(size.width * pixelRatio),
+ static_cast<uint32_t>(size.height * pixelRatio) }, contextMode)),
asyncInvalidate([this] {
if (renderer && updateParameters) {
gfx::BackendScope guard { *getBackend() };
diff --git a/platform/default/src/mbgl/gl/headless_backend.cpp b/platform/default/src/mbgl/gl/headless_backend.cpp
index c81952fadc..732e4babae 100644
--- a/platform/default/src/mbgl/gl/headless_backend.cpp
+++ b/platform/default/src/mbgl/gl/headless_backend.cpp
@@ -79,20 +79,22 @@ void HeadlessBackend::updateAssumedState() {
PremultipliedImage HeadlessBackend::readStillImage() {
return static_cast<gl::Context&>(getContext()).readFramebuffer<PremultipliedImage>(size);
}
-
+
RendererBackend* HeadlessBackend::getRendererBackend() {
return this;
}
} // namespace gl
-#ifndef OVERRIDE_HEADLESS_BACKEND_FACTORY
-// Default factory implementation.
-std::unique_ptr<gfx::HeadlessBackend> gfx::HeadlessBackend::make(Size size, gfx::ContextMode contextMode) {
+namespace gfx {
+
+template <>
+std::unique_ptr<gfx::HeadlessBackend>
+Backend::Create<gfx::Backend::Type::OpenGL>(const Size size, const gfx::ContextMode contextMode) {
return std::make_unique<gl::HeadlessBackend>(size, contextMode);
}
-#endif
+} // namespace gfx
} // namespace mbgl
diff --git a/platform/glfw/glfw_backend.hpp b/platform/glfw/glfw_backend.hpp
index 1a2c89ac7a..867e60d79e 100644
--- a/platform/glfw/glfw_backend.hpp
+++ b/platform/glfw/glfw_backend.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/size.hpp>
+#include <mbgl/gfx/backend.hpp>
namespace mbgl {
namespace gfx {
@@ -8,6 +9,8 @@ class RendererBackend;
} // namespace gfx
} // namespace mbgl
+struct GLFWwindow;
+
class GLFWBackend {
public:
explicit GLFWBackend() = default;
@@ -15,6 +18,10 @@ public:
GLFWBackend& operator=(const GLFWBackend&) = delete;
virtual ~GLFWBackend() = default;
+ static std::unique_ptr<GLFWBackend> Create(GLFWwindow* window, bool capFrameRate) {
+ return mbgl::gfx::Backend::Create<GLFWBackend, GLFWwindow*, bool>(window, capFrameRate);
+ }
+
virtual mbgl::gfx::RendererBackend& getRendererBackend() = 0;
virtual mbgl::Size getSize() const = 0;
virtual void setSize(mbgl::Size) = 0;
diff --git a/platform/glfw/glfw_gl_backend.cpp b/platform/glfw/glfw_gl_backend.cpp
index 4d9d87dd72..d0975fc08f 100644
--- a/platform/glfw/glfw_gl_backend.cpp
+++ b/platform/glfw/glfw_gl_backend.cpp
@@ -72,3 +72,15 @@ void GLFWGLBackend::setSize(const mbgl::Size newSize) {
void GLFWGLBackend::swap() {
glfwSwapBuffers(window);
}
+
+namespace mbgl {
+namespace gfx {
+
+template <>
+std::unique_ptr<GLFWBackend>
+Backend::Create<mbgl::gfx::Backend::Type::OpenGL>(GLFWwindow* window, bool capFrameRate) {
+ return std::make_unique<GLFWGLBackend>(window, capFrameRate);
+}
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 91e2345bb6..82519e6ac2 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -1,5 +1,5 @@
#include "glfw_view.hpp"
-#include "glfw_gl_backend.hpp"
+#include "glfw_backend.hpp"
#include "glfw_renderer_frontend.hpp"
#include "ny_route.hpp"
@@ -17,6 +17,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/renderer/renderer.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
@@ -76,6 +77,10 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
+ if (mbgl::gfx::Backend::GetType() != mbgl::gfx::Backend::Type::OpenGL) {
+ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
+ }
+
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
@@ -100,7 +105,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
glfwGetWindowSize(window, &width, &height);
- backend = std::make_unique<GLFWGLBackend>(window, benchmark);
+ backend = GLFWBackend::Create(window, benchmark);
pixelRatio = static_cast<float>(backend->getSize().width) / width;
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index 1f27bb4421..3322932dde 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -17,7 +17,7 @@ class RendererBackend;
class GLFWView : public mbgl::MapObserver {
public:
- GLFWView(bool fullscreen = false, bool benchmark = false);
+ GLFWView(bool fullscreen, bool benchmark);
~GLFWView() override;
float getPixelRatio() const;
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 04cff3962a..a5001d1204 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -2,6 +2,7 @@
#include "glfw_renderer_frontend.hpp"
#include "settings_json.hpp"
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
@@ -42,6 +43,7 @@ int main(int argc, char *argv[]) {
args::Flag benchmarkFlag(argumentParser, "benchmark", "Toggle benchmark", {'b', "benchmark"});
args::Flag offlineFlag(argumentParser, "offline", "Toggle offline", {'o', "offline"});
+ args::ValueFlag<std::string> backendValue(argumentParser, "Backend", "Rendering backend", {"backend"});
args::ValueFlag<std::string> styleValue(argumentParser, "URL", "Map stylesheet", {'s', "style"});
args::ValueFlag<std::string> cacheDBValue(argumentParser, "file", "Cache database file name", {'c', "cache"});
args::ValueFlag<double> lonValue(argumentParser, "degrees", "Longitude", {'x', "lon"});
diff --git a/platform/node/src/node_mapbox_gl_native.cpp b/platform/node/src/node_mapbox_gl_native.cpp
index 96e96e4298..9b4437b0aa 100644
--- a/platform/node/src/node_mapbox_gl_native.cpp
+++ b/platform/node/src/node_mapbox_gl_native.cpp
@@ -6,12 +6,23 @@
#pragma GCC diagnostic pop
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/gfx/backend.hpp>
#include "node_map.hpp"
#include "node_logging.hpp"
#include "node_request.hpp"
#include "node_expression.hpp"
+
+void SetBackendType(const Nan::FunctionCallbackInfo<v8::Value>& info) {
+ if (info.Length() < 1 || info[0]->IsUndefined()) {
+ return Nan::ThrowTypeError("Requires a render backend name");
+ }
+
+ const std::string backendName { *Nan::Utf8String(info[0]) };
+ (void)backendName;
+}
+
void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module) {
// This has the effect of:
// a) Ensuring that the static local variable is initialized before any thread contention.
@@ -19,6 +30,8 @@ void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module)
static mbgl::util::RunLoop nodeRunLoop;
nodeRunLoop.stop();
+ Nan::SetMethod(target, "setBackendType", SetBackendType);
+
node_mbgl::NodeMap::Init(target);
node_mbgl::NodeRequest::Init();
node_mbgl::NodeExpression::Init(target);
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index 3fe6cafaf6..cb0c945f3c 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -178,8 +178,8 @@ constexpr const uint8_t ShaderSource<${ShaderName}Program>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<${ShaderName}Program>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<${ShaderName}Program>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<${ShaderName}Program>>(programParameters);
}
diff --git a/src/core-files.json b/src/core-files.json
index 05870661db..eb581f7959 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -321,6 +321,7 @@
"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/gfx/backend.hpp": "include/mbgl/gfx/backend.hpp",
"mbgl/gfx/backend_scope.hpp": "include/mbgl/gfx/backend_scope.hpp",
"mbgl/gfx/renderable.hpp": "include/mbgl/gfx/renderable.hpp",
"mbgl/gfx/renderer_backend.hpp": "include/mbgl/gfx/renderer_backend.hpp",
@@ -513,7 +514,6 @@
"mbgl/gfx/color_mode.hpp": "src/mbgl/gfx/color_mode.hpp",
"mbgl/gfx/command_encoder.hpp": "src/mbgl/gfx/command_encoder.hpp",
"mbgl/gfx/context.hpp": "src/mbgl/gfx/context.hpp",
- "mbgl/gfx/context_impl.hpp": "src/mbgl/gfx/context_impl.hpp",
"mbgl/gfx/cull_face_mode.hpp": "src/mbgl/gfx/cull_face_mode.hpp",
"mbgl/gfx/debug_group.hpp": "src/mbgl/gfx/debug_group.hpp",
"mbgl/gfx/depth_mode.hpp": "src/mbgl/gfx/depth_mode.hpp",
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp
index 118df30a26..53cd318642 100644
--- a/src/mbgl/gfx/context.hpp
+++ b/src/mbgl/gfx/context.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/renderbuffer.hpp>
#include <mbgl/gfx/command_encoder.hpp>
#include <mbgl/gfx/draw_scope.hpp>
@@ -17,12 +18,11 @@ class OffscreenTexture;
class Context {
protected:
- Context(ContextType type_, uint32_t maximumVertexBindingCount_)
- : backend(type_), maximumVertexBindingCount(maximumVertexBindingCount_) {
+ Context(uint32_t maximumVertexBindingCount_)
+ : maximumVertexBindingCount(maximumVertexBindingCount_) {
}
public:
- const ContextType backend;
static constexpr const uint32_t minimumRequiredVertexBindingCount = 8;
const uint32_t maximumVertexBindingCount;
bool supportsHalfFloatTextures = false;
@@ -80,11 +80,9 @@ protected:
public:
template <typename Name>
- std::unique_ptr<Program<Name>> createProgram(const ProgramParameters&);
-
-private:
- template <typename Backend, typename Name>
- std::unique_ptr<Program<Name>> createProgram(const ProgramParameters&);
+ std::unique_ptr<Program<Name>> createProgram(const ProgramParameters& programParameters) {
+ return Backend::Create<Program<Name>, const ProgramParameters&>(programParameters);
+ }
public:
virtual std::unique_ptr<CommandEncoder> createCommandEncoder() = 0;
diff --git a/src/mbgl/gfx/context_impl.hpp b/src/mbgl/gfx/context_impl.hpp
deleted file mode 100644
index 0145535bb3..0000000000
--- a/src/mbgl/gfx/context_impl.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <mbgl/gfx/context.hpp>
-
-namespace mbgl {
-
-namespace gl {
-class Context;
-} // namespace gl
-
-namespace gfx {
-
-template <typename Name>
-std::unique_ptr<Program<Name>> Context::createProgram(const ProgramParameters& programParameters) {
- if (backend == ContextType::OpenGL) {
- return createProgram<gl::Context, Name>(programParameters);
- }
- assert(false);
- return nullptr;
-}
-
-} // namespace gfx
-} // namespace mbgl
diff --git a/src/mbgl/gfx/types.hpp b/src/mbgl/gfx/types.hpp
index 24209c5cc5..cafb2f3f84 100644
--- a/src/mbgl/gfx/types.hpp
+++ b/src/mbgl/gfx/types.hpp
@@ -5,10 +5,6 @@
namespace mbgl {
namespace gfx {
-enum class ContextType : uint8_t {
- OpenGL,
-};
-
enum class PrimitiveType : uint8_t {
Point,
Line,
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 436e1f6a61..626e1f4b66 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -50,7 +50,7 @@ static_assert(underlying_type(UniformDataType::Sampler2D) == GL_SAMPLER_2D, "Ope
static_assert(underlying_type(UniformDataType::SamplerCube) == GL_SAMPLER_CUBE, "OpenGL type mismatch");
Context::Context(RendererBackend& backend_)
- : gfx::Context(gfx::ContextType::OpenGL, [] {
+ : gfx::Context([] {
GLint value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value));
return value;
diff --git a/src/mbgl/gl/renderer_backend.cpp b/src/mbgl/gl/renderer_backend.cpp
index 9da6ceb589..fe0ca4b5b2 100644
--- a/src/mbgl/gl/renderer_backend.cpp
+++ b/src/mbgl/gl/renderer_backend.cpp
@@ -21,50 +21,46 @@ std::unique_ptr<gfx::Context> RendererBackend::createContext() {
return std::move(result);
}
-gl::Context& RendererBackend::getGLContext() {
- return static_cast<gl::Context&>(getContext());
-}
-
PremultipliedImage RendererBackend::readFramebuffer(const Size& size) {
- return getGLContext().readFramebuffer<PremultipliedImage>(size);
+ return getContext<gl::Context>().readFramebuffer<PremultipliedImage>(size);
}
void RendererBackend::assumeFramebufferBinding(const gl::FramebufferID fbo) {
- getGLContext().bindFramebuffer.setCurrentValue(fbo);
+ getContext<gl::Context>().bindFramebuffer.setCurrentValue(fbo);
if (fbo != ImplicitFramebufferBinding) {
- assert(gl::value::BindFramebuffer::Get() == getGLContext().bindFramebuffer.getCurrentValue());
+ assert(gl::value::BindFramebuffer::Get() == getContext<gl::Context>().bindFramebuffer.getCurrentValue());
}
}
void RendererBackend::assumeViewport(int32_t x, int32_t y, const Size& size) {
- getGLContext().viewport.setCurrentValue({ x, y, size });
- assert(gl::value::Viewport::Get() == getGLContext().viewport.getCurrentValue());
+ getContext<gl::Context>().viewport.setCurrentValue({ x, y, size });
+ assert(gl::value::Viewport::Get() == getContext<gl::Context>().viewport.getCurrentValue());
}
void RendererBackend::assumeScissorTest(bool enabled) {
- getGLContext().scissorTest.setCurrentValue(enabled);
- assert(gl::value::ScissorTest::Get() == getGLContext().scissorTest.getCurrentValue());
+ getContext<gl::Context>().scissorTest.setCurrentValue(enabled);
+ assert(gl::value::ScissorTest::Get() == getContext<gl::Context>().scissorTest.getCurrentValue());
}
bool RendererBackend::implicitFramebufferBound() {
- return getGLContext().bindFramebuffer.getCurrentValue() == ImplicitFramebufferBinding;
+ return getContext<gl::Context>().bindFramebuffer.getCurrentValue() == ImplicitFramebufferBinding;
}
void RendererBackend::setFramebufferBinding(const gl::FramebufferID fbo) {
- getGLContext().bindFramebuffer = fbo;
+ getContext<gl::Context>().bindFramebuffer = fbo;
if (fbo != ImplicitFramebufferBinding) {
- assert(gl::value::BindFramebuffer::Get() == getGLContext().bindFramebuffer.getCurrentValue());
+ assert(gl::value::BindFramebuffer::Get() == getContext<gl::Context>().bindFramebuffer.getCurrentValue());
}
}
void RendererBackend::setViewport(int32_t x, int32_t y, const Size& size) {
- getGLContext().viewport = { x, y, size };
- assert(gl::value::Viewport::Get() == getGLContext().viewport.getCurrentValue());
+ getContext<gl::Context>().viewport = { x, y, size };
+ assert(gl::value::Viewport::Get() == getContext<gl::Context>().viewport.getCurrentValue());
}
void RendererBackend::setScissorTest(bool enabled) {
- getGLContext().scissorTest = enabled;
- assert(gl::value::ScissorTest::Get() == getGLContext().scissorTest.getCurrentValue());
+ getContext<gl::Context>().scissorTest = enabled;
+ assert(gl::value::ScissorTest::Get() == getContext<gl::Context>().scissorTest.getCurrentValue());
}
RendererBackend::~RendererBackend() = default;
diff --git a/src/mbgl/programs/background_program.cpp b/src/mbgl/programs/background_program.cpp
index 772d481578..edabce8ee3 100644
--- a/src/mbgl/programs/background_program.cpp
+++ b/src/mbgl/programs/background_program.cpp
@@ -1,5 +1,4 @@
#include <mbgl/programs/background_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
#include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
#include <mbgl/tile/tile_id.hpp>
@@ -7,9 +6,6 @@
namespace mbgl {
-template std::unique_ptr<gfx::Program<BackgroundProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<BackgroundPatternProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
using namespace style;
static_assert(sizeof(BackgroundLayoutVertex) == 4, "expected BackgroundLayoutVertex size");
diff --git a/src/mbgl/programs/circle_program.cpp b/src/mbgl/programs/circle_program.cpp
index 577410d94e..99b47dd5c0 100644
--- a/src/mbgl/programs/circle_program.cpp
+++ b/src/mbgl/programs/circle_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/circle_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<CircleProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(CircleLayoutVertex) == 4, "expected CircleLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/clipping_mask_program.cpp b/src/mbgl/programs/clipping_mask_program.cpp
index 9b1a9ef4fc..aca7605037 100644
--- a/src/mbgl/programs/clipping_mask_program.cpp
+++ b/src/mbgl/programs/clipping_mask_program.cpp
@@ -1,8 +1,5 @@
#include <mbgl/programs/clipping_mask_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<ClippingMaskProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
} // namespace mbgl
diff --git a/src/mbgl/programs/collision_box_program.cpp b/src/mbgl/programs/collision_box_program.cpp
index 885894526e..584013640e 100644
--- a/src/mbgl/programs/collision_box_program.cpp
+++ b/src/mbgl/programs/collision_box_program.cpp
@@ -1,11 +1,7 @@
#include <mbgl/programs/collision_box_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<CollisionBoxProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<CollisionCircleProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(CollisionBoxProgram::LayoutVertex) == 24, "expected CollisionBoxVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/debug_program.cpp b/src/mbgl/programs/debug_program.cpp
index 9b8df789e4..3396e74872 100644
--- a/src/mbgl/programs/debug_program.cpp
+++ b/src/mbgl/programs/debug_program.cpp
@@ -1,8 +1,5 @@
#include <mbgl/programs/debug_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<DebugProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
} // namespace mbgl
diff --git a/src/mbgl/programs/fill_extrusion_program.cpp b/src/mbgl/programs/fill_extrusion_program.cpp
index 09da6931b6..d22e911589 100644
--- a/src/mbgl/programs/fill_extrusion_program.cpp
+++ b/src/mbgl/programs/fill_extrusion_program.cpp
@@ -1,5 +1,4 @@
#include <mbgl/programs/fill_extrusion_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
#include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
#include <mbgl/tile/tile_id.hpp>
@@ -8,9 +7,6 @@
namespace mbgl {
-template std::unique_ptr<gfx::Program<FillExtrusionProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<FillExtrusionPatternProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
using namespace style;
static_assert(sizeof(FillExtrusionLayoutVertex) == 12, "expected FillExtrusionLayoutVertex size");
diff --git a/src/mbgl/programs/fill_program.cpp b/src/mbgl/programs/fill_program.cpp
index 703d61399f..f314fcc597 100644
--- a/src/mbgl/programs/fill_program.cpp
+++ b/src/mbgl/programs/fill_program.cpp
@@ -1,5 +1,4 @@
#include <mbgl/programs/fill_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
#include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
#include <mbgl/tile/tile_id.hpp>
@@ -7,11 +6,6 @@
namespace mbgl {
-template std::unique_ptr<gfx::Program<FillProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<FillPatternProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<FillOutlineProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<FillOutlinePatternProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
using namespace style;
static_assert(sizeof(FillLayoutVertex) == 4, "expected FillLayoutVertex size");
diff --git a/src/mbgl/programs/gl/background.cpp b/src/mbgl/programs/gl/background.cpp
index 78074d670f..f3d2cdfd90 100644
--- a/src/mbgl/programs/gl/background.cpp
+++ b/src/mbgl/programs/gl/background.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<BackgroundProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<BackgroundProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<BackgroundProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<BackgroundProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/background_pattern.cpp b/src/mbgl/programs/gl/background_pattern.cpp
index 04111c7abd..482814cbda 100644
--- a/src/mbgl/programs/gl/background_pattern.cpp
+++ b/src/mbgl/programs/gl/background_pattern.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<BackgroundPatternProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<BackgroundPatternProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<BackgroundPatternProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<BackgroundPatternProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/circle.cpp b/src/mbgl/programs/gl/circle.cpp
index 5cf7eef13c..bd86c0385a 100644
--- a/src/mbgl/programs/gl/circle.cpp
+++ b/src/mbgl/programs/gl/circle.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<CircleProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<CircleProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<CircleProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<CircleProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/clipping_mask.cpp b/src/mbgl/programs/gl/clipping_mask.cpp
index 1b6c7b51c5..2c53bc6070 100644
--- a/src/mbgl/programs/gl/clipping_mask.cpp
+++ b/src/mbgl/programs/gl/clipping_mask.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<ClippingMaskProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<ClippingMaskProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<ClippingMaskProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<ClippingMaskProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/collision_box.cpp b/src/mbgl/programs/gl/collision_box.cpp
index 89c4fe81ae..a3ad030f5c 100644
--- a/src/mbgl/programs/gl/collision_box.cpp
+++ b/src/mbgl/programs/gl/collision_box.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<CollisionBoxProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<CollisionBoxProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<CollisionBoxProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<CollisionBoxProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/collision_circle.cpp b/src/mbgl/programs/gl/collision_circle.cpp
index 96f5d68ce5..3878122f4b 100644
--- a/src/mbgl/programs/gl/collision_circle.cpp
+++ b/src/mbgl/programs/gl/collision_circle.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<CollisionCircleProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<CollisionCircleProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<CollisionCircleProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<CollisionCircleProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/debug.cpp b/src/mbgl/programs/gl/debug.cpp
index 2e5db36dac..9705fc4801 100644
--- a/src/mbgl/programs/gl/debug.cpp
+++ b/src/mbgl/programs/gl/debug.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<DebugProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<DebugProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<DebugProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<DebugProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill.cpp b/src/mbgl/programs/gl/fill.cpp
index 7a281c24ba..77c839850b 100644
--- a/src/mbgl/programs/gl/fill.cpp
+++ b/src/mbgl/programs/gl/fill.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill_extrusion.cpp b/src/mbgl/programs/gl/fill_extrusion.cpp
index d90988070a..87ef4858fc 100644
--- a/src/mbgl/programs/gl/fill_extrusion.cpp
+++ b/src/mbgl/programs/gl/fill_extrusion.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillExtrusionProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillExtrusionProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillExtrusionProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillExtrusionProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill_extrusion_pattern.cpp b/src/mbgl/programs/gl/fill_extrusion_pattern.cpp
index a6292b9fe1..1d330220e4 100644
--- a/src/mbgl/programs/gl/fill_extrusion_pattern.cpp
+++ b/src/mbgl/programs/gl/fill_extrusion_pattern.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillExtrusionPatternProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillExtrusionPatternProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillExtrusionPatternProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillExtrusionPatternProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill_outline.cpp b/src/mbgl/programs/gl/fill_outline.cpp
index 82d56710a7..efef689f91 100644
--- a/src/mbgl/programs/gl/fill_outline.cpp
+++ b/src/mbgl/programs/gl/fill_outline.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillOutlineProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillOutlineProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillOutlineProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillOutlineProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill_outline_pattern.cpp b/src/mbgl/programs/gl/fill_outline_pattern.cpp
index 7709991353..d526d5801d 100644
--- a/src/mbgl/programs/gl/fill_outline_pattern.cpp
+++ b/src/mbgl/programs/gl/fill_outline_pattern.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillOutlinePatternProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillOutlinePatternProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillOutlinePatternProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillOutlinePatternProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/fill_pattern.cpp b/src/mbgl/programs/gl/fill_pattern.cpp
index ff4f2045ac..0f62206f99 100644
--- a/src/mbgl/programs/gl/fill_pattern.cpp
+++ b/src/mbgl/programs/gl/fill_pattern.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<FillPatternProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<FillPatternProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<FillPatternProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<FillPatternProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/heatmap.cpp b/src/mbgl/programs/gl/heatmap.cpp
index 7685b568cb..41f804a37b 100644
--- a/src/mbgl/programs/gl/heatmap.cpp
+++ b/src/mbgl/programs/gl/heatmap.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<HeatmapProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<HeatmapProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<HeatmapProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<HeatmapProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/heatmap_texture.cpp b/src/mbgl/programs/gl/heatmap_texture.cpp
index 60ef68597d..a6583bfbb7 100644
--- a/src/mbgl/programs/gl/heatmap_texture.cpp
+++ b/src/mbgl/programs/gl/heatmap_texture.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<HeatmapTextureProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<HeatmapTextureProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<HeatmapTextureProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<HeatmapTextureProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/hillshade.cpp b/src/mbgl/programs/gl/hillshade.cpp
index f0579aaf8c..b0c2c95aa8 100644
--- a/src/mbgl/programs/gl/hillshade.cpp
+++ b/src/mbgl/programs/gl/hillshade.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<HillshadeProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<HillshadeProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<HillshadeProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<HillshadeProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/hillshade_prepare.cpp b/src/mbgl/programs/gl/hillshade_prepare.cpp
index f9cd84ca73..1aef64293b 100644
--- a/src/mbgl/programs/gl/hillshade_prepare.cpp
+++ b/src/mbgl/programs/gl/hillshade_prepare.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<HillshadePrepareProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<HillshadePrepareProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<HillshadePrepareProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<HillshadePrepareProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/line.cpp b/src/mbgl/programs/gl/line.cpp
index 9eea81f69b..58f626bf19 100644
--- a/src/mbgl/programs/gl/line.cpp
+++ b/src/mbgl/programs/gl/line.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<LineProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<LineProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<LineProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<LineProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/line_gradient.cpp b/src/mbgl/programs/gl/line_gradient.cpp
index 4e7ee93b92..c555b09932 100644
--- a/src/mbgl/programs/gl/line_gradient.cpp
+++ b/src/mbgl/programs/gl/line_gradient.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<LineGradientProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<LineGradientProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<LineGradientProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<LineGradientProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/line_pattern.cpp b/src/mbgl/programs/gl/line_pattern.cpp
index 24406abf3b..17ec324c11 100644
--- a/src/mbgl/programs/gl/line_pattern.cpp
+++ b/src/mbgl/programs/gl/line_pattern.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<LinePatternProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<LinePatternProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<LinePatternProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<LinePatternProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/line_sdf.cpp b/src/mbgl/programs/gl/line_sdf.cpp
index aa72823ae7..2d0a5faacd 100644
--- a/src/mbgl/programs/gl/line_sdf.cpp
+++ b/src/mbgl/programs/gl/line_sdf.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<LineSDFProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<LineSDFProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<LineSDFProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<LineSDFProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/raster.cpp b/src/mbgl/programs/gl/raster.cpp
index 98cfade1f5..f6ae3b5bc5 100644
--- a/src/mbgl/programs/gl/raster.cpp
+++ b/src/mbgl/programs/gl/raster.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<RasterProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<RasterProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<RasterProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<RasterProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/symbol_icon.cpp b/src/mbgl/programs/gl/symbol_icon.cpp
index cb896b4160..834bfc16d2 100644
--- a/src/mbgl/programs/gl/symbol_icon.cpp
+++ b/src/mbgl/programs/gl/symbol_icon.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<SymbolIconProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<SymbolIconProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<SymbolIconProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<SymbolIconProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/symbol_sdf_icon.cpp b/src/mbgl/programs/gl/symbol_sdf_icon.cpp
index a25754ffad..2daa1e860d 100644
--- a/src/mbgl/programs/gl/symbol_sdf_icon.cpp
+++ b/src/mbgl/programs/gl/symbol_sdf_icon.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<SymbolSDFIconProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<SymbolSDFIconProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<SymbolSDFIconProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<SymbolSDFIconProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/gl/symbol_sdf_text.cpp b/src/mbgl/programs/gl/symbol_sdf_text.cpp
index 9aec77043b..5750e7730c 100644
--- a/src/mbgl/programs/gl/symbol_sdf_text.cpp
+++ b/src/mbgl/programs/gl/symbol_sdf_text.cpp
@@ -29,8 +29,8 @@ constexpr const uint8_t ShaderSource<SymbolSDFTextProgram>::hash[8];
namespace gfx {
template <>
-std::unique_ptr<Program<SymbolSDFTextProgram>>
-Context::createProgram<gl::Context>(const ProgramParameters& programParameters) {
+std::unique_ptr<gfx::Program<SymbolSDFTextProgram>>
+Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programParameters) {
return std::make_unique<gl::Program<SymbolSDFTextProgram>>(programParameters);
}
diff --git a/src/mbgl/programs/heatmap_program.cpp b/src/mbgl/programs/heatmap_program.cpp
index 32c30ea313..67f84fbd52 100644
--- a/src/mbgl/programs/heatmap_program.cpp
+++ b/src/mbgl/programs/heatmap_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/heatmap_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<HeatmapProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(HeatmapLayoutVertex) == 4, "expected HeatmapLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/heatmap_texture_program.cpp b/src/mbgl/programs/heatmap_texture_program.cpp
index 04c5ff56a7..3b0e24eab8 100644
--- a/src/mbgl/programs/heatmap_texture_program.cpp
+++ b/src/mbgl/programs/heatmap_texture_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/heatmap_texture_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<HeatmapTextureProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(HeatmapTextureLayoutVertex) == 4, "expected HeatmapTextureLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/hillshade_prepare_program.cpp b/src/mbgl/programs/hillshade_prepare_program.cpp
index 5bbac9eaec..0c0446d3f5 100644
--- a/src/mbgl/programs/hillshade_prepare_program.cpp
+++ b/src/mbgl/programs/hillshade_prepare_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/hillshade_prepare_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<HillshadePrepareProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(HillshadePrepareLayoutVertex) == 8, "expected HillshadeLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/hillshade_program.cpp b/src/mbgl/programs/hillshade_program.cpp
index 31673afcd4..f054ad4b74 100644
--- a/src/mbgl/programs/hillshade_program.cpp
+++ b/src/mbgl/programs/hillshade_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/hillshade_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<HillshadeProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(HillshadeLayoutVertex) == 8, "expected HillshadeLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp
index cab1e7e6fd..40b4617c77 100644
--- a/src/mbgl/programs/line_program.cpp
+++ b/src/mbgl/programs/line_program.cpp
@@ -1,5 +1,4 @@
#include <mbgl/programs/line_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
#include <mbgl/style/layers/line_layer_properties.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/image_atlas.hpp>
@@ -9,11 +8,6 @@
namespace mbgl {
-template std::unique_ptr<gfx::Program<LineProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<LinePatternProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<LineGradientProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<LineSDFProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
using namespace style;
static_assert(sizeof(LineLayoutVertex) == 12, "expected LineLayoutVertex size");
diff --git a/src/mbgl/programs/raster_program.cpp b/src/mbgl/programs/raster_program.cpp
index f3b1052284..6906903e6b 100644
--- a/src/mbgl/programs/raster_program.cpp
+++ b/src/mbgl/programs/raster_program.cpp
@@ -1,10 +1,7 @@
#include <mbgl/programs/raster_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
namespace mbgl {
-template std::unique_ptr<gfx::Program<RasterProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
static_assert(sizeof(RasterLayoutVertex) == 8, "expected RasterLayoutVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp
index 8a7dccd55e..3633bd7c2a 100644
--- a/src/mbgl/programs/symbol_program.cpp
+++ b/src/mbgl/programs/symbol_program.cpp
@@ -1,5 +1,4 @@
#include <mbgl/programs/symbol_program.hpp>
-#include <mbgl/gfx/context_impl.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
@@ -10,10 +9,6 @@
namespace mbgl {
-template std::unique_ptr<gfx::Program<SymbolIconProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<SymbolSDFTextProgram>> gfx::Context::createProgram(const ProgramParameters&);
-template std::unique_ptr<gfx::Program<SymbolSDFIconProgram>> gfx::Context::createProgram(const ProgramParameters&);
-
using namespace style;
static_assert(sizeof(SymbolLayoutVertex) == 16, "expected SymbolLayoutVertex size");
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index 5afc4152ba..175d053f93 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -87,6 +87,10 @@ public:
};
TEST(CustomLayer, Basic) {
+ if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
+ return;
+ }
+
util::RunLoop loop;
HeadlessFrontend frontend { 1 };
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index 54b0c01d95..4b6bad6f65 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -85,6 +85,10 @@ struct Buffer {
};
TEST(GLContextMode, Shared) {
+ if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
+ return;
+ }
+
util::RunLoop loop;
HeadlessFrontend frontend { 1, {}, gfx::ContextMode::Shared };
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 42edaedf22..fd831a05b7 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -610,6 +610,10 @@ TEST(Map, AddLayer) {
}
TEST(Map, WithoutVAOExtension) {
+ if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
+ return;
+ }
+
MapTest<DefaultFileSource> test { ":memory:", "test/fixtures/api/assets" };
gfx::BackendScope scope { *test.frontend.getBackend() };
diff --git a/test/src/mbgl/test/test.cpp b/test/src/mbgl/test/test.cpp
index 1c77aae2a1..30df01c488 100644
--- a/test/src/mbgl/test/test.cpp
+++ b/test/src/mbgl/test/test.cpp
@@ -1,9 +1,12 @@
#include <mbgl/actor/scheduler.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/test.hpp>
#include <mbgl/test/util.hpp>
#include <gtest/gtest.h>
+#include <args.hxx>
+
namespace mbgl {
int runTests(int argc, char *argv[]) {
@@ -12,6 +15,12 @@ int runTests(int argc, char *argv[]) {
#endif
testing::InitGoogleTest(&argc, argv);
+
+ args::ArgumentParser argumentParser("Unit tests");
+ args::ValueFlag<std::string> backendValue(argumentParser, "Backend", "Rendering backend", {"backend"});
+
+ argumentParser.ParseCLI(argc, argv);
+
return RUN_ALL_TESTS();
}
diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp
index ef10984364..ae56b347a4 100644
--- a/test/util/offscreen_texture.test.cpp
+++ b/test/util/offscreen_texture.test.cpp
@@ -14,6 +14,10 @@ using namespace mbgl;
using namespace mbgl::platform;
TEST(OffscreenTexture, EmptyRed) {
+ if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
+ return;
+ }
+
gl::HeadlessBackend backend({ 512, 256 });
gfx::BackendScope scope { backend };
@@ -76,6 +80,10 @@ struct Buffer {
TEST(OffscreenTexture, RenderToTexture) {
+ if (gfx::Backend::GetType() != gfx::Backend::Type::OpenGL) {
+ return;
+ }
+
gl::HeadlessBackend backend({ 512, 256 });
gfx::BackendScope scope { backend };
auto& context = static_cast<gl::Context&>(backend.getContext());