Shared attributes (#1898)

This commit is contained in:
Tim Sylvester
2023-11-28 18:57:51 -08:00
committed by GitHub
parent 5c86aee31a
commit fa9712cd8f
35 changed files with 290 additions and 346 deletions

View File

@@ -40,6 +40,7 @@ using DrawableTweakerPtr = std::shared_ptr<DrawableTweaker>;
using IndexVectorBasePtr = std::shared_ptr<IndexVectorBase>;
using ShaderProgramBasePtr = std::shared_ptr<ShaderProgramBase>;
using Texture2DPtr = std::shared_ptr<Texture2D>;
using VertexAttributeArrayPtr = std::shared_ptr<VertexAttributeArray>;
class Drawable {
public:
@@ -188,16 +189,10 @@ public:
virtual void setColorMode(const gfx::ColorMode&);
/// Get the vertex attributes that override default values in the shader program
virtual const gfx::VertexAttributeArray& getVertexAttributes() const = 0;
/// Get the mutable vertex attribute array
virtual gfx::VertexAttributeArray& mutableVertexAttributes() = 0;
const gfx::VertexAttributeArrayPtr& getVertexAttributes() const noexcept { return vertexAttributes; }
/// Set vertex attribute array
virtual void setVertexAttributes(const gfx::VertexAttributeArray&) = 0;
/// Set vertex attribute array
virtual void setVertexAttributes(gfx::VertexAttributeArray&&) = 0;
void setVertexAttributes(gfx::VertexAttributeArrayPtr value) noexcept { vertexAttributes = std::move(value); }
/// Provide raw data for vertices. Incompatible with adding primitives
virtual void setVertices(std::vector<uint8_t>&&, std::size_t, AttributeDataType) = 0;
@@ -259,6 +254,7 @@ protected:
int32_t subLayerIndex = 0;
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
UniqueDrawableData drawableData{};
gfx::VertexAttributeArrayPtr vertexAttributes;
struct Impl;
std::unique_ptr<Impl> impl;

View File

@@ -42,7 +42,7 @@ public:
UniqueDrawable& getCurrentDrawable(bool createIfNone);
/// Close the current drawable, using a new one for any further work
void flush();
void flush(gfx::Context& context);
/// Get all the completed drawables
const std::vector<UniqueDrawable>& getDrawables() const { return drawables; }
@@ -134,9 +134,6 @@ public:
/// Set the shader to be used
void setShader(gfx::ShaderProgramBasePtr value) { shader = std::move(value); }
/// Get the vertex attributes that override default values in the shader program
const gfx::VertexAttributeArray& getVertexAttributes() const;
/// Set the name given to new drawables
void setDrawableName(std::string value) { drawableName = std::move(value); }
@@ -157,9 +154,12 @@ public:
/// Clear the tweaker collection
void clearTweakers() { tweakers.clear(); }
/// Get the vertex attributes that override default values in the shader program
VertexAttributeArrayPtr& getVertexAttributes() { return vertexAttrs; }
const VertexAttributeArrayPtr& getVertexAttributes() const { return vertexAttrs; }
/// A set of attribute values to be added for each vertex
void setVertexAttributes(const VertexAttributeArray& value);
void setVertexAttributes(VertexAttributeArray&&);
void setVertexAttributes(VertexAttributeArrayPtr attrs) { vertexAttrs = std::move(attrs); }
/// Add some vertex elements, returns the index of the first one added
std::size_t addVertices(const std::vector<std::array<int16_t, 2>>& vertices,
@@ -232,6 +232,7 @@ protected:
std::vector<UniqueDrawable> drawables;
gfx::Drawable::Textures textures;
std::vector<DrawableTweakerPtr> tweakers;
gfx::VertexAttributeArrayPtr vertexAttrs;
class Impl;
std::unique_ptr<Impl> impl;

View File

@@ -366,23 +366,11 @@ public:
}
VertexAttributeArray& operator=(VertexAttributeArray&&);
VertexAttributeArray& operator=(const VertexAttributeArray&);
VertexAttributeArray& operator=(const VertexAttributeArray&) = delete;
/// Clone the collection
virtual UniqueVertexAttributeArray clone() const {
auto newAttrs = std::make_unique<VertexAttributeArray>();
newAttrs->copy(*this);
return newAttrs;
}
/// Copy another collection into this one
virtual void copy(const VertexAttributeArray& other) {
for (const auto& kv : other.attrs) {
if (kv.second) {
attrs.insert(std::make_pair(kv.first, copy(*kv.second)));
}
}
}
/// Specialized DataDrivenPaintProperty reader
/// @param binders Property binders for the target shader

View File

@@ -41,12 +41,6 @@ public:
void setVertices(std::vector<uint8_t>&&, std::size_t, gfx::AttributeDataType) override;
const gfx::VertexAttributeArray& getVertexAttributes() const override;
void setVertexAttributes(const gfx::VertexAttributeArray& value) override;
void setVertexAttributes(gfx::VertexAttributeArray&& value) override;
gfx::VertexAttributeArray& mutableVertexAttributes() override;
const gfx::UniformBufferArray& getUniformBuffers() const override;
gfx::UniformBufferArray& mutableUniformBuffers() override;

View File

@@ -61,16 +61,7 @@ public:
VertexAttributeArray::operator=(std::move(other));
return *this;
}
VertexAttributeArrayGL& operator=(const VertexAttributeArrayGL& other) {
VertexAttributeArray::operator=(other);
return *this;
}
std::unique_ptr<VertexAttributeArray> clone() const override {
auto newAttrs = std::make_unique<VertexAttributeArrayGL>();
newAttrs->copy(*this);
return newAttrs;
}
VertexAttributeArrayGL& operator=(const VertexAttributeArrayGL&) = delete;
/// Indicates whether any values have changed
bool isDirty() const override;

View File

@@ -22,6 +22,11 @@ namespace mbgl {
class ProgramParameters;
class RenderStaticData;
namespace gfx {
class VertexAttributeArray;
using VertexAttributeArrayPtr = std::shared_ptr<VertexAttributeArray>;
} // namespace gfx
namespace shaders {
struct ClipUBO;
} // namespace shaders
@@ -85,8 +90,6 @@ public:
RenderTargetPtr createRenderTarget(const Size size, const gfx::TextureChannelDataType type) override;
// UniqueFramebuffer createFramebuffer(const gfx::Texture2D& color);
void resetState(gfx::DepthMode depthMode, gfx::ColorMode colorMode) override;
void setDirtyState() override;
@@ -104,6 +107,8 @@ public:
std::unique_ptr<gfx::DrawScopeResource> createDrawScopeResource() override;
gfx::VertexAttributeArrayPtr createVertexAttributeArray() const override;
#if !defined(NDEBUG)
void visualizeStencilBuffer() override;
void visualizeDepthBuffer(float depthRangeSize) override;

View File

@@ -40,12 +40,6 @@ public:
void setVertices(std::vector<uint8_t>&&, std::size_t, gfx::AttributeDataType) override;
const gfx::VertexAttributeArray& getVertexAttributes() const override;
void setVertexAttributes(const gfx::VertexAttributeArray& value) override;
void setVertexAttributes(gfx::VertexAttributeArray&& value) override;
gfx::VertexAttributeArray& mutableVertexAttributes() override;
const gfx::UniformBufferArray& getUniformBuffers() const override;
gfx::UniformBufferArray& mutableUniformBuffers() override;

View File

@@ -18,17 +18,13 @@ private:
friend VertexAttributeArray;
VertexAttribute(int index_, gfx::AttributeDataType dataType_, std::size_t count_)
: gfx::VertexAttribute(index_, dataType_, count_) {}
VertexAttribute(const VertexAttribute& other)
: gfx::VertexAttribute(other) {}
VertexAttribute(const VertexAttribute& other) = delete;
VertexAttribute(VertexAttribute&& other)
: gfx::VertexAttribute(std::move(other)) {}
public:
~VertexAttribute() override = default;
/// Get the Metal buffer, creating it if necessary
// const gfx::UniqueVertexBufferResource& getBuffer(UploadPass&, const gfx::BufferUsageType);
static const gfx::UniqueVertexBufferResource& getBuffer(gfx::VertexAttribute&,
UploadPass&,
const gfx::BufferUsageType);
@@ -45,16 +41,7 @@ public:
gfx::VertexAttributeArray::operator=(std::move(other));
return *this;
}
VertexAttributeArray& operator=(const VertexAttributeArray& other) {
gfx::VertexAttributeArray::operator=(other);
return *this;
}
gfx::UniqueVertexAttributeArray clone() const override {
auto newAttrs = std::make_unique<VertexAttributeArray>();
newAttrs->copy(*this);
return newAttrs;
}
VertexAttributeArray& operator=(const VertexAttributeArray& other) = delete;
/// Indicates whether any values have changed
bool isDirty() const override;
@@ -63,12 +50,6 @@ private:
gfx::UniqueVertexAttribute create(int index, gfx::AttributeDataType dataType, std::size_t count) const override {
return gfx::UniqueVertexAttribute(new VertexAttribute(index, dataType, count));
}
using gfx::VertexAttributeArray::copy;
gfx::UniqueVertexAttribute copy(const gfx::VertexAttribute& attr) const override {
return gfx::UniqueVertexAttribute(new VertexAttribute(static_cast<const VertexAttribute&>(attr)));
}
};
} // namespace mtl

View File

@@ -48,8 +48,6 @@ public:
protected:
gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; }
gfx::VertexAttributeArray& mutableVertexAttributes() override { return vertexAttributes; }
protected:
UniqueProgram glProgram;

View File

@@ -62,7 +62,6 @@ public:
std::optional<uint32_t> getSamplerLocation(const StringIdentity id) const override;
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
gfx::VertexAttributeArray& mutableVertexAttributes() override { return vertexAttributes; }
const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; }
gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; }

View File

@@ -41,14 +41,8 @@ public:
/// Get the available vertex attributes and their default values
virtual const gfx::VertexAttributeArray& getVertexAttributes() const = 0;
template <typename T>
bool setAttribute(const std::string& name, std::size_t i, T value) {
return set(mutableVertexAttributes(), name, i, value);
}
protected:
virtual gfx::UniformBlockArray& mutableUniformBlocks() = 0;
virtual gfx::VertexAttributeArray& mutableVertexAttributes() = 0;
protected:
util::SimpleIdentity shaderProgramID;