Drawable Renderer (#1570), rework attributes for fill drawables

This commit is contained in:
Tim Sylvester
2023-05-15 15:02:41 -07:00
committed by Bart Louwers
parent cec22b8572
commit fffbfcfbb5
12 changed files with 198 additions and 45 deletions

View File

@@ -15,26 +15,28 @@ void DrawableGLBuilder::init() {
auto& drawableGL = static_cast<DrawableGL&>(*currentDrawable);
auto& attrs = drawableGL.mutableVertexAttributes();
if (const auto& posAttr = attrs.getOrAdd("a_pos")) {
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]});
}
}
if (const auto& colorAttr = attrs.getOrAdd("a_color")) {
// We should have either a single color or one per vertex. Otherwise,
// the color mode was probably changed after vertexes were added.
if (impl->colors.size() > 1 && impl->colors.size() != impl->vertices.elements()) {
impl->colors.clear();
}
if (impl->colors.empty()) {
colorAttr->set(0, DrawableGL::colorAttrValue(getColor()));
} else {
std::size_t index = 0;
colorAttr->reserve(impl->colors.size());
for (const auto& color : impl->colors) {
colorAttr->set(index++, DrawableGL::colorAttrValue(color));
if (colorMode != ColorMode::None && !colorAttrName.empty()) {
if (const auto& colorAttr = attrs.getOrAdd(colorAttrName)) {
// We should have either a single color or one per vertex. Otherwise,
// the color mode was probably changed after vertexes were added.
if (impl->colors.size() > 1 && impl->colors.size() != impl->vertices.elements()) {
impl->colors.clear();
}
if (impl->colors.empty()) {
colorAttr->set(0, DrawableGL::colorAttrValue(getColor()));
} else {
std::size_t index = 0;
colorAttr->reserve(impl->colors.size());
for (const auto& color : impl->colors) {
colorAttr->set(index++, DrawableGL::colorAttrValue(color));
}
}
}
}