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) {
73 switch (vertex_mode_) {
84 void VerticesGeometry::NormalizeIndices() {
93 return colors_.size() > 0;
97 return texture_coordinates_.size() > 0;
104 auto vertex_count = vertices_.size();
105 if (vertex_count == 0) {
110 texture_coordinates_.end());
117 auto index_count = indices_.size();
118 auto vertex_count = vertices_.size();
120 size_t total_vtx_bytes = vertex_count *
sizeof(float) * 2;
121 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
124 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
128 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
130 if (!buffer->CopyHostBuffer(
131 reinterpret_cast<const uint8_t*
>(vertices_.data()),
132 Range{0, total_vtx_bytes}, 0)) {
135 if (index_count > 0 &&
136 !buffer->CopyHostBuffer(
137 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
138 Range{0, total_idx_bytes}, total_vtx_bytes)) {
143 .
type = GetPrimitiveType(),
146 .vertex_buffer = {.buffer = buffer,
147 .range =
Range{0, total_vtx_bytes}},
148 .index_buffer = {.buffer = buffer,
150 Range{total_vtx_bytes, total_idx_bytes}},
151 .vertex_count = index_count > 0 ? index_count : vertex_count,
157 .prevent_overdraw =
false,
167 auto index_count = indices_.size();
168 auto vertex_count = vertices_.size();
170 std::vector<VS::PerVertexData> vertex_data(vertex_count);
172 for (
auto i = 0u; i < vertex_count; i++) {
174 .position = vertices_[i],
180 size_t total_vtx_bytes = vertex_data.size() *
sizeof(VS::PerVertexData);
181 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
184 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
188 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
190 if (!buffer->CopyHostBuffer(
reinterpret_cast<uint8_t*
>(vertex_data.data()),
191 Range{0, total_vtx_bytes}, 0)) {
194 if (index_count > 0 &&
195 !buffer->CopyHostBuffer(
196 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
197 Range{0, total_idx_bytes}, total_vtx_bytes)) {
202 .
type = GetPrimitiveType(),
205 .vertex_buffer = {.buffer = buffer,
206 .range =
Range{0, total_vtx_bytes}},
207 .index_buffer = {.buffer = buffer,
209 Range{total_vtx_bytes, total_idx_bytes}},
210 .vertex_count = index_count > 0 ? index_count : vertex_count,
216 .prevent_overdraw =
false,
221 Rect texture_coverage,
228 auto index_count = indices_.size();
229 auto vertex_count = vertices_.size();
230 auto size = texture_coverage.
size;
231 auto origin = texture_coverage.
origin;
233 std::vector<VS::PerVertexData> vertex_data(vertex_count);
235 for (
auto i = 0u; i < vertex_count; i++) {
236 auto vertex = vertices_[i];
238 has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
240 effect_transform *
Point((texture_coord.x - origin.x) / size.width,
241 (texture_coord.y - origin.y) / size.height);
253 size_t total_vtx_bytes = vertex_data.size() *
sizeof(VS::PerVertexData);
254 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
257 buffer_desc.
size = total_vtx_bytes + total_idx_bytes;
261 renderer.
GetContext()->GetResourceAllocator()->CreateBuffer(buffer_desc);
263 if (!buffer->CopyHostBuffer(
reinterpret_cast<uint8_t*
>(vertex_data.data()),
264 Range{0, total_vtx_bytes}, 0)) {
267 if (index_count > 0u &&
268 !buffer->CopyHostBuffer(
269 reinterpret_cast<uint8_t*
>(
const_cast<uint16_t*
>(indices_.data())),
270 Range{0, total_idx_bytes}, total_vtx_bytes)) {
275 .
type = GetPrimitiveType(),
278 .vertex_buffer = {.buffer = buffer,
279 .range =
Range{0, total_vtx_bytes}},
280 .index_buffer = {.buffer = buffer,
282 Range{total_vtx_bytes, total_idx_bytes}},
283 .vertex_count = index_count > 0 ? index_count : vertex_count,
289 .prevent_overdraw =
false,
305 const Matrix& transform)
const {