Blender V5.3
draw_cache_impl_curve.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 "MEM_guardedalloc.h"
12
13#include "BLI_color_types.hh"
14#include "BLI_listbase.hh"
17#include "BLI_span.hh"
18#include "BLI_utildefines.hh"
19
20#include "DNA_curve_types.h"
21#include "DNA_object_types.h"
22#include "DNA_scene_types.h"
23
24#include "BKE_curve.hh"
25#include "BKE_curves.hh"
26#include "BKE_geometry_set.hh"
27#include "BKE_object_types.hh"
28#include "BKE_vfont.hh"
29
31#include "GPU_batch.hh"
32#include "GPU_capabilities.hh"
33#include "GPU_texture.hh"
34
35#include "UI_resources.hh"
36
37#include "DRW_render.hh"
38
39#include "draw_cache_inline.hh"
40
41#include "draw_cache_impl.hh" /* own include */
42
43namespace blender::draw {
44
45/* See: edit_curve_point_vert.glsl for duplicate includes. */
46#define SELECT 1
47#define ACTIVE_NURB (1 << 2)
48#define BEZIER_HANDLE (1 << 3)
49#define EVEN_U_BIT (1 << 4) /* Alternate this bit for every U vert. */
50#define COLOR_SHIFT 5
51
52/* Used as values of `color_id` in `edit_curve_overlay_handle_geom.glsl` */
53enum {
55
57};
58
65
66static void curve_batch_cache_clear(Curve *cu);
67
68/* ---------------------------------------------------------------------- */
69/* Curve Interface, direct access to basic data. */
70
71static void curve_render_overlay_verts_edges_len_get(ListBaseT<Nurb> *lb,
72 int *r_vert_len,
73 int *r_edge_len)
74{
75 BLI_assert(r_vert_len || r_edge_len);
76 int vert_len = 0;
77 int edge_len = 0;
78 for (Nurb &nu : *lb) {
79 if (nu.bezt) {
80 vert_len += nu.pntsu * 3;
81 /* 2x handles per point. */
82 edge_len += 2 * nu.pntsu;
83 }
84 else if (nu.bp) {
85 vert_len += nu.pntsu * nu.pntsv;
86 /* segments between points */
87 edge_len += (nu.pntsu - 1) * nu.pntsv;
88 edge_len += (nu.pntsv - 1) * nu.pntsu;
89 }
90 }
91 if (r_vert_len) {
92 *r_vert_len = vert_len;
93 }
94 if (r_edge_len) {
95 *r_edge_len = edge_len;
96 }
97}
98
100 int *r_curve_len,
101 int *r_vert_len,
102 int *r_edge_len)
103{
104 const OffsetIndices points_by_curve = curves.evaluated_points_by_curve();
105 const VArray<bool> cyclic = curves.cyclic();
106
107 *r_curve_len = curves.curves_num();
108 *r_vert_len = points_by_curve.total_size();
109 *r_edge_len = 0;
110 for (const int i : curves.curves_range()) {
111 *r_edge_len += bke::curves::segments_num(points_by_curve[i].size(), cyclic[i]);
112 }
113}
114
115static int curve_render_normal_len_get(const ListBaseT<Nurb> *lb, const CurveCache *ob_curve_cache)
116{
117 int normal_len = 0;
118 const BevList *bl;
119 const Nurb *nu;
120 for (bl = ob_curve_cache->bev.first(), nu = lb->first(); nu && bl; bl = bl->next, nu = nu->next)
121 {
122 int nr = bl->nr;
123 int skip = nu->resolu / 16;
124#if 0
125 while (nr-- > 0) { /* accounts for empty bevel lists */
126 normal_len += 1;
127 nr -= skip;
128 }
129#else
130 /* Same as loop above */
131 normal_len += (nr / (skip + 1)) + ((nr % (skip + 1)) != 0);
132#endif
133 }
134 return normal_len;
135}
136
137/* ---------------------------------------------------------------------- */
138/* Curve Interface, indirect, partially cached access to complex data. */
139
141 int types;
142
143 struct {
144 int vert_len;
145 int edge_len;
147
148 struct {
149 int curve_len;
150 int vert_len;
151 int edge_len;
153
154 /* edit mode normal's */
155 struct {
156 /* 'edge_len == len * 2'
157 * 'vert_len == len * 3' */
158 int len;
160
161 struct {
164
165 /* borrow from 'Object' */
167
168 /* Owned by the evaluated object's geometry set (#geometry_set_eval). */
170
171 /* borrow from 'Curve' */
172 ListBaseT<Nurb> *nurbs;
173
174 /* edit, index in nurb list */
175 int actnu;
176 /* edit, index in active nurb (BPoint or BezTriple) */
178};
179
180enum {
181 /* Wire center-line */
183 /* Edit-mode verts and optionally handles */
185 /* Edit-mode normals */
187 /* Geometry */
189 /* Text */
191};
192
197 CurveCache *ob_curve_cache,
198 const int types)
199{
201 rdata->types = types;
202 ListBaseT<Nurb> *nurbs;
203
204 rdata->actnu = cu->actnu;
205 rdata->actvert = cu->actvert;
206
207 rdata->ob_curve_cache = ob_curve_cache;
208
209 rdata->curve_eval = cu->curve_eval;
210
211 if (types & CU_DATATYPE_WIRE) {
212 if (rdata->curve_eval != nullptr) {
214 &rdata->wire.curve_len,
215 &rdata->wire.vert_len,
216 &rdata->wire.edge_len);
217 }
218 }
219
220 if (cu->editnurb) {
221 EditNurb *editnurb = cu->editnurb;
222 nurbs = &editnurb->nurbs;
223
224 if (types & CU_DATATYPE_OVERLAY) {
226 nurbs, &rdata->overlay.vert_len, &rdata->overlay.edge_len);
227
228 rdata->actnu = cu->actnu;
229 rdata->actvert = cu->actvert;
230 }
231 if (types & CU_DATATYPE_NORMAL) {
232 rdata->normal.len = curve_render_normal_len_get(nurbs, rdata->ob_curve_cache);
233 }
234 }
235 else {
236 nurbs = &cu->nurb;
237 }
238
239 rdata->nurbs = nurbs;
240
241 rdata->text.edit_font = cu->editfont;
242
243 return rdata;
244}
245
247{
248#if 0
249 if (rdata->loose_verts) {
250 MEM_delete(rdata->loose_verts);
251 }
252#endif
253 MEM_delete(rdata);
254}
255
257{
259 return rdata->overlay.vert_len;
260}
261
263{
265 return rdata->overlay.edge_len;
266}
267
269{
271 return rdata->wire.vert_len;
272}
273
275{
277 return rdata->wire.edge_len;
278}
279
281{
283 return rdata->wire.curve_len;
284}
285
287{
289 return rdata->normal.len;
290}
291
292/* ---------------------------------------------------------------------- */
293/* Curve gpu::Batch Cache */
294
300
301 struct {
303 /* Edit points (beztriples and bpoints) */
307
308 struct {
310 /* Edit mode */
314
315 struct {
316 gpu::Batch *curves;
317 gpu::Batch *curves_viewer_attribute;
318 /* control handles and vertices */
319 gpu::Batch *edit_edges;
320 gpu::Batch *edit_verts;
321 gpu::Batch *edit_normals;
323
324 /* settings to determine if cache is invalid */
327};
328
329/* gpu::Batch cache management. */
330
332{
333 CurveBatchCache *cache = cu->batch_cache;
334
335 if (cache == nullptr) {
336 return false;
337 }
338
339 if (cache->is_dirty) {
340 return false;
341 }
342
343 if (cache->is_editmode != ((cu->editnurb != nullptr) || (cu->editfont != nullptr))) {
344 return false;
345 }
346
347 if (cache->is_editmode) {
348 if (cu->editfont) {
349 /* TODO */
350 }
351 }
352
353 return true;
354}
355
357{
358 CurveBatchCache *cache = cu->batch_cache;
359
360 if (!cache) {
361 cache = MEM_new_zeroed<CurveBatchCache>(__func__);
362 cu->batch_cache = cache;
363 }
364 else {
365 memset(cache, 0, sizeof(*cache));
366 }
367
368#if 0
369 ListBaseT<Nurb> *nurbs;
370 if (cu->editnurb) {
371 EditNurb *editnurb = cu->editnurb;
372 nurbs = &editnurb->nurbs;
373 }
374 else {
375 nurbs = &cu->nurb;
376 }
377#endif
378
379 cache->is_editmode = (cu->editnurb != nullptr) || (cu->editfont != nullptr);
380
381 cache->is_dirty = false;
382}
383
391
393{
394 return cu->batch_cache;
395}
396
398{
399 CurveBatchCache *cache = cu->batch_cache;
400 if (cache == nullptr) {
401 return;
402 }
403 switch (mode) {
405 cache->is_dirty = true;
406 break;
408 GPU_VERTBUF_DISCARD_SAFE(cache->edit.data);
409
410 GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges);
411 GPU_BATCH_DISCARD_SAFE(cache->batch.edit_verts);
412 break;
413 default:
414 BLI_assert(0);
415 }
416}
417
419{
420 CurveBatchCache *cache = cu->batch_cache;
421 if (!cache) {
422 return;
423 }
424
425 for (int i = 0; i < sizeof(cache->ordered) / sizeof(void *); i++) {
426 gpu::VertBuf **vbo = reinterpret_cast<gpu::VertBuf **>(&cache->ordered);
428 }
429 for (int i = 0; i < sizeof(cache->edit) / sizeof(void *); i++) {
430 gpu::VertBuf **vbo = reinterpret_cast<gpu::VertBuf **>(&cache->edit);
432 }
433 for (int i = 0; i < sizeof(cache->ibo) / sizeof(void *); i++) {
434 gpu::IndexBuf **ibo = reinterpret_cast<gpu::IndexBuf **>(&cache->ibo);
436 }
437 for (int i = 0; i < sizeof(cache->batch) / sizeof(void *); i++) {
438 gpu::Batch **batch = reinterpret_cast<gpu::Batch **>(&cache->batch);
439 GPU_BATCH_DISCARD_SAFE(batch[i]);
440 }
441}
442
444{
446 MEM_SAFE_DELETE(cu->batch_cache);
447}
448
449/* -------------------------------------------------------------------- */
452
453/* gpu::Batch cache usage. */
454static void curve_create_curves_pos(CurveRenderData *rdata, gpu::VertBuf *vbo_curves_pos)
455{
456 if (rdata->curve_eval == nullptr) {
457 return;
458 }
459
460 static struct {
461 uint pos;
462 } attr_id;
463
464 static const GPUVertFormat format = [&]() {
465 GPUVertFormat format{};
466 attr_id.pos = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
467 return format;
468 }();
469
470 const int vert_len = curve_render_data_wire_verts_len_get(rdata);
471 GPU_vertbuf_init_with_format(*vbo_curves_pos, format);
472 GPU_vertbuf_data_alloc(*vbo_curves_pos, vert_len);
473
474 const bke::CurvesGeometry &curves = rdata->curve_eval->geometry.wrap();
475 const Span<float3> positions = curves.evaluated_positions();
476 GPU_vertbuf_attr_fill(vbo_curves_pos, attr_id.pos, positions.data());
477}
478
480{
481 if (rdata->curve_eval == nullptr) {
482 return;
483 }
484
485 static const GPUVertFormat format = []() {
486 GPUVertFormat format{};
487 GPU_vertformat_attr_add(&format, "attribute_value", gpu::VertAttrType::SFLOAT_32_32_32_32);
488 return format;
489 }();
490
491 const int vert_len = curve_render_data_wire_verts_len_get(rdata);
492 GPU_vertbuf_init_with_format(vbo_attr, format);
493 GPU_vertbuf_data_alloc(vbo_attr, vert_len);
494
495 const bke::CurvesGeometry &curves = rdata->curve_eval->geometry.wrap();
496 curves.ensure_can_interpolate_to_evaluated();
497 const VArraySpan colors = *curves.attributes().lookup<ColorGeometry4f>(".viewer",
499 curves.interpolate_to_evaluated(colors, vbo_attr.data<ColorGeometry4f>());
500}
501
502static void curve_create_curves_lines(CurveRenderData *rdata, gpu::IndexBuf *ibo_curve_lines)
503{
504 if (rdata->curve_eval == nullptr) {
505 return;
506 }
507
508 const int vert_len = curve_render_data_wire_verts_len_get(rdata);
509 const int edge_len = curve_render_data_wire_edges_len_get(rdata);
510 const int curve_len = curve_render_data_wire_curve_len_get(rdata);
511 /* Count the last vertex or each strip and the primitive restart. */
512 const int index_len = edge_len + curve_len * 2;
513
515 GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len);
516
517 const bke::CurvesGeometry &curves = rdata->curve_eval->geometry.wrap();
518 const OffsetIndices points_by_curve = curves.evaluated_points_by_curve();
519 const VArray<bool> cyclic = curves.cyclic();
520
521 for (const int i : curves.curves_range()) {
522 const IndexRange points = points_by_curve[i];
523 if (cyclic[i] && points.size() > 1) {
524 GPU_indexbuf_add_generic_vert(&elb, points.last());
525 }
526 for (const int i_point : points) {
527 GPU_indexbuf_add_generic_vert(&elb, i_point);
528 }
530 }
531
532 GPU_indexbuf_build_in_place(&elb, ibo_curve_lines);
533}
534
536 gpu::VertBuf &vbo_curves_nor,
537 const Scene *scene)
538{
539 const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 ||
541
542 static struct {
543 uint pos, nor, tan, rad;
544 uint pos_hq, nor_hq, tan_hq, rad_hq;
545 } attr_id;
546
547 static const GPUVertFormat format = [&]() {
548 GPUVertFormat format{};
549 attr_id.pos = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
550 attr_id.rad = GPU_vertformat_attr_add(&format, "rad", gpu::VertAttrType::SFLOAT_32);
551 attr_id.nor = GPU_vertformat_attr_add(&format, "nor", gpu::VertAttrType::SNORM_10_10_10_2);
552 attr_id.tan = GPU_vertformat_attr_add(&format, "tangent", gpu::VertAttrType::SNORM_10_10_10_2);
553 return format;
554 }();
555
556 static const GPUVertFormat format_hq = [&]() {
557 GPUVertFormat format{};
558 attr_id.pos_hq = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
559 attr_id.rad_hq = GPU_vertformat_attr_add(&format, "rad", gpu::VertAttrType::SFLOAT_32);
560 attr_id.nor_hq = GPU_vertformat_attr_add(&format, "nor", gpu::VertAttrType::SNORM_16_16_16_16);
561 attr_id.tan_hq = GPU_vertformat_attr_add(
562 &format, "tangent", gpu::VertAttrType::SNORM_16_16_16_16);
563 return format;
564 }();
565
566 const GPUVertFormat &format_ptr = do_hq_normals ? format_hq : format;
567
568 int verts_len_capacity = curve_render_data_normal_len_get(rdata) * 2;
569 int vbo_len_used = 0;
570
571 GPU_vertbuf_init_with_format(vbo_curves_nor, format_ptr);
572 GPU_vertbuf_data_alloc(vbo_curves_nor, verts_len_capacity);
573
574 const BevList *bl;
575 const Nurb *nu;
576
577 const uint pos_id = do_hq_normals ? attr_id.pos_hq : attr_id.pos;
578 const uint nor_id = do_hq_normals ? attr_id.nor_hq : attr_id.nor;
579 const uint tan_id = do_hq_normals ? attr_id.tan_hq : attr_id.tan;
580 const uint rad_id = do_hq_normals ? attr_id.rad_hq : attr_id.rad;
581
582 for (bl = rdata->ob_curve_cache->bev.first(), nu = rdata->nurbs->first(); nu && bl;
583 bl = bl->next, nu = nu->next)
584 {
585 const BevPoint *bevp = bl->bevpoints;
586 int nr = bl->nr;
587 int skip = nu->resolu / 16;
588
589 while (nr-- > 0) { /* accounts for empty bevel lists */
590 float nor[3] = {1.0f, 0.0f, 0.0f};
591 mul_qt_v3(bevp->quat, nor);
592
593 /* Only set attributes for one vertex. */
594 GPU_vertbuf_attr_set(&vbo_curves_nor, pos_id, vbo_len_used, bevp->vec);
595 GPU_vertbuf_attr_set(&vbo_curves_nor, rad_id, vbo_len_used, &bevp->radius);
596 if (do_hq_normals) {
597 const short4 pnor = gpu::convert_normal<short4>(nor);
598 const short4 ptan = gpu::convert_normal<short4>(bevp->dir);
599 GPU_vertbuf_attr_set(&vbo_curves_nor, nor_id, vbo_len_used, &pnor);
600 GPU_vertbuf_attr_set(&vbo_curves_nor, tan_id, vbo_len_used, &ptan);
601 }
602 else {
605 GPU_vertbuf_attr_set(&vbo_curves_nor, nor_id, vbo_len_used, &pnor);
606 GPU_vertbuf_attr_set(&vbo_curves_nor, tan_id, vbo_len_used, &ptan);
607 }
608 vbo_len_used++;
609
610 /* Skip the other vertex (it does not need to be offset). */
611 GPU_vertbuf_attr_set(&vbo_curves_nor, attr_id.pos, vbo_len_used, bevp->vec);
612 vbo_len_used++;
613
614 bevp += skip + 1;
615 nr -= skip;
616 }
617 }
618 BLI_assert(vbo_len_used == verts_len_capacity);
619}
620
622 uint8_t flag,
623 uint8_t col_id,
624 int v_idx,
625 int nu_id,
626 bool handle_point,
627 const bool handle_selected)
628{
629 uint8_t vflag = 0;
631 SET_FLAG_FROM_TEST(vflag, (v_idx == rdata->actvert && nu_id == rdata->actnu), VFLAG_VERT_ACTIVE);
632 SET_FLAG_FROM_TEST(vflag, (nu_id == rdata->actnu), ACTIVE_NURB);
633 SET_FLAG_FROM_TEST(vflag, handle_point, BEZIER_HANDLE);
635 /* Setting flags that overlap with will cause the color id not to work properly. */
636 BLI_assert((vflag >> COLOR_SHIFT) == 0);
637 /* handle color id */
638 vflag |= col_id << COLOR_SHIFT;
639 return vflag;
640}
641
642static uint8_t bpoint_vflag_get(CurveRenderData *rdata, uint8_t flag, int v_idx, int nu_id, int u)
643{
644 uint8_t vflag = 0;
646 SET_FLAG_FROM_TEST(vflag, (v_idx == rdata->actvert && nu_id == rdata->actnu), VFLAG_VERT_ACTIVE);
647 SET_FLAG_FROM_TEST(vflag, (nu_id == rdata->actnu), ACTIVE_NURB);
648 SET_FLAG_FROM_TEST(vflag, ((u % 2) == 0), EVEN_U_BIT);
649 /* Setting flags that overlap with will cause the color id not to work properly. */
650 BLI_assert((vflag >> COLOR_SHIFT) == 0);
652 return vflag;
653}
654
656 gpu::VertBuf *vbo_pos,
657 gpu::VertBuf *vbo_data,
658 gpu::IndexBuf *ibo_edit_verts_points,
659 gpu::IndexBuf *ibo_edit_lines)
660{
661 static struct {
662 uint pos, data;
663 } attr_id;
664
665 static const GPUVertFormat format_pos = [&]() {
666 GPUVertFormat format{};
667 attr_id.pos = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
668 return format;
669 }();
670
671 static const GPUVertFormat format_data = [&]() {
672 GPUVertFormat format{};
673 attr_id.data = GPU_vertformat_attr_add(&format, "data", gpu::VertAttrType::UINT_32);
674 return format;
675 }();
676
677 int verts_len_capacity = curve_render_data_overlay_verts_len_get(rdata);
678 int edges_len_capacity = curve_render_data_overlay_edges_len_get(rdata) * 2;
679 int vbo_len_used = 0;
680
681#define DRW_TEST_ASSIGN_VBO(v) (v = (DRW_vbo_requested(v) ? (v) : nullptr))
682#define DRW_TEST_ASSIGN_IBO(v) (v = (DRW_ibo_requested(v) ? (v) : nullptr))
683
684 if (DRW_TEST_ASSIGN_VBO(vbo_pos)) {
685 GPU_vertbuf_init_with_format(*vbo_pos, format_pos);
686 GPU_vertbuf_data_alloc(*vbo_pos, verts_len_capacity);
687 }
688 if (DRW_TEST_ASSIGN_VBO(vbo_data)) {
689 GPU_vertbuf_init_with_format(*vbo_data, format_data);
690 GPU_vertbuf_data_alloc(*vbo_data, verts_len_capacity);
691 }
692
693 GPUIndexBufBuilder elb_verts, *elbp_verts = nullptr;
694 GPUIndexBufBuilder elb_lines, *elbp_lines = nullptr;
695 if (DRW_TEST_ASSIGN_IBO(ibo_edit_verts_points)) {
696 elbp_verts = &elb_verts;
697 GPU_indexbuf_init(elbp_verts, GPU_PRIM_POINTS, verts_len_capacity, verts_len_capacity);
698 }
699 if (DRW_TEST_ASSIGN_IBO(ibo_edit_lines)) {
700 elbp_lines = &elb_lines;
701 GPU_indexbuf_init(elbp_lines, GPU_PRIM_LINES, edges_len_capacity, verts_len_capacity);
702 }
703
704#undef DRW_TEST_ASSIGN_VBO
705#undef DRW_TEST_ASSIGN_IBO
706
707 int nu_id = 0;
708 for (Nurb *nu = rdata->nurbs->first(); nu; nu = nu->next, nu_id++) {
709 const BezTriple *bezt = nu->bezt;
710 const BPoint *bp = nu->bp;
711
712 if (bezt) {
713 for (int a = 0; a < nu->pntsu; a++, bezt++) {
714 if (bezt->hide != 0) {
715 continue;
716 }
717 const bool handle_selected = BEZT_ISSEL_ANY(bezt);
718
719 if (elbp_verts) {
720 GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 0);
721 GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 1);
722 GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used + 2);
723 }
724 if (elbp_lines) {
725 GPU_indexbuf_add_line_verts(elbp_lines, vbo_len_used + 1, vbo_len_used + 0);
726 GPU_indexbuf_add_line_verts(elbp_lines, vbo_len_used + 1, vbo_len_used + 2);
727 }
728 if (vbo_data) {
729 const uint32_t vflag[3] = {
730 beztriple_vflag_get(rdata, bezt->f1, bezt->h1, a, nu_id, true, handle_selected),
731 beztriple_vflag_get(rdata, bezt->f2, bezt->h1, a, nu_id, false, handle_selected),
732 beztriple_vflag_get(rdata, bezt->f3, bezt->h2, a, nu_id, true, handle_selected),
733 };
734 for (int j = 0; j < 3; j++) {
735 GPU_vertbuf_attr_set(vbo_data, attr_id.data, vbo_len_used + j, &vflag[j]);
736 }
737 }
738 if (vbo_pos) {
739 for (int j = 0; j < 3; j++) {
740 GPU_vertbuf_attr_set(vbo_pos, attr_id.pos, vbo_len_used + j, bezt->vec[j]);
741 }
742 }
743 vbo_len_used += 3;
744 }
745 }
746 else if (bp) {
747 int pt_len = nu->pntsu * nu->pntsv;
748 for (int a = 0; a < pt_len; a++, bp++, vbo_len_used += 1) {
749 if (bp->hide != 0) {
750 continue;
751 }
752 int u = (a % nu->pntsu);
753 int v = (a / nu->pntsu);
754 /* Use indexed rendering for bezier.
755 * Specify all points and use indices to hide/show. */
756 if (elbp_verts) {
757 GPU_indexbuf_add_point_vert(elbp_verts, vbo_len_used);
758 }
759 if (elbp_lines) {
760 const BPoint *bp_next_u = (u < (nu->pntsu - 1)) ? &nu->bp[a + 1] : nullptr;
761 const BPoint *bp_next_v = (v < (nu->pntsv - 1)) ? &nu->bp[a + nu->pntsu] : nullptr;
762 if (bp_next_u && (bp_next_u->hide == false)) {
763 GPU_indexbuf_add_line_verts(elbp_lines, vbo_len_used, vbo_len_used + 1);
764 }
765 if (bp_next_v && (bp_next_v->hide == false)) {
766 GPU_indexbuf_add_line_verts(elbp_lines, vbo_len_used, vbo_len_used + nu->pntsu);
767 }
768 }
769 if (vbo_data) {
770 uint32_t vflag = bpoint_vflag_get(rdata, bp->f1, a, nu_id, u);
771 GPU_vertbuf_attr_set(vbo_data, attr_id.data, vbo_len_used, &vflag);
772 }
773 if (vbo_pos) {
774 GPU_vertbuf_attr_set(vbo_pos, attr_id.pos, vbo_len_used, bp->vec);
775 }
776 }
777 }
778 }
779
780 /* Resize & Finish */
781 if (elbp_verts != nullptr) {
782 GPU_indexbuf_build_in_place(elbp_verts, ibo_edit_verts_points);
783 }
784 if (elbp_lines != nullptr) {
785 GPU_indexbuf_build_in_place(elbp_lines, ibo_edit_lines);
786 }
787 if (vbo_len_used != verts_len_capacity) {
788 if (vbo_pos != nullptr) {
789 GPU_vertbuf_data_resize(*vbo_pos, vbo_len_used);
790 }
791 if (vbo_data != nullptr) {
792 GPU_vertbuf_data_resize(*vbo_data, vbo_len_used);
793 }
794 }
795}
796
798
799/* -------------------------------------------------------------------- */
802
804{
806 return DRW_batch_request(&cache->batch.curves);
807}
808
810{
812 return DRW_batch_request(&cache->batch.curves_viewer_attribute);
813}
814
816{
818 return DRW_batch_request(&cache->batch.edit_normals);
819}
820
822{
824 return DRW_batch_request(&cache->batch.edit_edges);
825}
826
828{
830 return DRW_batch_request(&cache->batch.edit_verts);
831}
832
834
835/* -------------------------------------------------------------------- */
838
840{
842
843 Curve *cu = id_cast<Curve *>(ob->data);
845
846 /* Init batches and request VBOs & IBOs */
847 if (DRW_batch_requested(cache->batch.curves, GPU_PRIM_LINE_STRIP)) {
848 DRW_ibo_request(cache->batch.curves, &cache->ibo.curves_lines);
849 DRW_vbo_request(cache->batch.curves, &cache->ordered.curves_pos);
850 }
851 if (DRW_batch_requested(cache->batch.curves_viewer_attribute, GPU_PRIM_LINE_STRIP)) {
852 DRW_ibo_request(cache->batch.curves_viewer_attribute, &cache->ibo.curves_lines);
853 DRW_vbo_request(cache->batch.curves_viewer_attribute, &cache->ordered.curves_pos);
854 DRW_vbo_request(cache->batch.curves_viewer_attribute, &cache->ordered.attr_viewer);
855 }
856
857 /* Edit mode */
858 if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) {
859 DRW_ibo_request(cache->batch.edit_edges, &cache->ibo.edit_lines);
860 DRW_vbo_request(cache->batch.edit_edges, &cache->edit.pos);
861 DRW_vbo_request(cache->batch.edit_edges, &cache->edit.data);
862 }
863 if (DRW_batch_requested(cache->batch.edit_verts, GPU_PRIM_POINTS)) {
864 DRW_ibo_request(cache->batch.edit_verts, &cache->ibo.edit_verts);
865 DRW_vbo_request(cache->batch.edit_verts, &cache->edit.pos);
866 DRW_vbo_request(cache->batch.edit_verts, &cache->edit.data);
867 }
868 if (DRW_batch_requested(cache->batch.edit_normals, GPU_PRIM_LINES)) {
869 DRW_vbo_request(cache->batch.edit_normals, &cache->edit.curves_nor);
870 }
871
872#ifdef DRW_DEBUG_MESH_CACHE_REQUEST
873 printf("-- %s %s --\n", __func__, ob->id.name + 2);
874#endif
875
876 /* Generate MeshRenderData flags */
877 int mr_flag = 0;
878 DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->ordered.curves_pos, CU_DATATYPE_WIRE);
880 mr_flag, cache->ordered.attr_viewer, CU_DATATYPE_WIRE | CU_DATATYPE_OVERLAY);
881 DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.curves_lines, CU_DATATYPE_WIRE);
882
885 DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.curves_nor, CU_DATATYPE_NORMAL);
886 DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_verts, CU_DATATYPE_OVERLAY);
887 DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_lines, CU_DATATYPE_OVERLAY);
888
889#ifdef DRW_DEBUG_MESH_CACHE_REQUEST
890 printf(" mr_flag %d\n\n", mr_flag);
891#endif
892
894
895 /* Generate VBOs */
896 if (DRW_vbo_requested(cache->ordered.curves_pos)) {
897 curve_create_curves_pos(rdata, cache->ordered.curves_pos);
898 }
899 if (DRW_vbo_requested(cache->ordered.attr_viewer)) {
900 curve_create_attribute(rdata, *cache->ordered.attr_viewer);
901 }
902 if (DRW_ibo_requested(cache->ibo.curves_lines)) {
903 curve_create_curves_lines(rdata, cache->ibo.curves_lines);
904 }
905 if (DRW_vbo_requested(cache->edit.pos) || DRW_vbo_requested(cache->edit.data) ||
906 DRW_ibo_requested(cache->ibo.edit_verts) || DRW_ibo_requested(cache->ibo.edit_lines))
907 {
909 rdata, cache->edit.pos, cache->edit.data, cache->ibo.edit_verts, cache->ibo.edit_lines);
910 }
911 if (DRW_vbo_requested(cache->edit.curves_nor)) {
912 curve_create_edit_curves_nor(rdata, *cache->edit.curves_nor, scene);
913 }
914
916
917#ifndef NDEBUG
918 /* Make sure all requested batches have been setup. */
919 for (int i = 0; i < sizeof(cache->batch) / sizeof(void *); i++) {
920 BLI_assert(!DRW_batch_requested(((gpu::Batch **)&cache->batch)[i], (GPUPrimType)0));
921 }
922#endif
923}
924
926
927} // namespace blender::draw
Low-level operations for curves.
#define SELECT
Definition BKE_mask.hh:19
#define BEZT_ISSEL_ANY(bezt)
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 SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr const T * data() const
Definition BLI_span.hh:219
MutableSpan< T > data()
#define DRW_TEST_ASSIGN_VBO(v)
#define EVEN_U_BIT
#define DRW_TEST_ASSIGN_IBO(v)
#define COLOR_SHIFT
#define BEZIER_HANDLE
#define ACTIVE_NURB
#define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value)
#define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value)
#define tan
int segments_num(const int points_num, const bool cyclic)
static int curve_render_normal_len_get(const ListBaseT< Nurb > *lb, const CurveCache *ob_curve_cache)
static void curve_batch_cache_init(Curve *cu)
static void curve_create_curves_lines(CurveRenderData *rdata, gpu::IndexBuf *ibo_curve_lines)
static uint8_t beztriple_vflag_get(CurveRenderData *rdata, uint8_t flag, uint8_t col_id, int v_idx, int nu_id, bool handle_point, const bool handle_selected)
gpu::Batch * DRW_curve_batch_cache_get_wire_edge(Curve *cu)
gpu::Batch * DRW_curve_batch_cache_get_edit_verts(Curve *cu)
static int curve_render_data_wire_verts_len_get(const CurveRenderData *rdata)
static int curve_render_data_normal_len_get(const CurveRenderData *rdata)
gpu::Batch * DRW_curve_batch_cache_get_edit_edges(Curve *cu)
void DRW_curve_batch_cache_validate(Curve *cu)
static void curve_create_curves_pos(CurveRenderData *rdata, gpu::VertBuf *vbo_curves_pos)
void DRW_curve_batch_cache_create_requested(Object *ob, const Scene *scene)
static int curve_render_data_overlay_edges_len_get(const CurveRenderData *rdata)
gpu::Batch * DRW_curve_batch_cache_get_normal_edge(Curve *cu)
static int curve_render_data_overlay_verts_len_get(const CurveRenderData *rdata)
static void curve_batch_cache_clear(Curve *cu)
void DRW_curve_batch_cache_free(Curve *cu)
static CurveRenderData * curve_render_data_create(Curve *cu, CurveCache *ob_curve_cache, const int types)
static void curve_create_edit_data_and_handles(CurveRenderData *rdata, gpu::VertBuf *vbo_pos, gpu::VertBuf *vbo_data, gpu::IndexBuf *ibo_edit_verts_points, gpu::IndexBuf *ibo_edit_lines)
static void curve_render_data_free(CurveRenderData *rdata)
static void curve_create_edit_curves_nor(CurveRenderData *rdata, gpu::VertBuf &vbo_curves_nor, const Scene *scene)
static void curve_eval_render_wire_verts_edges_len_get(const bke::CurvesGeometry &curves, int *r_curve_len, int *r_vert_len, int *r_edge_len)
static CurveBatchCache * curve_batch_cache_get(Curve *cu)
static int curve_render_data_wire_edges_len_get(const CurveRenderData *rdata)
static void curve_create_attribute(CurveRenderData *rdata, gpu::VertBuf &vbo_attr)
static bool curve_batch_cache_valid(Curve *cu)
static uint8_t bpoint_vflag_get(CurveRenderData *rdata, uint8_t flag, int v_idx, int nu_id, int u)
static void curve_render_overlay_verts_edges_len_get(ListBaseT< Nurb > *lb, int *r_vert_len, int *r_edge_len)
static int curve_render_data_wire_curve_len_get(const CurveRenderData *rdata)
gpu::Batch * DRW_curve_batch_cache_get_wire_edge_viewer_attribute(Curve *cu)
void DRW_curve_batch_cache_dirty_tag(Curve *cu, int mode)
GPUType convert_normal(const float3 &src)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool DRW_vbo_requested(gpu::VertBuf *vbo)
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)
unsigned int uint
Definition BKE_text.h:55
void GPU_indexbuf_add_line_verts(GPUIndexBufBuilder *, uint v1, uint v2)
@ BKE_CURVE_BATCH_DIRTY_SELECT
Definition BKE_curve.hh:388
@ BKE_CURVE_BATCH_DIRTY_ALL
Definition BKE_curve.hh:387
bool DRW_batch_requested(gpu::Batch *batch, GPUPrimType prim_type)
NormalizedIntVecBase< int32_t, 4, 10, 10, 10, 2 > int1010102_norm
void GPU_indexbuf_add_primitive_restart(GPUIndexBufBuilder *)
@ GPU_PRIM_LINE_STRIP
@ TH_HANDLE_AUTOCLAMP
ATTR_WARN_UNUSED_RESULT const BMVert * v
void mul_qt_v3(const float q[4], float r[3])
void GPU_indexbuf_add_point_vert(GPUIndexBufBuilder *, uint v)
unsigned int uint32_t
Definition BKE_text.h:81
bool GPU_use_hq_normals_workaround()
void DRW_ibo_request(gpu::Batch *batch, gpu::IndexBuf **ibo)
VecBase< int16_t, 4 > short4
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BMesh const char void * data
void GPU_vertbuf_attr_set(gpu::VertBuf *, uint a_idx, uint v_idx, const void *data)
unsigned char uint8_t
Definition BKE_text.h:79
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
void GPU_indexbuf_build_in_place(GPUIndexBufBuilder *, gpu::IndexBuf *)
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
void GPU_vertbuf_data_resize(gpu::VertBuf &verts, uint v_len)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v)
void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
bool DRW_ibo_requested(gpu::IndexBuf *ibo)
struct BevList * next
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
ListBaseT< BevList > bev
Definition BKE_curve.hh:45
draw::CurveBatchCache * batch_cache
ListBaseT< Nurb > nurb
EditNurb * editnurb
struct EditFont * editfont
const struct Curves * curve_eval
ListBaseT< Nurb > nurbs
char name[258]
Definition DNA_ID.h:433
struct Nurb * next
bke::ObjectRuntime * runtime
eQualityOption perf_flag
struct RenderData r
struct blender::draw::CurveBatchCache::@117233340275271205236250237042040155364224105215 batch
struct blender::draw::CurveBatchCache::@040107133132046031343153272054144012243140154177 ordered
struct blender::draw::CurveBatchCache::@355071361272372030321231073334204212050152124174 edit
struct blender::draw::CurveBatchCache::@260144065074011242340067260211121017253277205337 ibo
struct blender::draw::CurveRenderData::@337107320215060062110314175061257367143143163165 text
struct blender::draw::CurveRenderData::@124206200031341362373017142205366153206353154353 overlay
struct blender::draw::CurveRenderData::@211171046232016311055316251124002356125250256323 normal
struct blender::draw::CurveRenderData::@075216234255024276045273253146004311125135140117 wire