[core] add gfx::CommandEncoder::present()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user