Isolated drawable/builder refactoring portion of the symbol work (#1252)
This commit is contained in:
committed by
Bart Louwers
parent
f3247dd6aa
commit
2c18d579cb
@@ -133,6 +133,10 @@ public:
|
||||
std::size_t vertexOffset,
|
||||
std::size_t vertexLength);
|
||||
|
||||
/// Provide raw data for vertices
|
||||
/// Incompatible with adding primitives
|
||||
void setRawVertices(std::vector<uint8_t>&&, std::size_t, AttributeDataType);
|
||||
|
||||
void setSegments(gfx::DrawMode, std::vector<uint16_t> indexes, const std::vector<SegmentBase>&);
|
||||
void setSegments(gfx::DrawMode, std::vector<uint16_t> indexes, const SegmentBase*, std::size_t segmentCount);
|
||||
|
||||
@@ -149,6 +153,8 @@ public:
|
||||
std::size_t baseIndex = 0);
|
||||
|
||||
protected:
|
||||
std::size_t curVertexCount() const;
|
||||
|
||||
/// Create an instance of the appropriate drawable type
|
||||
virtual UniqueDrawable createDrawable() const = 0;
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
struct DrawSegmentGL;
|
||||
void setIndexData(std::vector<std::uint16_t> indexes, std::vector<UniqueDrawSegment> segments);
|
||||
|
||||
void setVertices(std::vector<uint8_t>&&, std::size_t, gfx::AttributeDataType);
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override;
|
||||
void setVertexAttributes(const gfx::VertexAttributeArray& value) override;
|
||||
void setVertexAttributes(gfx::VertexAttributeArray&& value) override;
|
||||
@@ -47,6 +49,9 @@ public:
|
||||
const gfx::UniformBufferArray& getUniformBuffers() const override;
|
||||
gfx::UniformBufferArray& mutableUniformBuffers() override;
|
||||
|
||||
void setColorAttrName(std::string);
|
||||
void setVertexAttrName(std::string);
|
||||
|
||||
/// Reset a single color attribute for all vertexes
|
||||
void resetColor(const Color&) override;
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ const UniqueDrawable& DrawableBuilder::getCurrentDrawable(bool createIfNone) {
|
||||
}
|
||||
|
||||
void DrawableBuilder::flush() {
|
||||
if (!impl->vertices.empty()) {
|
||||
const auto vertexCount = curVertexCount();
|
||||
if (vertexCount) {
|
||||
const auto& draw = getCurrentDrawable(/*createIfNone=*/true);
|
||||
draw->setLineWidth(static_cast<int32_t>(lineWidth));
|
||||
draw->setNeedsStencil(needsStencil);
|
||||
@@ -57,11 +58,11 @@ void DrawableBuilder::flush() {
|
||||
if (auto& drawAttr = drawAttrs->getOrAdd(iName)) {
|
||||
if (iAttr.getCount() == 1) {
|
||||
// Apply the value to all vertexes
|
||||
for (std::size_t i = 0; i < impl->vertices.elements(); ++i) {
|
||||
for (std::size_t i = 0; i < vertexCount; ++i) {
|
||||
drawAttr->setVariant(i, iAttr.get(0));
|
||||
}
|
||||
} else if (iAttr.getCount() == impl->vertices.elements()) {
|
||||
for (std::size_t i = 0; i < impl->vertices.elements(); ++i) {
|
||||
} else if (iAttr.getCount() == vertexCount) {
|
||||
for (std::size_t i = 0; i < vertexCount; ++i) {
|
||||
drawAttr->setVariant(i, iAttr.get(i));
|
||||
}
|
||||
} else {
|
||||
@@ -167,6 +168,12 @@ std::size_t DrawableBuilder::addVertices(const std::vector<std::array<int16_t, 2
|
||||
return baseIndex;
|
||||
}
|
||||
|
||||
void DrawableBuilder::setRawVertices(std::vector<uint8_t>&& data, std::size_t count, AttributeDataType type) {
|
||||
impl->rawVertices = std::move(data);
|
||||
impl->rawVerticesCount = count;
|
||||
impl->rawVerticesType = type;
|
||||
}
|
||||
|
||||
void DrawableBuilder::setSegments(gfx::DrawMode mode,
|
||||
std::vector<uint16_t> indexes,
|
||||
const std::vector<SegmentBase>& segments) {
|
||||
@@ -186,10 +193,10 @@ void DrawableBuilder::setSegments(gfx::DrawMode mode,
|
||||
} else if (mode.type == DrawModeType::Lines) {
|
||||
assert(seg.indexLength % 2 == 0);
|
||||
}
|
||||
assert(seg.vertexOffset + seg.vertexLength <= impl->vertices.elements());
|
||||
assert(seg.vertexOffset + seg.vertexLength <= curVertexCount());
|
||||
assert(seg.indexOffset + seg.indexLength <= impl->indexes.size());
|
||||
for (decltype(seg.indexLength) j = 0; j < seg.indexLength; ++j) {
|
||||
assert(impl->indexes[seg.indexOffset + j] < impl->vertices.elements());
|
||||
assert(impl->indexes[seg.indexOffset + j] < curVertexCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -253,5 +260,9 @@ void DrawableBuilder::addTriangles(const std::vector<uint16_t>& indexes,
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t DrawableBuilder::curVertexCount() const {
|
||||
return impl->rawVerticesCount ? impl->rawVerticesCount : impl->vertices.elements();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -14,6 +14,9 @@ namespace gfx {
|
||||
struct DrawableBuilder::Impl {
|
||||
using VT = gfx::detail::VertexType<gfx::AttributeType<std::int16_t, 2>>;
|
||||
gfx::VertexVector<VT> vertices;
|
||||
std::vector<uint8_t> rawVertices;
|
||||
std::size_t rawVerticesCount = 0;
|
||||
AttributeDataType rawVerticesType = static_cast<AttributeDataType>(-1);
|
||||
std::vector<uint16_t> indexes;
|
||||
std::vector<std::unique_ptr<Drawable::DrawSegment>> segments;
|
||||
|
||||
|
||||
@@ -68,6 +68,9 @@ public:
|
||||
|
||||
virtual gfx::AttributeBindingArray buildAttributeBindings(
|
||||
const std::size_t vertexCount,
|
||||
const gfx::AttributeDataType vertexType,
|
||||
const std::size_t vertexAttributeIndex,
|
||||
const std::vector<std::uint8_t>& vertexData,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
gfx::BufferUsageType,
|
||||
|
||||
@@ -75,6 +75,12 @@ void DrawableGL::setIndexData(std::vector<std::uint16_t> indexes, std::vector<Un
|
||||
impl->segments = std::move(segments);
|
||||
}
|
||||
|
||||
void DrawableGL::setVertices(std::vector<uint8_t>&& data, std::size_t count, gfx::AttributeDataType type) {
|
||||
impl->vertexData = std::move(data);
|
||||
impl->vertexCount = count;
|
||||
impl->vertexType = type;
|
||||
}
|
||||
|
||||
const gfx::VertexAttributeArray& DrawableGL::getVertexAttributes() const {
|
||||
return impl->vertexAttributes;
|
||||
}
|
||||
@@ -98,8 +104,16 @@ gfx::UniformBufferArray& DrawableGL::mutableUniformBuffers() {
|
||||
return impl->uniformBuffers;
|
||||
}
|
||||
|
||||
void DrawableGL::setColorAttrName(std::string value) {
|
||||
impl->colorAttrName = std::move(value);
|
||||
}
|
||||
|
||||
void DrawableGL::setVertexAttrName(std::string value) {
|
||||
impl->vertexAttrName = std::move(value);
|
||||
}
|
||||
|
||||
void DrawableGL::resetColor(const Color& newColor) {
|
||||
if (const auto& colorAttr = impl->vertexAttributes.get("a_color")) {
|
||||
if (const auto& colorAttr = impl->vertexAttributes.get(impl->colorAttrName)) {
|
||||
colorAttr->clear();
|
||||
colorAttr->set(0, Drawable::colorAttrRGBA(newColor));
|
||||
}
|
||||
@@ -150,10 +164,19 @@ void DrawableGL::upload(gfx::UploadPass& uploadPass) {
|
||||
// Apply drawable values to shader defaults
|
||||
const auto& defaults = shader->getVertexAttributes();
|
||||
const auto& overrides = impl->vertexAttributes;
|
||||
const auto vertexCount = overrides.getMaxCount();
|
||||
|
||||
const auto& indexAttribute = defaults.get(impl->vertexAttrName);
|
||||
const auto vertexAttributeIndex = static_cast<std::size_t>(indexAttribute ? indexAttribute->getIndex() : -1);
|
||||
|
||||
std::unique_ptr<gfx::VertexBufferResource> vertexBuffer;
|
||||
auto bindings = uploadPass.buildAttributeBindings(vertexCount, defaults, overrides, usage, vertexBuffer);
|
||||
auto bindings = uploadPass.buildAttributeBindings(impl->vertexCount,
|
||||
impl->vertexType,
|
||||
vertexAttributeIndex,
|
||||
impl->vertexData,
|
||||
defaults,
|
||||
overrides,
|
||||
usage,
|
||||
vertexBuffer);
|
||||
|
||||
impl->attributeBuffer = std::move(vertexBuffer);
|
||||
impl->indexBuffer = std::move(indexBuffer);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <mbgl/gl/drawable_gl_impl.hpp>
|
||||
#include <mbgl/util/convert.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
|
||||
@@ -20,13 +22,21 @@ std::unique_ptr<gfx::Drawable::DrawSegment> DrawableGLBuilder::createSegment(gfx
|
||||
void DrawableGLBuilder::init() {
|
||||
auto& drawableGL = static_cast<DrawableGL&>(*currentDrawable);
|
||||
|
||||
auto& attrs = drawableGL.mutableVertexAttributes();
|
||||
if (const auto& posAttr = attrs.getOrAdd(vertexAttrName)) {
|
||||
std::size_t index = 0;
|
||||
for (const auto& vert : impl->vertices.vector()) {
|
||||
posAttr->set(index++, gfx::VertexAttribute::int2{vert.a1[0], vert.a1[1]});
|
||||
}
|
||||
drawableGL.setColorAttrName(colorAttrName);
|
||||
drawableGL.setVertexAttrName(vertexAttrName);
|
||||
|
||||
if (impl->rawVerticesCount) {
|
||||
auto raw = impl->rawVertices;
|
||||
drawableGL.setVertices(std::move(raw), impl->rawVerticesCount, impl->rawVerticesType);
|
||||
} else {
|
||||
const auto& verts = impl->vertices.vector();
|
||||
constexpr auto vertSize = sizeof(std::remove_reference<decltype(verts)>::type::value_type);
|
||||
std::vector<uint8_t> raw(verts.size() * vertSize);
|
||||
std::memcpy(raw.data(), verts.data(), raw.size());
|
||||
drawableGL.setVertices(std::move(raw), verts.size(), gfx::AttributeDataType::Short2);
|
||||
}
|
||||
|
||||
auto& attrs = drawableGL.mutableVertexAttributes();
|
||||
if (colorAttrMode != ColorAttrMode::None && !colorAttrName.empty()) {
|
||||
if (const auto& colorAttr = attrs.getOrAdd(colorAttrName)) {
|
||||
// We should have either a single color or one per vertex. Otherwise,
|
||||
|
||||
@@ -34,6 +34,10 @@ public:
|
||||
|
||||
std::vector<std::uint16_t> indexes;
|
||||
|
||||
std::vector<std::uint8_t> vertexData;
|
||||
std::size_t vertexCount = 0;
|
||||
gfx::AttributeDataType vertexType = static_cast<gfx::AttributeDataType>(-1);
|
||||
|
||||
VertexAttributeArrayGL vertexAttributes;
|
||||
|
||||
gfx::IndexBuffer indexBuffer = {0, nullptr};
|
||||
@@ -46,6 +50,9 @@ public:
|
||||
gfx::ColorMode colorMode;
|
||||
gfx::CullFaceMode cullFaceMode;
|
||||
GLfloat pointSize = 0.0f;
|
||||
|
||||
std::string vertexAttrName = "a_pos";
|
||||
std::string colorAttrName = "a_color";
|
||||
};
|
||||
|
||||
struct DrawableGL::DrawSegmentGL final : public gfx::Drawable::DrawSegment {
|
||||
|
||||
@@ -96,7 +96,11 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar
|
||||
shaders::BuiltIn::FillOutlineShader,
|
||||
shaders::BuiltIn::FillOutlinePatternShader,
|
||||
shaders::BuiltIn::FillPatternShader,
|
||||
shaders::BuiltIn::RasterShader>(shaders, programParameters);
|
||||
shaders::BuiltIn::RasterShader,
|
||||
shaders::BuiltIn::SymbolIconShader,
|
||||
shaders::BuiltIn::SymbolSDFTextShader,
|
||||
shaders::BuiltIn::SymbolSDFIconShader,
|
||||
shaders::BuiltIn::SymbolTextAndIconShader>(shaders, programParameters);
|
||||
}
|
||||
|
||||
} // namespace gl
|
||||
|
||||
@@ -135,6 +135,9 @@ static std::size_t pad(std::vector<T>& vector, std::size_t size, T value) {
|
||||
|
||||
gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
const std::size_t vertexCount,
|
||||
const gfx::AttributeDataType vertexType,
|
||||
const std::size_t vertexAttributeIndex,
|
||||
const std::vector<std::uint8_t>& vertexData,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
const gfx::BufferUsageType usage,
|
||||
@@ -146,16 +149,35 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
constexpr std::uint8_t padding = 0;
|
||||
|
||||
std::vector<std::uint8_t> allData;
|
||||
allData.reserve(defaults.getTotalSize() * vertexCount);
|
||||
allData.reserve(vertexData.size() + (defaults.getTotalSize() + align) * vertexCount);
|
||||
|
||||
uint32_t vertexStride = 0;
|
||||
if (vertexAttributeIndex != static_cast<std::size_t>(-1)) {
|
||||
// Fill in vertices
|
||||
allData.insert(allData.end(), vertexData.begin(), vertexData.end());
|
||||
bindings.resize(vertexAttributeIndex + 1);
|
||||
vertexStride = static_cast<uint32_t>(vertexData.size() / vertexCount);
|
||||
bindings[vertexAttributeIndex] = {
|
||||
/*.attribute = */ {vertexType, 0},
|
||||
/* vertexStride = */ vertexStride,
|
||||
/* vertexBufferResource = */ nullptr, // buffer details established later
|
||||
/* vertexOffset = */ 0,
|
||||
};
|
||||
}
|
||||
|
||||
// For each attribute in the program, with the corresponding default and optional override...
|
||||
uint32_t vertexStride = 0;
|
||||
const auto resolveAttr = [&](const std::string& name, const auto& defaultAttr, const auto& overrideAttr) -> void {
|
||||
const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr;
|
||||
const auto& effectiveGL = static_cast<const gl::VertexAttributeGL&>(effectiveAttr);
|
||||
const auto& defaultGL = static_cast<const gl::VertexAttributeGL&>(defaultAttr);
|
||||
const auto stride = defaultAttr.getStride();
|
||||
const auto offset = static_cast<uint32_t>(allData.size());
|
||||
const auto index = static_cast<std::size_t>(defaultGL.getIndex());
|
||||
|
||||
if (index == vertexAttributeIndex) {
|
||||
// already handled
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the raw data for the values in the desired format
|
||||
const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType());
|
||||
@@ -178,7 +200,6 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
|
||||
return;
|
||||
}
|
||||
|
||||
const auto index = static_cast<std::size_t>(defaultGL.getIndex());
|
||||
bindings.resize(std::max(bindings.size(), index + 1));
|
||||
bindings[index] = {
|
||||
/*.attribute = */ {defaultAttr.getDataType(), offset},
|
||||
|
||||
@@ -40,6 +40,9 @@ public:
|
||||
|
||||
gfx::AttributeBindingArray buildAttributeBindings(
|
||||
const std::size_t vertexCount,
|
||||
const gfx::AttributeDataType vertexType,
|
||||
const std::size_t vertexAttributeIndex,
|
||||
const std::vector<std::uint8_t>& vertexData,
|
||||
const gfx::VertexAttributeArray& defaults,
|
||||
const gfx::VertexAttributeArray& overrides,
|
||||
gfx::BufferUsageType,
|
||||
|
||||
@@ -197,14 +197,6 @@ void RenderBackgroundLayer::prepare(const LayerPrepareParameters& params) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderBackgroundLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
// Remove everything
|
||||
if (tileLayerGroup) {
|
||||
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
|
||||
tileLayerGroup.reset();
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr std::string_view BackgroundPlainShaderName = "BackgroundShader";
|
||||
static constexpr std::string_view BackgroundPatternShaderName = "BackgroundPatternShader";
|
||||
|
||||
@@ -215,19 +207,12 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
const auto removeAll = [&]() {
|
||||
if (tileLayerGroup) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
|
||||
tileLayerGroup->clearDrawables();
|
||||
}
|
||||
};
|
||||
|
||||
const auto zoom = state.getIntegerZoom();
|
||||
const auto tileCover = util::tileCover(state, zoom);
|
||||
|
||||
// renderTiles is always empty, we use tileCover instead
|
||||
if (tileCover.empty()) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -245,7 +230,7 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
|
||||
|
||||
// If the result is transparent or missing, just remove any existing drawables and stop
|
||||
if (drawPasses == RenderPass::None) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -266,7 +251,7 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
|
||||
|
||||
const auto& curShader = hasPattern ? patternShader : plainShader;
|
||||
if (!curShader) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ public:
|
||||
explicit RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl>);
|
||||
~RenderBackgroundLayer() override;
|
||||
|
||||
void layerRemoved(UniqueChangeRequestVec&) override;
|
||||
|
||||
/// Generate any changes needed by the layer
|
||||
void update(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
|
||||
@@ -245,18 +245,6 @@ bool RenderCircleLayer::queryIntersectsFeature(const GeometryCoordinates& queryG
|
||||
return false;
|
||||
}
|
||||
|
||||
void RenderCircleLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
// Remove everything
|
||||
if (tileLayerGroup) {
|
||||
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
|
||||
tileLayerGroup.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCircleLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
|
||||
}
|
||||
|
||||
struct alignas(16) CircleInterpolateUBO {
|
||||
float color_t;
|
||||
float radius_t;
|
||||
@@ -276,18 +264,11 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context& context,
|
||||
const TransformState& state,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
UniqueChangeRequestVec& /*changes*/) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
const auto removeAll = [&]() {
|
||||
if (tileLayerGroup) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
|
||||
tileLayerGroup->clearDrawables();
|
||||
}
|
||||
};
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -298,14 +279,13 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
return;
|
||||
}
|
||||
tileLayerGroup->setLayerTweaker(std::make_shared<CircleLayerTweaker>(evaluatedProperties));
|
||||
changes.emplace_back(std::make_unique<AddLayerGroupRequest>(tileLayerGroup, /*canReplace=*/true));
|
||||
}
|
||||
|
||||
if (!circleShaderGroup) {
|
||||
circleShaderGroup = shaders.getShaderGroup(CircleShaderGroupName);
|
||||
}
|
||||
if (!circleShaderGroup) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ public:
|
||||
explicit RenderCircleLayer(Immutable<style::CircleLayer::Impl>);
|
||||
~RenderCircleLayer() final = default;
|
||||
|
||||
void layerRemoved(UniqueChangeRequestVec&) override;
|
||||
|
||||
/// Generate any changes needed by the layer
|
||||
void update(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
@@ -37,9 +35,6 @@ private:
|
||||
const mat4&,
|
||||
const FeatureState&) const override;
|
||||
|
||||
/// Remove all drawables for the tile from the layer group
|
||||
void removeTile(RenderPass, const OverscaledTileID&);
|
||||
|
||||
// Paint properties
|
||||
style::CirclePaintProperties::Unevaluated unevaluated;
|
||||
|
||||
|
||||
@@ -273,18 +273,6 @@ bool RenderFillLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeo
|
||||
feature.getGeometries());
|
||||
}
|
||||
|
||||
void RenderFillLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
// Remove everything
|
||||
if (tileLayerGroup) {
|
||||
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
|
||||
tileLayerGroup.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderFillLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
|
||||
}
|
||||
|
||||
void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context& context,
|
||||
const TransformState& state,
|
||||
@@ -293,9 +281,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
if (tileLayerGroup) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->clearDrawables();
|
||||
}
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,13 +294,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
tileLayerGroup->setLayerTweaker(std::make_shared<FillLayerTweaker>(evaluatedProperties));
|
||||
}
|
||||
|
||||
const auto removeAll = [&]() {
|
||||
if (tileLayerGroup) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
|
||||
tileLayerGroup->clearDrawables();
|
||||
}
|
||||
};
|
||||
|
||||
if (!fillShaderGroup) {
|
||||
fillShaderGroup = shaders.getShaderGroup(std::string(FillShaderName));
|
||||
}
|
||||
@@ -328,7 +307,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
outlinePatternShaderGroup = shaders.getShaderGroup(std::string(FillOutlinePatternShaderName));
|
||||
}
|
||||
if (!fillShaderGroup || !outlineShaderGroup || !patternShaderGroup || !outlinePatternShaderGroup) {
|
||||
removeAll();
|
||||
removeAllTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -342,7 +321,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
std::unique_ptr<gfx::DrawableBuilder> outlineBuilder;
|
||||
std::unique_ptr<gfx::DrawableBuilder> patternBuilder;
|
||||
std::unique_ptr<gfx::DrawableBuilder> outlinePatternBuilder;
|
||||
std::vector<gfx::DrawablePtr> newTiles;
|
||||
gfx::VertexAttributeArray fillVertexAttrs;
|
||||
gfx::VertexAttributeArray outlineVertexAttrs;
|
||||
gfx::VertexAttributeArray patternVertexAttrs;
|
||||
|
||||
@@ -14,16 +14,12 @@ class FillProgram;
|
||||
class FillPatternProgram;
|
||||
class FillOutlineProgram;
|
||||
class FillOutlinePatternProgram;
|
||||
class TileLayerGroup;
|
||||
using TileLayerGroupPtr = std::shared_ptr<TileLayerGroup>;
|
||||
|
||||
class RenderFillLayer final : public RenderLayer {
|
||||
public:
|
||||
explicit RenderFillLayer(Immutable<style::FillLayer::Impl>);
|
||||
~RenderFillLayer() override;
|
||||
|
||||
void layerRemoved(UniqueChangeRequestVec&) override;
|
||||
|
||||
/// Generate any changes needed by the layer
|
||||
void update(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
@@ -46,9 +42,6 @@ private:
|
||||
const mat4&,
|
||||
const FeatureState&) const override;
|
||||
|
||||
/// Remove all drawables for the tile from the layer group
|
||||
void removeTile(RenderPass, const OverscaledTileID&);
|
||||
|
||||
// Paint properties
|
||||
style::FillPaintProperties::Unevaluated unevaluated;
|
||||
|
||||
|
||||
@@ -207,18 +207,6 @@ void RenderRasterLayer::render(PaintParameters& parameters) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderRasterLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
// Remove everything
|
||||
if (tileLayerGroup) {
|
||||
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
|
||||
tileLayerGroup.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderRasterLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
|
||||
}
|
||||
|
||||
void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context& context,
|
||||
const TransformState& /*state*/,
|
||||
@@ -395,7 +383,6 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
// Set up a layer group
|
||||
imageLayerGroup = context.createLayerGroup(layerIndex, /*initialCapacity=*/64, getID());
|
||||
imageLayerGroup->setLayerTweaker(std::make_shared<RasterLayerTweaker>(evaluatedProperties));
|
||||
changes.emplace_back(std::make_unique<AddLayerGroupRequest>(imageLayerGroup, /*canReplace=*/true));
|
||||
}
|
||||
|
||||
auto builder = createBuilder();
|
||||
@@ -431,7 +418,6 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
// Set up a tile layer group
|
||||
tileLayerGroup = context.createTileLayerGroup(layerIndex, /*initialCapacity=*/64, getID());
|
||||
tileLayerGroup->setLayerTweaker(std::make_shared<RasterLayerTweaker>(evaluatedProperties));
|
||||
changes.emplace_back(std::make_unique<AddLayerGroupRequest>(tileLayerGroup, /*canReplace=*/true));
|
||||
}
|
||||
|
||||
auto builder = createBuilder();
|
||||
|
||||
@@ -15,8 +15,6 @@ public:
|
||||
explicit RenderRasterLayer(Immutable<style::RasterLayer::Impl>);
|
||||
~RenderRasterLayer() override;
|
||||
|
||||
void layerRemoved(UniqueChangeRequestVec&) override;
|
||||
|
||||
/// Generate any changes needed by the layer
|
||||
void update(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
@@ -32,9 +30,6 @@ private:
|
||||
void prepare(const LayerPrepareParameters&) override;
|
||||
void render(PaintParameters&) override;
|
||||
|
||||
/// Remove all drawables for the tile from the layer group
|
||||
void removeTile(RenderPass, const OverscaledTileID&);
|
||||
|
||||
// Paint properties
|
||||
style::RasterPaintProperties::Unevaluated unevaluated;
|
||||
const ImageSourceRenderData* imageData = nullptr;
|
||||
|
||||
@@ -60,6 +60,14 @@ std::optional<Color> RenderLayer::getSolidBackground() const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void RenderLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
// Remove everything
|
||||
if (tileLayerGroup) {
|
||||
changes.emplace_back(std::make_unique<RemoveLayerGroupRequest>(tileLayerGroup->getLayerIndex()));
|
||||
tileLayerGroup.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderLayer::markContextDestroyed() {
|
||||
// no-op
|
||||
}
|
||||
@@ -112,6 +120,17 @@ const LayerRenderData* RenderLayer::getRenderDataForPass(const RenderTile& tile,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RenderLayer::removeTile(RenderPass renderPass, const OverscaledTileID& tileID) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->removeDrawables(renderPass, tileID).size();
|
||||
}
|
||||
|
||||
void RenderLayer::removeAllTiles() {
|
||||
if (tileLayerGroup) {
|
||||
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
|
||||
tileLayerGroup->clearDrawables();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderLayer::layerIndexChanged(int32_t newLayerIndex, UniqueChangeRequestVec& changes) {
|
||||
layerIndex = newLayerIndex;
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
virtual void update(
|
||||
gfx::ShaderRegistry&, gfx::Context&, const TransformState&, const RenderTree&, UniqueChangeRequestVec&) {}
|
||||
|
||||
virtual void layerRemoved(UniqueChangeRequestVec&) {}
|
||||
virtual void layerRemoved(UniqueChangeRequestVec&);
|
||||
|
||||
/// @brief Called by the RenderOrchestrator during RenderTree construction.
|
||||
/// This event is run when a layer is added or removed from the style.
|
||||
@@ -175,6 +175,12 @@ protected:
|
||||
|
||||
const LayerRenderData* getRenderDataForPass(const RenderTile&, RenderPass) const;
|
||||
|
||||
/// Remove all drawables for the tile from the layer group
|
||||
void removeTile(RenderPass, const OverscaledTileID&);
|
||||
|
||||
/// Remove all the drawables for tiles
|
||||
void removeAllTiles();
|
||||
|
||||
protected:
|
||||
// Stores current set of tiles to be rendered for this layer.
|
||||
RenderTiles renderTiles;
|
||||
|
||||
@@ -772,25 +772,6 @@ void RenderOrchestrator::addChanges(UniqueChangeRequestVec& changes) {
|
||||
changes.clear();
|
||||
}
|
||||
|
||||
void RenderOrchestrator::addDrawable(gfx::DrawablePtr drawable) {
|
||||
if (drawable) {
|
||||
const auto& id = drawable->getId();
|
||||
if (!drawables.insert(std::make_pair(id, std::move(drawable))).second) {
|
||||
Log::Warning(Event::General, "Duplicate drawable " + std::to_string(id) + " ignored");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderOrchestrator::removeDrawable(const util::SimpleIdentity& drawableId) {
|
||||
drawables.erase(drawableId);
|
||||
}
|
||||
|
||||
const gfx::DrawablePtr noDrawable;
|
||||
const gfx::DrawablePtr& RenderOrchestrator::getDrawable(const util::SimpleIdentity& id) {
|
||||
const auto hit = drawables.find(id);
|
||||
return (hit != drawables.end()) ? hit->second : noDrawable;
|
||||
}
|
||||
|
||||
void RenderOrchestrator::onRemoveLayerGroup(LayerGroupBase&) {}
|
||||
|
||||
void RenderOrchestrator::updateLayerGroupOrder() {
|
||||
|
||||
@@ -95,14 +95,6 @@ public:
|
||||
|
||||
void update(const std::shared_ptr<UpdateParameters>&);
|
||||
|
||||
using DrawableMap = std::map<util::SimpleIdentity, gfx::DrawablePtr>;
|
||||
const DrawableMap& getDrawables() const { return drawables; }
|
||||
|
||||
void addDrawable(gfx::DrawablePtr);
|
||||
void removeDrawable(const util::SimpleIdentity& drawableId);
|
||||
|
||||
const gfx::DrawablePtr& getDrawable(const util::SimpleIdentity&);
|
||||
|
||||
bool addLayerGroup(LayerGroupBasePtr, bool replace);
|
||||
bool removeLayerGroup(const int32_t layerIndex);
|
||||
size_t numLayerGroups() const noexcept;
|
||||
@@ -189,7 +181,6 @@ private:
|
||||
RenderLayerReferences orderedLayers;
|
||||
RenderLayerReferences layersNeedPlacement;
|
||||
|
||||
DrawableMap drawables;
|
||||
std::vector<std::unique_ptr<ChangeRequest>> pendingChanges;
|
||||
|
||||
using LayerGroupMap = std::map<int32_t, LayerGroupBasePtr>;
|
||||
|
||||
Reference in New Issue
Block a user