diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-04-02 14:11:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-05-28 16:11:05 +0200 |
commit | 7f9274035bad30980e03574c315904ab7a85fe83 (patch) | |
tree | 7b9cd0f2e2883d6da22611eaa68fae07bb7245b6 /platform/glfw | |
parent | 33ee7e23de24bd3c076eafef819029cf45451d23 (diff) | |
download | qtlocation-mapboxgl-7f9274035bad30980e03574c315904ab7a85fe83.tar.gz |
[core] refactor program object creation
Diffstat (limited to 'platform/glfw')
-rw-r--r-- | platform/glfw/glfw_backend.hpp | 7 | ||||
-rw-r--r-- | platform/glfw/glfw_gl_backend.cpp | 12 | ||||
-rw-r--r-- | platform/glfw/glfw_view.cpp | 9 | ||||
-rw-r--r-- | platform/glfw/glfw_view.hpp | 2 | ||||
-rw-r--r-- | platform/glfw/main.cpp | 2 |
5 files changed, 29 insertions, 3 deletions
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"}); |