[core] introduce CommandEncoder object

This commit is contained in:
Konstantin Käfer
2019-03-21 12:43:22 +01:00
parent 5270b2ffbd
commit 543b678982
9 changed files with 75 additions and 10 deletions

View File

@@ -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",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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