summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-03-21 12:43:22 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-04-05 11:49:17 +0200
commit543b678982037595895a474f3a69348dc235e0fa (patch)
tree404902164dd27e409515de5fcf9a43fe81231686 /src
parent5270b2ffbd4fca75f93e7052bd928ebed3ea272a (diff)
downloadqtlocation-mapboxgl-543b678982037595895a474f3a69348dc235e0fa.tar.gz
[core] introduce CommandEncoder object
Diffstat (limited to 'src')
-rw-r--r--src/core-files.json3
-rw-r--r--src/mbgl/gfx/command_encoder.hpp17
-rw-r--r--src/mbgl/gfx/context.hpp4
-rw-r--r--src/mbgl/gl/command_encoder.cpp12
-rw-r--r--src/mbgl/gl/command_encoder.hpp22
-rw-r--r--src/mbgl/gl/context.cpp5
-rw-r--r--src/mbgl/gl/context.hpp2
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp1
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp19
9 files changed, 75 insertions, 10 deletions
diff --git a/src/core-files.json b/src/core-files.json
index 7ba2bd51e2..875f636dfe 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -19,6 +19,7 @@
"src/mbgl/gfx/attribute.cpp",
"src/mbgl/gl/attribute.cpp",
"src/mbgl/gl/binary_program.cpp",
+ "src/mbgl/gl/command_encoder.cpp",
"src/mbgl/gl/context.cpp",
"src/mbgl/gl/debugging.cpp",
"src/mbgl/gl/debugging_extension.cpp",
@@ -510,6 +511,7 @@
"mbgl/geometry/line_atlas.hpp": "src/mbgl/geometry/line_atlas.hpp",
"mbgl/gfx/attribute.hpp": "src/mbgl/gfx/attribute.hpp",
"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",
@@ -528,6 +530,7 @@
"mbgl/gfx/vertex_vector.hpp": "src/mbgl/gfx/vertex_vector.hpp",
"mbgl/gl/attribute.hpp": "src/mbgl/gl/attribute.hpp",
"mbgl/gl/binary_program.hpp": "src/mbgl/gl/binary_program.hpp",
+ "mbgl/gl/command_encoder.hpp": "src/mbgl/gl/command_encoder.hpp",
"mbgl/gl/context.hpp": "src/mbgl/gl/context.hpp",
"mbgl/gl/debugging.hpp": "src/mbgl/gl/debugging.hpp",
"mbgl/gl/debugging_extension.hpp": "src/mbgl/gl/debugging_extension.hpp",
diff --git a/src/mbgl/gfx/command_encoder.hpp b/src/mbgl/gfx/command_encoder.hpp
new file mode 100644
index 0000000000..3f996bb701
--- /dev/null
+++ b/src/mbgl/gfx/command_encoder.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+namespace mbgl {
+namespace gfx {
+
+class CommandEncoder {
+protected:
+ explicit CommandEncoder() = default;
+
+public:
+ virtual ~CommandEncoder() = default;
+ CommandEncoder(const CommandEncoder&) = delete;
+ CommandEncoder& operator=(const CommandEncoder&) = delete;
+};
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp
index fcce2d3070..06a59fd238 100644
--- a/src/mbgl/gfx/context.hpp
+++ b/src/mbgl/gfx/context.hpp
@@ -6,6 +6,7 @@
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/renderbuffer.hpp>
+#include <mbgl/gfx/command_encoder.hpp>
#include <mbgl/gfx/draw_scope.hpp>
#include <mbgl/gfx/program.hpp>
#include <mbgl/gfx/types.hpp>
@@ -148,6 +149,9 @@ public:
private:
template <typename Backend, typename Name>
std::unique_ptr<Program<Name>> createProgram(const ProgramParameters&);
+
+public:
+ virtual std::unique_ptr<CommandEncoder> createCommandEncoder() = 0;
};
} // namespace gfx
diff --git a/src/mbgl/gl/command_encoder.cpp b/src/mbgl/gl/command_encoder.cpp
new file mode 100644
index 0000000000..82046202bc
--- /dev/null
+++ b/src/mbgl/gl/command_encoder.cpp
@@ -0,0 +1,12 @@
+#include <mbgl/gl/command_encoder.hpp>
+#include <mbgl/gl/context.hpp>
+
+namespace mbgl {
+namespace gl {
+
+CommandEncoder::~CommandEncoder() {
+ context.performCleanup();
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/command_encoder.hpp b/src/mbgl/gl/command_encoder.hpp
new file mode 100644
index 0000000000..0cfe80f433
--- /dev/null
+++ b/src/mbgl/gl/command_encoder.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <mbgl/gfx/command_encoder.hpp>
+
+namespace mbgl {
+namespace gl {
+
+class Context;
+
+class CommandEncoder : public gfx::CommandEncoder {
+public:
+ explicit CommandEncoder(gl::Context& context_) : context(context_) {
+ }
+
+ ~CommandEncoder() override;
+
+private:
+ gl::Context& context;
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index fcaae59804..97c1cd24d7 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -6,6 +6,7 @@
#include <mbgl/gl/renderbuffer_resource.hpp>
#include <mbgl/gl/draw_scope_resource.hpp>
#include <mbgl/gl/texture.hpp>
+#include <mbgl/gl/command_encoder.hpp>
#include <mbgl/gl/debugging.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/gl/vertex_array_extension.hpp>
@@ -691,6 +692,10 @@ void Context::setColorMode(const gfx::ColorMode& color) {
colorMask = color.mask;
}
+std::unique_ptr<gfx::CommandEncoder> Context::createCommandEncoder() {
+ return std::make_unique<gl::CommandEncoder>(*this);
+}
+
void Context::draw(const gfx::DrawMode& drawMode,
std::size_t indexOffset,
std::size_t indexLength) {
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 74ea2c076e..d09bf7522e 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -214,6 +214,8 @@ private:
VertexArray createVertexArray();
bool supportsVertexArrays() const;
+ std::unique_ptr<gfx::CommandEncoder> createCommandEncoder() override;
+
friend detail::ProgramDeleter;
friend detail::ShaderDeleter;
friend detail::BufferDeleter;
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
index 25c3db2e49..2c9fac0131 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
@@ -72,7 +72,6 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
// Flag the depth buffer as no longer needing to be cleared for the remainder of this pass.
parameters.staticData.depthRenderbuffer->setShouldClear(false);
- glContext.setStencilMode(gfx::StencilMode::disabled());
glContext.clear(Color{ 0.0f, 0.0f, 0.0f, 0.0f }, depthClearValue, {});
auto draw = [&](auto& programInstance, const auto& tileBucket, auto&& uniformValues,
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index f5d72712b6..c58f4a091d 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -310,13 +310,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
backend.updateAssumedState();
- // TODO: remove cast
- gl::Context& glContext = static_cast<gl::Context&>(parameters.context);
-
- if (parameters.contextMode == GLContextMode::Shared) {
- glContext.setDirtyState();
- }
-
// Set render tiles to the render items.
for (auto& renderItem : renderItems) {
if (!renderItem.source) {
@@ -372,6 +365,15 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
}
}
+ const auto encoder = parameters.context.createCommandEncoder();
+
+ // TODO: remove cast
+ gl::Context& glContext = static_cast<gl::Context&>(parameters.context);
+
+ if (parameters.contextMode == GLContextMode::Shared) {
+ glContext.setDirtyState();
+ }
+
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{
@@ -595,8 +597,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
observer->onDidFinishRenderingMap();
}
- // Cleanup only after signaling completion
- parameters.context.performCleanup();
+ // CommandEncoder destructor submits render commands.
}
void Renderer::Impl::flush() {