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

@@ -306,7 +306,10 @@ void Drawable::setVertices(std::vector<uint8_t>&& data, std::size_t count, gfx::
impl->vertexType = type;
if (count && type != gfx::AttributeDataType::Invalid && !data.empty()) {
if (auto& attrib = impl->vertexAttributes.getOrAdd(impl->idVertexAttrName, /*index=*/-1, type)) {
if (!vertexAttributes) {
vertexAttributes = std::make_shared<VertexAttributeArray>();
}
if (auto& attrib = vertexAttributes->getOrAdd(impl->idVertexAttrName, /*index=*/-1, type)) {
attrib->setRawData(std::move(data));
attrib->setStride(VertexAttribute::getStrideOf(type));
} else {
@@ -319,21 +322,6 @@ void Drawable::setVertices(std::vector<uint8_t>&& data, std::size_t count, gfx::
}
}
const gfx::VertexAttributeArray& Drawable::getVertexAttributes() const {
return impl->vertexAttributes;
}
gfx::VertexAttributeArray& Drawable::mutableVertexAttributes() {
return impl->vertexAttributes;
}
void Drawable::setVertexAttributes(const gfx::VertexAttributeArray& value) {
impl->vertexAttributes = static_cast<const VertexAttributeArray&>(value);
}
void Drawable::setVertexAttributes(gfx::VertexAttributeArray&& value) {
impl->vertexAttributes = std::move(static_cast<VertexAttributeArray&&>(value));
}
const gfx::UniformBufferArray& Drawable::getUniformBuffers() const {
return impl->uniformBuffers;
}
@@ -513,13 +501,17 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
impl->indexes->setDirty(false);
}
const bool buildAttribs = impl->vertexAttributes.isDirty() || !impl->vertexDesc;
const bool buildAttribs = !vertexAttributes || vertexAttributes->isDirty() || !impl->vertexDesc;
if (buildAttribs) {
#if !defined(NDEBUG)
const auto debugGroup = uploadPass.createDebugGroup(debugLabel(*this));
#endif
if (!vertexAttributes) {
vertexAttributes = std::make_shared<VertexAttributeArray>();
}
// Apply drawable values to shader defaults
std::vector<std::unique_ptr<gfx::VertexBufferResource>> vertexBuffers;
auto attributeBindings_ = uploadPass.buildAttributeBindings(impl->vertexCount,
@@ -527,13 +519,12 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
/*vertexAttributeIndex=*/-1,
/*vertexData=*/{},
shader->getVertexAttributes(),
impl->vertexAttributes,
*vertexAttributes,
usage,
vertexBuffers);
impl->attributeBuffers = std::move(vertexBuffers);
impl->vertexAttributes.visitAttributes(
[](const auto&, gfx::VertexAttribute& attrib) { attrib.setDirty(false); });
vertexAttributes->visitAttributes([](const auto&, gfx::VertexAttribute& attrib) { attrib.setDirty(false); });
if (impl->attributeBindings != attributeBindings_) {
impl->attributeBindings = std::move(attributeBindings_);