44#define EDIT_CURVES_NURBS_CONTROL_POINT (1u)
45#define EDIT_CURVES_BEZIER_HANDLE (1u << 1)
46#define EDIT_CURVES_ACTIVE_HANDLE (1u << 2)
49#define EDIT_CURVES_BEZIER_KNOT (1u << 3)
50#define EDIT_CURVES_HANDLE_TYPES_SHIFT (4u)
156 return (cache && cache->
is_dirty ==
false &&
164 if (cache ==
nullptr) {
165 cache = MEM_new<GreasePencilBatchCache>(__func__);
182 if (cache ==
nullptr) {
231 const float softness,
232 const float miter_angle)
236 float asp_normalized = (asp > 1.0f) ? (1.0f / asp) : asp;
238 if (asp_normalized <= 0.0f) {
239 asp_normalized = 1.0f;
265 const float miter_norm = (miter_angle /
M_PI);
285 const int layer_index,
290 object, drawing, layer_index, memory);
292 return editable_strokes;
307 object, drawing, memory);
309 return visible_strokes;
321 int *r_drawing_line_index,
322 int *r_drawing_line_start_offset)
328 const int offset = *r_drawing_line_start_offset;
329 int line_index = *r_drawing_line_index;
333 const IndexRange points = points_by_curve_eval[curve_i];
334 const bool is_cyclic = cyclic[curve_i];
336 for (
const int point : points) {
337 lines_data[line_index++] = point + offset;
341 lines_data[line_index++] = points.
first() + offset;
347 *r_drawing_line_index = line_index;
348 *r_drawing_line_start_offset +=
curves.evaluated_points_num();
354 int *r_drawing_point_index,
355 int *r_drawing_start_offset)
360 const int offset = *r_drawing_start_offset;
361 int ibo_index = *r_drawing_point_index;
365 const IndexRange points = points_by_curve[curve_i];
366 for (
const int point : points) {
367 points_data[ibo_index++] = point + offset;
371 *r_drawing_point_index = ibo_index;
372 *r_drawing_start_offset +=
curves.points_num();
387 const IndexMask selected_editable_strokes =
389 object, drawing, layer_index, memory);
392 curves.curve_type_counts(),
394 selected_editable_strokes,
410 object, drawing, layer_index, memory);
413 curves.curve_type_counts(),
415 selected_editable_strokes,
422 const float4x4 &layer_space_to_object_space,
425 int *r_drawing_line_start_offset,
426 int *r_total_line_ids_num)
437 curves.points_by_curve(), nurbs_curves, memory);
450 *r_drawing_line_start_offset += nurbs_points.
size();
451 *r_total_line_ids_num += nurbs_points.
size();
454 *r_total_line_ids_num += nurbs_curves.
size();
460 int *r_drawing_line_index,
461 int *r_drawing_line_start_offset)
469 int line_index = *r_drawing_line_index;
473 const IndexRange points = points_by_curve[curve_i];
476 lines_data[line_index++] = point + *r_drawing_line_start_offset;
481 *r_drawing_line_start_offset += points.
size();
484 *r_drawing_line_index = line_index;
493 constexpr float no_active_weight = 666.0f;
508 const char *active_defgroup_name = (active_defgroup ==
nullptr) ?
"" : active_defgroup->
name;
517 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
520 "selection", gpu::VertAttrType::SFLOAT_32);
523 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
526 "selection", gpu::VertAttrType::SFLOAT_32);
535 int visible_points_num = 0;
536 int total_line_ids_num = 0;
537 int total_points_num = 0;
538 int total_line_points_num = 0;
540 const Layer &
layer = *layers[info.layer_index];
542 total_line_points_num +=
curves.evaluated_points_num();
545 if (
layer.is_locked()) {
549 total_points_num +=
curves.points_num();
553 object, info.drawing, info.layer_index, memory);
555 curves.points_by_curve(), nurbs_curves, memory);
558 total_line_points_num += nurbs_points.
size();
561 if (total_points_num == 0) {
575 int drawing_start_offset = 0;
576 int drawing_line_start_offset = 0;
578 const Layer &
layer = *layers[info.layer_index];
579 const float4x4 layer_space_to_object_space =
layer.to_object_space(
object);
587 object, info.drawing, info.layer_index, memory);
589 object, info.drawing, memory);
592 const IndexRange points_eval(drawing_line_start_offset,
curves.evaluated_points_num());
595 layer_space_to_object_space,
596 edit_line_points.slice(points_eval));
598 drawing_line_start_offset +=
curves.evaluated_points_num();
601 total_line_ids_num += visible_strokes_for_lines.
size();
604 visible_strokes_for_lines);
619 curves.ensure_can_interpolate_to_evaluated();
622 curves.interpolate_to_evaluated(weights_array.
as_span(), line_weights_slice);
627 for (
const int point : line_weights_slice.index_range()) {
628 if (line_weights_slice[point] == no_active_weight) {
631 line_weights_slice[point] =
math::clamp(line_weights_slice[point], 0.0f, 1.0f);
637 if (
layer.is_locked()) {
642 curves.positions(), layer_space_to_object_space, points_pos.
slice(points));
646 drawing_start_offset +=
curves.points_num();
649 object, info.drawing, info.layer_index, memory);
653 layer_space_to_object_space,
656 &drawing_line_start_offset,
657 &total_line_ids_num);
660 points_by_curve, visible_strokes_for_points);
661 visible_points_num += drawing_visible_points_num;
667 int lines_ibo_index = 0;
672 int points_ibo_index = 0;
675 drawing_start_offset = 0;
676 drawing_line_start_offset = 0;
678 const Layer &
layer = *layers[info.layer_index];
682 object, info.drawing, memory);
684 object, info.drawing, info.layer_index, memory);
687 visible_strokes_for_lines,
690 &drawing_line_start_offset);
693 if (
layer.is_locked()) {
698 object, info.drawing, info.layer_index, memory);
700 info.drawing, nurbs_curves, lines_data, &lines_ibo_index, &drawing_line_start_offset);
702 visible_strokes_for_points,
705 &drawing_start_offset);
730 const int all_points,
732 int *r_drawing_line_index,
733 const int *r_drawing_line_start_offset)
739 const int offset = *r_drawing_line_start_offset;
740 int line_index = *r_drawing_line_index;
743 bezier_points.
foreach_index([&](
const int point_i,
const int pos) {
744 handle_lines[line_index++] =
uint2(offset + all_points + pos + bezier_points.
size() * 0,
746 handle_lines[line_index++] =
uint2(offset + all_points + pos + bezier_points.
size() * 1,
750 *r_drawing_line_index = line_index;
761 int *r_drawing_point_index,
762 int *r_drawing_start_offset)
768 const int offset = *r_drawing_start_offset;
769 int ibo_index = *r_drawing_point_index;
773 points_data[ibo_index++] = point + offset;
776 *r_drawing_point_index = ibo_index;
777 *r_drawing_start_offset += bezier_points.
size() * 2;
781#define GREASE_PENCIL_EDIT_POINT_SELECTED (1 << 0)
782#define GREASE_PENCIL_EDIT_STROKE_SELECTED (1 << 1)
783#define GREASE_PENCIL_EDIT_MULTIFRAME (1 << 2)
784#define GREASE_PENCIL_EDIT_STROKE_START (1 << 3)
785#define GREASE_PENCIL_EDIT_STROKE_END (1 << 4)
786#define GREASE_PENCIL_EDIT_POINT_DIMMED (1 << 5)
810 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
813 "rad", gpu::VertAttrType::SFLOAT_32);
816 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
819 "selection", gpu::VertAttrType::SFLOAT_32);
822 "vflag", gpu::VertAttrType::UINT_32);
825 "selection", gpu::VertAttrType::SFLOAT_32);
828 "data", gpu::VertAttrType::UINT_32);
841 int total_points_num = 0;
843 const Layer &
layer = *layers[info.layer_index];
845 if (
layer.is_locked()) {
850 total_points_num +=
curves.points_num();
853 int total_line_points_num = 0;
856 total_line_points_num +=
curves.evaluated_points_num();
859 int total_bezier_point_num = 0;
865 total_bezier_point_num += bezier_points.
size();
873 object, info.drawing, info.layer_index, memory);
875 curves.points_by_curve(), nurbs_curves, memory);
878 total_line_points_num += nurbs_points.
size();
882 total_points_num += total_bezier_point_num * 2;
884 if (total_points_num == 0) {
903 edit_points_selection.fill(0.0f);
904 edit_points_vflag.fill(0);
905 edit_points_info.fill(0);
906 edit_line_selection.fill(0.0f);
909 int visible_points_num = 0;
910 int total_line_ids_num = 0;
911 int total_bezier_num = 0;
912 int drawing_start_offset = 0;
913 int drawing_line_start_offset = 0;
915 const Layer &
layer = *layers[info.layer_index];
916 const float4x4 layer_space_to_object_space =
layer.to_object_space(
object);
925 object, info.drawing, info.layer_index, memory);
928 const IndexRange points_eval(drawing_line_start_offset,
curves.evaluated_points_num());
930 if (!
layer.is_locked()) {
932 curves.positions(), layer_space_to_object_space, edit_points.
slice(points));
933 edit_rad.slice(points).copy_from(radii);
937 layer_space_to_object_space,
938 edit_line_points.slice(points_eval));
941 if (!
layer.is_locked()) {
944 for (
const int curve_i :
curves.curves_range()) {
945 const IndexRange sub_points = points_by_curve[curve_i].shift(drawing_start_offset);
950 const IndexMask selected_editable_points =
952 object, info.drawing, info.layer_index, memory);
957 const IndexMask selected_editable_points_with_bezier =
968 curves.ensure_can_interpolate_to_evaluated();
971 selected_points.
as_mutable_span(), 1.0f, selected_editable_points_with_bezier);
972 curves.interpolate_to_evaluated(selected_points.
as_span(), line_selection_slice);
976 drawing_line_start_offset +=
curves.evaluated_points_num();
979 total_line_ids_num += visible_strokes_for_lines.
size();
982 visible_strokes_for_lines);
987 if (
layer.is_locked()) {
991 drawing_start_offset +=
curves.points_num();
992 const IndexMask selected_editable_strokes =
994 object, info.drawing, info.layer_index, memory);
1001 selected_editable_fill_strokes);
1007 object, info.drawing, info.layer_index, memory);
1011 layer_space_to_object_space,
1013 edit_line_selection,
1014 &drawing_line_start_offset,
1015 &total_line_ids_num);
1025 bezier_points.
size());
1033 if (
const std::optional<
Span<float3>> handles_left =
curves.handle_positions_left()) {
1039 if (
const std::optional<
Span<float3>> handles_right =
curves.handle_positions_right()) {
1062 bezier_points.
foreach_index([&](
const int point_i,
const int pos) {
1063 const bool selected = selected_point[point_i] || selected_left[point_i] ||
1064 selected_right[point_i];
1065 edit_points_info.slice(left_slice)[pos] =
bezier_data_value(types_left[point_i], selected);
1066 edit_points_info.slice(right_slice)[pos] =
bezier_data_value(types_right[point_i], selected);
1068 radius_slice_left[pos] = radii[point_i];
1069 radius_slice_right[pos] = radii[point_i];
1075 visible_points_num += bezier_points.
size() * 2;
1076 drawing_start_offset += bezier_points.
size() * 2;
1078 total_bezier_num += bezier_points.
size();
1085 int lines_ibo_index = 0;
1090 int points_ibo_index = 0;
1096 int handle_lines_id = 0;
1098 drawing_start_offset = 0;
1099 drawing_line_start_offset = 0;
1101 const Layer *
layer = layers[info.layer_index];
1105 object, info.drawing, info.layer_index, memory);
1108 visible_strokes_for_lines,
1111 &drawing_line_start_offset);
1113 if (!
layer->is_locked()) {
1116 const IndexMask selected_editable_strokes =
1118 object, info.drawing, info.layer_index, memory);
1120 object, info.drawing, info.layer_index, memory);
1125 info.drawing, nurbs_curves, lines_data, &lines_ibo_index, &drawing_line_start_offset);
1127 info.drawing.strokes().points_num(),
1130 &drawing_start_offset);
1132 selected_editable_fill_strokes,
1135 &drawing_start_offset);
1137 bezier_points, points_data, &points_ibo_index, &drawing_start_offset);
1191 return miter_angles;
1209 for (const int curve_i : range) {
1210 const IndexRange eval_points = evaluated_points_by_curve[curve_i];
1211 const IndexRange points = points_by_curve[curve_i];
1212 MutableSpan<float> eval_corners_range = eval_corners.as_mutable_span().slice(eval_points);
1214 switch (types[curve_i]) {
1215 case CURVE_TYPE_POLY:
1216 for (const int i : points.index_range()) {
1217 eval_corners_range[i] = miter_angles[points[i]];
1220 case CURVE_TYPE_BEZIER: {
1221 const Span<int> offsets = curves.bezier_evaluated_offsets_for_curve(curve_i);
1222 for (const int i : points.index_range()) {
1223 eval_corners_range[offsets[i]] = miter_angles[points[i]];
1227 case CURVE_TYPE_NURBS:
1228 case CURVE_TYPE_CATMULL_ROM: {
1246 const float a = r2 - r1;
1249 if (r1 <= 0.0f ||
l <= 0.0f ||
l == a) {
1254 if (
abs(a) < 0.001f *
l) {
1258 const float E = (
l + a) / (
l - a);
1259 const float E_i = a / r1 + 1.0f;
1262 if (E <= 0.0f || E_i <= 0.0f) {
1266 return 2.0f *
log(E_i) /
log(E);
1275 float radii_length = 0.0f;
1277 const float l = lengths[i] - (i > 0 ? lengths[i - 1] : 0.0f);
1278 const float r1 = radii[points[i]];
1279 const float r2 = radii[points[(i + 1) % points.size()]];
1281 radii_lengths[i] = radii_length;
1284 return radii_lengths;
1295 if (cache->
vbo !=
nullptr) {
1309 int total_verts_num = 0;
1310 int total_triangles_num = 0;
1318 object, info.drawing, memory);
1320 object, info.drawing, memory);
1321 const std::optional<GroupedSpan<int3>> triangles = info.drawing.triangles();
1329 total_triangles_num += triangles ?
1335 IndexRange points = points_by_curve[curve_i];
1336 const bool is_cyclic = cyclic[curve_i] && (points.
size() > 2);
1342 verts_start_offsets[curve_i] = total_verts_num;
1344 total_verts_num += 1 + points.
size() + 1;
1346 total_verts_num += (is_cyclic ? 1 : 0);
1347 num_points += points.
size();
1350 verts_start_offsets.
last() = total_verts_num;
1352 for (
const int fill_index : intersection_points.
index_range()) {
1353 const Span<float3> inter_points = intersection_points[fill_index];
1355 total_verts_num += inter_points.
size();
1358 total_triangles_num += (num_points + num_cyclic) * 2;
1360 verts_start_offsets_per_visible_drawing.
append(std::move(verts_start_offsets));
1379 int triangle_ibo_index = 0;
1382 for (
const int drawing_i : drawings.
index_range()) {
1385 const float4x4 layer_space_to_object_space =
layer.to_object_space(
object);
1388 if (
curves.evaluated_points_num() == 0) {
1397 curves.ensure_can_interpolate_to_evaluated();
1432 const std::optional<GroupedSpan<int3>> triangles = info.
drawing.
triangles();
1433 const std::optional<GroupedSpan<int>> fills = info.
drawing.
fills();
1437 const Span<int> verts_start_offsets = verts_start_offsets_per_visible_drawing[drawing_i];
1440 object, info.
drawing, memory);
1442 curves.ensure_evaluated_lengths();
1444 auto populate_point = [&](
IndexRange verts_range,
1461 s_vert.radius =
math::max(radii[point_i], 0.0f) *
1463 s_vert.opacity = opacities[point_i] *
1467 s_vert.point_id = cyclic ? -verts_range[idx] : verts_range[idx];
1468 s_vert.stroke_id = first_vert;
1476 stroke_point_aspect_ratios[curve_i],
1477 stroke_softness[curve_i],
1478 miter_angles[point_i]);
1479 s_vert.u_stroke = u_stroke;
1482 copy_v4_v4(c_vert.vcol, vertex_colors[point_i]);
1483 copy_v4_v4(c_vert.fcol, stroke_fill_colors[first_curve]);
1484 c_vert.fcol[3] = (int(c_vert.fcol[3] * 10000.0f) * 10.0f) + fill_opacities[first_curve];
1487 auto populate_curve = [&](
const int curve_i,
1488 const int first_curve,
1489 const int first_vert,
1491 const IndexRange points = points_by_curve[curve_i];
1492 const bool is_cyclic = cyclic[curve_i] && (points.
size() > 2);
1493 const int verts_start_offset = verts_start_offsets[curve_i];
1494 const int num_verts = 1 + points.
size() + (is_cyclic ? 1 : 0) + 1;
1499 const Span<float> lengths =
curves.evaluated_lengths_for_curve(curve_i, cyclic[curve_i]);
1500 const float u_translation = u_translations[curve_i];
1501 const float u_scale = u_scales[curve_i];
1502 const int mat_id = materials[curve_i];
1513 auto get_u_stroke = [&](
const int i) {
1515 const float u = i > 0 ? lengths[i - 1] : 0.0f;
1516 return u_scale * u + u_translation;
1521 return float(i +
int(u_translation));
1523 return u_scale *
float(i) + u_translation;
1526 const float u = i > 0 ? radii_lengths[i - 1] : 0.0f;
1527 return u + u_translation;
1530 const float u = i > 0 ? lengths[i - 1] : 0.0f;
1531 return u_scale * u + u_translation;
1535 return float(i +
int(u_translation));
1539 verts_slice.
first().mat = -1;
1541 verts_slice.
first().stroke_id = verts_range.
last();
1545 const int idx = i + 1;
1546 const float u_stroke = get_u_stroke(i);
1547 populate_point(verts_range,
1549 start_caps[curve_i],
1563 const int idx = points.
size() + 1;
1564 const float u_stroke = get_u_stroke(points.
size());
1565 populate_point(verts_range,
1567 start_caps[curve_i],
1581 verts_slice.
last().mat = -1;
1583 verts_slice.
last().stroke_id = verts_range.
first();
1592 for (
const int curve_i :
curves.curves_range()) {
1593 const bool is_filled = fill_ids[curve_i] != 0;
1594 const bool active_filled = is_filled && !added_fill_drawcalls[curve_i];
1597 if (active_filled) {
1598 const Span<int> fill = (*fills)[fill_index];
1599 const int first_curve = fill.first();
1600 for (
const int pos : fill.index_range()) {
1601 const int curve_i = fill[pos];
1602 added_fill_drawcalls[curve_i] =
true;
1603 first_curves[curve_i] = first_curve;
1614 visible_strokes.slice(range).foreach_index([&](const int64_t curve_i) {
1615 const int first_curve = first_curves[curve_i];
1616 const int first_vert = verts_start_offsets[first_curve];
1617 const float4x2 texture_matrix = texture_matrices[first_curve] *
1618 object_space_to_layer_space;
1620 populate_curve(curve_i, first_curve, first_vert, texture_matrix);
1628 for (
const int fill_index : intersection_points.
index_range()) {
1629 const Span<float3> inter_points = intersection_points[fill_index];
1635 const int first_curve = (*fills)[fill_index].first();
1637 const float4x2 texture_matrix = texture_matrices[first_curve] *
1638 object_space_to_layer_space;
1640 const int fill_intersect_offset = intersection_offsets[fill_index].first();
1642 for (
const int inter_i : inter_points.
index_range()) {
1643 const float3 &pos_3d = inter_points[inter_i];
1645 const int verts_start_offset = verts_start_offsets.
last() + inter_i +
1646 fill_intersect_offset;
1654 s_vert.
point_id = verts_start_offset;
1655 s_vert.
stroke_id = verts_start_offsets[first_curve];
1665 c_vert.
fcol[3] = (int(c_vert.
fcol[3] * 10000.0f) * 10.0f) + fill_opacities[first_curve];
1671 visible_strokes.index_range(),
1674 visible_strokes.slice(range).foreach_index([&](const int64_t curve_i) {
1675 const int first_curve = curve_i;
1676 const int first_vert = verts_start_offsets[first_curve];
1677 const float4x2 texture_matrix = texture_matrices[first_curve] *
1678 object_space_to_layer_space;
1680 populate_curve(curve_i, first_curve, first_vert, texture_matrix);
1696 for (
const int curve_i :
curves.curves_range()) {
1697 const bool is_filled = fill_ids[curve_i] != 0;
1698 const bool active_filled = is_filled && (fill_index_by_curves[curve_i] == -1);
1701 if (active_filled) {
1702 const Span<int> fill = (*fills)[fill_index];
1703 const int first_curve = fill.first();
1704 for (
const int pos : fill.index_range()) {
1705 const int curve_i = fill[pos];
1706 fill_index_by_curves[curve_i] = fill_index;
1707 first_curves[curve_i] = first_curve;
1714 visible_strokes.foreach_index([&](
const int curve_i) {
1716 const int fill_index = fill_index_by_curves[curve_i];
1718 const bool is_filled = fill_index != -1;
1719 const bool active_filled = triangles && is_filled && (first_curves[curve_i] == curve_i);
1721 if (active_filled) {
1722 const int fill_index = fill_index_by_curves[curve_i];
1723 const Span<int3> tris_slice = (*triangles)[fill_index];
1731 fill_point_offset_data.as_mutable_span());
1733 Array<int> fill_point_to_pos_map(fill_point_offset_data.last());
1735 for (const int i : range) {
1736 fill_point_to_pos_map.as_mutable_span().slice(fill_point_offset[i]).fill(i);
1740 const int fill_intersect_offset = intersection_points.is_empty() ?
1742 intersection_offsets[fill_index].start();
1744 auto point_to_id = [&](
int32_t p) {
1746 return (-(p + 1) + fill_intersect_offset + verts_start_offsets.last())
1749 const int pos_ = fill_point_to_pos_map[p];
1750 const int curve_ =
fill[pos_];
1751 const int fill_offset = fill_point_offset[pos_].first();
1756 for (
const int3 tri : tris_slice) {
1757 triangle_ibo_data[triangle_ibo_index] =
uint3(
1758 point_to_id(tri.x), point_to_id(tri.y), point_to_id(tri.z));
1759 triangle_ibo_index++;
1763 const IndexRange points = points_by_curve[curve_i];
1764 const bool is_cyclic = cyclic[curve_i] && (points.
size() > 2);
1765 const int verts_start_offset = verts_start_offsets[curve_i];
1766 const int num_verts = 1 + points.
size() + (is_cyclic ? 1 : 0) + 1;
1770 const int idx = i + 1;
1772 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 0, v_mat + 1, v_mat + 2);
1773 triangle_ibo_index++;
1774 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 2, v_mat + 1, v_mat + 3);
1775 triangle_ibo_index++;
1779 const int idx = points.
size() + 1;
1782 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 0, v_mat + 1, v_mat + 2);
1783 triangle_ibo_index++;
1784 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 2, v_mat + 1, v_mat + 3);
1785 triangle_ibo_index++;
1790 visible_strokes.foreach_index([&](
const int curve_i) {
1791 const IndexRange points = points_by_curve[curve_i];
1792 const bool is_cyclic = cyclic[curve_i] && (points.
size() > 2);
1793 const int verts_start_offset = verts_start_offsets[curve_i];
1794 const int num_verts = 1 + points.
size() + (is_cyclic ? 1 : 0) + 1;
1798 const int idx = i + 1;
1800 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 0, v_mat + 1, v_mat + 2);
1801 triangle_ibo_index++;
1802 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 2, v_mat + 1, v_mat + 3);
1803 triangle_ibo_index++;
1807 const int idx = points.
size() + 1;
1810 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 0, v_mat + 1, v_mat + 2);
1811 triangle_ibo_index++;
1812 triangle_ibo_data[triangle_ibo_index] =
uint3(v_mat + 2, v_mat + 1, v_mat + 3);
1813 triangle_ibo_index++;
1820 verts[total_verts_num + 0].mat = -1;
1821 verts[total_verts_num + 1].mat = -1;
1833 cache->is_dirty =
false;
1862 int curve_inter_offset = 0;
1870 object, info.drawing, memory);
1873 const IndexRange points = points_by_curve[curve_i];
1874 const int point_len = points.
size();
1875 const int point_start = index_len;
1876 const bool is_cyclic = cyclic[curve_i] && (point_len > 2);
1878 index_len += point_len + (is_cyclic ? 1 : 0) + 1;
1880 index_start_per_curve.
append(point_start);
1881 cyclic_per_curve.
append(is_cyclic);
1882 is_onion_per_curve.
append(info.onion_id != 0);
1885 curve_intersections_start_offsets.
append_n_times(curve_inter_offset, visible_strokes.
size());
1888 index_start_per_curve.
append(index_len);
1897 for (const int curve : range) {
1899 const IndexRange offset_range = range_per_curve[curve].drop_back(1);
1904 const IndexRange index_range = offset_range.shift(curve + 1 +
1905 curve_intersections_start_offsets[curve]);
1906 if (is_onion_per_curve[curve]) {
1907 for (const int i : offset_range.index_range()) {
1908 indices[offset_range[i]] = gpu::RESTART_INDEX;
1910 if (cyclic_per_curve[curve]) {
1911 indices[offset_range.last()] = gpu::RESTART_INDEX;
1915 for (const int i : offset_range.index_range()) {
1916 indices[offset_range[i]] = index_range[i];
1918 if (cyclic_per_curve[curve]) {
1919 indices[offset_range.last()] = index_range.first();
1922 indices[offset_range.one_after_last()] = gpu::RESTART_INDEX;
1931 cache->is_dirty =
false;
1940 if (cache ==
nullptr) {
Low-level operations for curves.
Low-level operations for curves.
Low-level operations for grease pencil that cannot be defined in the C++ header yet.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define GP_STROKE_MITER_ANGLE_BEVEL
#define GP_STROKE_MITER_ANGLE_ROUND
#define GPU_batch_create(primitive_type, vertex_buf, index_buf)
#define GPU_BATCH_DISCARD_SAFE(batch)
#define GPU_INDEXBUF_DISCARD_SAFE(elem)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
#define BLI_assert_unreachable()
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
const T & last(const int64_t n=0) const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr IndexRange index_range() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr void fill(const T &value) const
constexpr T & first() const
constexpr T & last(const int64_t n=0) const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
T get_internal_single() const
static VArray from_single(T value, const int64_t size)
static VArray from_container(ContainerT container)
void append(const T &value)
IndexRange index_range() const
void append_n_times(const T &value, const int64_t n)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
std::optional< GroupedSpan< int > > fills() const
Span< float4x2 > texture_matrices() const
const bke::CurvesGeometry & strokes() const
VArray< float > radii() const
std::optional< GroupedSpan< int3 > > triangles() const
VArray< ColorGeometry4f > fill_colors() const
VArray< float > opacities() const
GroupedSpan< float3 > intersection_points() const
constexpr Span slice(int64_t start, int64_t size) const
IndexMask slice(IndexRange range) const
IndexRange index_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define EDIT_CURVES_ACTIVE_HANDLE
#define EDIT_CURVES_HANDLE_TYPES_SHIFT
#define EDIT_CURVES_BEZIER_KNOT
#define EDIT_CURVES_BEZIER_HANDLE
#define GREASE_PENCIL_EDIT_STROKE_START
#define GREASE_PENCIL_EDIT_STROKE_END
#define GPENCIL_MATERIAL_BUFFER_LEN
#define GP_IS_STROKE_VERTEX_BIT
#define GP_CORNER_TYPE_BEVEL_BITS
#define GP_CORNER_TYPE_ROUND_BITS
#define GP_VERTEX_ID_SHIFT
#define GP_CORNER_TYPE_MITER_NUMBER
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void fill_index_range(MutableSpan< T > span, const T start=0)
int64_t count_booleans(const VArray< bool > &varray)
IndexMask indices_for_type(const VArray< int8_t > &types, const std::array< int, CURVE_TYPES_NUM > &type_counts, const CurveType type, const IndexMask &selection, LinearAllocator<> &memory)
IndexMask curve_to_point_selection(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, LinearAllocator<> &memory)
IndexMask selected_mask_to_fills(const IndexMask &selected_mask, const CurvesGeometry &curves, AttrDomain selection_domain, IndexMaskMemory &memory)
static bool grease_pencil_batch_cache_valid(const GreasePencil &grease_pencil)
gpu::Batch * DRW_cache_grease_pencil_get(const Scene *scene, Object *ob)
void DRW_grease_pencil_batch_cache_validate(GreasePencil *grease_pencil)
static const GPUVertFormat * grease_pencil_stroke_format()
static Array< float > get_radii_lengths(const Span< float > lengths, const VArray< float > &radii, const IndexRange &points)
static void grease_pencil_cache_add_nurbs(const bke::greasepencil::Drawing &drawing, const IndexMask &nurbs_curves, const VArray< float > &selected_point, const float4x4 &layer_space_to_object_space, MutableSpan< float3 > edit_line_points, MutableSpan< float > edit_line_selection, int *r_drawing_line_start_offset, int *r_total_line_ids_num)
static void grease_pencil_batch_cache_clear(GreasePencil &grease_pencil)
static VArray< float > interpolate_corners(const bke::CurvesGeometry &curves)
static void index_buf_add_nurbs_lines(const bke::greasepencil::Drawing &drawing, const IndexMask &nurbs_curves, MutableSpan< uint > lines_data, int *r_drawing_line_index, int *r_drawing_line_start_offset)
static void index_buf_add_line_points(const bke::greasepencil::Drawing &drawing, const IndexMask &curves_mask, MutableSpan< uint > lines_data, int *r_drawing_line_index, int *r_drawing_line_start_offset)
void DRW_grease_pencil_batch_cache_free(GreasePencil *grease_pencil)
gpu::Batch * DRW_cache_grease_pencil_face_wireframe_get(const Scene *scene, Object *ob)
static void index_buf_add_bezier_line_points(const IndexMask bezier_points, MutableSpan< uint > points_data, int *r_drawing_point_index, int *r_drawing_start_offset)
gpu::Batch * DRW_cache_grease_pencil_edit_handles_get(const Scene *scene, Object *ob)
static GreasePencilBatchCache * grease_pencil_batch_cache_init(GreasePencil &grease_pencil)
static void grease_pencil_edit_batch_ensure(Object &object, const GreasePencil &grease_pencil, const Scene &scene)
void DRW_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode)
static float segment_radius_length(const float l, const float r1, const float r2)
static IndexMask grease_pencil_get_editable_selected_nurbs_curves(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
static void grease_pencil_weight_batch_ensure(Object &object, const GreasePencil &grease_pencil, const Scene &scene)
static void index_buf_add_points(const bke::greasepencil::Drawing &drawing, const IndexMask &curves_mask, MutableSpan< uint > points_data, int *r_drawing_point_index, int *r_drawing_start_offset)
static VArray< T > attribute_interpolate(const VArray< T > &input, const bke::CurvesGeometry &curves)
static GreasePencilBatchCache * grease_pencil_batch_cache_get(GreasePencil &grease_pencil)
gpu::VertBuf * DRW_cache_grease_pencil_position_buffer_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_grease_pencil_edit_lines_get(const Scene *scene, Object *ob)
static IndexMask grease_pencil_get_visible_non_nurbs_curves(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
static IndexMask grease_pencil_get_visible_nurbs_curves(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
static const GPUVertFormat * grease_pencil_color_format()
gpu::Batch * DRW_cache_grease_pencil_weight_lines_get(const Scene *scene, Object *ob)
static bool grease_pencil_batch_cache_is_edit_discarded(GreasePencilBatchCache *cache)
gpu::Batch * DRW_cache_grease_pencil_edit_points_get(const Scene *scene, Object *ob)
static uint32_t bezier_data_value(int8_t handle_type, bool is_active)
static void index_buf_add_bezier_handle_lines(const IndexMask bezier_points, const int all_points, MutableSpan< uint2 > handle_lines, int *r_drawing_line_index, const int *r_drawing_line_start_offset)
BLI_INLINE int32_t pack_rotation_aspect_hardness_miter(const float rot, const float asp, const float softness, const float miter_angle)
gpu::Batch * DRW_cache_grease_pencil_weight_points_get(const Scene *scene, Object *ob)
static void grease_pencil_wire_batch_ensure(Object &object, const GreasePencil &grease_pencil, const Scene &scene)
static void grease_pencil_geom_batch_ensure(Object &object, const GreasePencil &grease_pencil, const Scene &scene)
gpu::VertBuf * DRW_cache_grease_pencil_color_buffer_get(const Scene *scene, Object *ob)
static IndexMask grease_pencil_get_editable_non_nurbs_curves(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, IndexMaskMemory &memory)
IndexMask retrieve_editable_and_selected_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
IndexMask retrieve_editable_and_all_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const eHandleDisplay handle_display, IndexMaskMemory &memory)
IndexMask retrieve_editable_and_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
IndexMask retrieve_visible_bezier_handle_points(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const eHandleDisplay handle_display, IndexMaskMemory &memory)
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
IndexMask retrieve_visible_fills(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
IndexMask retrieve_editable_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
constexpr uint32_t RESTART_INDEX
BLI_NOINLINE void fill(T *__restrict data, const T &value, const IndexMask &mask)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T clamp(const T &a, const T &min, const T &max)
CartesianBasis invert(const CartesianBasis &basis)
T max(const T &a, const T &b)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
int sum_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
auto accumulated_task_sizes(Fn &&fn)
VecBase< uint32_t, 2 > uint2
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
void GPU_indexbuf_init_ex(GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len)
MINLINE void copy_v3_v3(float r[3], const float a[3])
@ GP_MATERIAL_PLACEMENT_RADIUS
@ GP_MATERIAL_PLACEMENT_COUNT
@ GP_MATERIAL_PLACEMENT_DENSITY
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_use(gpu::VertBuf *)
VecBase< uint32_t, 3 > uint3
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
T & DRW_object_get_data_for_drawing(const Object &object)
MatBase< float, 4, 2 > float4x2
@ BKE_GREASEPENCIL_BATCH_DIRTY_ALL
MutableSpan< uint32_t > GPU_indexbuf_get_data(GPUIndexBufBuilder *)
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
gpu::IndexBuf * GPU_indexbuf_build_ex(GPUIndexBufBuilder *builder, uint index_min, uint index_max, bool uses_restart_indices)
uint GPU_vertbuf_get_vertex_len(const gpu::VertBuf *verts)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
MINLINE void copy_v4_v4(float r[4], const float a[4])
VecBase< float, 3 > float3
@ GP_STROKE_CAP_TYPE_ROUND
MINLINE int clamp_i(int value, int min, int max)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eMaterialGPencilStyle_Mode mode
eMaterialGPencilPlacementMode placement_mode
gpu::IndexBuf * edit_handles_ibo
gpu::IndexBuf * edit_line_indices
gpu::Batch * edit_handles
gpu::VertBuf * edit_points_info
gpu::VertBuf * edit_points_vflag
gpu::VertBuf * edit_points_rad
gpu::VertBuf * edit_line_pos
gpu::IndexBuf * edit_points_indices
gpu::VertBuf * edit_line_selection
gpu::VertBuf * edit_points_selection
gpu::VertBuf * edit_points_pos
int32_t packed_asp_hard_rot
const bke::greasepencil::Drawing & drawing
OffsetIndices< int > offsets
IndexRange index_range() const