Drawable Renderer (#1570), Rebase on main.

Fix drawable ordering issue that was leading to rendering without setting up the VAO
This commit is contained in:
Tim Sylvester
2023-04-26 13:58:24 -07:00
committed by Bart Louwers
parent 107a4ef467
commit 3122f81328
9 changed files with 22 additions and 21 deletions

View File

@@ -38,7 +38,11 @@ public:
const std::vector<DrawablePtr>& getDrawables() const { return drawables; }
/// Get all the completed drawables and release ownership
std::vector<DrawablePtr> clearDrawables() { auto v = std::move(drawables); return v; }
std::vector<DrawablePtr> clearDrawables() {
std::vector<DrawablePtr> v = std::move(drawables);
drawables = {};
return v;
}
/// Get the ID of the drawable we're currently working on, if any
util::SimpleIdentity getDrawableId();

View File

@@ -13,7 +13,7 @@ class DrawableGLBuilder final : public gfx::DrawableBuilder {
public:
DrawableGLBuilder() {
}
virtual ~DrawableGLBuilder() = default;
~DrawableGLBuilder() override = default;
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
void setVertexAttributes(const VertexAttributeArrayGL& value) { vertexAttributes = value; }

View File

@@ -18,9 +18,9 @@ public:
DrawableGLTweaker() = default;
public:
virtual ~DrawableGLTweaker() = default;
~DrawableGLTweaker() override = default;
virtual void execute(gfx::Drawable&, const PaintParameters&) override;
void execute(gfx::Drawable&, const PaintParameters&) override;
};
} // namespace gl

View File

@@ -8,7 +8,7 @@ namespace mtl {
class ShaderProgramMTL : public gfx::ShaderProgramBase {
public:
ShaderProgramMTL() : ShaderProgramBase() { }
virtual ~ShaderProgramMTL() = default;
~ShaderProgramMTL() noexcept override = default;
static constexpr std::string_view Name{"GenericMTLShader"};
const std::string_view typeName() const noexcept override { return Name; }

View File

@@ -90,7 +90,7 @@ public:
public:
/// Activate the shader, vertex attributes, etc., specified by the drawable
virtual void setupDraw(const gfx::Drawable&) = 0;
virtual bool setupDraw(const gfx::Drawable&) = 0;
};
} // namespace gfx

View File

@@ -449,7 +449,7 @@ void Context::setDirtyState() {
globalVertexArrayState.setDirty();
}
void Context::setupDraw(const gfx::Drawable& drawable) {
bool Context::setupDraw(const gfx::Drawable& drawable) {
if (const auto &shader = drawable.getShader()) {
const auto& shaderGL = static_cast<const ShaderProgramGL&>(*shader);
if (shaderGL.getGLProgramID() != program.getCurrentValue()) {
@@ -471,11 +471,10 @@ void Context::setupDraw(const gfx::Drawable& drawable) {
auto& vao = drawableGL.getVertexArray();
if (vao.isValid()) {
bindVertexArray = vao.getID(); // glBindVertexArray
//vertexBuffer = static_cast<gl::VertexBufferResource&>(*drawableGL.getBuffer()).buffer.get();
//globalVertexArrayState.indexBuffer =
// drawableGL.getIndexBuffer().getResource<gl::IndexBufferResource>().buffer;
return true;
} else {
bindVertexArray = value::BindVertexArray::Default;
return false;
}
}

View File

@@ -104,7 +104,7 @@ public:
void setCleanupOnDestruction(bool cleanup) { cleanupOnDestruction = cleanup; }
void setupDraw(const gfx::Drawable&) override;
bool setupDraw(const gfx::Drawable&) override;
private:
RendererBackend& backend;

View File

@@ -88,6 +88,9 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
const auto& sourceRenderItems = renderTree.getSourceRenderItems();
const auto& layerRenderItems = renderTree.getLayerRenderItems();
// Run changes
orchestrator.processChanges();
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{
@@ -139,6 +142,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
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),
@@ -195,9 +199,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
parameters.depthRangeSize = 1 - (layerRenderItems.size() + 2) * parameters.numSublayers * parameters.depthEpsilon;
// Run changes
orchestrator.processChanges();
// - OPAQUE PASS -------------------------------------------------------------------------------
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
{
@@ -238,7 +239,9 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
for (const auto &pair : orchestrator.getDrawables()) {
const auto& drawable = *pair.second;
context.setupDraw(drawable);
if (!context.setupDraw(drawable)) {
continue;
}
mat4 matrix = drawable.getMatrix();
if (drawable.getTileID()) {
@@ -254,11 +257,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) {
}
drawable.draw(parameters);
//static_cast<gl::Context&>(context).program = 0;
//static_cast<gl::Context&>(context).bindVertexArray = 0;
//static_cast<gl::Context&>(context).vertexBuffer = 0;
//static_cast<gl::Context&>(context).globalVertexArrayState.indexBuffer = 0;
}
}

View File

@@ -4,7 +4,7 @@
namespace {
// This is not in the class declaration to minimize include dependencies
static std::atomic<std::int64_t> nextId = 1;
std::atomic<std::int64_t> nextId = 1;
} // anonymous namespace
namespace mbgl {