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 reinterpret_cast<const uint8_t*
>(vertices_.data()), total_vtx_bytes,
128 indices_.data(), total_idx_bytes,
alignof(uint16_t));
132 .
type = GetPrimitiveType(),
135 .vertex_buffer = vertex_buffer,
136 .index_buffer = index_buffer,
137 .vertex_count = index_count > 0 ? index_count : vertex_count,
151 auto index_count = indices_.size();
152 auto vertex_count = vertices_.size();
153 size_t total_vtx_bytes = vertex_count *
sizeof(VS::PerVertexData);
154 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
157 total_vtx_bytes,
alignof(VS::PerVertexData), [&](uint8_t* data) {
158 VS::PerVertexData* vtx_contents =
159 reinterpret_cast<VS::PerVertexData*
>(data);
160 for (
auto i = 0u; i < vertices_.size(); i++) {
161 VS::PerVertexData vertex_data = {
162 .position = vertices_[i],
165 std::memcpy(vtx_contents++, &vertex_data,
sizeof(VS::PerVertexData));
170 if (index_count > 0) {
172 indices_.data(), total_idx_bytes,
alignof(uint16_t));
176 .
type = GetPrimitiveType(),
179 .vertex_buffer = vertex_buffer,
180 .index_buffer = index_buffer,
181 .vertex_count = index_count > 0 ? index_count : vertex_count,
190 Rect texture_coverage,
197 auto index_count = indices_.size();
198 auto vertex_count = vertices_.size();
203 size_t total_vtx_bytes = vertices_.size() *
sizeof(VS::PerVertexData);
204 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
206 total_vtx_bytes,
alignof(VS::PerVertexData), [&](uint8_t* data) {
207 VS::PerVertexData* vtx_contents =
208 reinterpret_cast<VS::PerVertexData*
>(data);
209 for (
auto i = 0u; i < vertices_.size(); i++) {
210 auto vertex = vertices_[i];
212 has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
213 auto uv = uv_transform * texture_coord;
216 VS::PerVertexData vertex_data = {
222 std::memcpy(vtx_contents++, &vertex_data,
sizeof(VS::PerVertexData));
227 if (index_count > 0) {
229 indices_.data(), total_idx_bytes,
alignof(uint16_t));
233 .
type = GetPrimitiveType(),
236 .vertex_buffer = vertex_buffer,
237 .index_buffer = index_buffer,
238 .vertex_count = index_count > 0 ? index_count : vertex_count,
258 const Matrix& transform)
const {