53#define EDIT_CURVES_NURBS_CONTROL_POINT (1u)
54#define EDIT_CURVES_BEZIER_HANDLE (1u << 1)
55#define EDIT_CURVES_ACTIVE_HANDLE (1u << 2)
58#define EDIT_CURVES_BEZIER_KNOT (1u << 3)
59#define EDIT_CURVES_HANDLE_TYPES_SHIFT (4u)
105 return (cache && cache->
is_dirty ==
false);
113 cache = MEM_new<CurvesBatchCache>(__func__);
114 curves.batch_cache = cache;
145 for (
const int i :
IndexRange(GPU_MAX_ATTR)) {
148 for (
const int i :
IndexRange(GPU_MAX_ATTR)) {
200 return *
curves.batch_cache;
211 return points_num + bezier_offsets.
total_size() * 2;
227 const bool mark_active,
232 [&](
const int curve) {
233 const IndexRange points = points_by_curve[curve];
234 bool is_active =
false;
239 data.slice(points).fill(data_value);
253 const int points_num = points_by_curve.
total_size();
259 gpu::VertAttrType::UINT_32);
280 [&](
const int curve,
const int64_t pos) {
281 const IndexRange points = points_by_curve[curve];
282 const IndexRange bezier_range = bezier_offsets[pos];
284 const int point = points[i];
287 const bool selected = selection[point] || selection_left[point] ||
288 selection_right[point];
289 const int bezier_point = bezier_range[i];
309 const int points_num = positions.
size();
312 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
317 data.take_front(positions.
size()).copy_from(positions);
321 const std::optional<Span<float3>> handles_left =
curves.handle_positions_left();
322 const std::optional<Span<float3>> handles_right =
curves.handle_positions_right();
323 if (handles_left && handles_right) {
347 const int points_num = radii.
size();
350 gpu::VertAttrType::SFLOAT_32);
355 data.take_front(radii.
size()).copy_from(radii);
365 [&](
const int curve,
const int64_t pos) {
366 const IndexRange points = points_by_curve[curve];
367 const IndexRange bezier_range = bezier_offsets[pos];
369 const int point = points[i];
370 const int bezier_point = bezier_range[i];
371 data_left[bezier_point] =
data[point];
372 data_right[bezier_point] =
data[point];
385 "selection", gpu::VertAttrType::SFLOAT_32);
387 const int points_num = points_by_curve.
total_size();
418 const int points_num = points_by_curve.
total_size();
419 const int curves_num = points_by_curve.
size();
420 const int indices_num = points_num + curves_num;
425 for (
const int curve : range) {
426 const IndexRange points = points_by_curve[curve];
429 ibo_data[ibo_range[i]] = points[i];
441 const int points_num = points_by_curve.
total_size();
442 const int curves_num = points_by_curve.
size();
443 const int indices_num = points_num + curves_num * 2;
448 for (
const int curve : range) {
449 const IndexRange points = points_by_curve[curve];
452 ibo_data[ibo_range[i]] = points[i];
481 [&](
const int curve) {
482 const IndexRange points = points_by_curve[curve];
485 curve_lines[i] =
uint2(points[i]) +
uint2(0, 1);
511 const int points_num = points_by_curve.
total_size();
512 const int extra_bezier_segments = bezier_offsets.
total_size();
518 points_num + extra_bezier_segments,
521 BLI_assert(lines.size() == points_num + extra_bezier_segments);
525 lines.fill(
uint2(std::numeric_limits<uint32_t>::max()));
529 points_by_curve, cyclic, catmull_rom_curves, curve_or_handle_segments);
537 [&](
const int curve,
const int pos) {
538 const IndexRange points = points_by_curve[curve];
539 const IndexRange bezier_point_range = bezier_offsets[pos];
541 const int point = points[i];
542 const int bezier_point = bezier_point_range[i];
543 curve_or_handle_segments[point] =
uint2(handles_left[bezier_point], point);
550 [&](
const int curve,
const int pos) {
551 const IndexRange points = points_by_curve[curve];
552 const IndexRange bezier_point_range = bezier_offsets[pos];
554 const int point = points[i];
555 const int bezier_point = bezier_point_range[i];
556 right_handle_segments[bezier_point] =
uint2(handles_right[bezier_point], point);
561 BLI_assert(!lines.contains(
uint2(std::numeric_limits<uint32_t>::max())));
581 bool &r_is_point_domain)
602 r_is_point_domain =
false;
614 std::optional<StringRef> name;
641 char attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
652 char sampler_name[32];
678 format, name, evaluated_point_count_with_cyclic(
curves));
680 module.evaluate_curve_attribute(curves.has_curve_with_type(CURVE_TYPE_CATMULL_ROM),
681 curves.has_curve_with_type(CURVE_TYPE_BEZIER),
682 curves.has_curve_with_type(CURVE_TYPE_POLY),
683 curves.has_curve_with_type(CURVE_TYPE_NURBS),
684 curves.has_cyclic_curve(),
689 this->evaluated_attributes_buf[index]);
720 for (
const int i :
IndexRange(GPU_MAX_ATTR)) {
744 curves.evaluated_points_by_curve().data());
763 curves.runtime->evaluated_offsets_cache.data().all_bezier_offsets.as_span());
776 if (
curves.nurbs_weights().has_value()) {
780 curves.ensure_can_interpolate_to_evaluated();
786 for (
const BasisCache &cache : nurbs_basis_cache) {
787 basis_cache_offset.
append(cache.invalid ? -1 : basis_cache_packed.
size());
788 if (!cache.invalid) {
789 basis_cache_packed.
extend(cache.start_indices.as_span().cast<
uint32_t>());
790 basis_cache_packed.
extend(cache.weights.as_span().cast<
uint32_t>());
794 if (basis_cache_packed.
is_empty()) {
795 basis_cache_packed.
append(0);
804 if (
curves.has_cyclic_curve()) {
805 return curves.evaluated_points_num() +
curves.curves_num();
807 return curves.evaluated_points_num();
835 evaluated_point_count_with_cyclic(
curves));
837 module.evaluate_positions(curves.has_curve_with_type(CURVE_TYPE_CATMULL_ROM),
838 curves.has_curve_with_type(CURVE_TYPE_BEZIER),
839 curves.has_curve_with_type(CURVE_TYPE_POLY),
840 curves.has_curve_with_type(CURVE_TYPE_NURBS),
841 curves.has_cyclic_curve(),
844 std::move(points_pos_buf),
845 std::move(points_rad_buf),
846 evaluated_pos_rad_buf);
850 evaluated_point_count_with_cyclic(
curves));
853 module.evaluate_curve_length_intercept(curves.has_cyclic_curve(), curves.curves_num(), *this);
858 const int face_per_segment)
860 const bool is_ribbon = face_per_segment < 2;
864 if (indirection_buf) {
865 return indirection_buf;
870 indirection_buf =
module.evaluate_topology_indirection(curves.curves_num(),
871 curves.evaluated_points_num(),
874 curves.has_cyclic_curve());
876 return indirection_buf;
880 const int curve_count,
881 const int face_per_segment,
882 const bool use_cyclic,
885 gpu::Batch *&
batch = this->batch[face_per_segment];
894 if (face_per_segment == 0) {
896 segment_count =
int64_t(evaluated_point_count) + curve_count;
898 segment_count += curve_count;
902 segment_count -= (segment_count > 0) ? 1 : 0;
903 vert_per_segment = 1;
906 else if (face_per_segment == 1) {
908 segment_count =
int64_t(evaluated_point_count) + curve_count;
910 segment_count += curve_count;
914 segment_count -= (segment_count > 0) ? 1 : 0;
915 vert_per_segment = 2;
918 else if (face_per_segment >= 2) {
919 segment_count =
int64_t(evaluated_point_count) - curve_count;
921 segment_count += curve_count;
924 vert_per_segment = (face_per_segment + 1) * 2 + 1;
934 if (segment_count > segment_limit) {
935 segment_count = segment_limit;
938 r_over_limit =
false;
940 uint32_t vertex_count = segment_count * vert_per_segment;
953 if (cache ==
nullptr) {
977 MEM_delete(batch_cache);
978 curves->batch_cache =
nullptr;
984 if (cache ==
nullptr) {
988 bool do_discard =
false;
1033 bool &r_is_point_domain,
1034 bool &r_valid_attribute)
1038 if (
curves->geometry.wrap().is_empty()) {
1039 r_valid_attribute =
false;
1040 r_is_point_domain =
false;
1052 r_valid_attribute =
true;
1054 r_is_point_domain =
true;
1057 r_is_point_domain =
false;
1061 r_valid_attribute =
false;
1062 r_is_point_domain =
false;
1072 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
1085 if (ob_orig ==
nullptr) {
1093 bool is_edit_data_needed =
false;
1100 is_edit_data_needed =
true;
1107 is_edit_data_needed =
true;
1115 is_edit_data_needed =
true;
1143 if (!is_edit_data_needed) {
1149 const std::array<int, CURVE_TYPES_NUM> type_counts = curves_orig.
curve_type_counts();
1164 points_by_curve, bezier_curves, bezier_point_offset_data);
1176 curves_orig, points_by_curve, bezier_curves, bezier_offsets, *cache.
edit_points_rad);
Low-level operations for curves.
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
Object is a sort of wrapper for general info.
#define GPU_BATCH_DISCARD_SAFE(batch)
#define GPU_INDEXBUF_DISCARD_SAFE(elem)
#define GPU_vertbuf_init_with_format(verts, format)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
constexpr int64_t size() const
IndexRange index_range() const
void append(const T &value)
void extend(Span< T > array)
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
VArray< int8_t > curve_types() const
VArray< bool > cyclic() const
AttributeAccessor attributes() const
IndexRange curves_range() const
OffsetIndices< int > evaluated_points_by_curve() const
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
OffsetIndices< int > points_by_curve() const
constexpr int64_t size() const
constexpr bool is_empty() const
static VertBufPtr device_only(uint size)
static VertBufPtr from_varray(const VArray< T > &array)
static VertBufPtr from_span(const Span< T > data)
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
Utilities for rendering attributes.
#define EDIT_CURVES_ACTIVE_HANDLE
#define EDIT_CURVES_HANDLE_TYPES_SHIFT
#define EDIT_CURVES_BEZIER_KNOT
#define EDIT_CURVES_BEZIER_HANDLE
#define EDIT_CURVES_NURBS_CONTROL_POINT
void gather_group_to_group(const OffsetIndices< int > src_offsets, const OffsetIndices< int > dst_offsets, const IndexMask &selection, const Span< T > src, MutableSpan< T > dst)
BooleanMix booleans_mix_calc(const VArray< bool > &varray, IndexRange range_to_check)
int64_t count_booleans(const VArray< bool > &varray)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
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)
void drw_attributes_add_request(VectorSet< std::string > *attrs, const StringRef name)
static void create_segments_with_cyclic(const OffsetIndices< int > points_by_curve, const VArray< bool > &cyclic, const IndexMask &selection, MutableSpan< uint2 > lines)
void DRW_curves_batch_cache_validate(Curves *curves)
static void request_attribute(Curves &curves, const StringRef name)
static void calc_edit_handles_ibo(const OffsetIndices< int > points_by_curve, const IndexMask &catmull_rom_curves, const IndexMask &poly_curves, const IndexMask &bezier_curves, const IndexMask &nurbs_curves, const OffsetIndices< int > bezier_offsets, const VArray< bool > &cyclic, gpu::IndexBuf &ibo)
static gpu::VertBufPtr alloc_evaluated_point_attribute_vbo(const GPUVertFormat &format, const StringRef, int64_t size)
gpu::Batch * DRW_curves_batch_cache_get_edit_points(Curves *curves)
static bool batch_cache_is_dirty(const Curves &curves)
void DRW_curves_batch_cache_free_old(Curves *curves, int ctime)
CurvesEvalCache & curves_get_eval_cache(Curves &curves_id)
static gpu::VertBufPtr ensure_control_point_attribute(const bke::CurvesGeometry &curves, const StringRef name, const GPUVertFormat &format, bool &r_is_point_domain)
static void clear_edit_data(CurvesBatchCache *cache)
static void create_edit_points_selection(const OffsetIndices< int > points_by_curve, const IndexMask &bezier_curves, const OffsetIndices< int > bezier_offsets, const bke::AttributeAccessor attributes, gpu::VertBuf &vbo)
gpu::Batch * DRW_curves_batch_cache_get_edit_curves_handles(Curves *curves)
static std::optional< StringRef > get_first_uv_name(const bke::AttributeAccessor &attributes)
static void init_batch_cache(Curves &curves)
gpu::Batch * DRW_curves_batch_cache_get_sculpt_curves_cage(Curves *curves)
static void create_lines_ibo_with_cyclic(const OffsetIndices< int > points_by_curve, const Span< bool > cyclic, gpu::IndexBuf &ibo)
void drw_curves_get_attribute_sampler_name(const StringRef layer_name, char r_sampler_name[32])
static void create_edit_points_position_vbo(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &, CurvesBatchCache &cache)
static void clear_batch_cache(Curves &curves)
static CurvesBatchCache & get_batch_cache(Curves &curves)
void DRW_curves_batch_cache_dirty_tag(Curves *curves, int mode)
static uint32_t bezier_data_value(int8_t handle_type, bool is_active)
bool drw_attributes_overlap(const VectorSet< std::string > *a, const VectorSet< std::string > *b)
static void create_edit_points_data(const OffsetIndices< int > points_by_curve, const IndexMask &catmull_rom_curves, const IndexMask &poly_curves, const IndexMask &bezier_curves, const IndexMask &nurbs_curves, const OffsetIndices< int > bezier_offsets, const bke::CurvesGeometry &curves, gpu::VertBuf &vbo)
static void create_edit_points_position(const bke::CurvesGeometry &curves, const OffsetIndices< int > points_by_curve, const IndexMask &bezier_curves, const OffsetIndices< int > bezier_offsets, const bke::crazyspace::GeometryDeformation deformation, gpu::VertBuf &vbo)
static void extract_edit_data(const OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, const VArray< bool > &selection_attr, const bool mark_active, const uint32_t fill_value, MutableSpan< uint32_t > data)
static void create_edit_points_radius(const bke::CurvesGeometry &curves, const OffsetIndices< int > points_by_curve, const IndexMask &bezier_curves, const OffsetIndices< int > bezier_offsets, gpu::VertBuf &vbo)
static void create_lines_ibo_no_cyclic(const OffsetIndices< int > points_by_curve, gpu::IndexBuf &ibo)
gpu::Batch * DRW_curves_batch_cache_get_edit_curves_lines(Curves *curves)
static IndexRange handle_range_right(const int points_num, const OffsetIndices< int > bezier_offsets)
void drw_attributes_merge(VectorSet< std::string > *dst, const VectorSet< std::string > *src)
static IndexRange handle_range_left(const int points_num, const OffsetIndices< int > bezier_offsets)
gpu::VertBufPtr & DRW_curves_texture_for_evaluated_attribute(Curves *curves, StringRef name, bool &r_is_point_domain, bool &r_valid_attribute)
void DRW_curves_batch_cache_free(Curves *curves)
void DRW_curves_batch_cache_create_requested(Object *ob)
static int handles_and_points_num(const int points_num, const OffsetIndices< int > bezier_offsets)
constexpr ParallelGrainSize grain_size(int grain_size)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
constexpr uint32_t RESTART_INDEX
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))
VecBase< uint32_t, 2 > uint2
uint32_t GPU_max_buffer_texture_size()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
bool DRW_vbo_requested(gpu::VertBuf *vbo)
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
bool DRW_batch_requested(gpu::Batch *batch, GPUPrimType prim_type)
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
void DRW_ibo_request(gpu::Batch *batch, gpu::IndexBuf **ibo)
void GPU_vertformat_safe_attr_name(StringRef attr_name, char *r_safe_name, uint max_len)
void GPU_indexbuf_build_in_place_ex(GPUIndexBufBuilder *builder, uint index_min, uint index_max, bool uses_restart_indices, gpu::IndexBuf *elem)
T & DRW_object_get_data_for_drawing(const Object &object)
BMesh const char void * data
ListBaseT< GPUMaterialAttribute > GPU_material_attributes(const GPUMaterial *material)
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)
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
T * DEG_get_original(T *id)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
@ BKE_CURVES_BATCH_DIRTY_ALL
void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
bool DRW_ibo_requested(gpu::IndexBuf *ibo)
draw::CurvesModule * curves_module
gpu::IndexBuf * edit_handles_ibo
gpu::VertBuf * edit_points_pos
gpu::VertBuf * edit_points_rad
CurvesEvalCache eval_cache
gpu::Batch * edit_curves_lines
gpu::VertBuf * edit_points_selection
gpu::IndexBuf * edit_curves_lines_ibo
gpu::IndexBuf * sculpt_cage_ibo
gpu::VertBuf * edit_curves_lines_pos
gpu::VertBuf * edit_points_data
gpu::Batch * edit_handles
gpu::VertBufPtr curves_cyclic_buf
gpu::VertBufPtr evaluated_time_buf
gpu::VertBufPtr evaluated_attributes_buf[GPU_MAX_ATTR]
void ensure_bezier(const bke::CurvesGeometry &curves)
gpu::VertBufPtr curves_resolution_buf
gpu::VertBufPtr indirection_ribbon_buf
int last_attr_matching_time
std::array< gpu::Batch *, MAX_FACE_PER_SEGMENT > batch
gpu::VertBufPtr curves_length_buf
std::array< bool, GPU_MAX_ATTR > attributes_point_domain
gpu::VertBufPtr curves_type_buf
gpu::VertBufPtr bezier_offsets_buf
void ensure_common(const bke::CurvesGeometry &curves)
void discard_attributes()
gpu::VertBufPtr indirection_cylinder_buf
gpu::VertBufPtr control_weights_buf
gpu::Batch * batch_get(int evaluated_point_count, int curve_count, int face_per_segment, bool use_cyclic, bool &r_over_limit)
gpu::VertBufPtr & indirection_buf_get(CurvesModule &module, const bke::CurvesGeometry &curves, int face_per_segment)
gpu::VertBufPtr evaluated_pos_rad_buf
gpu::VertBufPtr evaluated_points_by_curve_buf
void ensure_attributes(struct CurvesModule &module, const bke::CurvesGeometry &curves, const GPUMaterial *gpu_material)
void ensure_positions(CurvesModule &module, const bke::CurvesGeometry &curves)
gpu::VertBufPtr curve_attributes_buf[GPU_MAX_ATTR]
VectorSet< std::string > attr_used_over_time
gpu::VertBufPtr points_by_curve_buf
gpu::VertBufPtr curves_order_buf
gpu::VertBufPtr handles_positions_right_buf
VectorSet< std::string > attr_used
gpu::VertBufPtr handles_positions_left_buf
void ensure_attribute(struct CurvesModule &module, const bke::CurvesGeometry &curves, StringRef name, int index)
void ensure_nurbs(const bke::CurvesGeometry &curves)
gpu::VertBufPtr basis_cache_offset_buf
gpu::VertBufPtr basis_cache_buf