5#ifndef FLUTTER_IMPELLER_RENDERER_VERTEX_BUFFER_BUILDER_H_
6#define FLUTTER_IMPELLER_RENDERER_VERTEX_BUFFER_BUILDER_H_
9#include <initializer_list>
23template <
class VertexType,
size_t size>
28 input.data(),
sizeof(VertexType) * size,
alignof(VertexType)),
34template <
class VertexType_,
class IndexType_ = u
int16_t>
45 if (indices_.size() == 0) {
57 void SetLabel(
const std::string& label) { label_ = label; }
59 void Reserve(
size_t count) {
return vertices_.reserve(count); }
68 return indices_.size() > 0 ? indices_.size() : vertices_.size();
73 return vertices_.back();
77 vertices_.emplace_back(std::move(vertex));
82 std::initializer_list<VertexType_> vertices) {
83 vertices_.reserve(vertices.size());
84 for (
auto& vertex : vertices) {
85 vertices_.emplace_back(std::move(vertex));
91 indices_.emplace_back(index);
98 buffer.vertex_buffer = CreateVertexBufferView(data_host_buffer);
99 buffer.index_buffer = CreateIndexBufferView(indexes_host_buffer);
108 buffer.vertex_buffer = CreateVertexBufferView(device_allocator);
109 buffer.index_buffer = CreateIndexBufferView(device_allocator);
116 for (
auto& vertex : vertices_) {
122 std::vector<VertexType> vertices_;
123 std::vector<IndexType> indices_;
127 return data_host_buffer.
Emplace(vertices_.data(),
132 BufferView CreateVertexBufferView(Allocator& allocator)
const {
133 auto buffer = allocator.CreateBufferWithCopy(
134 reinterpret_cast<const uint8_t*
>(vertices_.data()),
139 if (!label_.empty()) {
140 buffer->SetLabel(std::format(
"{} Vertices", label_));
145 std::vector<IndexType> CreateIndexBuffer()
const {
return indices_; }
147 BufferView CreateIndexBufferView(HostBuffer& indexes_host_buffer)
const {
148 const auto index_buffer = CreateIndexBuffer();
149 if (index_buffer.size() == 0) {
152 return indexes_host_buffer.Emplace(index_buffer.data(),
157 BufferView CreateIndexBufferView(Allocator& allocator)
const {
158 const auto index_buffer = CreateIndexBuffer();
159 if (index_buffer.size() == 0) {
162 auto buffer = allocator.CreateBufferWithCopy(
163 reinterpret_cast<const uint8_t*
>(index_buffer.data()),
164 index_buffer.size() *
sizeof(
IndexType));
168 if (!label_.empty()) {
169 buffer->SetLabel(std::format(
"{} Indices", label_));
An object that allocates device memory.
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
size_t GetVertexCount() const
VertexBufferBuilder & AppendVertex(VertexType_ vertex)
const VertexType & Last() const
~VertexBufferBuilder()=default
VertexBufferBuilder()=default
size_t GetIndexCount() const
VertexBuffer CreateVertexBuffer(HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer) const
void ReserveIndices(size_t count)
void IterateVertices(const std::function< void(VertexType &)> &iterator)
void Reserve(size_t count)
VertexBuffer CreateVertexBuffer(Allocator &device_allocator) const
VertexBufferBuilder & AppendIndex(IndexType_ index)
void SetLabel(const std::string &label)
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
constexpr impeller::IndexType GetIndexType() const
#define FML_DCHECK(condition)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
@ kNone
Does not use the index buffer.
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.