summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-04-02 22:35:46 +0200
committerKonstantin Käfer <mail@kkaefer.com>2019-04-05 11:49:17 +0200
commitd7aaf83421261087a99d18d92eca9637c1bf72f8 (patch)
treedf938a5b6fe40c9e665e028285d28eb88e0dfea2
parentb1a2513b61761d09b3ae08904c03d28caedd09fe (diff)
downloadqtlocation-mapboxgl-d7aaf83421261087a99d18d92eca9637c1bf72f8.tar.gz
[core] introduce gfx::RenderPass
-rw-r--r--src/core-files.json3
-rw-r--r--src/mbgl/gfx/command_encoder.hpp7
-rw-r--r--src/mbgl/gfx/program.hpp2
-rw-r--r--src/mbgl/gfx/render_pass.hpp41
-rw-r--r--src/mbgl/gl/command_encoder.cpp6
-rw-r--r--src/mbgl/gl/command_encoder.hpp5
-rw-r--r--src/mbgl/gl/program.hpp1
-rw-r--r--src/mbgl/gl/render_pass.cpp28
-rw-r--r--src/mbgl/gl/render_pass.hpp31
-rw-r--r--src/mbgl/programs/collision_box_program.hpp4
-rw-r--r--src/mbgl/programs/program.hpp6
-rw-r--r--src/mbgl/programs/symbol_program.hpp2
-rw-r--r--src/mbgl/renderer/layers/render_background_layer.cpp1
-rw-r--r--src/mbgl/renderer/layers/render_circle_layer.cpp1
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp14
-rw-r--r--src/mbgl/renderer/layers/render_fill_layer.cpp2
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.cpp20
-rw-r--r--src/mbgl/renderer/layers/render_hillshade_layer.cpp8
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp1
-rw-r--r--src/mbgl/renderer/layers/render_raster_layer.cpp1
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp3
-rw-r--r--src/mbgl/renderer/paint_parameters.cpp1
-rw-r--r--src/mbgl/renderer/paint_parameters.hpp2
-rw-r--r--src/mbgl/renderer/render_tile.cpp3
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp34
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp1
26 files changed, 189 insertions, 39 deletions
diff --git a/src/core-files.json b/src/core-files.json
index 08a6aa4aac..9860212399 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -26,6 +26,7 @@
"src/mbgl/gl/enum.cpp",
"src/mbgl/gl/object.cpp",
"src/mbgl/gl/offscreen_texture.cpp",
+ "src/mbgl/gl/render_pass.cpp",
"src/mbgl/gl/renderer_backend.cpp",
"src/mbgl/gl/texture.cpp",
"src/mbgl/gl/uniform.cpp",
@@ -525,6 +526,7 @@
"mbgl/gfx/index_vector.hpp": "src/mbgl/gfx/index_vector.hpp",
"mbgl/gfx/offscreen_texture.hpp": "src/mbgl/gfx/offscreen_texture.hpp",
"mbgl/gfx/program.hpp": "src/mbgl/gfx/program.hpp",
+ "mbgl/gfx/render_pass.hpp": "src/mbgl/gfx/render_pass.hpp",
"mbgl/gfx/renderbuffer.hpp": "src/mbgl/gfx/renderbuffer.hpp",
"mbgl/gfx/stencil_mode.hpp": "src/mbgl/gfx/stencil_mode.hpp",
"mbgl/gfx/texture.hpp": "src/mbgl/gfx/texture.hpp",
@@ -548,6 +550,7 @@
"mbgl/gl/offscreen_texture.hpp": "src/mbgl/gl/offscreen_texture.hpp",
"mbgl/gl/program.hpp": "src/mbgl/gl/program.hpp",
"mbgl/gl/program_binary_extension.hpp": "src/mbgl/gl/program_binary_extension.hpp",
+ "mbgl/gl/render_pass.hpp": "src/mbgl/gl/render_pass.hpp",
"mbgl/gl/renderbuffer_resource.hpp": "src/mbgl/gl/renderbuffer_resource.hpp",
"mbgl/gl/state.hpp": "src/mbgl/gl/state.hpp",
"mbgl/gl/texture.hpp": "src/mbgl/gl/texture.hpp",
diff --git a/src/mbgl/gfx/command_encoder.hpp b/src/mbgl/gfx/command_encoder.hpp
index f095c5b867..145c2bef82 100644
--- a/src/mbgl/gfx/command_encoder.hpp
+++ b/src/mbgl/gfx/command_encoder.hpp
@@ -2,9 +2,14 @@
#include <mbgl/gfx/debug_group.hpp>
+#include <memory>
+
namespace mbgl {
namespace gfx {
+class RenderPassDescriptor;
+class RenderPass;
+
class CommandEncoder {
protected:
explicit CommandEncoder() = default;
@@ -21,6 +26,8 @@ public:
DebugGroup<CommandEncoder> createDebugGroup(const char* name) {
return { *this, name };
}
+
+ virtual std::unique_ptr<RenderPass> createRenderPass(const char* name, const RenderPassDescriptor&) = 0;
};
} // namespace gfx
diff --git a/src/mbgl/gfx/program.hpp b/src/mbgl/gfx/program.hpp
index 94ba3b18ef..b636bc2654 100644
--- a/src/mbgl/gfx/program.hpp
+++ b/src/mbgl/gfx/program.hpp
@@ -13,6 +13,7 @@ class ColorMode;
class CullFaceMode;
class DrawScope;
class IndexBuffer;
+class RenderPass;
template <class> class UniformValues;
template <class> class AttributeBindings;
template <class> class TextureBindings;
@@ -35,6 +36,7 @@ public:
using TextureList = typename Name::TextureList;
virtual void draw(Context&,
+ RenderPass&,
const DrawMode&,
const DepthMode&,
const StencilMode&,
diff --git a/src/mbgl/gfx/render_pass.hpp b/src/mbgl/gfx/render_pass.hpp
new file mode 100644
index 0000000000..db5ba661ba
--- /dev/null
+++ b/src/mbgl/gfx/render_pass.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <mbgl/gfx/debug_group.hpp>
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/optional.hpp>
+
+#include <cstdint>
+
+namespace mbgl {
+namespace gfx {
+
+class Renderable;
+
+class RenderPassDescriptor {
+public:
+ Renderable& renderable;
+ optional<Color> clearColor;
+ optional<float> clearDepth;
+ optional<int32_t> clearStencil;
+};
+
+class RenderPass {
+protected:
+ RenderPass() = default;
+
+ friend class DebugGroup<RenderPass>;
+ virtual void pushDebugGroup(const char* name) = 0;
+ virtual void popDebugGroup() = 0;
+
+public:
+ virtual ~RenderPass() = default;
+ RenderPass(const RenderPass&) = delete;
+ RenderPass& operator=(const RenderPass&) = delete;
+
+ DebugGroup<RenderPass> createDebugGroup(const char* name) {
+ return { *this, name };
+ }
+};
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/src/mbgl/gl/command_encoder.cpp b/src/mbgl/gl/command_encoder.cpp
index e1bf5e1187..26d1008789 100644
--- a/src/mbgl/gl/command_encoder.cpp
+++ b/src/mbgl/gl/command_encoder.cpp
@@ -1,4 +1,5 @@
#include <mbgl/gl/command_encoder.hpp>
+#include <mbgl/gl/render_pass.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/platform/gl_functions.hpp>
@@ -13,6 +14,11 @@ CommandEncoder::~CommandEncoder() {
context.performCleanup();
}
+std::unique_ptr<gfx::RenderPass>
+CommandEncoder::createRenderPass(const char* name, const gfx::RenderPassDescriptor& descriptor) {
+ return std::make_unique<gl::RenderPass>(*this, name, descriptor);
+}
+
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 b4f7d2af13..8074000034 100644
--- a/src/mbgl/gl/command_encoder.hpp
+++ b/src/mbgl/gl/command_encoder.hpp
@@ -6,6 +6,7 @@ namespace mbgl {
namespace gl {
class Context;
+class RenderPass;
class CommandEncoder final : public gfx::CommandEncoder {
public:
@@ -14,6 +15,10 @@ public:
~CommandEncoder() override;
+ friend class RenderPass;
+
+ std::unique_ptr<gfx::RenderPass> createRenderPass(const char* name, const gfx::RenderPassDescriptor&) override;
+
private:
void pushDebugGroup(const char* name) override;
void popDebugGroup() override;
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 023b738b93..3757c442de 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -156,6 +156,7 @@ public:
};
void draw(gfx::Context& genericContext,
+ gfx::RenderPass&,
const gfx::DrawMode& drawMode,
const gfx::DepthMode& depthMode,
const gfx::StencilMode& stencilMode,
diff --git a/src/mbgl/gl/render_pass.cpp b/src/mbgl/gl/render_pass.cpp
new file mode 100644
index 0000000000..b327f7954f
--- /dev/null
+++ b/src/mbgl/gl/render_pass.cpp
@@ -0,0 +1,28 @@
+#include <mbgl/gl/render_pass.hpp>
+#include <mbgl/gl/command_encoder.hpp>
+#include <mbgl/gl/renderable_resource.hpp>
+#include <mbgl/gl/context.hpp>
+
+namespace mbgl {
+namespace gl {
+
+RenderPass::RenderPass(gl::CommandEncoder& commandEncoder_,
+ const char* name,
+ const gfx::RenderPassDescriptor& descriptor)
+ : commandEncoder(commandEncoder_), debugGroup(commandEncoder.createDebugGroup(name)) {
+ descriptor.renderable.getResource<gl::RenderableResource>().bind();
+ const auto clearDebugGroup(commandEncoder.createDebugGroup("clear"));
+ commandEncoder.context.clear(descriptor.clearColor, descriptor.clearDepth,
+ descriptor.clearStencil);
+}
+
+void RenderPass::pushDebugGroup(const char* name) {
+ commandEncoder.pushDebugGroup(name);
+}
+
+void RenderPass::popDebugGroup() {
+ commandEncoder.popDebugGroup();
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/render_pass.hpp b/src/mbgl/gl/render_pass.hpp
new file mode 100644
index 0000000000..85a56243a6
--- /dev/null
+++ b/src/mbgl/gl/render_pass.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <mbgl/gfx/render_pass.hpp>
+
+namespace mbgl {
+namespace gfx {
+
+class CommandEncoder;
+
+} // namespace gfx
+
+namespace gl {
+
+class CommandEncoder;
+class Context;
+
+class RenderPass final : public gfx::RenderPass {
+public:
+ RenderPass(gl::CommandEncoder&, const char* name, const gfx::RenderPassDescriptor&);
+
+private:
+ void pushDebugGroup(const char* name) override;
+ void popDebugGroup() override;
+
+private:
+ gl::CommandEncoder& commandEncoder;
+ const gfx::DebugGroup<gfx::CommandEncoder> debugGroup;
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp
index 677704b154..1677be1250 100644
--- a/src/mbgl/programs/collision_box_program.hpp
+++ b/src/mbgl/programs/collision_box_program.hpp
@@ -57,6 +57,7 @@ public:
template <class DrawMode>
void draw(gfx::Context& context,
+ gfx::RenderPass& renderPass,
const DrawMode& drawMode,
const gfx::DepthMode& depthMode,
const gfx::StencilMode& stencilMode,
@@ -90,6 +91,7 @@ public:
program->draw(
context,
+ renderPass,
std::move(drawMode),
std::move(depthMode),
std::move(stencilMode),
@@ -141,6 +143,7 @@ public:
template <class DrawMode>
void draw(gfx::Context& context,
+ gfx::RenderPass& renderPass,
const DrawMode& drawMode,
const gfx::DepthMode& depthMode,
const gfx::StencilMode& stencilMode,
@@ -172,6 +175,7 @@ public:
program->draw(
context,
+ renderPass,
std::move(drawMode),
std::move(depthMode),
std::move(stencilMode),
diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp
index e4d2af95f8..cb68735bf8 100644
--- a/src/mbgl/programs/program.hpp
+++ b/src/mbgl/programs/program.hpp
@@ -13,6 +13,10 @@
namespace mbgl {
+namespace gfx {
+class RenderPass;
+} // namespace gfx
+
template <class Name,
gfx::PrimitiveType Primitive,
class LayoutAttributeList,
@@ -67,6 +71,7 @@ public:
template <class DrawMode>
void draw(gfx::Context& context,
+ gfx::RenderPass& renderPass,
const DrawMode& drawMode,
const gfx::DepthMode& depthMode,
const gfx::StencilMode& stencilMode,
@@ -93,6 +98,7 @@ public:
program->draw(
context,
+ renderPass,
drawMode,
depthMode,
stencilMode,
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index d640eb74da..56477166d8 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -300,6 +300,7 @@ public:
template <class DrawMode>
void draw(gfx::Context& context,
+ gfx::RenderPass& renderPass,
const DrawMode& drawMode,
const gfx::DepthMode& depthMode,
const gfx::StencilMode& stencilMode,
@@ -326,6 +327,7 @@ public:
program->draw(
context,
+ renderPass,
drawMode,
depthMode,
stencilMode,
diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp
index 269b227a7d..b633ad0671 100644
--- a/src/mbgl/renderer/layers/render_background_layer.cpp
+++ b/src/mbgl/renderer/layers/render_background_layer.cpp
@@ -67,6 +67,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
program.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp
index 1c13a6152b..ad4e6a020f 100644
--- a/src/mbgl/renderer/layers/render_circle_layer.cpp
+++ b/src/mbgl/renderer/layers/render_circle_layer.cpp
@@ -97,6 +97,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
parameters.mapMode != MapMode::Continuous
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
index 720d2ff2f8..6f69916734 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
@@ -13,9 +13,8 @@
#include <mbgl/util/intersection_tests.hpp>
#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
+#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
-#include <mbgl/gl/context.hpp>
-#include <mbgl/gl/renderable_resource.hpp>
namespace mbgl {
@@ -52,9 +51,6 @@ bool RenderFillExtrusionLayer::hasCrossfade() const {
}
void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*) {
- // TODO: remove cast
- gl::Context& glContext = static_cast<gl::Context&>(parameters.context);
-
if (parameters.pass == RenderPass::Opaque) {
return;
}
@@ -67,14 +63,14 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
renderTexture = parameters.context.createOffscreenTexture(size, *parameters.staticData.depthRenderbuffer);
}
- renderTexture->getResource<gl::RenderableResource>().bind();
-
optional<float> depthClearValue = {};
if (parameters.staticData.depthRenderbuffer->needsClearing()) depthClearValue = 1.0;
// Flag the depth buffer as no longer needing to be cleared for the remainder of this pass.
parameters.staticData.depthRenderbuffer->setShouldClear(false);
- glContext.clear(Color{ 0.0f, 0.0f, 0.0f, 0.0f }, depthClearValue, {});
+ auto renderPass = parameters.encoder->createRenderPass(
+ "fill extrusion",
+ { *renderTexture, Color{ 0.0f, 0.0f, 0.0f, 0.0f }, depthClearValue, {} });
auto draw = [&](auto& programInstance, const auto& tileBucket, auto&& uniformValues,
const optional<ImagePosition>& patternPositionA,
@@ -98,6 +94,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
programInstance.draw(
parameters.context,
+ *renderPass,
gfx::Triangles(),
parameters.depthModeFor3D(gfx::DepthMaskType::ReadWrite),
gfx::StencilMode::disabled(),
@@ -201,6 +198,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp
index 3e44f7bfb0..aba1481044 100644
--- a/src/mbgl/renderer/layers/render_fill_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_layer.cpp
@@ -104,6 +104,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
drawMode,
depthMode,
parameters.stencilModeForClipping(tile.clip),
@@ -194,6 +195,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
drawMode,
depthMode,
parameters.stencilModeForClipping(tile.clip),
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
index f8a159f3da..333b8f9890 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
@@ -10,8 +10,8 @@
#include <mbgl/style/layers/heatmap_layer_impl.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
-#include <mbgl/gl/context.hpp>
-#include <mbgl/gl/renderable_resource.hpp>
+#include <mbgl/gfx/render_pass.hpp>
+#include <mbgl/gfx/context.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/intersection_tests.hpp>
@@ -57,6 +57,10 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
const auto& viewportSize = parameters.staticData.backendSize;
const auto size = Size{viewportSize.width / 4, viewportSize.height / 4};
+ if (!colorRampTexture) {
+ colorRampTexture = parameters.context.createTexture(colorRamp, gfx::TextureChannelDataType::UnsignedByte);
+ }
+
if (!renderTexture || renderTexture->getSize() != size) {
renderTexture.reset();
if (parameters.context.supportsHalfFloatTextures) {
@@ -74,14 +78,8 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
}
}
- renderTexture->getResource<gl::RenderableResource>().bind();
-
- if (!colorRampTexture) {
- colorRampTexture = parameters.context.createTexture(colorRamp, gfx::TextureChannelDataType::UnsignedByte);
- }
-
- // TODO: remove cast
- static_cast<gl::Context&>(parameters.context).clear(Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {});
+ auto renderPass = parameters.encoder->createRenderPass(
+ "heatmap texture", { *renderTexture, Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {} });
for (const RenderTile& tile : renderTiles) {
auto bucket_ = tile.tile.getBucket<HeatmapBucket>(*baseImpl);
@@ -120,6 +118,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
stencilMode,
@@ -165,6 +164,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
index 426c34e599..5736280892 100644
--- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp
+++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
@@ -11,7 +11,7 @@
#include <mbgl/style/layers/hillshade_layer_impl.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/offscreen_texture.hpp>
-#include <mbgl/gl/renderable_resource.hpp>
+#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/util/geo.hpp>
namespace mbgl {
@@ -98,6 +98,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
@@ -132,7 +133,9 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
const uint16_t stride = bucket.getDEMData().stride;
const uint16_t tilesize = bucket.getDEMData().dim;
auto view = parameters.context.createOffscreenTexture({ tilesize, tilesize });
- view->getResource<gl::RenderableResource>().bind();
+
+ auto renderPass = parameters.encoder->createRenderPass(
+ "hillshade prepare", { *view, Color{ 0.0f, 0.0f, 0.0f, 0.0f }, {}, {} });
const Properties<>::PossiblyEvaluated properties;
const HillshadePrepareProgram::Binders paintAttributeData{ properties, 0 };
@@ -160,6 +163,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
programInstance.draw(
parameters.context,
+ *renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index dbc1fa2f3e..ba6d045b49 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -86,6 +86,7 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
parameters.stencilModeForClipping(tile.clip),
diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp
index 09aa94800f..4964afe6a7 100644
--- a/src/mbgl/renderer/layers/render_raster_layer.cpp
+++ b/src/mbgl/renderer/layers/render_raster_layer.cpp
@@ -110,6 +110,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index 313a86539e..84ce0a73e0 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -130,6 +130,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
values_.pitchAlignment == AlignmentType::Map
? parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly)
@@ -352,6 +353,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
}};
parameters.programs.getSymbolLayerPrograms().collisionBox.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Lines { 1.0f },
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
@@ -388,6 +390,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.programs.getSymbolLayerPrograms().collisionCircle.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp
index 51e85dd91b..624deeec0a 100644
--- a/src/mbgl/renderer/paint_parameters.cpp
+++ b/src/mbgl/renderer/paint_parameters.cpp
@@ -2,6 +2,7 @@
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/gfx/command_encoder.hpp>
+#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/map/transform_state.hpp>
namespace mbgl {
diff --git a/src/mbgl/renderer/paint_parameters.hpp b/src/mbgl/renderer/paint_parameters.hpp
index 7b0f941d23..523975c78c 100644
--- a/src/mbgl/renderer/paint_parameters.hpp
+++ b/src/mbgl/renderer/paint_parameters.hpp
@@ -26,6 +26,7 @@ namespace gfx {
class Context;
class RendererBackend;
class CommandEncoder;
+class RenderPass;
} // namespace gfx
class PaintParameters {
@@ -44,6 +45,7 @@ public:
gfx::Context& context;
gfx::RendererBackend& backend;
const std::unique_ptr<gfx::CommandEncoder> encoder;
+ std::unique_ptr<gfx::RenderPass> renderPass;
const TransformState& state;
const EvaluatedLight& evaluatedLight;
diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp
index 636c184e9e..5429536c3f 100644
--- a/src/mbgl/renderer/render_tile.cpp
+++ b/src/mbgl/renderer/render_tile.cpp
@@ -98,6 +98,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
program.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Lines { 4.0f * parameters.pixelRatio },
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
@@ -121,6 +122,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
program.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Lines { 2.0f * parameters.pixelRatio },
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
@@ -147,6 +149,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
assert(tile.debugBucket);
parameters.programs.debug.draw(
parameters.context,
+ *parameters.renderPass,
gfx::LineStrip { 4.0f * parameters.pixelRatio },
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index 6d4c7b6320..87178d775e 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -16,9 +16,10 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
+#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
-#include <mbgl/gl/context.hpp>
-#include <mbgl/gl/renderable_resource.hpp>
+#include <mbgl/gfx/context.hpp>
+#include <mbgl/gfx/renderable.hpp>
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/transition_options.hpp>
@@ -366,9 +367,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
parameters.symbolFadeChange = placement->symbolFadeChange(updateParameters.timePoint);
- // TODO: remove cast
- gl::Context& glContext = static_cast<gl::Context&>(parameters.context);
-
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{
@@ -415,22 +413,19 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
// Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any
// tiles whatsoever.
{
- using namespace gl::value;
-
- parameters.backend.getDefaultRenderable().getResource<gl::RenderableResource>().bind();
+ optional<Color> color;
if (parameters.debugOptions & MapDebugOptions::Overdraw) {
- glContext.clear(Color::black(), ClearDepth::Default, ClearStencil::Default);
- } else if (backend.contextIsShared()) {
- glContext.clear({}, ClearDepth::Default, ClearStencil::Default);
- } else {
- glContext.clear(backgroundColor, ClearDepth::Default, ClearStencil::Default);
+ color = Color::black();
+ } else if (!backend.contextIsShared()) {
+ color = backgroundColor;
}
+ parameters.renderPass = parameters.encoder->createRenderPass("main buffer", { parameters.backend.getDefaultRenderable(), color, 1, 0 });
}
// - CLIPPING MASKS ----------------------------------------------------------------------------
// Draws the clipping masks to the stencil buffer.
{
- const auto debugGroup(parameters.encoder->createDebugGroup("clipping masks"));
+ const auto debugGroup(parameters.renderPass->createDebugGroup("clipping masks"));
static const Properties<>::PossiblyEvaluated properties {};
static const ClippingMaskProgram::Binders paintAttributeData(properties, 0);
@@ -440,6 +435,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
program.draw(
parameters.context,
+ *parameters.renderPass,
gfx::Triangles(),
gfx::DepthMode::disabled(),
gfx::StencilMode {
@@ -489,13 +485,13 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
{
parameters.pass = RenderPass::Opaque;
- const auto debugGroup(parameters.encoder->createDebugGroup("opaque"));
+ const auto debugGroup(parameters.renderPass->createDebugGroup("opaque"));
uint32_t i = 0;
for (auto it = renderItems.rbegin(); it != renderItems.rend(); ++it, ++i) {
parameters.currentLayer = i;
if (it->layer.hasRenderPass(parameters.pass)) {
- const auto layerDebugGroup(parameters.encoder->createDebugGroup(it->layer.getID().c_str()));
+ const auto layerDebugGroup(parameters.renderPass->createDebugGroup(it->layer.getID().c_str()));
it->layer.render(parameters, it->source);
}
}
@@ -505,13 +501,13 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
// Make a second pass, rendering translucent objects. This time, we render bottom-to-top.
{
parameters.pass = RenderPass::Translucent;
- const auto debugGroup(parameters.encoder->createDebugGroup("translucent"));
+ const auto debugGroup(parameters.renderPass->createDebugGroup("translucent"));
uint32_t i = static_cast<uint32_t>(renderItems.size()) - 1;
for (auto it = renderItems.begin(); it != renderItems.end(); ++it, --i) {
parameters.currentLayer = i;
if (it->layer.hasRenderPass(parameters.pass)) {
- const auto layerDebugGroup(parameters.encoder->createDebugGroup(it->layer.getID().c_str()));
+ const auto layerDebugGroup(parameters.renderPass->createDebugGroup(it->layer.getID().c_str()));
it->layer.render(parameters, it->source);
}
}
@@ -520,7 +516,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
// - DEBUG PASS --------------------------------------------------------------------------------
// Renders debug overlays.
{
- const auto debugGroup(parameters.encoder->createDebugGroup("debug"));
+ const auto debugGroup(parameters.renderPass->createDebugGroup("debug"));
// Finalize the rendering, e.g. by calling debug render calls per tile.
// This guarantees that we have at least one function per tile called.
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index dee3eab750..102125be19 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -64,6 +64,7 @@ void RenderImageSource::finishRender(PaintParameters& parameters) {
for (auto matrix : matrices) {
programInstance.draw(
parameters.context,
+ *parameters.renderPass,
gfx::LineStrip { 4.0f * parameters.pixelRatio },
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),