23 const std::vector<Point>& vertices,
24 const std::vector<uint16_t>& indices) {
25 std::vector<uint16_t> unrolled_indices;
28 if (indices.size() > 0u) {
29 if (indices.size() < 3u) {
33 auto center_point = indices[0];
34 for (
auto i = 1u;
i < indices.size() - 1;
i++) {
35 unrolled_indices.push_back(center_point);
36 unrolled_indices.push_back(indices[
i]);
37 unrolled_indices.push_back(indices[
i + 1]);
40 if (vertices.size() < 3u) {
46 for (
auto i = 1u;
i < vertices.size() - 1;
i++) {
47 unrolled_indices.push_back(0);
48 unrolled_indices.push_back(
i);
49 unrolled_indices.push_back(
i + 1);
52 return unrolled_indices;
58 std::vector<uint16_t> indices,
59 std::vector<Point> texture_coordinates,
63 : vertices_(
std::move(vertices)),
65 texture_coordinates_(
std::move(texture_coordinates)),
66 indices_(
std::move(indices)),
68 vertex_mode_(vertex_mode) {
73 switch (vertex_mode_) {
84void 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);
123 auto vertex_buffer =
renderer.GetTransientsBuffer().Emplace(
124 reinterpret_cast<const uint8_t*
>(vertices_.data()), total_vtx_bytes,
129 index_buffer =
renderer.GetTransientsBuffer().Emplace(
130 indices_.data(), total_idx_bytes,
alignof(uint16_t));
134 .
type = GetPrimitiveType(),
137 .vertex_buffer = vertex_buffer,
138 .index_buffer = index_buffer,
139 .vertex_count = index_count > 0 ? index_count : vertex_count,
148 Rect texture_coverage,
155 auto vertex_count = vertices_.size();
161 size_t total_vtx_bytes = vertices_.size() *
sizeof(VS::PerVertexData);
162 auto vertex_buffer =
renderer.GetTransientsBuffer().Emplace(
163 total_vtx_bytes,
alignof(VS::PerVertexData), [&](uint8_t*
data) {
164 VS::PerVertexData* vtx_contents =
165 reinterpret_cast<VS::PerVertexData*
>(
data);
166 for (
auto i = 0u;
i < vertices_.size();
i++) {
167 auto vertex = vertices_[
i];
169 has_texture_coordinates ? texture_coordinates_[
i] : vertices_[
i];
170 auto uv = uv_transform * texture_coord;
171 VS::PerVertexData vertex_data = {
173 .texture_coords = uv,
176 std::memcpy(vtx_contents++, &vertex_data,
sizeof(VS::PerVertexData));
181 auto index_count = indices_.size();
182 size_t total_idx_bytes = index_count *
sizeof(uint16_t);
183 if (index_count > 0) {
184 index_buffer =
renderer.GetTransientsBuffer().Emplace(
185 indices_.data(), total_idx_bytes,
alignof(uint16_t));
189 .
type = GetPrimitiveType(),
192 .vertex_buffer = vertex_buffer,
193 .index_buffer = index_buffer,
194 .vertex_count = index_count > 0 ? index_count : vertex_count,
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexShader_ VertexShader
bool HasTextureCoordinates() const
std::optional< Rect > GetCoverage(const Matrix &transform) const override
std::optional< Rect > GetTextureCoordinateCoverge() const
GeometryResult GetPositionUVColorBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
VerticesGeometry(std::vector< Point > vertices, std::vector< uint16_t > indices, std::vector< Point > texture_coordinates, std::vector< Color > colors, Rect bounds, VerticesGeometry::VertexMode vertex_mode)
bool HasVertexColors() const
Optional< SkRect > bounds
PODArray< SkColor > colors
@ kNone
Does not use the index buffer.
PrimitiveType
Decides how backend draws pixels based on input vertices.
static std::vector< uint16_t > fromFanIndices(const std::vector< Point > &vertices, const std::vector< uint16_t > &indices)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
static constexpr Color BlackTransparent()
A 4x4 matrix using column-major storage.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
static constexpr std::optional< TRect > MakePointBounds(const U &value)
std::shared_ptr< const fml::Mapping > data