Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,18 @@ TEST_P(RendererTest, DefaultIndexSize) {
// Default to 16bit index buffer size, as this is a reasonable default and
// supported on all backends without extensions.
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
vertex_builder.AppendIndex(0u);
ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::k16bit);
}

TEST_P(RendererTest, DefaultIndexBehavior) {
using VS = BoxFadeVertexShader;

// Do not create any index buffer if no indices were provided.
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
ASSERT_EQ(vertex_builder.GetIndexType(), IndexType::kNone);
}

TEST_P(RendererTest, VertexBufferBuilder) {
// Does not create index buffer if one is provided.
using VS = BoxFadeVertexShader;
Expand Down
29 changes: 13 additions & 16 deletions impeller/renderer/vertex_buffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ class VertexBufferBuilder {
~VertexBufferBuilder() = default;

constexpr impeller::IndexType GetIndexType() const {
if (indices_.size() == 0) {
return impeller::IndexType::kNone;
}
if constexpr (sizeof(IndexType) == 2) {
return impeller::IndexType::k16bit;
} else if (sizeof(IndexType) == 4) {
}
if (sizeof(IndexType) == 4) {
return impeller::IndexType::k32bit;
} else {
return impeller::IndexType::kUnknown;
}
return impeller::IndexType::kUnknown;
}

void SetLabel(std::string label) { label_ = std::move(label); }
Expand Down Expand Up @@ -121,29 +124,23 @@ class VertexBufferBuilder {
return buffer->AsBufferView();
}

std::vector<IndexType> CreateIndexBuffer() const {
if (indices_.size() > 0) {
return indices_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I misread the condition here when I was reading above.

}

// So dumb! We don't actually need an index buffer right now. But we will
// once de-duplication is done. So assume this is always done.
std::vector<IndexType> index_buffer;
for (size_t i = 0; i < vertices_.size(); i++) {
index_buffer.push_back(i);
}
return index_buffer;
}
std::vector<IndexType> CreateIndexBuffer() const { return indices_; }

BufferView CreateIndexBufferView(HostBuffer& buffer) const {
const auto index_buffer = CreateIndexBuffer();
if (index_buffer.size() == 0) {
return {};
}
return buffer.Emplace(index_buffer.data(),
index_buffer.size() * sizeof(IndexType),
alignof(IndexType));
}

BufferView CreateIndexBufferView(Allocator& allocator) const {
const auto index_buffer = CreateIndexBuffer();
if (index_buffer.size() == 0) {
return {};
}
auto buffer = allocator.CreateBufferWithCopy(
reinterpret_cast<const uint8_t*>(index_buffer.data()),
index_buffer.size() * sizeof(IndexType));
Expand Down