33// found in the LICENSE file.
44
55#include " impeller/entity/geometry.h"
6+ #include < iostream>
67
78#include " impeller/core/device_buffer.h"
89#include " impeller/entity/contents/content_context.h"
@@ -825,6 +826,10 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
825826 const ContentContext& renderer,
826827 const Entity& entity,
827828 RenderPass& pass) {
829+ if (radius_ <= 0 ) {
830+ return {};
831+ }
832+
828833 if (!renderer.GetDeviceCapabilities ().SupportsDisabledRasterization ()) {
829834 return GetPositionBufferCPU (renderer, entity, pass);
830835 }
@@ -836,21 +841,11 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
836841
837842 using VS = PointFieldGeometryPipeline::VertexShader;
838843
839- // Create Dummy index buffer.
840- auto index_count = divisions_per_circle * points_.size () * 3 ;
841- std::vector<uint16_t > dummy_index (index_count);
842- for (auto i = 0u ; i < index_count; i++) {
843- dummy_index[i] = i;
844- }
845-
846844 auto vtx_buffer = VertexBuffer{
847845 .vertex_buffer = host_buffer.Emplace (
848846 points_.data (), points_.size () * sizeof (Point), alignof (Point)),
849- .index_buffer = host_buffer.Emplace (dummy_index.data (),
850- points_.size () * sizeof (uint16_t ),
851- alignof (uint16_t )),
852847 .index_count = points_.size (),
853- .index_type = IndexType::k16bit ,
848+ .index_type = IndexType::kNone ,
854849 };
855850
856851 DeviceBufferDescriptor buffer_desc;
@@ -860,9 +855,6 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
860855 auto buffer =
861856 renderer.GetContext ()->GetResourceAllocator ()->CreateBuffer (buffer_desc);
862857
863- auto index_buffer = host_buffer.Emplace (
864- dummy_index.data (), index_count * sizeof (uint16_t ), alignof (uint16_t ));
865-
866858 Command cmd;
867859 cmd.label = " Points Geometry" ;
868860
@@ -905,9 +897,8 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
905897 .vertex_buffer = {.vertex_buffer = {.buffer = buffer,
906898 .range =
907899 Range{0 , total * sizeof (Point)}},
908- .index_buffer = index_buffer,
909- .index_count = index_count,
910- .index_type = IndexType::k16bit},
900+ .index_count = divisions_per_circle * points_.size () * 3 ,
901+ .index_type = IndexType::kNone },
911902 .transform = Matrix::MakeOrthographic (pass.GetRenderTargetSize ()) *
912903 entity.GetTransformation (),
913904 .prevent_overdraw = false ,
@@ -925,7 +916,8 @@ GeometryResult PointFieldGeometry::GetPositionBufferCPU(
925916 auto radian_start = round_ ? 0 .0f : 0 .785398f ;
926917 auto radian_step = k2Pi / divisions_per_circle;
927918
928- VertexBufferBuilder<SolidFillVertexShader::PerVertexData> vtx_builder;
919+ VertexBufferBuilder<SolidFillVertexShader::PerVertexData, uint32_t >
920+ vtx_builder;
929921 vtx_builder.Reserve (total);
930922
931923 for (auto i = 0u ; i < points_.size (); i++) {
@@ -940,7 +932,7 @@ GeometryResult PointFieldGeometry::GetPositionBufferCPU(
940932 auto pt2 = center + Point (cos (elapsed_angle), sin (elapsed_angle)) * radius_;
941933 vtx_builder.AppendVertex ({pt2});
942934
943- for (auto j = 1u ; j < divisions_per_circle; j++) {
935+ for (auto j = 0u ; j < divisions_per_circle - 1 ; j++) {
944936 vtx_builder.AppendVertex ({center});
945937
946938 pt1 = pt2;
@@ -978,18 +970,22 @@ size_t PointFieldGeometry::ComputeCircleDivisions(Scalar scaled_radius,
978970 if (!round) {
979971 return 4 ;
980972 }
981- // note: this formula is completely arbitrary, we should find a reasonable
982- // curve based on experimental data.
983- if (scaled_radius < 4.0 ) {
973+
974+ // Note: these values are approximated based on the values returned from
975+ // the decomposition of 4 cubics performed by Path::CreatePolyline.
976+ if (scaled_radius < 1.0 ) {
977+ return 4 ;
978+ }
979+ if (scaled_radius < 2.0 ) {
984980 return 8 ;
985981 }
986- if (scaled_radius < 16 ) {
987- return 16 ;
982+ if (scaled_radius < 12.0 ) {
983+ return 24 ;
988984 }
989- if (scaled_radius < 32 ) {
990- return 32 ;
985+ if (scaled_radius < 22.0 ) {
986+ return 34 ;
991987 }
992- return 64 ;
988+ return std::min (scaled_radius, 140 . 0f ) ;
993989}
994990
995991// |Geometry|
@@ -1000,7 +996,11 @@ GeometryVertexType PointFieldGeometry::GetVertexType() const {
1000996// |Geometry|
1001997std::optional<Rect> PointFieldGeometry::GetCoverage (
1002998 const Matrix& transform) const {
1003- return Rect::MakeMaximum ();
999+ auto pt_bounds = Rect::MakePointBounds (points_.begin (), points_.end ());
1000+ if (pt_bounds.has_value ()) {
1001+ return pt_bounds->TransformBounds (transform);
1002+ }
1003+ return std::nullopt ;
10041004}
10051005
10061006} // namespace impeller
0 commit comments