| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::VerticesGeometry Class Referencefinal

A geometry that is created from a vertices object. More...

`#include <vertices_geometry.h>`

Inheritance diagram for impeller::VerticesGeometry:

## Public Types
enum | VertexMode { VertexMode::kTriangles, VertexMode::kTriangleStrip, VertexMode::kTriangleFan }

## Public Member Functions
| 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)
| ~VerticesGeometry ()=default
GeometryResult | GetPositionColorBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass)
GeometryResult | GetPositionUVBuffer (Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
GeometryResult | GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > | GetCoverage (const Matrix &transform) const override
GeometryVertexType | GetVertexType () const override
bool | HasVertexColors () const
bool | HasTextureCoordinates () const
std::optional< Rect > | GetTextureCoordinateCoverge () const
Public Member Functions inherited from impeller::Geometry
virtual GeometryResult::Mode | GetResultMode () const
virtual bool | CoversArea (const Matrix &transform, const Rect &rect) const
| Determines if this geometry, transformed by the given `transform`, will completely cover all surface area of the given `rect`. More...
virtual bool | IsAxisAlignedRect () const
virtual bool | CanApplyMaskFilter () const

## Additional Inherited Members
Static Public Member Functions inherited from impeller::Geometry
static std::shared_ptr< Geometry > | MakeFillPath (const Path &path, std::optional< Rect > inner_rect=std::nullopt)
static std::shared_ptr< Geometry > | MakeStrokePath (const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
static std::shared_ptr< Geometry > | MakeCover ()
static std::shared_ptr< Geometry > | MakeRect (const Rect &rect)
static std::shared_ptr< Geometry > | MakeOval (const Rect &rect)
static std::shared_ptr< Geometry > | MakeLine (const Point &p0, const Point &p1, Scalar width, Cap cap)
static std::shared_ptr< Geometry > | MakeCircle (const Point &center, Scalar radius)
static std::shared_ptr< Geometry > | MakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
static std::shared_ptr< Geometry > | MakeRoundRect (const Rect &rect, const Size &radii)
static std::shared_ptr< Geometry > | MakePointField (std::vector< Point > points, Scalar radius, bool round)
Static Protected Member Functions inherited from impeller::Geometry
static GeometryResult | ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
static GeometryResult | ComputePositionUVGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)

## Detailed Description

A geometry that is created from a vertices object.

Definition at line 13 of file vertices_geometry.h.

## Member Enumeration Documentation

## ◆ VertexMode

enum impeller::VerticesGeometry::VertexMode
| strong

Enumerator
kTriangles |
kTriangleStrip |
kTriangleFan |

Definition at line 15 of file vertices_geometry.h.

15 {
16 kTriangles,
17 kTriangleStrip,
18 kTriangleFan,
19 };

## Constructor & Destructor Documentation

## ◆ VerticesGeometry()

impeller::VerticesGeometry::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
| ) |  |

Definition at line 55 of file vertices_geometry.cc.

61 : vertices_(std::move(vertices)),
62 colors_(std::move(colors)),
63 texture_coordinates_(std::move(texture_coordinates)),
64 indices_(std::move(indices)),
65 bounds_(bounds),
66 vertex_mode_(vertex_mode) {
67 NormalizeIndices();
68 }

## ◆ ~VerticesGeometry()

impeller::VerticesGeometry::~VerticesGeometry | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetCoverage()

std::optional< Rect > impeller::VerticesGeometry::GetCoverage | ( | const Matrix & | transform | ) | const
| override virtual

Implements impeller::Geometry.

Definition at line 257 of file vertices_geometry.cc.

258 {
259 return bounds_.TransformBounds(transform);
260 }

References impeller::TRect< T >::TransformBounds().

## ◆ GetPositionBuffer()

GeometryResult impeller::VerticesGeometry::GetPositionBuffer | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| override virtual

Implements impeller::Geometry.

Definition at line 111 of file vertices_geometry.cc.

114 {
115 auto index_count = indices_.size();
116 auto vertex_count = vertices_.size();
117
118 size_t total_vtx_bytes = vertex_count * sizeof(float) * 2;
119 size_t total_idx_bytes = index_count * sizeof(uint16_t);
120
121 auto vertex_buffer = renderer.GetTransientsBuffer().Emplace(
122 reinterpret_cast<const uint8_t*>(vertices_.data()), total_vtx_bytes,
123 alignof(float));
124
125 BufferView index_buffer = {};
126 if (index_count) {
127 index_buffer = renderer.GetTransientsBuffer().Emplace(
128 indices_.data(), total_idx_bytes, alignof(uint16_t));
129 }
130
131 return GeometryResult{
132 .type = GetPrimitiveType(),
133 .vertex_buffer =
134 {
135 .vertex_buffer = vertex_buffer,
136 .index_buffer = index_buffer,
137 .vertex_count = index_count > 0 ? index_count : vertex_count,
138 .index_type =
139 index_count > 0 ? IndexType::k16bit : IndexType::kNone,
140 },
141 .transform = entity.GetShaderTransform(pass),
142 };
143 }

References impeller::HostBuffer::Emplace(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), impeller::k16bit, impeller::kNone, and impeller::GeometryResult::type.

## ◆ GetPositionColorBuffer()

GeometryResult impeller::VerticesGeometry::GetPositionColorBuffer | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  |

Definition at line 145 of file vertices_geometry.cc.

148 {
149 using VS = GeometryColorPipeline::VertexShader;
150
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);
155
156 auto vertex_buffer = renderer.GetTransientsBuffer().Emplace(
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],
163 .color = colors_[i],
164 };
165 std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData));
166 }
167 });
168
169 BufferView index_buffer = {};
170 if (index_count > 0) {
171 index_buffer = renderer.GetTransientsBuffer().Emplace(
172 indices_.data(), total_idx_bytes, alignof(uint16_t));
173 }
174
175 return GeometryResult{
176 .type = GetPrimitiveType(),
177 .vertex_buffer =
178 {
179 .vertex_buffer = vertex_buffer,
180 .index_buffer = index_buffer,
181 .vertex_count = index_count > 0 ? index_count : vertex_count,
182 .index_type =
183 index_count > 0 ? IndexType::k16bit : IndexType::kNone,
184 },
185 .transform = entity.GetShaderTransform(pass),
186 };
187 }

References impeller::HostBuffer::Emplace(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), impeller::k16bit, impeller::kNone, and impeller::GeometryResult::type.

## ◆ GetPositionUVBuffer()

GeometryResult impeller::VerticesGeometry::GetPositionUVBuffer | ( | Rect | texture_coverage,
|  | Matrix | effect_transform,
|  | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| override virtual

Implements impeller::Geometry.

Definition at line 189 of file vertices_geometry.cc.

194 {
195 using VS = TexturePipeline::VertexShader;
196
197 auto index_count = indices_.size();
198 auto vertex_count = vertices_.size();
199 auto uv_transform =
200 texture_coverage.GetNormalizingTransform() * effect_transform;
201 auto has_texture_coordinates = HasTextureCoordinates();
202
203 size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData);
204 size_t total_idx_bytes = index_count * sizeof(uint16_t);
205 auto vertex_buffer = renderer.GetTransientsBuffer().Emplace(
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];
211 auto texture_coord =
212 has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
213 auto uv = uv_transform * texture_coord;
214 // From experimentation we need to clamp these values to < 1.0 or else
215 // there can be flickering.
216 VS::PerVertexData vertex_data = {
217 .position = vertex,
218 .texture_coords =
219 Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough),
220 std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)),
221 };
222 std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData));
223 }
224 });
225
226 BufferView index_buffer = {};
227 if (index_count > 0) {
228 index_buffer = renderer.GetTransientsBuffer().Emplace(
229 indices_.data(), total_idx_bytes, alignof(uint16_t));
230 }
231
232 return GeometryResult{
233 .type = GetPrimitiveType(),
234 .vertex_buffer =
235 {
236 .vertex_buffer = vertex_buffer,
237 .index_buffer = index_buffer,
238 .vertex_count = index_count > 0 ? index_count : vertex_count,
239 .index_type =
240 index_count > 0 ? IndexType::k16bit : IndexType::kNone,
241 },
242 .transform = entity.GetShaderTransform(pass),
243 };
244 }

References impeller::HostBuffer::Emplace(), impeller::TRect< T >::GetNormalizingTransform(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), HasTextureCoordinates(), impeller::k16bit, impeller::kEhCloseEnough, impeller::kNone, and impeller::GeometryResult::type.

## ◆ GetTextureCoordinateCoverge()

std::optional< Rect > impeller::VerticesGeometry::GetTextureCoordinateCoverge | ( |  | ) | const

Definition at line 98 of file vertices_geometry.cc.

98 {
99 if (!HasTextureCoordinates()) {
100 return std::nullopt;
101 }
102 auto vertex_count = vertices_.size();
103 if (vertex_count == 0) {
104 return std::nullopt;
105 }
106
107 return Rect::MakePointBounds(texture_coordinates_.begin(),
108 texture_coordinates_.end());
109 }

References HasTextureCoordinates(), and impeller::TRect< Scalar >::MakePointBounds().

## ◆ GetVertexType()

GeometryVertexType impeller::VerticesGeometry::GetVertexType | ( |  | ) | const
| override virtual

Implements impeller::Geometry.

Definition at line 246 of file vertices_geometry.cc.

246 {
247 if (HasVertexColors()) {
248 return GeometryVertexType::kColor;
249 }
250 if (HasTextureCoordinates()) {
251 return GeometryVertexType::kUV;
252 }
253
254 return GeometryVertexType::kPosition;
255 }

References HasTextureCoordinates(), HasVertexColors(), impeller::kColor, impeller::kPosition, and impeller::kUV.

## ◆ HasTextureCoordinates()

bool impeller::VerticesGeometry::HasTextureCoordinates | ( |  | ) | const

Definition at line 94 of file vertices_geometry.cc.

94 {
95 return texture_coordinates_.size() > 0;
96 }

Referenced by GetPositionUVBuffer(), GetTextureCoordinateCoverge(), and GetVertexType().

## ◆ HasVertexColors()

bool impeller::VerticesGeometry::HasVertexColors | ( |  | ) | const

Definition at line 90 of file vertices_geometry.cc.

90 {
91 return colors_.size() > 0;
92 }

Referenced by GetVertexType().

The documentation for this class was generated from the following files:

- impeller/entity/geometry/vertices_geometry.h
- impeller/entity/geometry/vertices_geometry.cc

impeller::IndexType::k16bit
@ k16bit
impeller::kEhCloseEnough
constexpr float kEhCloseEnough
Definition: constants.h:56
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:405
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:151
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:15
impeller::kColor
@ kColor
Definition: geometry.h:51
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::Point
TPoint< Scalar > Point
Definition: point.h:316
impeller::VerticesGeometry::HasVertexColors
bool HasVertexColors() const
Definition: vertices_geometry.cc:90
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::kUV
@ kUV
Definition: geometry.h:52
impeller::VerticesGeometry::HasTextureCoordinates
bool HasTextureCoordinates() const
Definition: vertices_geometry.cc:94
impeller::RenderPipelineT::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:93
impeller::kPosition
@ kPosition
Definition: geometry.h:50