@@ -42,6 +42,10 @@ std::unique_ptr<Geometry> Geometry::MakeCover() {
4242 return std::make_unique<CoverGeometry>();
4343}
4444
45+ std::unique_ptr<Geometry> Geometry::MakeRect (Rect rect) {
46+ return std::make_unique<RectGeometry>(rect);
47+ }
48+
4549// ///// Vertices Geometry ///////
4650
4751VerticesGeometry::VerticesGeometry (Vertices vertices)
@@ -695,4 +699,54 @@ std::optional<Rect> CoverGeometry::GetCoverage(const Matrix& transform) const {
695699 return Rect::MakeMaximum ();
696700}
697701
702+ // ///// Rect Geometry ///////
703+
704+ RectGeometry::RectGeometry (Rect rect) : rect_(rect) {}
705+
706+ RectGeometry::~RectGeometry () = default ;
707+
708+ GeometryResult RectGeometry::GetPositionBuffer (const ContentContext& renderer,
709+ const Entity& entity,
710+ RenderPass& pass) {
711+ constexpr uint16_t kRectIndicies [4 ] = {0 , 1 , 2 , 3 };
712+ auto & host_buffer = pass.GetTransientsBuffer ();
713+ return GeometryResult{
714+ .type = PrimitiveType::kTriangleStrip ,
715+ .vertex_buffer = {.vertex_buffer = host_buffer.Emplace (
716+ rect_.GetPoints ().data (), 8 * sizeof (float ),
717+ alignof (float )),
718+ .index_buffer = host_buffer.Emplace (
719+ kRectIndicies , 4 * sizeof (uint16_t ),
720+ alignof (uint16_t )),
721+ .index_count = 4 ,
722+ .index_type = IndexType::k16bit},
723+ .prevent_overdraw = false ,
724+ };
725+ }
726+
727+ GeometryResult RectGeometry::GetPositionColorBuffer (
728+ const ContentContext& renderer,
729+ const Entity& entity,
730+ RenderPass& pass,
731+ Color paint_color,
732+ BlendMode blend_mode) {
733+ // TODO(jonahwilliams): support per-color vertex in rect geometry.
734+ return {};
735+ }
736+
737+ GeometryResult RectGeometry::GetPositionUVBuffer (const ContentContext& renderer,
738+ const Entity& entity,
739+ RenderPass& pass) {
740+ // TODO(jonahwilliams): support texture coordinates in rect geometry.
741+ return {};
742+ }
743+
744+ GeometryVertexType RectGeometry::GetVertexType () const {
745+ return GeometryVertexType::kPosition ;
746+ }
747+
748+ std::optional<Rect> RectGeometry::GetCoverage (const Matrix& transform) const {
749+ return rect_;
750+ }
751+
698752} // namespace impeller
0 commit comments