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

@@ -33,10 +33,6 @@ void DrawableBuilder::setCullFaceMode(const gfx::CullFaceMode& value) {
impl->cullFaceMode = value;
}
const gfx::VertexAttributeArray& DrawableBuilder::getVertexAttributes() const {
return impl->vertexAttrs;
}
UniqueDrawable& DrawableBuilder::getCurrentDrawable(bool createIfNone) {
if (!currentDrawable && createIfNone) {
currentDrawable = createDrawable();
@@ -44,11 +40,11 @@ UniqueDrawable& DrawableBuilder::getCurrentDrawable(bool createIfNone) {
return currentDrawable;
}
void DrawableBuilder::flush() {
void DrawableBuilder::flush(gfx::Context& context) {
if (curVertexCount()) {
if (Impl::Mode::Polylines == impl->getMode()) {
// setup for polylines
impl->setupForPolylines(*this);
impl->setupForPolylines(context, *this);
}
const auto& draw = getCurrentDrawable(/*createIfNone=*/true);
@@ -68,9 +64,10 @@ void DrawableBuilder::flush() {
draw->setTextures(textures);
draw->setTweakers(tweakers);
const auto& builderAttrs = getVertexAttributes();
if (auto drawAttrs = builderAttrs.clone()) {
draw->setVertexAttributes(std::move(*drawAttrs));
if (vertexAttrs) {
draw->setVertexAttributes(vertexAttrs);
} else {
draw->setVertexAttributes(context.createVertexAttributeArray());
}
init();
@@ -151,14 +148,6 @@ void DrawableBuilder::addQuad(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
appendTriangle(x1, y1);
}
void DrawableBuilder::setVertexAttributes(const VertexAttributeArray& attrs) {
impl->vertexAttrs = attrs;
}
void DrawableBuilder::setVertexAttributes(VertexAttributeArray&& attrs) {
impl->vertexAttrs = std::move(attrs);
}
std::size_t DrawableBuilder::addVertices(const std::vector<std::array<int16_t, 2>>& vertices,
std::size_t vertexOffset,
std::size_t vertexLength) {