Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2023-05-12 17:11:05 +00:00
committed by Bart Louwers
parent 99af73ebaa
commit 722900a0f3
9 changed files with 26 additions and 29 deletions

View File

@@ -11,14 +11,13 @@ namespace gl {
class TileLayerGroupGL : public TileLayerGroup {
public:
TileLayerGroupGL(int32_t layerIndex, std::size_t initialCapacity);
~TileLayerGroupGL() override { }
~TileLayerGroupGL() override {}
void upload(gfx::Context&, gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;
protected:
};
} // namespace gl
} // namespace mbgl

View File

@@ -71,7 +71,7 @@ public:
RemoveLayerGroupRequest(const RemoveLayerGroupRequest &) = default;
void execute(RenderOrchestrator &) override;
protected:
int32_t layerIndex;
};

View File

@@ -75,7 +75,7 @@ public:
void observeDrawables(std::function<void(gfx::Drawable&)>) override;
void observeDrawables(std::function<void(const gfx::Drawable&)>) const override;
void observeDrawables(std::function<void(gfx::UniqueDrawable&)>) override;
void clearDrawables();
protected:

View File

@@ -115,7 +115,7 @@ public:
/// Get the generic shader with the specified name
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;
/// Create a layer group implementation
virtual TileLayerGroupPtr createTileLayerGroup(int32_t layerIndex, std::size_t initialCapacity) = 0;
};

View File

@@ -13,36 +13,35 @@ namespace mbgl {
namespace gl {
TileLayerGroupGL::TileLayerGroupGL(int32_t layerIndex, std::size_t initialCapacity)
: TileLayerGroup(layerIndex, initialCapacity) {
}
: TileLayerGroup(layerIndex, initialCapacity) {}
void TileLayerGroupGL::upload(gfx::Context& context, gfx::UploadPass& uploadPass) {
observeDrawables([&](gfx::Drawable& drawable) {
auto& drawableGL = static_cast<gl::DrawableGL&>(drawable);
const auto& shader = drawable.getShader();
// Generate a vertex array object for the drawable state, if necessary
if (shader && (!drawableGL.getVertexArray().isValid() || drawableGL.getVertexAttributes().isDirty())) {
const auto usage = gfx::BufferUsageType::StaticDraw;
// Build index buffer
const auto& indexData = drawable.getIndexData();
auto indexBuffer = gfx::IndexBuffer{
indexData.size(),
uploadPass.createIndexBufferResource(indexData.data(), indexData.size() * sizeof(indexData[0]), usage)};
// Apply drawable values to shader defaults
const auto& defaults = shader->getVertexAttributes();
const auto& overrides = drawable.getVertexAttributes();
const auto vertexCount = drawable.getVertexCount();
std::unique_ptr<gfx::VertexBufferResource> vertexBuffer;
auto bindings = uploadPass.buildAttributeBindings(vertexCount, defaults, overrides, usage, vertexBuffer);
auto& glContext = static_cast<gl::Context&>(context);
auto vertexArray = glContext.createVertexArray();
vertexArray.bind(glContext, indexBuffer, bindings);
glContext.bindVertexArray = gl::value::BindVertexArray::Default;
drawableGL.setVertexArray(std::move(vertexArray), std::move(vertexBuffer), std::move(indexBuffer));
}
});
@@ -87,7 +86,6 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
drawable.draw(parameters);
});
}
} // namespace gl
} // namespace mbgl

View File

@@ -93,7 +93,7 @@ void TileLayerGroup::observeDrawables(std::function<void(const gfx::Drawable&)>
}
void TileLayerGroup::observeDrawables(std::function<void(gfx::UniqueDrawable&)> f) {
for (auto i = impl->tileDrawables.begin(); i != impl->tileDrawables.end(); ) {
for (auto i = impl->tileDrawables.begin(); i != impl->tileDrawables.end();) {
auto& drawable = i->second;
if (drawable) {
f(drawable);

View File

@@ -216,7 +216,7 @@ void RenderBackgroundLayer::update(const int32_t layerIndex,
shader = context.getGenericShader(shaders, "BackgroundShader");
}
const auto removeAll = [&](){
const auto removeAll = [&]() {
if (tileLayerGroup) {
stats.tileDrawablesRemoved += tileLayerGroup->getDrawableCount();
tileLayerGroup->clearDrawables();
@@ -227,7 +227,7 @@ void RenderBackgroundLayer::update(const int32_t layerIndex,
const auto tileCover = util::tileCover(state, zoom);
// renderTiles is always empty, we use tileCover instead
//if (!renderTiles || renderTiles->empty()) {
// if (!renderTiles || renderTiles->empty()) {
if (tileCover.empty()) {
removeAll();
return;
@@ -309,7 +309,7 @@ void RenderBackgroundLayer::update(const int32_t layerIndex,
tileDrawable->mutableUniformBuffers().addOrReplace("BackgroundLayerUBO", uniformBuffer);
continue;
}
// We actually need to build things, so set up a builder if we haven't already
if (!builder) {
builder = context.createDrawableBuilder("background");
@@ -320,15 +320,15 @@ void RenderBackgroundLayer::update(const int32_t layerIndex,
builder->setDepthType(gfx::DepthMaskType::ReadWrite);
builder->setLayerIndex(layerIndex);
}
// Tile coordinates are fixed...
builder->addQuad(0, 0, util::EXTENT, util::EXTENT);
// ... they're placed with the matrix in the uniforms, which changes with the view
builder->setMatrix(/*parameters.matrixForTile(tileID.toUnwrapped())*/ matrix::identity4());
builder->flush();
auto newDrawables = builder->clearDrawables();
if (!newDrawables.empty()) {
auto& drawable = newDrawables[0];

View File

@@ -425,7 +425,7 @@ void RenderFillLayer::update(const int32_t layerIndex,
drawable->setTileID(tileID);
// Track it.
//tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
// tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
++stats.tileDrawablesAdded;
// Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " +
// std::to_string(stats.tileDrawablesAdded+1));

View File

@@ -180,7 +180,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
parameters.pass = RenderPass::Opaque;
parameters.currentLayer = 0;
parameters.opaquePassCutoff = 1;
// draw layer groups, opaque pass
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables-opaque"));
@@ -214,12 +214,12 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
parameters.pass = RenderPass::Translucent;
parameters.currentLayer = 1;
parameters.opaquePassCutoff = 1;
// draw layer groups, translucent pass
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables-translucent"));
orchestrator.observeLayerGroups([&](LayerGroup& layerGroup) { layerGroup.render(orchestrator, parameters); });
parameters.opaquePassCutoff = renderTreeParameters.opaquePassCutOff;
}