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-15 11:57:43 -0700 |
commit | 179c5fe83ba4ebe593208db9ca41f409024824ef (patch) | |
tree | c54be0d8debe9d7ed3a7f4fd4be21af041b5bc88 | |
parent | da5bd4d6e3a0202cc4f9e4d3d17e159eb90acba6 (diff) | |
download | qtlocation-mapboxgl-179c5fe83ba4ebe593208db9ca41f409024824ef.tar.gz |
[core] add gfx::CommandEncoder::present()
-rw-r--r-- | include/mbgl/gl/renderable_resource.hpp | 7 | ||||
-rw-r--r-- | platform/glfw/glfw_gl_backend.cpp | 17 | ||||
-rw-r--r-- | platform/glfw/glfw_gl_backend.hpp | 4 | ||||
-rw-r--r-- | platform/glfw/glfw_view.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/gfx/command_encoder.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/command_encoder.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/gl/command_encoder.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer_impl.cpp | 4 |
8 files changed, 39 insertions, 14 deletions
diff --git a/include/mbgl/gl/renderable_resource.hpp b/include/mbgl/gl/renderable_resource.hpp index 0be0ae9c67..9585269270 100644 --- a/include/mbgl/gl/renderable_resource.hpp +++ b/include/mbgl/gl/renderable_resource.hpp @@ -2,6 +2,8 @@ #include <mbgl/gfx/renderable.hpp> +#include <cstdlib> + namespace mbgl { namespace gl { @@ -11,6 +13,11 @@ protected: public: virtual void bind() = 0; + + virtual void swap() { + // Renderable resources that require a swap function to be called explicitly + // can override this method. + } }; } // namespace gl diff --git a/platform/glfw/glfw_gl_backend.cpp b/platform/glfw/glfw_gl_backend.cpp index 2d622fc193..4d9d87dd72 100644 --- a/platform/glfw/glfw_gl_backend.cpp +++ b/platform/glfw/glfw_gl_backend.cpp @@ -15,11 +15,15 @@ public: backend.setViewport(0, 0, backend.getSize()); } + void swap() override { + backend.swap(); + } + private: GLFWGLBackend& backend; }; -GLFWGLBackend::GLFWGLBackend(GLFWwindow* window_) +GLFWGLBackend::GLFWGLBackend(GLFWwindow* window_, const bool capFrameRate) : mbgl::gl::RendererBackend(mbgl::gfx::ContextMode::Unique), mbgl::gfx::Renderable( [window_] { @@ -29,6 +33,13 @@ GLFWGLBackend::GLFWGLBackend(GLFWwindow* window_) }(), std::make_unique<GLFWGLRenderableResource>(*this)), window(window_) { + glfwMakeContextCurrent(window); + if (!capFrameRate) { + // Disables vsync on platforms that support it. + glfwSwapInterval(0); + } else { + glfwSwapInterval(1); + } } GLFWGLBackend::~GLFWGLBackend() = default; @@ -57,3 +68,7 @@ mbgl::Size GLFWGLBackend::getSize() const { void GLFWGLBackend::setSize(const mbgl::Size newSize) { size = newSize; } + +void GLFWGLBackend::swap() { + glfwSwapBuffers(window); +} diff --git a/platform/glfw/glfw_gl_backend.hpp b/platform/glfw/glfw_gl_backend.hpp index ba4f6fa788..5971bbd0c5 100644 --- a/platform/glfw/glfw_gl_backend.hpp +++ b/platform/glfw/glfw_gl_backend.hpp @@ -11,9 +11,11 @@ class GLFWGLBackend final : public GLFWBackend, public mbgl::gl::RendererBackend, public mbgl::gfx::Renderable { public: - GLFWGLBackend(GLFWwindow*); + GLFWGLBackend(GLFWwindow*, bool capFrameRate); ~GLFWGLBackend() override; + void swap(); + // GLFWRendererBackend implementation public: mbgl::gfx::RendererBackend& getRendererBackend() override { diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index cd979822c4..91e2345bb6 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -91,15 +91,6 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) } glfwSetWindowUserPointer(window, this); - glfwMakeContextCurrent(window); - if (benchmark) { - // Disables vsync on platforms that support it. - glfwSwapInterval(0); - } else { - glfwSwapInterval(1); - } - - glfwSetCursorPosCallback(window, onMouseMove); glfwSetMouseButtonCallback(window, onMouseClick); glfwSetWindowSizeCallback(window, onWindowResize); @@ -109,7 +100,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) glfwGetWindowSize(window, &width, &height); - backend = std::make_unique<GLFWGLBackend>(window); + backend = std::make_unique<GLFWGLBackend>(window, benchmark); pixelRatio = static_cast<float>(backend->getSize().width) / width; @@ -585,8 +576,6 @@ void GLFWView::run() { rendererFrontend->render(); - glfwSwapBuffers(window); - report(1000 * (glfwGetTime() - started)); if (benchmark) { invalidate(); diff --git a/src/mbgl/gfx/command_encoder.hpp b/src/mbgl/gfx/command_encoder.hpp index 145c2bef82..46ae551982 100644 --- a/src/mbgl/gfx/command_encoder.hpp +++ b/src/mbgl/gfx/command_encoder.hpp @@ -9,6 +9,7 @@ namespace gfx { class RenderPassDescriptor; class RenderPass; +class Renderable; class CommandEncoder { protected: @@ -28,6 +29,7 @@ public: } virtual std::unique_ptr<RenderPass> createRenderPass(const char* name, const RenderPassDescriptor&) = 0; + virtual void present(Renderable&) = 0; }; } // namespace gfx diff --git a/src/mbgl/gl/command_encoder.cpp b/src/mbgl/gl/command_encoder.cpp index 26d1008789..37c4479734 100644 --- a/src/mbgl/gl/command_encoder.cpp +++ b/src/mbgl/gl/command_encoder.cpp @@ -1,6 +1,7 @@ #include <mbgl/gl/command_encoder.hpp> #include <mbgl/gl/render_pass.hpp> #include <mbgl/gl/context.hpp> +#include <mbgl/gl/renderable_resource.hpp> #include <mbgl/gl/debugging_extension.hpp> #include <mbgl/platform/gl_functions.hpp> @@ -19,6 +20,10 @@ CommandEncoder::createRenderPass(const char* name, const gfx::RenderPassDescript return std::make_unique<gl::RenderPass>(*this, name, descriptor); } +void CommandEncoder::present(gfx::Renderable& renderable) { + renderable.getResource<gl::RenderableResource>().swap(); +} + void CommandEncoder::pushDebugGroup(const char* name) { (void)name; #ifndef NDEBUG diff --git a/src/mbgl/gl/command_encoder.hpp b/src/mbgl/gl/command_encoder.hpp index 8074000034..31d67d13a6 100644 --- a/src/mbgl/gl/command_encoder.hpp +++ b/src/mbgl/gl/command_encoder.hpp @@ -18,6 +18,7 @@ public: friend class RenderPass; std::unique_ptr<gfx::RenderPass> createRenderPass(const char* name, const gfx::RenderPassDescriptor&) override; + void present(gfx::Renderable&) override; private: void pushDebugGroup(const char* name) override; diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index b14a255024..52a2342454 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -493,6 +493,10 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { observer->onDidFinishRenderingMap(); } + if (updateParameters.mode == MapMode::Continuous) { + parameters.encoder->present(parameters.backend.getDefaultRenderable()); + } + // CommandEncoder destructor submits render commands. } |