367 "draw_curves_evaluate_length_intercept");
369 const int curve_resolution = 2;
377 gpu::VertBuf *points_by_curve_buf = GPU_vertbuf_create_with_format(IntBuf::format());
379 points_by_curve_buf->
data<
int>().copy_from({0, 3, 5});
381 gpu::VertBuf *curves_type_buf = GPU_vertbuf_create_with_format(IntBuf::format());
382 curves_type_buf->allocate(1);
385 gpu::VertBuf *curves_resolution_buf = GPU_vertbuf_create_with_format(IntBuf::format());
386 curves_resolution_buf->allocate(2);
387 curves_resolution_buf->data<
int>().copy_from({curve_resolution, curve_resolution});
389 gpu::VertBuf *evaluated_points_by_curve_buf = GPU_vertbuf_create_with_format(IntBuf::format());
390 evaluated_points_by_curve_buf->allocate(3);
391 evaluated_points_by_curve_buf->data<
int>().copy_from(evaluated_offsets);
393 const Vector<float> points_radius = {1.0f, 0.5f, 0.0f, 0.0f, 2.0f};
404 positions_buf->
data<
float3>().copy_from(positions);
413 radii_buf->
data<
float>().copy_from(points_radius);
423 PassSimple pass(
"Curves Interpolation Catmull Rom");
458 evaluated_positions_radii_buf.
read();
459 evaluated_time_buf.
read();
460 curves_length_buf.
read();
488 EXPECT_FLOAT_EQ(curves_length_buf[0], std::numbers::sqrt3);
489 EXPECT_FLOAT_EQ(curves_length_buf[1], 2.0f * std::numbers::sqrt3);
491 EXPECT_FLOAT_EQ(evaluated_time_buf[0], 0.0f);
492 EXPECT_FLOAT_EQ(evaluated_time_buf[1], 0.218749985f);
493 EXPECT_FLOAT_EQ(evaluated_time_buf[2], 0.5f);
494 EXPECT_FLOAT_EQ(evaluated_time_buf[3], 0.78125f);
495 EXPECT_FLOAT_EQ(evaluated_time_buf[4], 1.0f);
496 EXPECT_FLOAT_EQ(evaluated_time_buf[5], 0.0f);
497 EXPECT_FLOAT_EQ(evaluated_time_buf[6], 0.5f);
498 EXPECT_FLOAT_EQ(evaluated_time_buf[7], 1.0f);
510 handles_positions_left_buf->
allocate(handle_pos_left.
size());
511 handles_positions_left_buf->
data<
float3>().copy_from(handle_pos_left);
515 handles_positions_right_buf->
allocate(handle_pos_right.
size());
516 handles_positions_right_buf->
data<
float3>().copy_from(handle_pos_right);
518 const Vector<int> bezier_offsets = {0, 2, 4, 5, 0, 2, 3};
523 bezier_offsets_buf->
data<
int>().copy_from(bezier_offsets);
525 gpu::VertBuf *curves_type_bezier_buf = GPU_vertbuf_create_with_format(IntBuf::format());
526 curves_type_bezier_buf->
allocate(1);
537 PassSimple pass(
"Curves Interpolation Bezier");
571 evaluated_positions_radii_buf.
read();
572 evaluated_time_buf.
read();
573 curves_length_buf.
read();
582 const int curve_index = 0;
588 positions.
as_span().slice(points),
589 handle_pos_left.
as_span().slice(points),
590 handle_pos_right.
as_span().slice(points),
591 bezier_offsets.
as_span().slice(offsets),
595 points_radius.
as_span().slice(points),
596 bezier_offsets.
as_span().slice(offsets),
600 const int curve_index = 1;
606 positions.
as_span().slice(points),
607 handle_pos_left.
as_span().slice(points),
608 handle_pos_right.
as_span().slice(points),
609 bezier_offsets.
as_span().slice(offsets),
613 points_radius.
as_span().slice(points),
614 bezier_offsets.
as_span().slice(offsets),
618 EXPECT_EQ(evaluated_positions_radii_buf[0],
float4(interp_pos[0], interp_rad[0]));
619 EXPECT_EQ(evaluated_positions_radii_buf[1],
float4(interp_pos[1], interp_rad[1]));
620 EXPECT_EQ(evaluated_positions_radii_buf[2],
float4(interp_pos[2], interp_rad[2]));
621 EXPECT_EQ(evaluated_positions_radii_buf[3],
float4(interp_pos[3], interp_rad[3]));
622 EXPECT_EQ(evaluated_positions_radii_buf[4],
float4(interp_pos[4], interp_rad[4]));
623 EXPECT_EQ(evaluated_positions_radii_buf[5],
float4(interp_pos[5], interp_rad[5]));
624 EXPECT_EQ(evaluated_positions_radii_buf[6],
float4(interp_pos[6], interp_rad[6]));
625 EXPECT_EQ(evaluated_positions_radii_buf[7],
float4(interp_pos[7], interp_rad[7]));
629 float curve_len[2] = {0.0f, 0.0f};
632 interp_time[0] = 0.0f;
635 interp_time[i] = curve_len[0];
638 interp_time[i] /= curve_len[0];
640 interp_time[5] = 0.0f;
643 interp_time[i] = curve_len[1];
646 interp_time[i] /= curve_len[1];
649 EXPECT_FLOAT_EQ(curves_length_buf[0], curve_len[0]);
650 EXPECT_FLOAT_EQ(curves_length_buf[1], curve_len[1]);
652 EXPECT_FLOAT_EQ(evaluated_time_buf[0], interp_time[0]);
653 EXPECT_FLOAT_EQ(evaluated_time_buf[1], interp_time[1]);
654 EXPECT_FLOAT_EQ(evaluated_time_buf[2], interp_time[2]);
655 EXPECT_FLOAT_EQ(evaluated_time_buf[3], interp_time[3]);
656 EXPECT_FLOAT_EQ(evaluated_time_buf[4], interp_time[4]);
657 EXPECT_FLOAT_EQ(evaluated_time_buf[5], interp_time[5]);
658 EXPECT_FLOAT_EQ(evaluated_time_buf[6], interp_time[6]);
659 EXPECT_FLOAT_EQ(evaluated_time_buf[7], interp_time[7]);
665 {0.1f, 0.2f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f},
670 {0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 2.0f},
678 basis_cache_offset.
append(basis_cache_c0.
invalid ? -1 : basis_cache_packed.
size());
679 basis_cache_packed.
extend(
682 basis_cache_packed.
extend(
686 basis_cache_offset.
append(basis_cache_c1.
invalid ? -1 : basis_cache_packed.
size());
687 basis_cache_packed.
extend(
690 basis_cache_packed.
extend(
699 basis_cache_buf->
data<
uint>().copy_from(basis_cache_packed);
703 basis_cache_offset_buf->
allocate(basis_cache_offset.
size());
704 basis_cache_offset_buf->
data<
int>().copy_from(basis_cache_offset);
711 curves_order_buf->
data<
int>().copy_from(
712 Span<int>(
reinterpret_cast<const int *
>(curves_order.
data()), curves_order.
size() / 4));
714 const Vector<float> control_weights = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
716 gpu::VertBuf *control_weights_buf = GPU_vertbuf_create_with_format(Radius::format());
718 control_weights_buf->
data<
float>().copy_from(control_weights);
720 gpu::VertBuf *curves_type_nurbs_buf = GPU_vertbuf_create_with_format(IntBuf::format());
732 PassSimple pass(
"Curves Interpolation Nurbs");
768 evaluated_positions_radii_buf.
read();
769 evaluated_time_buf.
read();
770 curves_length_buf.
read();
779 const int curve_index = 0;
785 curves_order[curve_index],
786 control_weights.
as_span().slice(points),
787 positions.
as_span().slice(points),
792 curves_order[curve_index],
793 control_weights.
as_span().slice(points),
794 points_radius.
as_span().slice(points),
798 const int curve_index = 1;
804 curves_order[curve_index],
805 control_weights.
as_span().slice(points),
806 positions.
as_span().slice(points),
811 curves_order[curve_index],
812 control_weights.
as_span().slice(points),
813 points_radius.
as_span().slice(points),
817 EXPECT_NEAR(evaluated_positions_radii_buf[0].
x, interp_pos[0].
x, 0.000001f);
818 EXPECT_NEAR(evaluated_positions_radii_buf[1].
x, interp_pos[1].
x, 0.000001f);
819 EXPECT_NEAR(evaluated_positions_radii_buf[2].
x, interp_pos[2].
x, 0.000001f);
820 EXPECT_NEAR(evaluated_positions_radii_buf[3].
x, interp_pos[3].
x, 0.000001f);
821 EXPECT_NEAR(evaluated_positions_radii_buf[4].
x, interp_pos[4].
x, 0.000001f);
822 EXPECT_NEAR(evaluated_positions_radii_buf[5].
x, interp_pos[5].
x, 0.000001f);
823 EXPECT_NEAR(evaluated_positions_radii_buf[6].
x, interp_pos[6].
x, 0.000001f);
824 EXPECT_NEAR(evaluated_positions_radii_buf[7].
x, interp_pos[7].
x, 0.000001f);
826 EXPECT_NEAR(evaluated_positions_radii_buf[0].
w, interp_rad[0], 0.000001f);
827 EXPECT_NEAR(evaluated_positions_radii_buf[1].
w, interp_rad[1], 0.000001f);
828 EXPECT_NEAR(evaluated_positions_radii_buf[2].
w, interp_rad[2], 0.000001f);
829 EXPECT_NEAR(evaluated_positions_radii_buf[3].
w, interp_rad[3], 0.000001f);
830 EXPECT_NEAR(evaluated_positions_radii_buf[4].
w, interp_rad[4], 0.000001f);
831 EXPECT_NEAR(evaluated_positions_radii_buf[5].
w, interp_rad[5], 0.000001f);
832 EXPECT_NEAR(evaluated_positions_radii_buf[6].
w, interp_rad[6], 0.000001f);
833 EXPECT_NEAR(evaluated_positions_radii_buf[7].
w, interp_rad[7], 0.000001f);
837 float curve_len[2] = {0.0f, 0.0f};
840 interp_time[0] = 0.0f;
843 interp_time[i] = curve_len[0];
846 interp_time[i] /= curve_len[0];
848 interp_time[5] = 0.0f;
851 interp_time[i] = curve_len[1];
854 interp_time[i] /= curve_len[1];
857 EXPECT_NEAR(curves_length_buf[0], curve_len[0], 0.000001f);
858 EXPECT_NEAR(curves_length_buf[1], curve_len[1], 0.000001f);
860 EXPECT_EQ(evaluated_time_buf[0], interp_time[0]);
861 EXPECT_NEAR(evaluated_time_buf[1], interp_time[1], 0.000001f);
862 EXPECT_NEAR(evaluated_time_buf[2], interp_time[2], 0.000001f);
863 EXPECT_NEAR(evaluated_time_buf[3], interp_time[3], 0.000001f);
864 EXPECT_NEAR(evaluated_time_buf[4], interp_time[4], 0.000001f);
865 EXPECT_EQ(evaluated_time_buf[5], interp_time[5]);
866 EXPECT_NEAR(evaluated_time_buf[6], interp_time[6], 0.000001f);
867 EXPECT_NEAR(evaluated_time_buf[7], interp_time[7], 0.000001f);
898 const int curve_resolution = 2;
901 const Vector<int> evaluated_offsets = {0, 5, 8, 11};
907 gpu::VertBuf *points_by_curve_buf = GPU_vertbuf_create_with_format(IntBuf::format());
909 points_by_curve_buf->
data<
int>().copy_from(curves_to_point);
911 gpu::VertBuf *curves_type_buf = GPU_vertbuf_create_with_format(IntBuf::format());
913 curves_type_buf->
data<
char>().copy_from(
916 gpu::VertBuf *curves_resolution_buf = GPU_vertbuf_create_with_format(IntBuf::format());
917 curves_resolution_buf->allocate(3);
918 curves_resolution_buf->data<
int>().copy_from(
919 {curve_resolution, curve_resolution, curve_resolution});
921 gpu::VertBuf *evaluated_points_by_curve_buf = GPU_vertbuf_create_with_format(IntBuf::format());
922 evaluated_points_by_curve_buf->allocate(evaluated_offsets.
size());
923 evaluated_points_by_curve_buf->data<
int>().copy_from(evaluated_offsets);
928 float4(0.5f, 0.0f, 0.0f, 4.0f),
929 float4(0.0f, 0.0f, 2.0f, 4.0f),
930 float4(2.0f, 3.0f, 4.0f, 7.0f),
931 float4(3.0f, 4.0f, 3.0f, 4.0f),
932 float4(2.0f, 2.0f, 3.0f, 4.0f),
933 float4(4.0f, 5.0f, 6.0f, 7.0f)};
935 attr_float4.
as_span().cast<
float>().take_front(attr_float4.
size() * 3).cast<
float3>();
937 attr_float4.
as_span().cast<
float>().take_front(attr_float4.
size() * 2).cast<
float2>();
945 gpu::VertBuf *attribute_float4_buf = GPU_vertbuf_create_with_format(Float4::format());
947 attribute_float4_buf->
data<
float4>().copy_from(attr_float4);
953 gpu::VertBuf *attribute_float3_buf = GPU_vertbuf_create_with_format(Float3::format());
955 attribute_float3_buf->
data<
float3>().copy_from(attr_float3);
961 gpu::VertBuf *attribute_float2_buf = GPU_vertbuf_create_with_format(Float2::format());
963 attribute_float2_buf->
data<
float2>().copy_from(attr_float2);
969 gpu::VertBuf *attribute_float_buf = GPU_vertbuf_create_with_format(Float::format());
971 attribute_float_buf->
data<
float>().copy_from(attr_float);
976 {0.1f, 0.2f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f},
984 basis_cache_offset.
append(basis_cache_c0.
invalid ? -1 : basis_cache_packed.
size());
985 basis_cache_packed.
extend(
988 basis_cache_packed.
extend(
992 basis_cache_offset.
append(-1);
993 basis_cache_offset.
append(-1);
997 gpu::VertBuf *basis_cache_buf = GPU_vertbuf_create_with_format(IntBuf::format());
999 basis_cache_buf->
data<
uint>().copy_from(basis_cache_packed);
1001 gpu::VertBuf *basis_cache_offset_buf = GPU_vertbuf_create_with_format(IntBuf::format());
1002 basis_cache_offset_buf->
allocate(basis_cache_offset.
size());
1003 basis_cache_offset_buf->
data<
int>().copy_from(basis_cache_offset);
1007 gpu::VertBuf *curves_order_buf = GPU_vertbuf_create_with_format(IntBuf::format());
1009 curves_order_buf->
data<
int>().copy_from(
1010 Span<int>(
reinterpret_cast<const int *
>(curves_order.
data()), curves_order.
size() / 4));
1012 const Vector<float> control_weights = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
1014 gpu::VertBuf *control_weights_buf = GPU_vertbuf_create_with_format(Float::format());
1016 control_weights_buf->
data<
float>().copy_from(control_weights);
1025 gpu::VertBuf *handles_positions_left_buf = GPU_vertbuf_create_with_format(Float3::format());
1026 handles_positions_left_buf->
allocate(handle_pos_left.
size());
1027 handles_positions_left_buf->
data<
float3>().copy_from(handle_pos_left);
1029 gpu::VertBuf *handles_positions_right_buf = GPU_vertbuf_create_with_format(Float3::format());
1030 handles_positions_right_buf->
allocate(handle_pos_right.
size());
1031 handles_positions_right_buf->
data<
float3>().copy_from(handle_pos_right);
1033 const Vector<int> bezier_offsets = {0, 2, 4, 5, 0, 2, 3};
1035 gpu::VertBuf *bezier_offsets_buf = GPU_vertbuf_create_with_format(IntBuf::format());
1037 bezier_offsets_buf->
data<
int>().copy_from(bezier_offsets);
1041 std::string pass_name = std::string(
"Curves ") + attr_type +
" Interpolation";
1042 std::string sh_name = std::string(
"draw_curves_interpolate_") + attr_type +
"_attribute";
1100 dispatch(
"float4", attribute_float4_buf, evaluated_float4_buf);
1102 evaluated_float4_buf.
read();
1112 const int curve_index = 0;
1113 const IndexRange points = curves_to_point_indices[curve_index];
1114 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1116 curves_order[curve_index],
1117 control_weights.
as_span().slice(points),
1118 in_attr.
slice(points),
1119 out_attr.
slice(evaluated_points));
1122 const int curve_index = 1;
1123 const IndexRange points = curves_to_point_indices[curve_index];
1124 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1127 bezier_offsets.
as_span().slice(offsets),
1128 out_attr.slice(evaluated_points));
1131 const int curve_index = 2;
1132 const IndexRange points = curves_to_point_indices[curve_index];
1133 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1135 in_attr.
slice(points),
false, curve_resolution, out_attr.
slice(evaluated_points));
1157 dispatch(
"float3", attribute_float3_buf, evaluated_float3_buf);
1159 evaluated_float3_buf.
read();
1169 const int curve_index = 0;
1170 const IndexRange points = curves_to_point_indices[curve_index];
1171 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1173 curves_order[curve_index],
1174 control_weights.
as_span().slice(points),
1175 in_attr.
slice(points),
1176 out_attr.
slice(evaluated_points));
1179 const int curve_index = 1;
1180 const IndexRange points = curves_to_point_indices[curve_index];
1181 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1184 bezier_offsets.
as_span().slice(offsets),
1185 out_attr.
slice(evaluated_points));
1188 const int curve_index = 2;
1189 const IndexRange points = curves_to_point_indices[curve_index];
1190 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1192 in_attr.
slice(points),
false, curve_resolution, out_attr.
slice(evaluated_points));
1214 dispatch(
"float2", attribute_float2_buf, evaluated_float2_buf);
1216 evaluated_float2_buf.
read();
1226 const int curve_index = 0;
1227 const IndexRange points = curves_to_point_indices[curve_index];
1228 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1230 curves_order[curve_index],
1231 control_weights.
as_span().slice(points),
1232 in_attr.
slice(points),
1233 out_attr.
slice(evaluated_points));
1236 const int curve_index = 1;
1237 const IndexRange points = curves_to_point_indices[curve_index];
1238 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1241 bezier_offsets.
as_span().slice(offsets),
1242 out_attr.
slice(evaluated_points));
1245 const int curve_index = 2;
1246 const IndexRange points = curves_to_point_indices[curve_index];
1247 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1249 in_attr.
slice(points),
false, curve_resolution, out_attr.
slice(evaluated_points));
1271 dispatch(
"float", attribute_float_buf, evaluated_float_buf);
1273 evaluated_float_buf.
read();
1283 const int curve_index = 0;
1284 const IndexRange points = curves_to_point_indices[curve_index];
1285 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1287 curves_order[curve_index],
1288 control_weights.
as_span().slice(points),
1289 in_attr.
slice(points),
1290 out_attr.
slice(evaluated_points));
1293 const int curve_index = 1;
1294 const IndexRange points = curves_to_point_indices[curve_index];
1295 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1298 bezier_offsets.
as_span().slice(offsets),
1299 out_attr.
slice(evaluated_points));
1302 const int curve_index = 2;
1303 const IndexRange points = curves_to_point_indices[curve_index];
1304 const IndexRange evaluated_points = curves_to_eval_indices[curve_index];
1306 in_attr.
slice(points),
false, curve_resolution, out_attr.
slice(evaluated_points));
1309 EXPECT_EQ(evaluated_float_buf[0],
float(interp_data[0]));
1310 EXPECT_EQ(evaluated_float_buf[1],
float(interp_data[1]));
1311 EXPECT_EQ(evaluated_float_buf[2],
float(interp_data[2]));
1312 EXPECT_EQ(evaluated_float_buf[3],
float(interp_data[3]));
1313 EXPECT_EQ(evaluated_float_buf[4],
float(interp_data[4]));
1314 EXPECT_EQ(evaluated_float_buf[5],
float(interp_data[5]));
1315 EXPECT_EQ(evaluated_float_buf[6],
float(interp_data[6]));
1316 EXPECT_EQ(evaluated_float_buf[7],
float(interp_data[7]));
1317 EXPECT_EQ(evaluated_float_buf[8],
float(interp_data[8]));
1318 EXPECT_EQ(evaluated_float_buf[9],
float(interp_data[9]));
1319 EXPECT_EQ(evaluated_float_buf[10],
float(interp_data[10]));
1321 EXPECT_EQ(evaluated_float_buf[11],
float(0.0));