Blender V5.3
draw_cache_impl_curves.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_array_utils.hh"
16#include "BLI_listbase.hh"
17#include "BLI_math_base_c.hh"
18#include "BLI_math_vector.hh"
20#include "BLI_span.hh"
21#include "BLI_string_utf8.hh"
22#include "BLI_task.hh"
23
24#include "DNA_curves_types.h"
25#include "DNA_object_types.h"
26#include "DNA_userdef_types.h"
27
29
30#include "BKE_crazyspace.hh"
31#include "BKE_curves.hh"
32#include "BKE_curves_utils.hh"
33#include "BKE_customdata.hh"
34#include "BKE_geometry_set.hh"
35
36#include "GPU_batch.hh"
37#include "GPU_capabilities.hh"
38#include "GPU_context.hh"
39#include "GPU_material.hh"
40#include "GPU_texture.hh"
41
42#include "DRW_render.hh"
43
44#include "draw_attributes.hh"
45#include "draw_cache_impl.hh" /* own include */
46#include "draw_cache_inline.hh"
48#include "draw_curves_private.hh" /* own include */
49#include "draw_hair_private.hh"
50
51namespace blender::draw {
52
53#define EDIT_CURVES_NURBS_CONTROL_POINT (1u)
54#define EDIT_CURVES_BEZIER_HANDLE (1u << 1)
55#define EDIT_CURVES_ACTIVE_HANDLE (1u << 2)
56/* Bezier curve control point lying on the curve.
57 * The one between left and right handles. */
58#define EDIT_CURVES_BEZIER_KNOT (1u << 3)
59#define EDIT_CURVES_HANDLE_TYPES_SHIFT (4u)
60
61/* ---------------------------------------------------------------------- */
62
65
66 gpu::Batch *edit_points;
67 gpu::Batch *edit_handles;
68
69 gpu::Batch *sculpt_cage;
71
72 /* Crazy-space point positions for original points. */
75
76 /* Additional data needed for shader to choose color for each point in edit_points_pos.
77 * If first bit is set, then point is NURBS control point. EDIT_CURVES_NURBS_CONTROL_POINT is
78 * used to set and test. If second, then point is Bezier handle point. Set and tested with
79 * EDIT_CURVES_BEZIER_HANDLE.
80 * In Bezier case two handle types of HandleType are also encoded.
81 * Byte structure for Bezier knot point (handle middle point):
82 * | left handle type | right handle type | | BEZIER| NURBS|
83 * | 7 6 | 5 4 | 3 2 | 1 | 0 |
84 *
85 * If it is left or right handle point, then same handle type is repeated in both slots.
86 */
88
89 /* Selection of original points. */
91
93
94 gpu::Batch *edit_curves_lines;
97
98 /* Whether the cache is invalid. */
100};
101
103{
104 const CurvesBatchCache *cache = curves.batch_cache;
105 return (cache && cache->is_dirty == false);
106}
107
109{
110 CurvesBatchCache *cache = curves.batch_cache;
111
112 if (!cache) {
113 cache = MEM_new<CurvesBatchCache>(__func__);
114 curves.batch_cache = cache;
115 }
116 else {
117 cache->eval_cache = {};
118 }
119
120 cache->is_dirty = false;
121}
122
142
144{
145 for (const int i : IndexRange(GPU_MAX_ATTR)) {
146 this->evaluated_attributes_buf[i].reset();
147 }
148 for (const int i : IndexRange(GPU_MAX_ATTR)) {
149 this->curve_attributes_buf[i].reset();
150 }
151 this->attr_used.clear();
152}
153
155{
156 /* TODO: more granular update tagging. */
157 this->evaluated_pos_rad_buf.reset();
158 this->evaluated_time_buf.reset();
159 this->curves_length_buf.reset();
160
161 this->points_by_curve_buf.reset();
162 this->evaluated_points_by_curve_buf.reset();
163 this->curves_type_buf.reset();
164 this->curves_resolution_buf.reset();
165 this->curves_cyclic_buf.reset();
166
167 this->handles_positions_left_buf.reset();
168 this->handles_positions_right_buf.reset();
169 this->bezier_offsets_buf.reset();
170
171 this->curves_order_buf.reset();
172 this->control_weights_buf.reset();
173 this->basis_cache_buf.reset();
174 this->basis_cache_offset_buf.reset();
175
176 this->indirection_cylinder_buf.reset();
177 this->indirection_ribbon_buf.reset();
178
179 for (gpu::Batch *&batch : this->batch) {
181 }
182
183 this->discard_attributes();
184}
185
187{
188 CurvesBatchCache *cache = curves.batch_cache;
189 if (!cache) {
190 return;
191 }
192
193 cache->eval_cache.clear();
194 clear_edit_data(cache);
195}
196
202
203static uint32_t bezier_data_value(int8_t handle_type, bool is_active)
204{
206 (is_active ? EDIT_CURVES_ACTIVE_HANDLE : 0);
207}
208
209static int handles_and_points_num(const int points_num, const OffsetIndices<int> bezier_offsets)
210{
211 return points_num + bezier_offsets.total_size() * 2;
212}
213
214static IndexRange handle_range_left(const int points_num, const OffsetIndices<int> bezier_offsets)
215{
216 return IndexRange(points_num, bezier_offsets.total_size());
217}
218
219static IndexRange handle_range_right(const int points_num, const OffsetIndices<int> bezier_offsets)
220{
221 return IndexRange(points_num + bezier_offsets.total_size(), bezier_offsets.total_size());
222}
223
224static void extract_edit_data(const OffsetIndices<int> points_by_curve,
225 const IndexMask &curve_selection,
226 const VArray<bool> &selection_attr,
227 const bool mark_active,
228 const uint32_t fill_value,
230{
231 curve_selection.foreach_index(
232 [&](const int curve) {
233 const IndexRange points = points_by_curve[curve];
234 bool is_active = false;
235 if (mark_active) {
236 is_active = array_utils::count_booleans(selection_attr, points) > 0;
237 }
238 uint32_t data_value = fill_value | (is_active ? EDIT_CURVES_ACTIVE_HANDLE : 0u);
239 data.slice(points).fill(data_value);
240 },
242}
243
244static void create_edit_points_data(const OffsetIndices<int> points_by_curve,
245 const IndexMask &catmull_rom_curves,
246 const IndexMask &poly_curves,
247 const IndexMask &bezier_curves,
248 const IndexMask &nurbs_curves,
249 const OffsetIndices<int> bezier_offsets,
251 gpu::VertBuf &vbo)
252{
253 const int points_num = points_by_curve.total_size();
254 const bke::AttributeAccessor attributes = curves.attributes();
255 const VArray selection = *attributes.lookup_or_default<bool>(
256 ".selection", bke::AttrDomain::Point, true);
257
258 static const GPUVertFormat format = GPU_vertformat_from_attribute("data",
259 gpu::VertAttrType::UINT_32);
260 GPU_vertbuf_init_with_format(vbo, format);
261 GPU_vertbuf_data_alloc(vbo, handles_and_points_num(points_num, bezier_offsets));
263
264 extract_edit_data(points_by_curve, catmull_rom_curves, selection, false, 0, data);
265
266 extract_edit_data(points_by_curve, poly_curves, selection, false, 0, data);
267
268 if (!bezier_curves.is_empty()) {
269 const VArray<int8_t> type_right = curves.handle_types_left();
270 const VArray<int8_t> types_left = curves.handle_types_right();
271 const VArray selection_left = *attributes.lookup_or_default<bool>(
272 ".selection_handle_left", bke::AttrDomain::Point, true);
273 const VArray selection_right = *attributes.lookup_or_default<bool>(
274 ".selection_handle_right", bke::AttrDomain::Point, true);
275
276 MutableSpan data_left = data.slice(handle_range_left(points_num, bezier_offsets));
277 MutableSpan data_right = data.slice(handle_range_right(points_num, bezier_offsets));
278
279 bezier_curves.foreach_index(
280 [&](const int curve, const int64_t pos) {
281 const IndexRange points = points_by_curve[curve];
282 const IndexRange bezier_range = bezier_offsets[pos];
283 for (const int i : points.index_range()) {
284 const int point = points[i];
286
287 const bool selected = selection[point] || selection_left[point] ||
288 selection_right[point];
289 const int bezier_point = bezier_range[i];
290 data_left[bezier_point] = bezier_data_value(type_right[point], selected);
291 data_right[bezier_point] = bezier_data_value(types_left[point], selected);
292 }
293 },
295 }
296
298 points_by_curve, nurbs_curves, selection, true, EDIT_CURVES_NURBS_CONTROL_POINT, data);
299}
300
302 const OffsetIndices<int> points_by_curve,
303 const IndexMask &bezier_curves,
304 const OffsetIndices<int> bezier_offsets,
305 const bke::crazyspace::GeometryDeformation deformation,
306 gpu::VertBuf &vbo)
307{
308 const Span<float3> positions = deformation.positions;
309 const int points_num = positions.size();
310
311 static const GPUVertFormat format = GPU_vertformat_from_attribute(
312 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
313 GPU_vertbuf_init_with_format(vbo, format);
314 GPU_vertbuf_data_alloc(vbo, handles_and_points_num(points_num, bezier_offsets));
315
317 data.take_front(positions.size()).copy_from(positions);
318
319 if (!bezier_curves.is_empty()) {
320 /* TODO: Use deformed left_handle_positions and left_handle_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) {
325 points_by_curve,
326 bezier_offsets,
327 bezier_curves,
328 *handles_left,
329 data.slice(handle_range_left(points_num, bezier_offsets)));
331 points_by_curve,
332 bezier_offsets,
333 bezier_curves,
334 *handles_right,
335 data.slice(handle_range_right(points_num, bezier_offsets)));
336 }
337 }
338}
339
341 const OffsetIndices<int> points_by_curve,
342 const IndexMask &bezier_curves,
343 const OffsetIndices<int> bezier_offsets,
344 gpu::VertBuf &vbo)
345{
346 const VArraySpan<float> radii = curves.radius();
347 const int points_num = radii.size();
348
349 static const GPUVertFormat format = GPU_vertformat_from_attribute("rad",
350 gpu::VertAttrType::SFLOAT_32);
351 GPU_vertbuf_init_with_format(vbo, format);
352 GPU_vertbuf_data_alloc(vbo, handles_and_points_num(points_num, bezier_offsets));
353
354 MutableSpan<float> data = vbo.data<float>();
355 data.take_front(radii.size()).copy_from(radii);
356
357 if (bezier_curves.is_empty()) {
358 return;
359 }
360
361 MutableSpan data_left = data.slice(handle_range_left(points_num, bezier_offsets));
362 MutableSpan data_right = data.slice(handle_range_right(points_num, bezier_offsets));
363
364 bezier_curves.foreach_index(
365 [&](const int curve, const int64_t pos) {
366 const IndexRange points = points_by_curve[curve];
367 const IndexRange bezier_range = bezier_offsets[pos];
368 for (const int i : points.index_range()) {
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];
373 }
374 },
376}
377
378static void create_edit_points_selection(const OffsetIndices<int> points_by_curve,
379 const IndexMask &bezier_curves,
380 const OffsetIndices<int> bezier_offsets,
381 const bke::AttributeAccessor attributes,
382 gpu::VertBuf &vbo)
383{
384 static const GPUVertFormat format_data = GPU_vertformat_from_attribute(
385 "selection", gpu::VertAttrType::SFLOAT_32);
386
387 const int points_num = points_by_curve.total_size();
388 GPU_vertbuf_init_with_format(vbo, format_data);
389 GPU_vertbuf_data_alloc(vbo, handles_and_points_num(points_num, bezier_offsets));
390 MutableSpan<float> data = vbo.data<float>();
391
392 const VArray attribute = *attributes.lookup_or_default<float>(
393 ".selection", bke::AttrDomain::Point, 1.0f);
394 attribute.materialize(data.take_front(points_num));
395
396 if (!bezier_curves.is_empty()) {
397 const VArray selection_left = *attributes.lookup_or_default<float>(
398 ".selection_handle_left", bke::AttrDomain::Point, 1.0f);
399 const VArray selection_right = *attributes.lookup_or_default<float>(
400 ".selection_handle_right", bke::AttrDomain::Point, 1.0f);
401
403 bezier_offsets,
404 bezier_curves,
405 selection_left,
406 data.slice(handle_range_left(points_num, bezier_offsets)));
408 bezier_offsets,
409 bezier_curves,
410 selection_right,
411 data.slice(handle_range_right(points_num, bezier_offsets)));
412 }
413}
414
415static void create_lines_ibo_no_cyclic(const OffsetIndices<int> points_by_curve,
416 gpu::IndexBuf &ibo)
417{
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;
421 GPUIndexBufBuilder builder;
422 GPU_indexbuf_init(&builder, GPU_PRIM_LINE_STRIP, indices_num, points_num);
423 MutableSpan<uint> ibo_data = GPU_indexbuf_get_data(&builder);
424 threading::parallel_for(IndexRange(curves_num), 1024, [&](const IndexRange range) {
425 for (const int curve : range) {
426 const IndexRange points = points_by_curve[curve];
427 const IndexRange ibo_range = IndexRange(points.start() + curve, points.size() + 1);
428 for (const int i : points.index_range()) {
429 ibo_data[ibo_range[i]] = points[i];
430 }
431 ibo_data[ibo_range.last()] = gpu::RESTART_INDEX;
432 }
433 });
434 GPU_indexbuf_build_in_place_ex(&builder, 0, points_num, true, &ibo);
435}
436
437static void create_lines_ibo_with_cyclic(const OffsetIndices<int> points_by_curve,
438 const Span<bool> cyclic,
439 gpu::IndexBuf &ibo)
440{
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;
444 GPUIndexBufBuilder builder;
445 GPU_indexbuf_init(&builder, GPU_PRIM_LINE_STRIP, indices_num, points_num);
446 MutableSpan<uint> ibo_data = GPU_indexbuf_get_data(&builder);
447 threading::parallel_for(IndexRange(curves_num), 1024, [&](const IndexRange range) {
448 for (const int curve : range) {
449 const IndexRange points = points_by_curve[curve];
450 const IndexRange ibo_range = IndexRange(points.start() + curve * 2, points.size() + 2);
451 for (const int i : points.index_range()) {
452 ibo_data[ibo_range[i]] = points[i];
453 }
454 ibo_data[ibo_range.last(1)] = cyclic[curve] ? points.first() : gpu::RESTART_INDEX;
455 ibo_data[ibo_range.last()] = gpu::RESTART_INDEX;
456 }
457 });
458 GPU_indexbuf_build_in_place_ex(&builder, 0, points_num, true, &ibo);
459}
460
461static void create_lines_ibo_with_cyclic(const OffsetIndices<int> points_by_curve,
462 const VArray<bool> &cyclic,
463 gpu::IndexBuf &ibo)
464{
466 if (cyclic_mix == array_utils::BooleanMix::AllFalse) {
467 create_lines_ibo_no_cyclic(points_by_curve, ibo);
468 }
469 else {
470 const VArraySpan<bool> cyclic_span(cyclic);
471 create_lines_ibo_with_cyclic(points_by_curve, cyclic_span, ibo);
472 }
473}
474
475static void create_segments_with_cyclic(const OffsetIndices<int> points_by_curve,
476 const VArray<bool> &cyclic,
477 const IndexMask &selection,
478 MutableSpan<uint2> lines)
479{
480 selection.foreach_index(
481 [&](const int curve) {
482 const IndexRange points = points_by_curve[curve];
483 MutableSpan<uint2> curve_lines = lines.slice(points);
484 for (const int i : points.index_range().drop_back(1)) {
485 curve_lines[i] = uint2(points[i]) + uint2(0, 1);
486 }
487 if (cyclic[curve]) {
488 curve_lines.last() = uint2(points.first(), points.last());
489 }
490 else {
491 curve_lines.last() = uint2(points.last(), points.last());
492 }
493 },
495}
496
497static void calc_edit_handles_ibo(const OffsetIndices<int> points_by_curve,
498 const IndexMask &catmull_rom_curves,
499 const IndexMask &poly_curves,
500 const IndexMask &bezier_curves,
501 const IndexMask &nurbs_curves,
502 const OffsetIndices<int> bezier_offsets,
503 const VArray<bool> &cyclic,
504 gpu::IndexBuf &ibo)
505{
506 /* All curve types have poly-line segments draw of original (non-evaluate) topology to connect
507 * control points. Bezier have exception -- instead there is left and right handle segments. Left
508 * bezier handle segments point to original and handle points and lie at index of curve segment.
509 * Right bezier handle segments point to original and handle points and lie in a sequence after
510 * all other segments. */
511 const int points_num = points_by_curve.total_size();
512 const int extra_bezier_segments = bezier_offsets.total_size();
513
514 /* TODO: Use linestrip if there is no bezier curves. */
515 GPUIndexBufBuilder builder;
516 GPU_indexbuf_init(&builder,
518 points_num + extra_bezier_segments,
519 handles_and_points_num(points_num, bezier_offsets));
520 MutableSpan<uint2> lines = GPU_indexbuf_get_data(&builder).cast<uint2>();
521 BLI_assert(lines.size() == points_num + extra_bezier_segments);
522 MutableSpan<uint2> curve_or_handle_segments = lines.take_front(points_num);
523
524#ifndef NDEBUG
525 lines.fill(uint2(std::numeric_limits<uint32_t>::max()));
526#endif
527
529 points_by_curve, cyclic, catmull_rom_curves, curve_or_handle_segments);
530 create_segments_with_cyclic(points_by_curve, cyclic, poly_curves, curve_or_handle_segments);
531 create_segments_with_cyclic(points_by_curve, cyclic, nurbs_curves, curve_or_handle_segments);
532
533 const IndexRange handles_left = handle_range_left(points_num, bezier_offsets);
534 const IndexRange handles_right = handle_range_right(points_num, bezier_offsets);
535
536 bezier_curves.foreach_index(
537 [&](const int curve, const int pos) {
538 const IndexRange points = points_by_curve[curve];
539 const IndexRange bezier_point_range = bezier_offsets[pos];
540 for (const int i : points.index_range()) {
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);
544 }
545 },
547
548 MutableSpan<uint2> right_handle_segments = lines.drop_front(points_num);
549 bezier_curves.foreach_index(
550 [&](const int curve, const int pos) {
551 const IndexRange points = points_by_curve[curve];
552 const IndexRange bezier_point_range = bezier_offsets[pos];
553 for (const int i : points.index_range()) {
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);
557 }
558 },
560
561 BLI_assert(!lines.contains(uint2(std::numeric_limits<uint32_t>::max())));
562
564 &builder, 0, handles_and_points_num(points_num, bezier_offsets), false, &ibo);
565}
566
568 const StringRef /*name*/,
569 int64_t size)
570{
573 /* Create a destination buffer for the evaluation. Sized appropriately */
574 GPU_vertbuf_data_alloc(*buf, size);
575 return buf;
576}
577
579 const StringRef name,
580 const GPUVertFormat &format,
581 bool &r_is_point_domain)
582{
585
586 const bke::AttributeAccessor attributes = curves.wrap().attributes();
587
588 /* TODO(@kevindietrich): float4 is used for scalar attributes as the implicit conversion done
589 * by OpenGL to float4 for a scalar `s` will produce a `float4(s, 0, 0, 1)`. However, following
590 * the Blender convention, it should be `float4(s, s, s, 1)`. This could be resolved using a
591 * similar texture state swizzle to map the attribute correctly as for volume attributes, so we
592 * can control the conversion ourselves. */
594
595 if (!attribute) {
596 /* Attribute doesn't exist or is of an incompatible type.
597 * Replace it with a black curve domain attribute. */
598 /* TODO(@fclem): Eventually, this should become unnecessary if we merge
599 * all attributes into one buffer and use an indirection table. */
600 GPU_vertbuf_data_alloc(*vbo, curves.curves_num());
601 vbo->data<ColorGeometry4f>().fill({0.0f, 0.0f, 0.0f, 1.0f});
602 r_is_point_domain = false;
603 return vbo;
604 }
605
606 r_is_point_domain = attribute.domain == bke::AttrDomain::Point;
607 GPU_vertbuf_data_alloc(*vbo, r_is_point_domain ? curves.points_num() : curves.curves_num());
608 attribute.varray.materialize(vbo->data<ColorGeometry4f>());
609 return vbo;
610}
611
612static std::optional<StringRef> get_first_uv_name(const bke::AttributeAccessor &attributes)
613{
614 std::optional<StringRef> name;
615 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
616 if (iter.data_type == bke::AttrType::Float2) {
617 name = iter.name;
618 iter.stop();
619 }
620 });
621 return name;
622}
623
624static void request_attribute(Curves &curves, const StringRef name)
625{
627
628 VectorSet<std::string> attributes{};
629
630 bke::CurvesGeometry &curves_geometry = curves.geometry.wrap();
631 if (!curves_geometry.attributes().contains(name)) {
632 return;
633 }
634 drw_attributes_add_request(&attributes, name);
635
636 drw_attributes_merge(&cache.attr_used, &attributes);
637}
638
639void drw_curves_get_attribute_sampler_name(const StringRef layer_name, char r_sampler_name[32])
640{
641 char attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
642 GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
643 /* Attributes use auto-name. */
644 BLI_snprintf_utf8(r_sampler_name, 32, "a%s", attr_safe_name);
645}
646
649 const StringRef name,
650 const int index)
651{
652 char sampler_name[32];
653 drw_curves_get_attribute_sampler_name(name, sampler_name);
654
655 GPUVertFormat format = {0};
656 /* All attributes use float4, see comment below. */
657 /* TODO(fclem): Other types. */
658 GPU_vertformat_attr_add(&format, sampler_name, gpu::VertAttrType::SFLOAT_32_32_32_32);
659
661 curves, name, format, attributes_point_domain[index]);
662
663 /* Existing final data may have been for a different attribute (with a different name or domain),
664 * free the data. */
665 this->evaluated_attributes_buf[index].reset();
666
667 /* Ensure final data for points. */
669 this->ensure_common(curves);
670 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
671 this->ensure_bezier(curves);
672 }
673 if (curves.has_curve_with_type(CURVE_TYPE_NURBS)) {
674 this->ensure_nurbs(curves);
675 }
676
678 format, name, evaluated_point_count_with_cyclic(curves));
679
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(),
685 curves.curves_num(),
686 *this,
687 CURVES_EVAL_FLOAT4,
688 std::move(attr_buf),
689 this->evaluated_attributes_buf[index]);
690 }
691 else {
692 this->curve_attributes_buf[index] = std::move(attr_buf);
693 }
694}
695
698 const GPUMaterial *gpu_material)
699{
700 const bke::AttributeAccessor attributes = curves.attributes();
701
702 if (gpu_material) {
703 VectorSet<std::string> attrs_needed;
704 ListBaseT<GPUMaterialAttribute> gpu_attrs = GPU_material_attributes(gpu_material);
705 for (GPUMaterialAttribute &gpu_attr : gpu_attrs) {
706 StringRef name = gpu_attr.name;
707 if (name.is_empty()) {
708 if (std::optional<StringRef> uv_name = get_first_uv_name(attributes)) {
709 drw_attributes_add_request(&attrs_needed, *uv_name);
710 }
711 }
712 if (!attributes.contains(name)) {
713 continue;
714 }
715 drw_attributes_add_request(&attrs_needed, name);
716 }
717
718 if (!drw_attributes_overlap(&attr_used, &attrs_needed)) {
719 /* Some new attributes have been added, free all and start over. */
720 for (const int i : IndexRange(GPU_MAX_ATTR)) {
721 this->curve_attributes_buf[i].reset();
722 this->evaluated_attributes_buf[i].reset();
723 }
724 drw_attributes_merge(&attr_used, &attrs_needed);
725 }
727 }
728
729 for (const int i : attr_used.index_range()) {
730 if (this->curve_attributes_buf[i] || this->evaluated_attributes_buf[i]) {
731 continue;
732 }
733 ensure_attribute(module, curves, attr_used[i], i);
734 }
735}
736
738{
739 if (this->points_by_curve_buf) {
740 return;
741 }
742 this->points_by_curve_buf = gpu::VertBuf::from_span(curves.points_by_curve().data());
744 curves.evaluated_points_by_curve().data());
745
746 /* TODO(fclem): Optimize shaders to avoid needing to upload this data if data is uniform.
747 * This concerns all varray. */
748 this->curves_type_buf = gpu::VertBuf::from_varray(curves.curve_types());
751}
752
754{
755 if (this->handles_positions_left_buf) {
756 return;
757 }
758 const Span<float3> left = curves.handle_positions_left().value_or(curves.positions());
759 const Span<float3> right = curves.handle_positions_right().value_or(curves.positions());
763 curves.runtime->evaluated_offsets_cache.data().all_bezier_offsets.as_span());
764}
765
767{
768 if (curves_order_buf) {
769 return;
770 }
771 using BasisCache = bke::curves::nurbs::BasisCache;
772
773 /* TODO(fclem): Optimize shaders to avoid needing to upload this data if data is uniform.
774 * This concerns all varray. */
775 this->curves_order_buf = gpu::VertBuf::from_varray(curves.nurbs_orders());
776 if (curves.nurbs_weights().has_value()) {
777 this->control_weights_buf = gpu::VertBuf::from_span(curves.nurbs_weights().value());
778 }
779
780 curves.ensure_can_interpolate_to_evaluated();
781
782 const Span<BasisCache> nurbs_basis_cache = curves.runtime->nurbs_basis_cache.data();
783
784 Vector<int> basis_cache_offset;
785 Vector<uint32_t> basis_cache_packed;
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>());
791 }
792 }
793 /* Ensure buffer is not empty. */
794 if (basis_cache_packed.is_empty()) {
795 basis_cache_packed.append(0);
796 }
797
798 this->basis_cache_offset_buf = gpu::VertBuf::from_span(basis_cache_offset.as_span());
799 this->basis_cache_buf = gpu::VertBuf::from_span(basis_cache_packed.as_span());
800}
801
802int CurvesEvalCache::evaluated_point_count_with_cyclic(const bke::CurvesGeometry &curves)
803{
804 if (curves.has_cyclic_curve()) {
805 return curves.evaluated_points_num() + curves.curves_num();
806 }
807 return curves.evaluated_points_num();
808}
809
811{
813 return;
814 }
815
816 if (curves.is_empty()) {
817 /* Can happen when called from `curves_pos_buffer_get()`. Caller has to deal with nullptr. */
818 return;
819 }
820
821 this->ensure_common(curves);
822 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
823 this->ensure_bezier(curves);
824 }
825 if (curves.has_curve_with_type(CURVE_TYPE_NURBS)) {
826 this->ensure_nurbs(curves);
827 }
828
829 /* TODO(fclem): Optimize shaders to avoid needing to upload this data if data is uniform.
830 * This concerns all varray. */
831 gpu::VertBufPtr points_pos_buf = gpu::VertBuf::from_span(curves.positions());
832 gpu::VertBufPtr points_rad_buf = gpu::VertBuf::from_varray(curves.radius());
833
835 evaluated_point_count_with_cyclic(curves));
836
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(),
842 curves.curves_num(),
843 *this,
844 std::move(points_pos_buf),
845 std::move(points_rad_buf),
846 evaluated_pos_rad_buf);
847
848 /* TODO(fclem): Make time and length optional. */
850 evaluated_point_count_with_cyclic(curves));
852
853 module.evaluate_curve_length_intercept(curves.has_cyclic_curve(), curves.curves_num(), *this);
854}
855
858 const int face_per_segment)
859{
860 const bool is_ribbon = face_per_segment < 2;
861
862 gpu::VertBufPtr &indirection_buf = is_ribbon ? this->indirection_ribbon_buf :
864 if (indirection_buf) {
865 return indirection_buf;
866 }
867
868 this->ensure_common(curves);
869
870 indirection_buf = module.evaluate_topology_indirection(curves.curves_num(),
871 curves.evaluated_points_num(),
872 *this,
873 is_ribbon,
874 curves.has_cyclic_curve());
875
876 return indirection_buf;
877}
878
879gpu::Batch *CurvesEvalCache::batch_get(const int evaluated_point_count,
880 const int curve_count,
881 const int face_per_segment,
882 const bool use_cyclic,
883 bool &r_over_limit)
884{
885 gpu::Batch *&batch = this->batch[face_per_segment];
886 if (batch) {
887 return batch;
888 }
889
890 int64_t segment_count = 0;
891 int64_t vert_per_segment = 0;
892 GPUPrimType prim_type = GPU_PRIM_NONE;
893
894 if (face_per_segment == 0) {
895 /* Add one point per curve to restart the primitive. */
896 segment_count = int64_t(evaluated_point_count) + curve_count;
897 if (use_cyclic) {
898 segment_count += curve_count;
899 }
900 /* The last segment is always a restart vertex. However, it is not accounted for inside the
901 * data buffers and can lead to out of bound reads (see #148914). */
902 segment_count -= (segment_count > 0) ? 1 : 0;
903 vert_per_segment = 1;
904 prim_type = GPU_PRIM_LINE_STRIP;
905 }
906 else if (face_per_segment == 1) {
907 /* Add one point per curve to restart the primitive. */
908 segment_count = int64_t(evaluated_point_count) + curve_count;
909 if (use_cyclic) {
910 segment_count += curve_count;
911 }
912 /* The last segment is always a restart vertex. However, it is not accounted for inside the
913 * data buffers and can lead to out of bound reads (see #148914). */
914 segment_count -= (segment_count > 0) ? 1 : 0;
915 vert_per_segment = 2;
916 prim_type = GPU_PRIM_TRI_STRIP;
917 }
918 else if (face_per_segment >= 2) {
919 segment_count = int64_t(evaluated_point_count) - curve_count;
920 if (use_cyclic) {
921 segment_count += curve_count;
922 }
923 /* Add one vertex per segment to restart the primitive. */
924 vert_per_segment = (face_per_segment + 1) * 2 + 1;
925 prim_type = GPU_PRIM_TRI_STRIP;
926 }
927
928 /* Since we rely on buffer textures for reading the indirection buffer we have to abide by their
929 * size limit. This size is low enough on NVidia to discard strands after 130,000,000 points.
930 * We detect this case and display an error message in the viewport. */
931 uint32_t texel_buffer_limit = GPU_max_buffer_texture_size();
932 /* We are also limited by the number of vertices in a batch, which is INT_MAX. */
933 int64_t segment_limit = std::min(int64_t(texel_buffer_limit), int64_t(INT_MAX));
934 if (segment_count > segment_limit) {
935 segment_count = segment_limit;
936 r_over_limit = true;
937 }
938 r_over_limit = false;
939
940 uint32_t vertex_count = segment_count * vert_per_segment;
941 batch = GPU_batch_create_procedural(prim_type, vertex_count);
942 return batch;
943}
944
946{
947 return get_batch_cache(curves_id).eval_cache;
948}
949
951{
952 CurvesBatchCache *cache = curves->batch_cache;
953 if (cache == nullptr) {
954 return;
955 }
956 switch (mode) {
958 cache->is_dirty = true;
959 break;
960 default:
962 }
963}
964
972
974{
976 CurvesBatchCache *batch_cache = curves->batch_cache;
977 MEM_delete(batch_cache);
978 curves->batch_cache = nullptr;
979}
980
982{
983 CurvesBatchCache *cache = curves->batch_cache;
984 if (cache == nullptr) {
985 return;
986 }
987
988 bool do_discard = false;
989
990 CurvesEvalCache &eval_cache = cache->eval_cache;
991
992 if (drw_attributes_overlap(&eval_cache.attr_used_over_time, &eval_cache.attr_used)) {
993 eval_cache.last_attr_matching_time = ctime;
994 }
995
996 if (ctime - eval_cache.last_attr_matching_time > U.vbotimeout) {
997 do_discard = true;
998 }
999
1000 eval_cache.attr_used_over_time.clear();
1001
1002 if (do_discard) {
1004 }
1005}
1006
1012
1018
1024
1030
1032 const StringRef name,
1033 bool &r_is_point_domain,
1034 bool &r_valid_attribute)
1035{
1036 CurvesEvalCache &cache = get_batch_cache(*curves).eval_cache;
1037
1038 if (curves->geometry.wrap().is_empty()) {
1039 r_valid_attribute = false;
1040 r_is_point_domain = false;
1041 return cache.evaluated_attributes_buf[0];
1042 }
1043
1044 request_attribute(*curves, name);
1045
1046 /* TODO(fclem): Remove Global access. */
1047 CurvesModule &module = *drw_get().data->curves_module;
1048 cache.ensure_attributes(module, curves->geometry.wrap(), nullptr);
1049
1050 for (const int i : cache.attr_used.index_range()) {
1051 if (cache.attr_used[i] == name) {
1052 r_valid_attribute = true;
1053 if (cache.attributes_point_domain[i]) {
1054 r_is_point_domain = true;
1055 return cache.evaluated_attributes_buf[i];
1056 }
1057 r_is_point_domain = false;
1058 return cache.curve_attributes_buf[i];
1059 }
1060 }
1061 r_valid_attribute = false;
1062 r_is_point_domain = false;
1063 return cache.evaluated_attributes_buf[0];
1064}
1065
1068 const bke::crazyspace::GeometryDeformation & /*deformation*/,
1069 CurvesBatchCache &cache)
1070{
1071 static const GPUVertFormat format = GPU_vertformat_from_attribute(
1072 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
1073
1074 /* TODO: Deform curves using deformations. */
1075 const Span<float3> positions = curves.evaluated_positions();
1078 cache.edit_curves_lines_pos->data<float3>().copy_from(positions);
1079}
1080
1082{
1084 Object *ob_orig = DEG_get_original(ob);
1085 if (ob_orig == nullptr) {
1086 return;
1087 }
1088 const Curves &curves_orig_id = DRW_object_get_data_for_drawing<Curves>(*ob_orig);
1089
1091 const bke::CurvesGeometry &curves_orig = curves_orig_id.geometry.wrap();
1092
1093 bool is_edit_data_needed = false;
1094
1100 is_edit_data_needed = true;
1101 }
1107 is_edit_data_needed = true;
1108 }
1115 is_edit_data_needed = true;
1116 }
1120 }
1121
1122 const OffsetIndices<int> points_by_curve = curves_orig.points_by_curve();
1123 const VArray<bool> cyclic = curves_orig.cyclic();
1124
1125 const bke::crazyspace::GeometryDeformation deformation =
1126 is_edit_data_needed || DRW_vbo_requested(cache.edit_curves_lines_pos) ?
1129
1131 create_lines_ibo_no_cyclic(points_by_curve, *cache.sculpt_cage_ibo);
1132 }
1133
1135 create_edit_points_position_vbo(curves_orig, deformation, cache);
1136 }
1137
1140 curves_orig.evaluated_points_by_curve(), cyclic, *cache.edit_curves_lines_ibo);
1141 }
1142
1143 if (!is_edit_data_needed) {
1144 return;
1145 }
1146
1147 const IndexRange curves_range = curves_orig.curves_range();
1148 const VArray<int8_t> curve_types = curves_orig.curve_types();
1149 const std::array<int, CURVE_TYPES_NUM> type_counts = curves_orig.curve_type_counts();
1150 const bke::AttributeAccessor attributes = curves_orig.attributes();
1151
1152 IndexMaskMemory memory;
1153 const IndexMask catmull_rom_curves = bke::curves::indices_for_type(
1154 curve_types, type_counts, CURVE_TYPE_CATMULL_ROM, curves_range, memory);
1155 const IndexMask poly_curves = bke::curves::indices_for_type(
1156 curve_types, type_counts, CURVE_TYPE_POLY, curves_range, memory);
1157 const IndexMask bezier_curves = bke::curves::indices_for_type(
1158 curve_types, type_counts, CURVE_TYPE_BEZIER, curves_range, memory);
1159 const IndexMask nurbs_curves = bke::curves::indices_for_type(
1160 curve_types, type_counts, CURVE_TYPE_NURBS, curves_range, memory);
1161
1162 Array<int> bezier_point_offset_data(bezier_curves.size() + 1);
1164 points_by_curve, bezier_curves, bezier_point_offset_data);
1165
1167 create_edit_points_position(curves_orig,
1168 points_by_curve,
1169 bezier_curves,
1170 bezier_offsets,
1171 deformation,
1172 *cache.edit_points_pos);
1173 }
1176 curves_orig, points_by_curve, bezier_curves, bezier_offsets, *cache.edit_points_rad);
1177 }
1179 create_edit_points_data(points_by_curve,
1180 catmull_rom_curves,
1181 poly_curves,
1182 bezier_curves,
1183 nurbs_curves,
1184 bezier_offsets,
1185 curves_orig,
1186 *cache.edit_points_data);
1187 }
1190 points_by_curve, bezier_curves, bezier_offsets, attributes, *cache.edit_points_selection);
1191 }
1193 calc_edit_handles_ibo(points_by_curve,
1194 catmull_rom_curves,
1195 poly_curves,
1196 bezier_curves,
1197 nurbs_curves,
1198 bezier_offsets,
1199 cyclic,
1200 *cache.edit_handles_ibo);
1201 }
1202}
1203
1204} // namespace blender::draw
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)
Definition GPU_batch.hh:199
#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
Definition BLI_span.hh:695
constexpr int64_t size() const
Definition BLI_span.hh:256
IndexRange index_range() const
int64_t size() const
void append(const T &value)
bool is_empty() const
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)
MutableSpan< 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
#define INT_MAX
#define attribute(slot)
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))
Definition BLI_task.hh:69
VecBase< uint32_t, 2 > uint2
uint32_t GPU_max_buffer_texture_size()
UserDef U
Definition blender.cc:58
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
__int64 int64_t
Definition BKE_text.h:90
bool DRW_vbo_requested(gpu::VertBuf *vbo)
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
Definition gpu_batch.cc:85
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)
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_LINE_STRIP
DRWContext & drw_get()
unsigned int uint32_t
Definition BKE_text.h:81
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)
@ CURVE_TYPE_CATMULL_ROM
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
@ BKE_CURVES_BATCH_DIRTY_ALL
Definition BKE_curves.h:41
void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
signed char int8_t
Definition BKE_text.h:76
bool DRW_ibo_requested(gpu::IndexBuf *ibo)
draw::CurvesModule * curves_module
gpu::VertBufPtr evaluated_attributes_buf[GPU_MAX_ATTR]
void ensure_bezier(const bke::CurvesGeometry &curves)
std::array< gpu::Batch *, MAX_FACE_PER_SEGMENT > batch
std::array< bool, GPU_MAX_ATTR > attributes_point_domain
void ensure_common(const bke::CurvesGeometry &curves)
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)
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
VectorSet< std::string > attr_used
void ensure_attribute(struct CurvesModule &module, const bke::CurvesGeometry &curves, StringRef name, int index)
void ensure_nurbs(const bke::CurvesGeometry &curves)