Flutter Impeller
impeller::VerticesGeometry Class Referencefinal

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

#include <vertices_geometry.h>

Inheritance diagram for impeller::VerticesGeometry:
impeller::Geometry

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 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
 
std::optional< RectGetCoverage (const Matrix &transform) const override
 
bool HasVertexColors () const
 
bool HasTextureCoordinates () const
 
std::optional< RectGetTextureCoordinateCoverge () 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
 
virtual Scalar ComputeAlphaCoverage (const Entity &entitys) const
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Geometry
static std::shared_ptr< GeometryMakeFillPath (const Path &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::shared_ptr< GeometryMakeStrokePath (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< GeometryMakeCover ()
 
static std::shared_ptr< GeometryMakeRect (const Rect &rect)
 
static std::shared_ptr< GeometryMakeOval (const Rect &rect)
 
static std::shared_ptr< GeometryMakeLine (const Point &p0, const Point &p1, Scalar width, Cap cap)
 
static std::shared_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::shared_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::shared_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::shared_ptr< GeometryMakePointField (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)
 

Detailed Description

A geometry that is created from a vertices object.

Definition at line 13 of file vertices_geometry.h.

Member Enumeration Documentation

◆ VertexMode

Enumerator
kTriangles 
kTriangleStrip 
kTriangleFan 

Definition at line 15 of file vertices_geometry.h.

15  {
16  kTriangles,
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 57 of file vertices_geometry.cc.

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

◆ ~VerticesGeometry()

impeller::VerticesGeometry::~VerticesGeometry ( )
default

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::VerticesGeometry::GetCoverage ( const Matrix transform) const
overridevirtual

Implements impeller::Geometry.

Definition at line 202 of file vertices_geometry.cc.

203  {
204  return bounds_.TransformBounds(transform);
205 }

References transform, and impeller::TRect< T >::TransformBounds().

◆ GetPositionBuffer()

GeometryResult impeller::VerticesGeometry::GetPositionBuffer ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Geometry.

Definition at line 113 of file vertices_geometry.cc.

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

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

◆ GetPositionUVColorBuffer()

GeometryResult impeller::VerticesGeometry::GetPositionUVColorBuffer ( Rect  texture_coverage,
Matrix  effect_transform,
const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const

Definition at line 147 of file vertices_geometry.cc.

152  {
154 
155  auto vertex_count = vertices_.size();
156  auto uv_transform =
157  texture_coverage.GetNormalizingTransform() * effect_transform;
158  auto has_texture_coordinates = HasTextureCoordinates();
159  auto has_colors = HasVertexColors();
160 
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];
168  auto texture_coord =
169  has_texture_coordinates ? texture_coordinates_[i] : vertices_[i];
170  auto uv = uv_transform * texture_coord;
171  VS::PerVertexData vertex_data = {
172  .vertices = vertex,
173  .texture_coords = uv,
174  .color = has_colors ? colors_[i] : Color::BlackTransparent(),
175  };
176  std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData));
177  }
178  });
179 
180  BufferView index_buffer = {};
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));
186  }
187 
188  return GeometryResult{
189  .type = GetPrimitiveType(),
190  .vertex_buffer =
191  {
192  .vertex_buffer = vertex_buffer,
193  .index_buffer = index_buffer,
194  .vertex_count = index_count > 0 ? index_count : vertex_count,
195  .index_type =
196  index_count > 0 ? IndexType::k16bit : IndexType::kNone,
197  },
198  .transform = entity.GetShaderTransform(pass),
199  };
200 }

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

◆ GetTextureCoordinateCoverge()

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

Definition at line 100 of file vertices_geometry.cc.

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

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

◆ HasTextureCoordinates()

bool impeller::VerticesGeometry::HasTextureCoordinates ( ) const

Definition at line 96 of file vertices_geometry.cc.

96  {
97  return texture_coordinates_.size() > 0;
98 }

Referenced by GetPositionUVColorBuffer(), and GetTextureCoordinateCoverge().

◆ HasVertexColors()

bool impeller::VerticesGeometry::HasVertexColors ( ) const

Definition at line 92 of file vertices_geometry.cc.

92  {
93  return colors_.size() > 0;
94 }

Referenced by GetPositionUVColorBuffer().


The documentation for this class was generated from the following files:
impeller::IndexType::k16bit
@ k16bit
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:463
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:16
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:231
impeller::VerticesGeometry::HasVertexColors
bool HasVertexColors() const
Definition: vertices_geometry.cc:92
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:106
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Color::BlackTransparent
static constexpr Color BlackTransparent()
Definition: color.h:272
impeller::VerticesGeometry::HasTextureCoordinates
bool HasTextureCoordinates() const
Definition: vertices_geometry.cc:96