[core] add gfx::CommandEncoder::present()

This commit is contained in:
Konstantin Käfer
2019-04-02 14:11:37 +02:00
parent da5bd4d6e3
commit 179c5fe83b
8 changed files with 39 additions and 14 deletions

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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();