@@ -30,13 +30,16 @@ class VertexBufferBuilder {
3030 ~VertexBufferBuilder () = default ;
3131
3232 constexpr impeller::IndexType GetIndexType () const {
33+ if (indices_.size () == 0 ) {
34+ return impeller::IndexType::kNone ;
35+ }
3336 if constexpr (sizeof (IndexType) == 2 ) {
3437 return impeller::IndexType::k16bit;
35- } else if (sizeof (IndexType) == 4 ) {
38+ }
39+ if (sizeof (IndexType) == 4 ) {
3640 return impeller::IndexType::k32bit;
37- } else {
38- return impeller::IndexType::kUnknown ;
3941 }
42+ return impeller::IndexType::kUnknown ;
4043 }
4144
4245 void SetLabel (std::string label) { label_ = std::move (label); }
@@ -121,29 +124,23 @@ class VertexBufferBuilder {
121124 return buffer->AsBufferView ();
122125 }
123126
124- std::vector<IndexType> CreateIndexBuffer () const {
125- if (indices_.size () > 0 ) {
126- return indices_;
127- }
128-
129- // So dumb! We don't actually need an index buffer right now. But we will
130- // once de-duplication is done. So assume this is always done.
131- std::vector<IndexType> index_buffer;
132- for (size_t i = 0 ; i < vertices_.size (); i++) {
133- index_buffer.push_back (i);
134- }
135- return index_buffer;
136- }
127+ std::vector<IndexType> CreateIndexBuffer () const { return indices_; }
137128
138129 BufferView CreateIndexBufferView (HostBuffer& buffer) const {
139130 const auto index_buffer = CreateIndexBuffer ();
131+ if (index_buffer.size () == 0 ) {
132+ return {};
133+ }
140134 return buffer.Emplace (index_buffer.data (),
141135 index_buffer.size () * sizeof (IndexType),
142136 alignof (IndexType));
143137 }
144138
145139 BufferView CreateIndexBufferView (Allocator& allocator) const {
146140 const auto index_buffer = CreateIndexBuffer ();
141+ if (index_buffer.size () == 0 ) {
142+ return {};
143+ }
147144 auto buffer = allocator.CreateBufferWithCopy (
148145 reinterpret_cast <const uint8_t *>(index_buffer.data ()),
149146 index_buffer.size () * sizeof (IndexType));
0 commit comments