Selectable renderer implementation (#1247)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
mwilsnd
2023-06-26 15:49:48 -05:00
committed by Bart Louwers
parent fe165c8924
commit 1963697687
64 changed files with 1189 additions and 316 deletions

View File

@@ -207,6 +207,7 @@ DashPatternTexture::DashPatternTexture(const std::vector<float>& from_,
}
void DashPatternTexture::upload(gfx::UploadPass& uploadPass) {
#if MLN_DRAWABLE_RENDERER
if (std::holds_alternative<AlphaImage>(texture)) {
auto tempTexture = uploadPass.getContext().createTexture2D();
tempTexture->upload(std::get<AlphaImage>(texture));
@@ -214,23 +215,41 @@ void DashPatternTexture::upload(gfx::UploadPass& uploadPass) {
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp});
texture = std::move(tempTexture);
}
#else
if (texture.is<AlphaImage>()) {
texture = uploadPass.createTexture(texture.get<AlphaImage>());
}
#endif
}
gfx::TextureBinding DashPatternTexture::textureBinding() const {
// The texture needs to have been uploaded already.
#if MLN_DRAWABLE_RENDERER
assert(std::holds_alternative<gfx::Texture2DPtr>(texture));
return {std::get<gfx::Texture2DPtr>(texture)->getResource(),
gfx::TextureFilterType::Linear,
gfx::TextureMipMapType::No,
gfx::TextureWrapType::Repeat,
gfx::TextureWrapType::Clamp};
#else
assert(texture.is<gfx::Texture>());
return {texture.get<gfx::Texture>().getResource(),
gfx::TextureFilterType::Linear,
gfx::TextureMipMapType::No,
gfx::TextureWrapType::Repeat,
gfx::TextureWrapType::Clamp};
#endif
}
Size DashPatternTexture::getSize() const {
#if MLN_DRAWABLE_RENDERER
if (std::holds_alternative<AlphaImage>(texture)) {
return std::get<AlphaImage>(texture).size;
}
return std::get<gfx::Texture2DPtr>(texture)->getSize();
#else
return texture.match([](const auto& obj) { return obj.size; });
#endif
}
LineAtlas::LineAtlas() = default;

View File

@@ -1,14 +1,20 @@
#pragma once
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/texture2d.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/util/image.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/texture2d.hpp>
#include <variant>
#else
#include <mbgl/util/variant.hpp>
#include <optional>
#endif
#include <map>
#include <memory>
#include <vector>
#include <variant>
namespace mbgl {
@@ -55,7 +61,12 @@ public:
private:
LinePatternPos from, to;
#if MLN_DRAWABLE_RENDERER
std::variant<AlphaImage, gfx::Texture2DPtr> texture;
#else
variant<AlphaImage, gfx::Texture> texture;
#endif
};
class LineAtlas {

View File

@@ -6,10 +6,13 @@
#include <mbgl/gfx/program.hpp>
#include <mbgl/gfx/renderbuffer.hpp>
#include <mbgl/gfx/rendering_stats.hpp>
#include <mbgl/gfx/uniform_buffer.hpp>
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/types.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/uniform_buffer.hpp>
#endif
#include <memory>
#include <string>
@@ -17,19 +20,24 @@ namespace mbgl {
class PaintParameters;
class ProgramParameters;
#if MLN_DRAWABLE_RENDERER
class TileLayerGroup;
class LayerGroup;
using TileLayerGroupPtr = std::shared_ptr<TileLayerGroup>;
using LayerGroupPtr = std::shared_ptr<LayerGroup>;
#endif
namespace gfx {
class OffscreenTexture;
class ShaderRegistry;
#if MLN_DRAWABLE_RENDERER
class Drawable;
class DrawableBuilder;
class DrawableTweaker;
class OffscreenTexture;
class ShaderProgramBase;
class ShaderRegistry;
class Texture2D;
using DrawablePtr = std::shared_ptr<Drawable>;
@@ -38,6 +46,7 @@ using DrawableTweakerPtr = std::shared_ptr<DrawableTweaker>;
using UniformBufferPtr = std::shared_ptr<UniformBuffer>;
using ShaderProgramBasePtr = std::shared_ptr<ShaderProgramBase>;
using Texture2DPtr = std::shared_ptr<Texture2D>;
#endif
class Context {
protected:
@@ -104,6 +113,7 @@ public:
virtual void clearStencilBuffer(int32_t) = 0;
#if MLN_DRAWABLE_RENDERER
public:
/// Create a new drawable builder
virtual UniqueDrawableBuilder createDrawableBuilder(std::string name) = 0;
@@ -127,6 +137,7 @@ public:
/// Create a texture
virtual Texture2DPtr createTexture2D() = 0;
#endif
};
} // namespace gfx

View File

@@ -19,6 +19,7 @@
namespace mbgl {
namespace gfx {
constexpr int32_t MaxActiveTextureUnits = 8;
class TextureResource {
protected:
TextureResource() = default;
@@ -39,6 +40,8 @@ public:
return static_cast<T&>(*resource);
}
const Size& getSize() const noexcept { return size; }
Size size;
protected:

View File

@@ -7,21 +7,27 @@
#include <mbgl/gfx/index_vector.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/texture2d.hpp>
#include <mbgl/util/size.hpp>
#include <mbgl/util/image.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/texture2d.hpp>
#endif
#include <optional>
#include <vector>
namespace mbgl {
namespace gfx {
#if MLN_DRAWABLE_RENDERER
class Conext;
class Texture2D;
class VertexAttributeArray;
using AttributeBindingArray = std::vector<std::optional<gfx::AttributeBinding>>;
using Texture2DPtr = std::shared_ptr<Texture2D>;
#endif
class UploadPass {
protected:
@@ -38,8 +44,10 @@ public:
DebugGroup<UploadPass> createDebugGroup(const char* name) { return {*this, name}; }
#if MLN_DRAWABLE_RENDERER
virtual Context& getContext() = 0;
virtual const Context& getContext() const = 0;
#endif
public:
template <class Vertex>
@@ -66,6 +74,7 @@ public:
updateIndexBufferResource(buffer.getResource(), v.data(), v.bytes());
}
#if MLN_DRAWABLE_RENDERER
virtual gfx::AttributeBindingArray buildAttributeBindings(
const std::size_t vertexCount,
const gfx::AttributeDataType vertexType,
@@ -75,6 +84,7 @@ public:
const gfx::VertexAttributeArray& overrides,
gfx::BufferUsageType,
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) = 0;
#endif
protected:
virtual std::unique_ptr<VertexBufferResource> createVertexBufferResource(const void* data,
@@ -117,6 +127,7 @@ public:
updateTextureResourceSub(texture.getResource(), offsetX, offsetY, image.size, image.data.get(), format, type);
}
#if MLN_DRAWABLE_RENDERER
template <typename Image>
void updateTexture(Texture2D& texture,
const Image& image,
@@ -136,6 +147,7 @@ public:
const auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
updateTextureResourceSub(texture.getResource(), offsetX, offsetY, image.size, image.data.get(), format, type);
}
#endif
public:
virtual std::unique_ptr<TextureResource> createTextureResource(Size,

View File

@@ -3,26 +3,29 @@
#include <mbgl/gfx/shader_registry.hpp>
#include <mbgl/gl/command_encoder.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/drawable_gl.hpp>
#include <mbgl/gl/drawable_gl_builder.hpp>
#include <mbgl/gl/drawable_gl_tweaker.hpp>
#include <mbgl/gl/draw_scope_resource.hpp>
#include <mbgl/gl/enum.hpp>
#include <mbgl/gl/layer_group_gl.hpp>
#include <mbgl/gl/renderer_backend.hpp>
#include <mbgl/gl/renderbuffer_resource.hpp>
#include <mbgl/gl/uniform_buffer_gl.hpp>
#include <mbgl/gl/texture_resource.hpp>
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/texture2d.hpp>
#include <mbgl/gl/offscreen_texture.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/shaders/gl/shader_program_gl.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gl/drawable_gl.hpp>
#include <mbgl/gl/drawable_gl_builder.hpp>
#include <mbgl/gl/drawable_gl_tweaker.hpp>
#include <mbgl/gl/layer_group_gl.hpp>
#include <mbgl/gl/uniform_buffer_gl.hpp>
#include <mbgl/gl/texture2d.hpp>
#include <mbgl/shaders/gl/shader_program_gl.hpp>
#endif
#include <cstring>
#include <iterator>
@@ -455,6 +458,7 @@ void Context::setDirtyState() {
globalVertexArrayState.setDirty();
}
#if MLN_DRAWABLE_RENDERER
gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) {
return std::make_unique<gl::DrawableGLBuilder>(std::move(name));
}
@@ -484,6 +488,7 @@ LayerGroupPtr Context::createLayerGroup(int32_t layerIndex, std::size_t initialC
gfx::Texture2DPtr Context::createTexture2D() {
return std::make_shared<gl::Texture2D>(*this);
}
#endif
void Context::clear(std::optional<mbgl::Color> color, std::optional<float> depth, std::optional<int32_t> stencil) {
GLbitfield mask = 0;

View File

@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/texture2d.hpp>
#include <mbgl/gfx/draw_mode.hpp>
#include <mbgl/gfx/depth_mode.hpp>
#include <mbgl/gfx/stencil_mode.hpp>
@@ -16,6 +15,10 @@
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/util/noncopyable.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/texture2d.hpp>
#endif
#include <array>
#include <functional>
#include <vector>
@@ -103,6 +106,7 @@ public:
void setCleanupOnDestruction(bool cleanup) { cleanupOnDestruction = cleanup; }
#if MLN_DRAWABLE_RENDERER
gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;
gfx::DrawableTweakerPtr createDrawableTweaker() override;
gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size) override;
@@ -114,6 +118,7 @@ public:
LayerGroupPtr createLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name) override;
gfx::Texture2DPtr createTexture2D() override;
#endif
private:
RendererBackend& backend;

View File

@@ -4,9 +4,12 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/extension.hpp>
#include <mbgl/shaders/shader_manifest.hpp>
#include <mbgl/shaders/gl/shader_group_gl.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/shaders/gl/shader_group_gl.hpp>
#endif
#include <cassert>
namespace mbgl {
@@ -66,6 +69,7 @@ void RendererBackend::setScissorTest(bool enabled) {
RendererBackend::~RendererBackend() = default;
#if MLN_DRAWABLE_RENDERER
/// @brief Register a list of types with a shader registry instance
/// @tparam ...ShaderID Pack of BuiltIn:: shader IDs
/// @param registry A shader registry instance
@@ -98,6 +102,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
shaders::BuiltIn::FillPatternShader,
shaders::BuiltIn::RasterShader>(shaders, programParameters);
}
#endif
} // namespace gl
} // namespace mbgl

View File

@@ -3,13 +3,16 @@
#include <mbgl/gl/enum.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/command_encoder.hpp>
#include <mbgl/gl/vertex_attribute_gl.hpp>
#include <mbgl/gl/vertex_buffer_resource.hpp>
#include <mbgl/gl/index_buffer_resource.hpp>
#include <mbgl/gl/texture_resource.hpp>
#include <mbgl/gl/texture2d.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gl/vertex_attribute_gl.hpp>
#include <mbgl/gl/texture2d.hpp>
#endif
#include <algorithm>
namespace mbgl {
@@ -123,6 +126,7 @@ void UploadPass::updateTextureResourceSub(gfx::TextureResource& resource,
data));
}
#if MLN_DRAWABLE_RENDERER
static std::size_t padSize(std::size_t size, std::size_t padding) {
return (padding - (size % padding)) % padding;
}
@@ -231,6 +235,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
return {};
}
#endif
void UploadPass::pushDebugGroup(const char* name) {
commandEncoder.pushDebugGroup(name);
@@ -240,6 +245,7 @@ void UploadPass::popDebugGroup() {
commandEncoder.popDebugGroup();
}
#if MLN_DRAWABLE_RENDERER
gfx::Context& UploadPass::getContext() {
return commandEncoder.context;
}
@@ -247,6 +253,7 @@ gfx::Context& UploadPass::getContext() {
const gfx::Context& UploadPass::getContext() const {
return commandEncoder.context;
}
#endif
} // namespace gl
} // namespace mbgl

View File

@@ -26,8 +26,10 @@ private:
void popDebugGroup() override;
public:
#if MLN_DRAWABLE_RENDERER
gfx::Context& getContext() override;
const gfx::Context& getContext() const override;
#endif
std::unique_ptr<gfx::VertexBufferResource> createVertexBufferResource(const void* data,
std::size_t size,
@@ -38,6 +40,7 @@ public:
gfx::BufferUsageType) override;
void updateIndexBufferResource(gfx::IndexBufferResource&, const void* data, std::size_t size) override;
#if MLN_DRAWABLE_RENDERER
gfx::AttributeBindingArray buildAttributeBindings(
const std::size_t vertexCount,
const gfx::AttributeDataType vertexType,
@@ -47,6 +50,7 @@ public:
const gfx::VertexAttributeArray& overrides,
gfx::BufferUsageType,
/*out*/ std::unique_ptr<gfx::VertexBufferResource>& outBuffer) override;
#endif
public:
std::unique_ptr<gfx::TextureResource> createTextureResource(Size,

View File

@@ -1,5 +1,4 @@
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/background_program.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/programs/heatmap_program.hpp>
@@ -9,7 +8,6 @@
#include <mbgl/programs/line_program.hpp>
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/util/logging.hpp>
#include <exception>
@@ -42,6 +40,7 @@ void registerTypes(gfx::ShaderRegistry& registry, const ProgramParameters& progr
}
void Programs::registerWith(gfx::ShaderRegistry& registry) {
#if MLN_LEGACY_RENDERER
/// The following types will be registered
registerTypes<BackgroundProgram,
BackgroundPatternProgram,
@@ -69,6 +68,10 @@ void Programs::registerWith(gfx::ShaderRegistry& registry) {
CollisionCircleProgram,
DebugProgram,
ClippingMaskProgram>(registry, programParameters);
#else
/// The following types will be registered
registerTypes<DebugProgram, ClippingMaskProgram>(registry, programParameters);
#endif
}
} // namespace mbgl

View File

@@ -1,26 +1,29 @@
#include <mbgl/renderer/layers/render_background_layer.hpp>
#include <mbgl/renderer/layers/background_layer_tweaker.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/renderer/change_request.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/pattern_atlas.hpp>
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/renderer/upload_parameters.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/convert.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/layers/background_layer_tweaker.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/renderer/change_request.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#endif
#include <unordered_set>
namespace mbgl {
@@ -61,9 +64,12 @@ void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters& paramet
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
if (tileLayerGroup) {
tileLayerGroup->setLayerTweaker(std::make_shared<BackgroundLayerTweaker>(evaluatedProperties));
}
#endif
}
bool RenderBackgroundLayer::hasTransition() const {
@@ -74,6 +80,7 @@ bool RenderBackgroundLayer::hasCrossfade() const {
return getCrossfade<BackgroundLayerProperties>(evaluatedProperties).t != 1;
}
#if MLN_LEGACY_RENDERER
void RenderBackgroundLayer::render(PaintParameters& parameters) {
// Note that for bottommost layers without a pattern, the background color
// is drawn with glClear rather than this method.
@@ -167,6 +174,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
std::optional<Color> RenderBackgroundLayer::getSolidBackground() const {
const auto& evaluated = getEvaluated<BackgroundLayerProperties>(evaluatedProperties);
@@ -197,6 +205,7 @@ void RenderBackgroundLayer::prepare(const LayerPrepareParameters& params) {
}
}
#if MLN_DRAWABLE_RENDERER
static constexpr std::string_view BackgroundPlainShaderName = "BackgroundShader";
static constexpr std::string_view BackgroundPatternShaderName = "BackgroundPatternShader";
@@ -311,5 +320,6 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
}
}
}
#endif
} // namespace mbgl

View File

@@ -23,12 +23,14 @@ public:
explicit RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl>);
~RenderBackgroundLayer() override;
#if MLN_DRAWABLE_RENDERER
/// Generate any changes needed by the layer
void update(gfx::ShaderRegistry&,
gfx::Context&,
const TransformState&,
const RenderTree&,
UniqueChangeRequestVec&) override;
#endif
private:
void transition(const TransitionParameters&) override;
@@ -36,20 +38,27 @@ private:
bool hasTransition() const override;
bool hasCrossfade() const override;
std::optional<Color> getSolidBackground() const override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
void prepare(const LayerPrepareParameters&) override;
// Paint properties
style::BackgroundPaintProperties::Unevaluated unevaluated;
SegmentVector<BackgroundAttributes> segments;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<BackgroundProgram> backgroundProgram;
std::shared_ptr<BackgroundPatternProgram> backgroundPatternProgram;
#endif
#if MLN_DRAWABLE_RENDERER
// Drawable shaders
gfx::ShaderProgramBasePtr plainShader;
gfx::ShaderProgramBasePtr patternShader;
#endif
};
} // namespace mbgl

View File

@@ -1,28 +1,32 @@
#include <mbgl/renderer/layers/render_circle_layer.hpp>
#include <mbgl/renderer/layers/circle_layer_tweaker.hpp>
#include <mbgl/renderer/buckets/circle_bucket.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/shader_group.hpp>
#include <mbgl/gfx/shader_registry.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/intersection_tests.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/layers/circle_layer_tweaker.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#endif
namespace mbgl {
using namespace style;
namespace {
#if MLN_LEGACY_RENDERER
struct RenderableSegment {
RenderableSegment(const Segment<CircleAttributes>& segment_,
const RenderTile& tile_,
@@ -43,6 +47,7 @@ struct RenderableSegment {
return lhs.sortKey < rhs.sortKey;
}
};
#endif
inline const style::CircleLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
assert(impl->getTypeInfo() == CircleLayer::Impl::staticTypeInfo());
@@ -74,9 +79,12 @@ void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters)
: RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
if (tileLayerGroup) {
tileLayerGroup->setLayerTweaker(std::make_shared<CircleLayerTweaker>(evaluatedProperties));
}
#endif
}
bool RenderCircleLayer::hasTransition() const {
@@ -87,6 +95,7 @@ bool RenderCircleLayer::hasCrossfade() const {
return false;
}
#if MLN_LEGACY_RENDERER
void RenderCircleLayer::render(PaintParameters& parameters) {
assert(renderTiles);
@@ -166,6 +175,7 @@ void RenderCircleLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
GeometryCoordinate projectPoint(const GeometryCoordinate& p, const mat4& posMatrix, const Size& size) {
vec4 pos = {{static_cast<double>(p.x), static_cast<double>(p.y), 0, 1}};
@@ -245,6 +255,7 @@ bool RenderCircleLayer::queryIntersectsFeature(const GeometryCoordinates& queryG
return false;
}
#if MLN_DRAWABLE_RENDERER
struct alignas(16) CircleInterpolateUBO {
float color_t;
float radius_t;
@@ -401,5 +412,6 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
}
}
}
#endif
} // namespace mbgl

View File

@@ -13,19 +13,24 @@ public:
explicit RenderCircleLayer(Immutable<style::CircleLayer::Impl>);
~RenderCircleLayer() final = default;
#if MLN_DRAWABLE_RENDERER
/// Generate any changes needed by the layer
void update(gfx::ShaderRegistry&,
gfx::Context&,
const TransformState&,
const RenderTree&,
UniqueChangeRequestVec&) override;
#endif
private:
void transition(const TransitionParameters&) override;
void evaluate(const PropertyEvaluationParameters&) override;
bool hasTransition() const override;
bool hasCrossfade() const override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
bool queryIntersectsFeature(const GeometryCoordinates&,
const GeometryTileFeature&,
@@ -38,10 +43,13 @@ private:
// Paint properties
style::CirclePaintProperties::Unevaluated unevaluated;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<CircleProgram> circleProgram;
#endif
#if MLN_DRAWABLE_RENDERER
gfx::ShaderGroupPtr circleShaderGroup;
#endif
};
} // namespace mbgl

View File

@@ -65,6 +65,7 @@ bool RenderFillExtrusionLayer::is3D() const {
return true;
}
#if MLN_LEGACY_RENDERER
void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
assert(renderTiles);
if (parameters.pass != RenderPass::Translucent) {
@@ -219,6 +220,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
drawTiles(parameters.stencilModeFor3D(), parameters.colorModeForRenderPass(), "color");
}
}
#endif // MLN_LEGACY_RENDERER
bool RenderFillExtrusionLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,

View File

@@ -21,7 +21,10 @@ private:
bool hasTransition() const override;
bool hasCrossfade() const override;
bool is3D() const override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
bool queryIntersectsFeature(const GeometryCoordinates&,
const GeometryTileFeature&,
@@ -34,9 +37,11 @@ private:
// Paint properties
style::FillExtrusionPaintProperties::Unevaluated unevaluated;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<FillExtrusionProgram> fillExtrusionProgram;
std::shared_ptr<FillExtrusionPatternProgram> fillExtrusionPatternProgram;
#endif
std::unique_ptr<gfx::OffscreenTexture> renderTexture;
};

View File

@@ -1,6 +1,5 @@
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
@@ -8,14 +7,11 @@
#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/buckets/fill_bucket.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/layers/fill_layer_tweaker.hpp>
#include <mbgl/renderer/layers/render_fill_layer.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/tile_render_data.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/style/expression/image.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mbgl/tile/geometry_tile.hpp>
@@ -26,6 +22,13 @@
#include <mbgl/util/math.hpp>
#include <mbgl/util/std.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/renderer/layers/fill_layer_tweaker.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#endif
namespace mbgl {
using namespace style;
@@ -74,9 +77,12 @@ void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) {
}
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
if (tileLayerGroup) {
tileLayerGroup->setLayerTweaker(std::make_shared<FillLayerTweaker>(evaluatedProperties));
}
#endif
}
bool RenderFillLayer::hasTransition() const {
@@ -87,6 +93,7 @@ bool RenderFillLayer::hasCrossfade() const {
return getCrossfade<FillLayerProperties>(evaluatedProperties).t != 1;
}
#if MLN_LEGACY_RENDERER
void RenderFillLayer::render(PaintParameters& parameters) {
assert(renderTiles);
@@ -254,6 +261,7 @@ void RenderFillLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
bool RenderFillLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
@@ -273,6 +281,7 @@ bool RenderFillLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeo
feature.getGeometries());
}
#if MLN_DRAWABLE_RENDERER
void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context,
const TransformState& state,
@@ -560,5 +569,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
}
}
}
#endif
} // namespace mbgl

View File

@@ -20,19 +20,24 @@ public:
explicit RenderFillLayer(Immutable<style::FillLayer::Impl>);
~RenderFillLayer() override;
#if MLN_DRAWABLE_RENDERER
/// Generate any changes needed by the layer
void update(gfx::ShaderRegistry&,
gfx::Context&,
const TransformState&,
const RenderTree&,
UniqueChangeRequestVec&) override;
#endif
private:
void transition(const TransitionParameters&) override;
void evaluate(const PropertyEvaluationParameters&) override;
bool hasTransition() const override;
bool hasCrossfade() const override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
bool queryIntersectsFeature(const GeometryCoordinates&,
const GeometryTileFeature&,
@@ -45,16 +50,19 @@ private:
// Paint properties
style::FillPaintProperties::Unevaluated unevaluated;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<FillProgram> fillProgram;
std::shared_ptr<FillPatternProgram> fillPatternProgram;
std::shared_ptr<FillOutlineProgram> fillOutlineProgram;
std::shared_ptr<FillOutlinePatternProgram> fillOutlinePatternProgram;
#endif
#if MLN_DRAWABLE_RENDERER
gfx::ShaderGroupPtr fillShaderGroup;
gfx::ShaderGroupPtr outlineShaderGroup;
gfx::ShaderGroupPtr patternShaderGroup;
gfx::ShaderGroupPtr outlinePatternShaderGroup;
#endif
};
} // namespace mbgl

View File

@@ -63,6 +63,7 @@ void RenderHeatmapLayer::upload(gfx::UploadPass& uploadPass) {
}
}
#if MLN_LEGACY_RENDERER
void RenderHeatmapLayer::render(PaintParameters& parameters) {
assert(renderTiles);
if (parameters.pass == RenderPass::Opaque) {
@@ -171,6 +172,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters) {
getID());
}
}
#endif // MLN_LEGACY_RENDERER
void RenderHeatmapLayer::updateColorRamp() {
auto colorValue = unevaluated.get<HeatmapColor>().getValue();

View File

@@ -22,7 +22,10 @@ private:
bool hasTransition() const override;
bool hasCrossfade() const override;
void upload(gfx::UploadPass&) override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
bool queryIntersectsFeature(const GeometryCoordinates&,
const GeometryTileFeature&,
@@ -40,9 +43,11 @@ private:
std::optional<gfx::Texture> colorRampTexture;
SegmentVector<HeatmapTextureAttributes> segments;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<HeatmapProgram> heatmapProgram;
std::shared_ptr<HeatmapTextureProgram> heatmapTextureProgram;
#endif
};
} // namespace mbgl

View File

@@ -75,6 +75,7 @@ void RenderHillshadeLayer::prepare(const LayerPrepareParameters& params) {
maxzoom = params.source->getMaxZoom();
}
#if MLN_LEGACY_RENDERER
void RenderHillshadeLayer::render(PaintParameters& parameters) {
assert(renderTiles);
if (parameters.pass != RenderPass::Translucent && parameters.pass != RenderPass::Pass3D) return;
@@ -218,5 +219,6 @@ void RenderHillshadeLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
} // namespace mbgl

View File

@@ -21,7 +21,10 @@ private:
bool hasTransition() const override;
bool hasCrossfade() const override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
void prepare(const LayerPrepareParameters&) override;
// Paint properties
@@ -31,9 +34,11 @@ private:
std::array<float, 2> getLatRange(const UnwrappedTileID& id);
std::array<float, 2> getLight(const PaintParameters& parameters);
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<HillshadeProgram> hillshadeProgram;
std::shared_ptr<HillshadePrepareProgram> hillshadePrepareProgram;
#endif
};
} // namespace mbgl

View File

@@ -89,6 +89,7 @@ void RenderLineLayer::upload(gfx::UploadPass& uploadPass) {
}
}
#if MLN_LEGACY_RENDERER
void RenderLineLayer::render(PaintParameters& parameters) {
assert(renderTiles);
if (parameters.pass == RenderPass::Opaque) {
@@ -208,6 +209,7 @@ void RenderLineLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
namespace {

View File

@@ -27,7 +27,10 @@ private:
bool hasCrossfade() const override;
void prepare(const LayerPrepareParameters&) override;
void upload(gfx::UploadPass&) override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
bool queryIntersectsFeature(const GeometryCoordinates&,
const GeometryTileFeature&,
@@ -46,11 +49,13 @@ private:
PremultipliedImage colorRamp;
std::optional<gfx::Texture> colorRampTexture;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<LineProgram> lineProgram;
std::shared_ptr<LineGradientProgram> lineGradientProgram;
std::shared_ptr<LineSDFProgram> lineSDFProgram;
std::shared_ptr<LinePatternProgram> linePatternProgram;
#endif
};
} // namespace mbgl

View File

@@ -1,7 +1,5 @@
#include <mbgl/renderer/layers/render_raster_layer.hpp>
#include <mbgl/renderer/layers/raster_layer_tweaker.hpp>
#include <mbgl/renderer/buckets/raster_bucket.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_static_data.hpp>
@@ -10,12 +8,17 @@
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/math/angles.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/layers/raster_layer_tweaker.hpp>
#include <mbgl/gfx/image_drawable_data.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/shaders/shader_program_base.hpp>
#endif
namespace mbgl {
@@ -47,9 +50,11 @@ void RenderRasterLayer::evaluate(const PropertyEvaluationParameters& parameters)
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
#if MLN_DRAWABLE_RENDERER
if (tileLayerGroup && tileLayerGroup->getLayerTweaker()) {
tileLayerGroup->setLayerTweaker(std::make_shared<RasterLayerTweaker>(evaluatedProperties));
}
#endif
}
bool RenderRasterLayer::hasTransition() const {
@@ -60,6 +65,7 @@ bool RenderRasterLayer::hasCrossfade() const {
return false;
}
#if MLN_LEGACY_RENDERER
static float saturationFactor(float saturation) {
if (saturation > 0) {
return 1.f - 1.f / (1.001f - saturation);
@@ -84,6 +90,7 @@ static std::array<float, 3> spinWeights(float spin) {
{(2 * c + 1) / 3, (-std::sqrt(3.0f) * s - c + 1) / 3, (std::sqrt(3.0f) * s - c + 1) / 3}};
return spin_weights;
}
#endif
void RenderRasterLayer::prepare(const LayerPrepareParameters& params) {
renderTiles = params.source->getRenderTiles();
@@ -92,6 +99,7 @@ void RenderRasterLayer::prepare(const LayerPrepareParameters& params) {
assert(renderTiles || imageData || !params.source->isEnabled());
}
#if MLN_LEGACY_RENDERER
void RenderRasterLayer::render(PaintParameters& parameters) {
if (parameters.pass != RenderPass::Translucent || (!renderTiles && !imageData)) {
return;
@@ -206,7 +214,9 @@ void RenderRasterLayer::render(PaintParameters& parameters) {
}
}
}
#endif // MLN_LEGACY_RENDERER
#if MLN_DRAWABLE_RENDERER
void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context,
const TransformState& /*state*/,
@@ -445,5 +455,6 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
}
}
}
#endif // MLN_DRAWABLE_RENDERER
} // namespace mbgl

View File

@@ -15,12 +15,14 @@ public:
explicit RenderRasterLayer(Immutable<style::RasterLayer::Impl>);
~RenderRasterLayer() override;
#if MLN_DRAWABLE_RENDERER
/// Generate any changes needed by the layer
void update(gfx::ShaderRegistry&,
gfx::Context&,
const TransformState&,
const RenderTree&,
UniqueChangeRequestVec&) override;
#endif
private:
void transition(const TransitionParameters&) override;
@@ -28,17 +30,24 @@ private:
bool hasTransition() const override;
bool hasCrossfade() const override;
void prepare(const LayerPrepareParameters&) override;
#if MLN_LEGACY_RENDERER
void render(PaintParameters&) override;
#endif
// Paint properties
style::RasterPaintProperties::Unevaluated unevaluated;
const ImageSourceRenderData* imageData = nullptr;
#if MLN_LEGACY_RENDERER
// Programs
std::shared_ptr<RasterProgram> rasterProgram;
#endif
#if MLN_DRAWABLE_RENDERER
gfx::ShaderProgramBasePtr rasterShader;
LayerGroupPtr imageLayerGroup;
#endif
};
} // namespace mbgl

View File

@@ -1,7 +1,9 @@
#include <mbgl/renderer/pattern_atlas.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/gfx/context.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/texture2d.hpp>
#endif
namespace mbgl {
@@ -88,25 +90,40 @@ Size PatternAtlas::getPixelSize() const {
}
void PatternAtlas::upload([[maybe_unused]] gfx::UploadPass& uploadPass) {
#if MLN_DRAWABLE_RENDERER
if (!atlasTexture2D) {
atlasTexture2D = uploadPass.getContext().createTexture2D();
atlasTexture2D->upload(atlasImage);
} else if (dirty) {
atlasTexture2D->upload(atlasImage);
}
#else
if (!atlasTexture) {
atlasTexture = uploadPass.createTexture(atlasImage);
} else if (dirty) {
uploadPass.updateTexture(*atlasTexture, atlasImage);
}
#endif
dirty = false;
}
// @note: Deprecated
gfx::TextureBinding PatternAtlas::textureBinding() const {
#if MLN_DRAWABLE_RENDERER
assert(atlasTexture2D);
assert(!dirty);
return {atlasTexture2D->getResource(), gfx::TextureFilterType::Linear};
#else
assert(atlasTexture);
assert(!dirty);
return {atlasTexture->getResource(), gfx::TextureFilterType::Linear};
#endif
}
#if MLN_DRAWABLE_RENDERER
const std::shared_ptr<gfx::Texture2D>& PatternAtlas::texture() const {
return atlasTexture2D;
}
#endif
} // namespace mbgl

View File

@@ -15,7 +15,9 @@ template <class T>
class Actor;
namespace gfx {
#if MLN_DRAWABLE_RENDERER
class Texture2D;
#endif
class UploadPass;
} // namespace gfx
@@ -31,7 +33,9 @@ public:
void removePattern(const std::string&);
gfx::TextureBinding textureBinding() const; // @TODO: Migrate
#if MLN_DRAWABLE_RENDERER
const std::shared_ptr<gfx::Texture2D>& texture() const;
#endif
void upload(gfx::UploadPass&);
Size getPixelSize() const;
@@ -48,7 +52,11 @@ private:
mapbox::ShelfPack shelfPack;
std::unordered_map<std::string, Pattern> patterns;
PremultipliedImage atlasImage;
#if MLN_DRAWABLE_RENDERER
std::shared_ptr<gfx::Texture2D> atlasTexture2D{nullptr};
#else
std::optional<gfx::Texture> atlasTexture;
#endif
bool dirty = true;
};

View File

@@ -1,6 +1,4 @@
#include <mbgl/renderer/change_request.hpp>
#include <mbgl/renderer/render_layer.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_tile.hpp>
@@ -10,6 +8,10 @@
#include <mbgl/gfx/context.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/layer_group.hpp>
#endif
namespace mbgl {
using namespace style;
@@ -60,6 +62,7 @@ std::optional<Color> RenderLayer::getSolidBackground() const {
return std::nullopt;
}
#if MLN_DRAWABLE_RENDERER
void RenderLayer::layerRemoved(UniqueChangeRequestVec& changes) {
// Remove everything
if (tileLayerGroup) {
@@ -67,6 +70,7 @@ void RenderLayer::layerRemoved(UniqueChangeRequestVec& changes) {
tileLayerGroup.reset();
}
}
#endif
void RenderLayer::markContextDestroyed() {
// no-op
@@ -120,6 +124,7 @@ const LayerRenderData* RenderLayer::getRenderDataForPass(const RenderTile& tile,
return nullptr;
}
#if MLN_DRAWABLE_RENDERER
void RenderLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
stats.tileDrawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
}
@@ -158,5 +163,6 @@ void RenderLayer::markLayerRenderable(bool willRender, UniqueChangeRequestVec& c
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
}
}
#endif
} // namespace mbgl

View File

@@ -1,7 +1,9 @@
#pragma once
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable.hpp>
#include <mbgl/layout/layout.hpp>
#include <mbgl/renderer/change_request.hpp>
#endif
#include <mbgl/layout/layout.hpp>
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/style/layer_properties.hpp>
@@ -14,7 +16,6 @@
namespace mbgl {
class Bucket;
class ChangeRequest;
class DynamicFeatureIndex;
class LineAtlas;
class PropertyEvaluationParameters;
@@ -23,22 +24,28 @@ class PatternAtlas;
class RenderTile;
class RenderTree;
class SymbolBucket;
class TileLayerGroup;
class TransformState;
class TransitionParameters;
class UploadParameters;
#if MLN_DRAWABLE_RENDERER
class ChangeRequest;
class TileLayerGroup;
using TileLayerGroupPtr = std::shared_ptr<TileLayerGroup>;
using UniqueChangeRequest = std::unique_ptr<ChangeRequest>;
using UniqueChangeRequestVec = std::vector<UniqueChangeRequest>;
#endif
namespace gfx {
class Context;
class ShaderGroup;
class ShaderRegistry;
class UniformBuffer;
using ShaderGroupPtr = std::shared_ptr<ShaderGroup>;
#if MLN_DRAWABLE_RENDERER
class UniformBuffer;
using UniformBufferPtr = std::shared_ptr<UniformBuffer>;
#endif
} // namespace gfx
class LayerRenderData {
@@ -118,7 +125,7 @@ public:
bool supportsZoom(float zoom) const;
virtual void upload(gfx::UploadPass&) {}
virtual void render(PaintParameters&) = 0;
virtual void render(PaintParameters&){};
// Check wether the given geometry intersects
// with the feature
@@ -148,6 +155,7 @@ public:
// TODO: Only for background layers.
virtual std::optional<Color> getSolidBackground() const;
#if MLN_DRAWABLE_RENDERER
/// Generate any changes needed by the layer
virtual void update(
gfx::ShaderRegistry&, gfx::Context&, const TransformState&, const RenderTree&, UniqueChangeRequestVec&) {}
@@ -165,6 +173,7 @@ public:
/// @param willRender Indicates if this layer should render or not
/// @param changes The collection of current pending change requests
virtual void markLayerRenderable(bool willRender, UniqueChangeRequestVec& changes);
#endif
protected:
// Checks whether the current hardware can render this layer. If it can't,
@@ -175,11 +184,13 @@ protected:
const LayerRenderData* getRenderDataForPass(const RenderTile&, RenderPass) const;
#if MLN_DRAWABLE_RENDERER
/// Remove all drawables for the tile from the layer group
void removeTile(RenderPass, const OverscaledTileID&);
/// Remove all the drawables for tiles
void removeAllTiles();
#endif
protected:
// Stores current set of tiles to be rendered for this layer.
@@ -191,7 +202,9 @@ protected:
LayerPlacementData placementData;
#if MLN_DRAWABLE_RENDERER
TileLayerGroupPtr tileLayerGroup;
#endif
// Current layer index as specified by the layerIndexChanged event
int32_t layerIndex{0};
// Current renderable status as specified by the markLayerRenderable event

View File

@@ -2,7 +2,9 @@
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/layermanager/layer_manager.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/change_request.hpp>
#endif
#include <mbgl/renderer/renderer_observer.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_layer.hpp>
@@ -222,13 +224,17 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
layerImpls = updateParameters->layers;
const bool layersAddedOrRemoved = !layerDiff.added.empty() || !layerDiff.removed.empty();
#if MLN_DRAWABLE_RENDERER
std::vector<std::unique_ptr<ChangeRequest>> changes;
#endif
// Remove render layers for removed layers.
for (const auto& entry : layerDiff.removed) {
const auto hit = renderLayers.find(entry.first);
if (hit != renderLayers.end()) {
#if MLN_DRAWABLE_RENDERER
hit->second->layerRemoved(changes);
#endif
renderLayers.erase(hit);
}
}
@@ -248,14 +254,16 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
if (layersAddedOrRemoved) {
orderedLayers.clear();
orderedLayers.reserve(layerImpls->size());
int32_t layerIndex = 0;
[[maybe_unused]] int32_t layerIndex = 0;
for (const auto& layerImpl : *layerImpls) {
RenderLayer* layer = renderLayers.at(layerImpl->id).get();
assert(layer);
orderedLayers.emplace_back(*layer);
#if MLN_DRAWABLE_RENDERER
// We're mutating the list of ordered layers and must notify them of their new assigned indices
layer->layerIndexChanged(layerIndex++, changes);
#endif
}
}
assert(orderedLayers.size() == renderLayers.size());
@@ -338,7 +346,6 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
}
}
}
continue;
}
@@ -360,6 +367,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
filteredLayersForSource.clear();
}
#if MLN_DRAWABLE_RENDERER
// Mark layers included in the renderable set as renderable
// @TODO: Optimize this logic, combine with the above
for (size_t i = 0; i < orderedLayers.size(); ++i) {
@@ -371,6 +379,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
// Add all change requests up to this point
addChanges(changes);
#endif
renderTreeParameters->loaded = updateParameters->styleLoaded && isLoaded();
if (!isMapModeContinuous && !renderTreeParameters->loaded) {
@@ -766,6 +775,7 @@ void RenderOrchestrator::clearData() {
glyphManager->evict(fontStacks(*layerImpls));
}
#if MLN_DRAWABLE_RENDERER
void RenderOrchestrator::addChanges(UniqueChangeRequestVec& changes) {
pendingChanges.insert(
pendingChanges.end(), std::make_move_iterator(changes.begin()), std::make_move_iterator(changes.end()));
@@ -879,6 +889,7 @@ void RenderOrchestrator::processChanges() {
void RenderOrchestrator::markLayerGroupOrderDirty() {
layerGroupOrderDirty = true;
}
#endif // MLN_DRAWABLE_RENDERER
void RenderOrchestrator::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
Log::Error(Event::Style, "Failed to load glyph range " + std::to_string(glyphRange.first) + "-" + std::to_string(glyphRange.second) +

View File

@@ -1,6 +1,7 @@
#pragma once
#if MLN_DRAWABLE_RENDERER
#include <mbgl/renderer/layer_group.hpp>
#endif
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
#include <mbgl/renderer/render_light.hpp>
@@ -21,8 +22,9 @@
#include <vector>
namespace mbgl {
#if MLN_DRAWABLE_RENDERER
class ChangeRequest;
#endif
class RendererObserver;
class RenderSource;
class UpdateParameters;
@@ -37,10 +39,11 @@ class CrossTileSymbolIndex;
class RenderTree;
namespace gfx {
class Drawable;
class ShaderRegistry;
#if MLN_DRAWABLE_RENDERER
class Drawable;
using DrawablePtr = std::shared_ptr<Drawable>;
#endif
} // namespace gfx
namespace style {
@@ -95,6 +98,7 @@ public:
void update(const std::shared_ptr<UpdateParameters>&);
#if MLN_DRAWABLE_RENDERER
bool addLayerGroup(LayerGroupBasePtr, bool replace);
bool removeLayerGroup(const int32_t layerIndex);
size_t numLayerGroups() const noexcept;
@@ -111,6 +115,7 @@ public:
void processChanges();
/// @brief Indicate that the orchestrator needs to re-sort layer groups when processing changes
void markLayerGroupOrderDirty();
#endif
const ZoomHistory& getZoomHistory() const { return zoomHistory; }
@@ -143,12 +148,14 @@ private:
void onStyleImageMissing(const std::string&, const std::function<void()>&) override;
void onRemoveUnusedStyleImages(const std::vector<std::string>&) override;
#if MLN_DRAWABLE_RENDERER
/// Move changes into the pending set, clearing the provided collection
void addChanges(UniqueChangeRequestVec&);
void onRemoveLayerGroup(LayerGroupBase&);
void updateLayerGroupOrder();
#endif
RendererObserver* observer;
@@ -181,11 +188,13 @@ private:
RenderLayerReferences orderedLayers;
RenderLayerReferences layersNeedPlacement;
#if MLN_DRAWABLE_RENDERER
std::vector<std::unique_ptr<ChangeRequest>> pendingChanges;
using LayerGroupMap = std::map<int32_t, LayerGroupBasePtr>;
LayerGroupMap layerGroupsByLayerIndex;
bool layerGroupOrderDirty = false;
#endif
};
} // namespace mbgl

View File

@@ -96,6 +96,7 @@ std::optional<ImagePosition> RenderTile::getPattern(const std::string& pattern)
return renderData->getPattern(pattern);
}
#if MLN_DRAWABLE_RENDERER
static const gfx::Texture2DPtr noTexture;
bool RenderTile::hasGlyphAtlasTexture() const {
@@ -129,6 +130,28 @@ const std::shared_ptr<TileAtlasTextures>& RenderTile::getAtlasTextures() const {
return renderData ? renderData->getAtlasTextures() : noAtlas;
}
#else
gfx::TextureBinding RenderTile::getGlyphAtlasTextureBinding(gfx::TextureFilterType filter) const {
assert(renderData);
return {getGlyphAtlasTexture()->getResource(), filter};
}
gfx::TextureBinding RenderTile::getIconAtlasTextureBinding(gfx::TextureFilterType filter) const {
assert(renderData);
return {getIconAtlasTexture()->getResource(), filter};
}
const gfx::Texture* RenderTile::getGlyphAtlasTexture() const {
assert(renderData);
return &renderData->getGlyphAtlasTexture();
}
const gfx::Texture* RenderTile::getIconAtlasTexture() const {
assert(renderData);
return &renderData->getIconAtlasTexture();
}
#endif
void RenderTile::upload(gfx::UploadPass& uploadPass) const {
assert(renderData);
renderData->upload(uploadPass);

View File

@@ -14,9 +14,12 @@
namespace mbgl {
namespace gfx {
#if MLN_DRAWABLE_RENDERER
class Texture2D;
class UploadPass;
using Texture2DPtr = std::shared_ptr<Texture2D>;
#endif
class UploadPass;
} // namespace gfx
class Bucket;
@@ -59,6 +62,7 @@ public:
const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const;
std::optional<ImagePosition> getPattern(const std::string& pattern) const;
#if MLN_DRAWABLE_RENDERER
bool hasGlyphAtlasTexture() const;
const gfx::Texture2DPtr& getGlyphAtlasTexture() const;
gfx::TextureBinding getGlyphAtlasTextureBinding(gfx::TextureFilterType) const;
@@ -68,6 +72,13 @@ public:
gfx::TextureBinding getIconAtlasTextureBinding(gfx::TextureFilterType) const;
const std::shared_ptr<TileAtlasTextures>& getAtlasTextures() const;
#else
gfx::TextureBinding getGlyphAtlasTextureBinding(gfx::TextureFilterType) const;
gfx::TextureBinding getIconAtlasTextureBinding(gfx::TextureFilterType) const;
const gfx::Texture* getGlyphAtlasTexture() const;
const gfx::Texture* getIconAtlasTexture() const;
#endif
void upload(gfx::UploadPass&) const;
void prepare(const SourcePrepareParameters&);

View File

@@ -1,6 +1,7 @@
#pragma once
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable.hpp>
#endif
#include <mbgl/renderer/paint_parameters.hpp>
#include <cassert>

View File

@@ -33,6 +33,7 @@ void Renderer::render(const std::shared_ptr<UpdateParameters>& updateParameters)
if (auto renderTree = impl->orchestrator.createRenderTree(updateParameters)) {
renderTree->prepare();
#if MLN_DRAWABLE_RENDERER
const auto& renderTreeParameters = renderTree->getParameters();
const auto& state = renderTreeParameters.transformParams.state;
@@ -41,6 +42,7 @@ void Renderer::render(const std::shared_ptr<UpdateParameters>& updateParameters)
auto& shaders = *impl->staticData->shaders;
impl->orchestrator.updateLayers(shaders, context, state, updateParameters, *renderTree);
}
#endif
impl->render(*renderTree);
}

View File

@@ -4,32 +4,37 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/drawable_tweaker.hpp>
#include <mbgl/gfx/render_pass.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/gl/drawable_gl.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/layer_tweaker.hpp>
#include <mbgl/renderer/pattern_atlas.hpp>
#include <mbgl/renderer/renderer_observer.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/renderer/render_tree.hpp>
#include <mbgl/shaders/gl/shader_program_gl.hpp>
#include <mbgl/util/convert.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/logging.hpp>
#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/drawable_tweaker.hpp>
#include <mbgl/gl/drawable_gl.hpp>
#include <mbgl/renderer/layer_tweaker.hpp>
#include <mbgl/shaders/gl/shader_program_gl.hpp>
#endif
#if (MLN_LEGACY_RENDERER && MLN_DRAWABLE_RENDERER)
// DEBUG: Enable a debugging split view to compare drawables and vanilla rendering pathways
// Drawables will be on the left, vanilla rendering on the right
// #define SPLIT_VIEW
// If using SPLIT_VIEW, QUAD_SPLIT_VIEW will split each half, showing just the opaque
// #define MLN_RENDERER_SPLIT_VIEW 1
// If using SPLIT_VIEW, MLN_RENDERER_QUAD_SPLIT_VIEW will split each half, showing just the opaque
// pass on top and then a composited opaque+translucent pass on the bottom
// #define QUAD_SPLIT_VIEW
#ifdef SPLIT_VIEW
#if MLN_RENDERER_SPLIT_VIEW
#include <mbgl/gl/context.hpp>
#endif
#endif
namespace mbgl {
@@ -74,9 +79,11 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
// Initialize legacy shader programs
staticData->programs.registerWith(*staticData->shaders);
#if MLN_DRAWABLE_RENDERER
// Initialize shaders for drawables
const auto programParameters = ProgramParameters{pixelRatio, false};
backend.initShaders(*staticData->shaders, programParameters);
#endif
// Notify post-shader registration
observer->onRegisterShaders(*staticData->shaders);
@@ -100,6 +107,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
const auto& sourceRenderItems = renderTree.getSourceRenderItems();
const auto& layerRenderItems = renderTree.getLayerRenderItems();
#if MLN_DRAWABLE_RENDERER
// Run changes
orchestrator.processChanges();
@@ -111,8 +119,9 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
});
// Give the layers a chance to do setup
// orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters);
// });
// orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.preRender(orchestrator, parameters);
// });
#endif
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
@@ -130,8 +139,10 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
renderTree.getLineAtlas().upload(*uploadPass);
renderTree.getPatternAtlas().upload(*uploadPass);
#if MLN_DRAWABLE_RENDERER
// Give the layers a chance to upload
orchestrator.observeLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); });
#endif
}
// - 3D PASS
@@ -152,6 +163,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
}
parameters.staticData.depthRenderbuffer->setShouldClear(true);
#if MLN_LEGACY_RENDERER
int32_t i = static_cast<int32_t>(layerRenderItems.size()) - 1;
for (auto it = layerRenderItems.begin(); it != layerRenderItems.end() && i >= 0; ++it, --i) {
parameters.currentLayer = i;
@@ -161,6 +173,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
renderItem.render(parameters);
}
}
#endif
}
// - CLEAR
@@ -179,7 +192,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
}
// Actually render the layers
#if MLN_DRAWABLE_RENDERER
// Drawables
const auto drawableOpaquePass = [&] {
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables-opaque"));
@@ -210,7 +223,9 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
}
});
};
#endif
#if MLN_LEGACY_RENDERER
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
const auto renderLayerOpaquePass = [&] {
const auto debugGroup(parameters.renderPass->createDebugGroup("opaque"));
@@ -246,8 +261,16 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
}
}
};
#endif // MLN_LEGACY_RENDERER
#ifdef SPLIT_VIEW
#if (MLN_DRAWABLE_RENDERER && !MLN_LEGACY_RENDERER)
drawableOpaquePass();
drawableTranslucentPass();
#elif (MLN_LEGACY_RENDERER && !MLN_DRAWABLE_RENDERER)
renderLayerOpaquePass();
renderLayerTranslucentPass();
#elif (MLN_DRAWABLE_RENDERER && MLN_LEGACY_RENDERER)
#if MLN_RENDERER_SPLIT_VIEW
[[maybe_unused]] const auto W = backend.getDefaultRenderable().getSize().width;
[[maybe_unused]] const auto H = backend.getDefaultRenderable().getSize().height;
[[maybe_unused]] const auto halfW = static_cast<platform::GLsizei>(backend.getDefaultRenderable().getSize().width *
@@ -255,7 +278,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
[[maybe_unused]] const auto halfH = static_cast<platform::GLsizei>(backend.getDefaultRenderable().getSize().height *
0.5f);
platform::glEnable(GL_SCISSOR_TEST);
#ifdef QUAD_SPLIT_VIEW
#if MLN_RENDERER_QUAD_SPLIT_VIEW
// Drawable LayerGroups on the left
// Opaque only on top
platform::glScissor(0, 0, halfW, H);
@@ -293,17 +316,21 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
// Reset viewport
platform::glScissor(0, 0, W, H);
platform::glDisable(GL_SCISSOR_TEST);
#else // ifdef SPLIT_VIEW
#else // ifdef MLN_RENDERER_SPLIT_VIEW
// Do RenderLayers first, drawables last
renderLayerOpaquePass();
drawableOpaquePass();
renderLayerTranslucentPass();
drawableOpaquePass();
drawableTranslucentPass();
#endif // MLN_RENDERER_SPLIT_VIEW
#else
static_assert(0, "Must define one of (MLN_DRAWABLE_RENDERER, MLN_LEGACY_RENDERER)");
#endif
// - DEBUG PASS --------------------------------------------------------------------------------
#if MLN_LEGACY_RENDERER
// - DEBUG PASS
// --------------------------------------------------------------------------------
// Renders debug overlays.
{
const auto debugGroup(parameters.renderPass->createDebugGroup("debug"));
@@ -326,10 +353,13 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
parameters.context.visualizeDepthBuffer(parameters.depthRangeSize);
}
#endif
#endif // MLN_LEGACY_RENDERER
#if MLN_DRAWABLE_RENDERER
// Give the layers a chance to do cleanup
orchestrator.observeLayerGroups(
[&](LayerGroupBase& layerGroup) { layerGroup.postRender(orchestrator, parameters); });
#endif
// Ends the RenderPass
parameters.renderPass.reset();

View File

@@ -9,6 +9,7 @@ TileRenderData::TileRenderData(std::shared_ptr<TileAtlasTextures> atlasTextures_
TileRenderData::~TileRenderData() = default;
#if MLN_DRAWABLE_RENDERER
static gfx::Texture2DPtr noTexture;
const gfx::Texture2DPtr& TileRenderData::getGlyphAtlasTexture() const {
@@ -18,6 +19,19 @@ const gfx::Texture2DPtr& TileRenderData::getGlyphAtlasTexture() const {
const gfx::Texture2DPtr& TileRenderData::getIconAtlasTexture() const {
return atlasTextures ? atlasTextures->icon : noTexture;
}
#else
const gfx::Texture& TileRenderData::getGlyphAtlasTexture() const {
assert(atlasTextures);
assert(atlasTextures->glyph);
return *atlasTextures->glyph;
}
const gfx::Texture& TileRenderData::getIconAtlasTexture() const {
assert(atlasTextures);
assert(atlasTextures->icon);
return *atlasTextures->icon;
}
#endif
std::optional<ImagePosition> TileRenderData::getPattern(const std::string&) const {
assert(false);

View File

@@ -10,9 +10,12 @@
namespace mbgl {
namespace gfx {
#if MLN_DRAWABLE_RENDERER
class Texture2D;
class UploadPass;
using Texture2DPtr = std::shared_ptr<gfx::Texture2D>;
#endif
class UploadPass;
} // namespace gfx
class Bucket;
@@ -21,15 +24,27 @@ class SourcePrepareParameters;
class TileAtlasTextures {
public:
#if MLN_DRAWABLE_RENDERER
gfx::Texture2DPtr glyph;
gfx::Texture2DPtr icon;
#else
std::optional<gfx::Texture> glyph;
std::optional<gfx::Texture> icon;
#endif
};
class TileRenderData {
public:
virtual ~TileRenderData();
#if MLN_DRAWABLE_RENDERER
const gfx::Texture2DPtr& getGlyphAtlasTexture() const;
const gfx::Texture2DPtr& getIconAtlasTexture() const;
#else
const gfx::Texture& getGlyphAtlasTexture() const;
const gfx::Texture& getIconAtlasTexture() const;
#endif
const std::shared_ptr<TileAtlasTextures>& getAtlasTextures() const { return atlasTextures; }
// To be implemented for concrete tile types.
virtual std::optional<ImagePosition> getPattern(const std::string&) const;

View File

@@ -87,24 +87,39 @@ void GeometryTileRenderData::upload(gfx::UploadPass& uploadPass) {
assert(atlasTextures);
if (layoutResult->glyphAtlasImage && layoutResult->glyphAtlasImage->valid()) {
#if MLN_DRAWABLE_RENDERER
atlasTextures->glyph = uploadPass.getContext().createTexture2D();
atlasTextures->glyph->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
atlasTextures->glyph->upload(*layoutResult->glyphAtlasImage);
#else
atlasTextures->glyph = uploadPass.createTexture(*layoutResult->glyphAtlasImage);
#endif
layoutResult->glyphAtlasImage = {};
}
if (layoutResult->iconAtlas.image.valid()) {
#if MLN_DRAWABLE_RENDERER
atlasTextures->icon = uploadPass.getContext().createTexture2D();
atlasTextures->icon->upload(layoutResult->iconAtlas.image);
#else
atlasTextures->icon = uploadPass.createTexture(layoutResult->iconAtlas.image);
#endif
layoutResult->iconAtlas.image = {};
}
if (atlasTextures->icon && !imagePatches.empty()) {
for (const auto& imagePatch : imagePatches) { // patch updated images.
#if MLN_DRAWABLE_RENDERER
atlasTextures->icon->uploadSubRegion(imagePatch.image->image,
imagePatch.paddedRect.x + ImagePosition::padding,
imagePatch.paddedRect.y + ImagePosition::padding);
#else
uploadPass.updateTextureSub(*atlasTextures->icon,
imagePatch.image->image,
imagePatch.paddedRect.x + ImagePosition::padding,
imagePatch.paddedRect.y + ImagePosition::padding);
#endif
}
imagePatches.clear();
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include <mbgl/util/size.hpp>
#include "quaternion.hpp"
#include <mbgl/util/quaternion.hpp>
#include <optional>

View File

@@ -1,4 +1,4 @@
#include "quaternion.hpp"
#include <mbgl/util/quaternion.hpp>
#include <cassert>
#include <cmath>

View File

@@ -1,7 +1,7 @@
#pragma once
#include "mat3.hpp"
#include "mat4.hpp"
#include <mbgl/util/mat3.hpp>
#include <mbgl/util/mat4.hpp>
namespace mbgl {
@@ -39,4 +39,4 @@ struct Quaternion {
bool operator==(const Quaternion&, const Quaternion&);
bool operator!=(const Quaternion&, const Quaternion&);
} // namespace mbgl
} // namespace mbgl