21 const std::vector<Point>& vertices,
22 const std::vector<uint16_t>& indices) {
23 std::vector<uint16_t> unrolled_indices;
26 if (indices.size() > 0u) {
27 if (indices.size() < 3u) {
31 auto center_point = indices[0];
32 for (
auto i = 1u; i < indices.size() - 1; i++) {
33 unrolled_indices.push_back(center_point);
34 unrolled_indices.push_back(indices[i]);
35 unrolled_indices.push_back(indices[i + 1]);
38 if (vertices.size() < 3u) {
44 for (
auto i = 1u; i < vertices.size() - 1; i++) {
45 unrolled_indices.push_back(0);
46 unrolled_indices.push_back(i);
47 unrolled_indices.push_back(i + 1);
50 return unrolled_indices;
56 std::vector<uint16_t> indices,
57 std::vector<Point> texture_coordinates,
58 std::vector<Color> colors,
61 : vertices_(
std::move(vertices)),
62 colors_(
std::move(colors)),
63 texture_coordinates_(
std::move(texture_coordinates)),
64 indices_(
std::move(indices)),
66 vertex_mode_(vertex_mode) {
71 switch (vertex_mode_) {
82 void VerticesGeometry::NormalizeIndices() {
91 return colors_.size() > 0;
95 return texture_coordinates_.size() > 0;
102 auto vertex_count = vertices_.size();
103 if (vertex_count == 0) {
108 texture_coordinates_.end());
115 auto index_count = indices_.size();
116 auto vertex_count = vertices_.size();
118 size_t total_vtx_bytes = vertex_count *
sizeof(float) * 2;
119 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
122 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
126 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
128 if (!buffer->CopyHostBuffer(
129 reinterpret_cast<const uint8_t*
>(vertices_.data()),
130 Range{0, total_vtx_bytes}, 0)) {
133 if (index_count > 0 &&
134 !buffer->CopyHostBuffer(
135 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
136 Range{0, total_idx_bytes}, total_vtx_bytes)) {
141 .
type = GetPrimitiveType(),
144 .vertex_buffer = {.buffer = buffer,
145 .range =
Range{0, total_vtx_bytes}},
146 .index_buffer = {.buffer = buffer,
148 Range{total_vtx_bytes, total_idx_bytes}},
149 .vertex_count = index_count > 0 ? index_count : vertex_count,
154 .prevent_overdraw =
false,
164 auto index_count = indices_.size();
165 auto vertex_count = vertices_.size();
167 std::vector<VS::PerVertexData> vertex_data(vertex_count);
169 for (
auto i = 0u; i < vertex_count; i++) {
171 .position = vertices_[i],
177 size_t total_vtx_bytes = vertex_data.size() *
sizeof(VS::PerVertexData);
178 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
181 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
185 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
187 if (!buffer->CopyHostBuffer(
reinterpret_cast<uint8_t*
>(vertex_data.data()),
188 Range{0, total_vtx_bytes}, 0)) {
191 if (index_count > 0 &&
192 !buffer->CopyHostBuffer(
193 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
194 Range{0, total_idx_bytes}, total_vtx_bytes)) {
199 .
type = GetPrimitiveType(),
202 .vertex_buffer = {.buffer = buffer,
203 .range =
Range{0, total_vtx_bytes}},
204 .index_buffer = {.buffer = buffer,
206 Range{total_vtx_bytes, total_idx_bytes}},
207 .vertex_count = index_count > 0 ? index_count : vertex_count,
212 .prevent_overdraw =
false,
217 Rect texture_coverage,
224 auto index_count = indices_.size();
225 auto vertex_count = vertices_.size();
229 std::vector<VS::PerVertexData> vertex_data(vertex_count);
231 for (
auto i = 0u; i < vertex_count; i++) {
232 auto vertex = vertices_[i];
234 has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
235 auto uv = uv_transform * texture_coord;
247 size_t total_vtx_bytes = vertex_data.size() *
sizeof(VS::PerVertexData);
248 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
251 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
255 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
257 if (!buffer->CopyHostBuffer(
reinterpret_cast<uint8_t*
>(vertex_data.data()),
258 Range{0, total_vtx_bytes}, 0)) {
261 if (index_count > 0u &&
262 !buffer->CopyHostBuffer(
263 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
264 Range{0, total_idx_bytes}, total_vtx_bytes)) {
269 .
type = GetPrimitiveType(),
272 .vertex_buffer = {.buffer = buffer,
273 .range =
Range{0, total_vtx_bytes}},
274 .index_buffer = {.buffer = buffer,
276 Range{total_vtx_bytes, total_idx_bytes}},
277 .vertex_count = index_count > 0 ? index_count : vertex_count,
282 .prevent_overdraw =
false,
298 const Matrix& transform)
const {