Blender V5.3
draw_cache.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_curve_types.h"
10#include "DNA_curves_types.h"
12#include "DNA_lattice_types.h"
13#include "DNA_mesh_types.h"
14#include "DNA_modifier_types.h"
15#include "DNA_object_types.h"
16#include "DNA_particle_types.h"
18#include "DNA_scene_types.h"
19#include "DNA_volume_types.h"
20
21#include "BLI_ghash.hh"
22#include "BLI_listbase.hh"
23#include "BLI_string.hh"
24#include "BLI_utildefines.hh"
25
26#include "BKE_attribute.hh"
27#include "BKE_context.hh"
28#include "BKE_mesh_wrapper.hh"
29#include "BKE_object.hh"
30#include "BKE_object_types.hh"
32
33#include "DRW_render.hh"
34#include "GPU_batch.hh"
35#include "GPU_batch_utils.hh"
36#include "GPU_capabilities.hh"
37
38#include "draw_cache.hh"
39#include "draw_cache_impl.hh"
40#include "draw_common_c.hh"
42
43/* -------------------------------------------------------------------- */
46
47#define VCLASS_LIGHT_AREA_SHAPE (1 << 0)
48#define VCLASS_LIGHT_SPOT_SHAPE (1 << 1)
49#define VCLASS_LIGHT_SPOT_BLEND (1 << 2)
50#define VCLASS_LIGHT_SPOT_CONE (1 << 3)
51#define VCLASS_LIGHT_DIST (1 << 4)
52
53#define VCLASS_CAMERA_FRAME (1 << 5)
54#define VCLASS_CAMERA_DIST (1 << 6)
55#define VCLASS_CAMERA_VOLUME (1 << 7)
56
57#define VCLASS_SCREENSPACE (1 << 8)
58#define VCLASS_SCREENALIGNED (1 << 9)
59
60#define VCLASS_EMPTY_SCALED (1 << 10)
61#define VCLASS_EMPTY_AXES (1 << 11)
62#define VCLASS_EMPTY_AXES_NAME (1 << 12)
63#define VCLASS_EMPTY_AXES_SHADOW (1 << 13)
64#define VCLASS_EMPTY_SIZE (1 << 14)
65
67
68/* -------------------------------------------------------------------- */
71
72namespace blender::draw {
73
74void DRW_vertbuf_create_wiredata(gpu::VertBuf *vbo, const int vert_len)
75{
76 static const GPUVertFormat format = GPU_vertformat_from_attribute("wd",
77 gpu::VertAttrType::SFLOAT_32);
78 GPU_vertbuf_init_with_format(*vbo, format);
79 GPU_vertbuf_data_alloc(*vbo, vert_len);
80 vbo->data<float>().fill(1.0f);
81}
82
84
85/* -------------------------------------------------------------------- */
92
94{
95 switch (ob->type) {
96 case OB_MESH:
98 /* TODO: should match #DRW_cache_object_surface_get. */
99 default:
100 return nullptr;
101 }
102}
103
104gpu::Batch *DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold)
105{
106 switch (ob->type) {
107 case OB_MESH:
108 return DRW_cache_mesh_edge_detection_get(ob, r_is_manifold);
109 default:
110 return nullptr;
111 }
112}
113
115{
116 switch (ob->type) {
117 case OB_MESH:
119 case OB_POINTCLOUD:
122 case OB_VOLUME:
124 case OB_GREASE_PENCIL:
126 default:
127 return nullptr;
128 }
129}
130
132{
133 switch (ob->type) {
134 case OB_MESH:
136 default:
137 return nullptr;
138 }
139}
140
142{
143 switch (ob->type) {
144 case OB_MESH:
146 default:
147 return nullptr;
148 }
149}
150
152{
153 switch (ob->type) {
154 case OB_MESH:
156 default:
157 return nullptr;
158 }
159}
160
162 const Span<const GPUMaterial *> materials)
163{
164 switch (ob->type) {
165 case OB_MESH:
166 return DRW_cache_mesh_surface_shaded_get(ob, materials);
167 default:
168 return {};
169 }
170}
171
173
174/* -------------------------------------------------------------------- */
177
183
189
195
201
202gpu::Batch *DRW_cache_mesh_edge_detection_get(Object *ob, bool *r_is_manifold)
203{
204 BLI_assert(ob->type == OB_MESH);
206 r_is_manifold);
207}
208
214
216{
217 BLI_assert(ob->type == OB_MESH);
218 /* Ensure the surface VBOs/IBOs are requested, since BLAS relies on them. */
221}
222
229
235
243
250
257
264
270
276
282
288
295
297
298/* -------------------------------------------------------------------- */
301
308
315
322
330
338
340
341/* -------------------------------------------------------------------- */
344
351
353
354/* -------------------------------------------------------------------- */
357
364
366
367/* -------------------------------------------------------------------- */
370
378
379gpu::Batch *DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
380{
381 BLI_assert(ob->type == OB_LATTICE);
382
384 int actdef = -1;
385
386 if (use_weight && !lt.vertex_group_names.is_empty() && lt.editlatt && lt.editlatt->latt->dvert) {
387 actdef = lt.vertex_group_active_index - 1;
388 }
389
390 return DRW_lattice_batch_cache_get_all_edges(&lt, use_weight, actdef);
391}
392
400
402
403/* -------------------------------------------------------------------- */
406
412
414
415/* -------------------------------------------------------------------- */
418
424
426
427/* -------------------------------------------------------------------- */
430
436
443
445
446/* -------------------------------------------------------------------- */
449
451{
452 return DRW_particles_batch_cache_get_hair(object, psys, md);
453}
454
456{
457 return DRW_particles_batch_cache_get_dots(object, psys);
458}
459
461 ParticleSystem *psys,
462 PTCacheEdit *edit,
463 bool use_weight)
464{
465 return DRW_particles_batch_cache_get_edit_strands(object, psys, edit, use_weight);
466}
467
469 ParticleSystem *psys,
470 PTCacheEdit *edit)
471{
472 return DRW_particles_batch_cache_get_edit_inner_points(object, psys, edit);
473}
474
476 ParticleSystem *psys,
477 PTCacheEdit *edit)
478{
479 return DRW_particles_batch_cache_get_edit_tip_points(object, psys, edit);
480}
481
483
484/* -------------------------------------------------------------------- */
487
518
520{
521 const DRWContext *draw_ctx = DRW_context_get();
522 const Scene *scene = draw_ctx->scene;
524 draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
525 const bool is_paint_mode = ELEM(
527
528 const bool use_hide = ((ob->type == OB_MESH) &&
529 ((is_paint_mode && (ob == draw_ctx->obact) &&
531 ((mode == CTX_MODE_EDIT_MESH) && (ob->mode == OB_MODE_EDIT))));
532
533 switch (ob->type) {
534 case OB_MESH:
536 *ob,
538 *scene,
539 is_paint_mode,
540 use_hide);
541 break;
542 case OB_CURVES_LEGACY:
543 case OB_FONT:
544 case OB_SURF:
546 break;
547 case OB_CURVES:
549 break;
550 case OB_POINTCLOUD:
553 break;
554 /* TODO: all cases. */
555 default:
556 break;
557 }
558}
559
561{
562 /* NOTE: Logic here is duplicated from #drw_batch_cache_generate_requested. */
563
564 const DRWContext *draw_ctx = DRW_context_get();
565 const Scene *scene = draw_ctx->scene;
567 draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
568 const bool is_paint_mode = ELEM(
570
571 if (ob->type == OB_MESH) {
572 const bool use_hide = ((is_paint_mode && (ob == draw_ctx->obact) &&
574 ((mode == CTX_MODE_EDIT_MESH) && (ob->mode == OB_MODE_EDIT)));
577 task_graph, *ob, DRW_mesh_get_for_drawing(*mesh), *scene, is_paint_mode, use_hide);
578 }
579 }
581 /* Legacy curve objects can have evaluated mesh data while the original object is still a curve
582 * in edit mode (see #156971). #DRW_mesh_batch_cache_create_requested expects the object to
583 * match the mesh data and to be in object mode for non-edit mesh extraction, so use a shallow
584 * temporary mesh object for drawing. */
585 bke::ObjectRuntime tmp_runtime = *ob->runtime;
586 Object tmp_object = dna::shallow_copy(*ob);
587 tmp_object.runtime = &tmp_runtime;
588 tmp_object.mode = OB_MODE_OBJECT;
591 task_graph, tmp_object, DRW_mesh_get_for_drawing(*mesh), *scene, is_paint_mode, false);
592 }
593 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
595 }
596}
597
599{
600 DRWContext &draw_ctx = drw_get();
601 draw_ctx.delayed_extraction.add(ob);
602}
603
605{
606 switch (ob->type) {
607 case OB_MESH:
609 break;
610 case OB_CURVES:
612 break;
613 case OB_POINTCLOUD:
615 ctime);
617 break;
618 default:
619 break;
620 }
621}
622
624
626 const char *base_name,
627 const bke::AttrType data_type,
628 const StringRef layer_name,
629 bool is_active_render,
630 bool is_active_layer)
631{
632 char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
633 GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
634
635 /* Attribute layer name. */
636 SNPRINTF(attr_name, "%s%s", base_name, attr_safe_name);
637 GPU_vertformat_alias_add(format, attr_name);
638
639 /* Auto layer name. */
640 SNPRINTF(attr_name, "a%s", attr_safe_name);
641 GPU_vertformat_alias_add(format, attr_name);
642
643 /* Active render layer name. */
644 if (is_active_render) {
645 GPU_vertformat_alias_add(format, data_type == bke::AttrType::Float2 ? "a" : base_name);
646 }
647
648 /* Active display layer name. */
649 if (is_active_layer) {
650 SNPRINTF(attr_name, "a%s", base_name);
651 GPU_vertformat_alias_add(format, attr_name);
652 }
653}
654
655} // namespace blender::draw
General operations, lookup, etc. for blender objects.
#define SNPRINTF(dst, format,...)
Object is a sort of wrapper for general info.
#define GPU_vertbuf_init_with_format(verts, format)
#define ELEM(...)
MutableSpan< T > data()
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
void DRW_mesh_batch_cache_validate(Mesh &mesh)
gpu::Batch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
gpu::Batch * DRW_lattice_batch_cache_get_all_verts(Lattice *lt)
gpu::BottomLevelAS * DRW_cache_mesh_surface_blas_get(Object *ob)
void DRW_curves_batch_cache_validate(Curves *curves)
gpu::Batch * DRW_mesh_batch_cache_get_loose_edges(Mesh &mesh)
void DRW_grease_pencil_batch_cache_validate(GreasePencil *grease_pencil)
gpu::Batch * DRW_gsplat_batch_cache_get_dots(Object *ob)
gpu::Batch * DRW_cache_text_edge_wire_get(Object *ob)
void DRW_lattice_batch_cache_validate(Lattice *lt)
gpu::Batch * DRW_mesh_batch_cache_get_surface_texpaint_single(Object &object, Mesh &mesh)
void DRW_vertbuf_create_wiredata(gpu::VertBuf *vbo, const int vert_len)
Definition draw_cache.cc:74
gpu::Batch * DRW_cache_gsplat_vert_overlay_get(Object *ob)
gpu::Batch * DRW_cache_mesh_all_verts_get(Object *ob)
gpu::Batch * DRW_lattice_batch_cache_get_all_edges(Lattice *lt, bool use_weight, int actdef)
gpu::Batch * DRW_particles_batch_cache_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
gpu::Batch * DRW_curve_batch_cache_get_wire_edge(Curve *cu)
gpu::Batch * DRW_lattice_batch_cache_get_edit_verts(Lattice *lt)
gpu::Batch * DRW_curve_batch_cache_get_edit_verts(Curve *cu)
void DRW_curves_batch_cache_free_old(Curves *curves, int ctime)
gpu::Batch * DRW_particles_batch_cache_get_edit_tip_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
gpu::Batch * DRW_cache_mesh_paint_overlay_edges_get(Object *ob)
Span< gpu::Batch * > DRW_cache_mesh_surface_texpaint_get(Object *ob)
gpu::Batch * DRW_cache_curve_edge_wire_viewer_attribute_get(Object *ob)
gpu::Batch * DRW_cache_mesh_surface_sculptcolors_get(Object *ob)
gpu::Batch * DRW_cache_object_face_wireframe_get(const Scene *scene, Object *ob)
gpu::BottomLevelAS * DRW_cache_object_surface_blas_get(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh &mesh)
gpu::Batch * DRW_volume_batch_cache_get_selection_surface(Volume *volume)
void drw_batch_cache_generate_requested_evaluated_mesh_or_curve(Object *ob, TaskGraph &task_graph)
gpu::Batch * DRW_cache_grease_pencil_face_wireframe_get(const Scene *scene, Object *ob)
gpu::Batch * DRW_cache_mesh_surface_vertpaint_get(Object *ob)
gpu::Batch * DRW_curve_batch_cache_get_edit_edges(Curve *cu)
void DRW_curve_batch_cache_validate(Curve *cu)
gpu::Batch * DRW_mesh_batch_cache_get_surface(Mesh &mesh)
gpu::Batch * DRW_pointcloud_batch_cache_get_edit_dots(Object *ob)
gpu::Batch * DRW_particles_batch_cache_get_edit_strands(Object *object, ParticleSystem *psys, PTCacheEdit *edit, bool use_weight)
gpu::Batch * DRW_cache_mesh_loose_edges_get(Object *ob)
void drw_batch_cache_validate(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_surface_weights(Mesh &mesh)
gpu::Batch * DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *psys)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_shaded(Object &object, Mesh &mesh, Span< const GPUMaterial * > materials)
gpu::Batch * DRW_cache_mesh_face_wireframe_get(Object *ob)
gpu::Batch * DRW_cache_object_all_edges_get(Object *ob)
Definition draw_cache.cc:93
void DRW_gsplat_batch_cache_create_requested(Object *ob)
void DRW_curve_batch_cache_create_requested(Object *ob, const Scene *scene)
gpu::Batch * DRW_mesh_batch_cache_get_surface_vertpaint(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_wireframes_face(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface_sculpt(Object &object, Mesh &mesh)
bool pointcloud_is_gsplat(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_all_edges(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_verts(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edge_detection(Mesh &mesh, bool *r_is_manifold)
void DRW_mesh_batch_cache_free_old(Mesh *mesh, int ctime)
gpu::Batch * DRW_pointcloud_batch_cache_get_dots(Object *ob)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
gpu::Batch * DRW_curve_batch_cache_get_normal_edge(Curve *cu)
gpu::Batch * DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
void DRW_volume_batch_cache_validate(Volume *volume)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh)
gpu::Batch * DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
void DRW_pointcloud_batch_cache_free_old(PointCloud *pointcloud, int ctime)
gpu::Batch * DRW_cache_mesh_paint_overlay_verts_get(Object *ob)
gpu::Batch * DRW_volume_batch_cache_get_wireframes_face(Volume *volume)
void DRW_gsplat_batch_cache_validate(PointCloud *pointcloud)
gpu::Batch * DRW_cache_mesh_surface_viewer_attribute_get(Object *ob)
Span< gpu::Batch * > DRW_cache_mesh_surface_shaded_get(Object *ob, const Span< const GPUMaterial * > materials)
void drw_batch_cache_generate_requested(Object *ob, TaskGraph &task_graph)
void DRW_pointcloud_batch_cache_create_requested(Object *ob)
void DRW_pointcloud_batch_cache_validate(PointCloud *pointcloud)
void drw_batch_cache_generate_requested_delayed(Object *ob)
gpu::Batch * DRW_cache_curve_edge_overlay_get(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_surface(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface_viewer_attribute(Mesh &mesh)
gpu::Batch * DRW_cache_curve_edge_wire_get(Object *ob)
gpu::Batch * DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold)
void DRW_mesh_batch_cache_create_requested(TaskGraph &task_graph, Object &ob, Mesh &mesh, const Scene &scene, bool is_paint_mode, bool use_hide)
gpu::Batch * DRW_cache_lattice_verts_get(Object *ob)
gpu::Batch * DRW_cache_curve_edge_normal_get(Object *ob)
gpu::Batch * DRW_cache_mesh_edge_detection_get(Object *ob, bool *r_is_manifold)
gpu::Batch * DRW_cache_particles_get_edit_tip_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
gpu::Batch * DRW_cache_lattice_vert_overlay_get(Object *ob)
gpu::Batch * DRW_cache_pointcloud_vert_overlay_get(Object *ob)
gpu::Batch * DRW_cache_mesh_surface_weights_get(Object *ob)
gpu::Batch * DRW_cache_mesh_paint_overlay_surface_get(Object *ob)
gpu::Batch * DRW_cache_particles_get_hair(Object *object, ParticleSystem *psys, ModifierData *md)
gpu::Batch * DRW_gsplat_batch_cache_get_edit_dots(Object *ob)
Span< gpu::Batch * > DRW_cache_object_surface_material_get(Object *ob, const Span< const GPUMaterial * > materials)
gpu::Batch * DRW_particles_batch_cache_get_hair(Object *object, ParticleSystem *psys, ModifierData *md)
gpu::Batch * DRW_cache_surf_edge_wire_get(Object *ob)
gpu::Batch * DRW_cache_object_loose_edges_get(Object *ob)
gpu::Batch * DRW_cache_volume_selection_surface_get(Object *ob)
void DRW_batch_cache_free_old(Object *ob, int ctime)
gpu::Batch * DRW_cache_volume_face_wireframe_get(Object *ob)
gpu::Batch * DRW_cache_curve_vert_overlay_get(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_edges(Mesh &mesh)
gpu::Batch * DRW_cache_mesh_surface_get(Object *ob)
gpu::Batch * DRW_cache_mesh_all_edges_get(Object *ob)
gpu::Batch * DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
gpu::Batch * DRW_mesh_batch_cache_get_all_verts(Mesh &mesh)
gpu::Batch * DRW_curve_batch_cache_get_wire_edge_viewer_attribute(Curve *cu)
void DRW_curves_batch_cache_create_requested(Object *ob)
void DRW_gsplat_batch_cache_free_old(PointCloud *pointcloud, int ctime)
gpu::Batch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, PTCacheEdit *edit, bool use_weight)
gpu::BottomLevelAS * DRW_mesh_batch_cache_get_surface_blas(Mesh &mesh)
gpu::Batch * DRW_cache_mesh_surface_mesh_analysis_get(Object *ob)
void DRW_cdlayer_attr_aliases_add(GPUVertFormat *format, const char *base_name, bke::AttrType data_type, StringRef layer_name, bool is_active_render, bool is_active_layer)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_vertformat_alias_add(GPUVertFormat *, StringRef alias)
Mesh * BKE_object_get_evaluated_mesh_no_subsurf_unchecked(const Object *object)
Definition object.cc:4392
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
DRWContext & drw_get()
Mesh & DRW_mesh_get_for_drawing(Mesh &mesh)
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_SCULPT
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_PAINT_WEIGHT
void GPU_vertformat_safe_attr_name(StringRef attr_name, char *r_safe_name, uint max_len)
T & DRW_object_get_data_for_drawing(const Object &object)
bool DRW_object_use_hide_faces(const Object *ob)
const DRWContext * DRW_context_get()
void BKE_object_replace_data_on_shallow_copy(Object *ob, ID *new_data)
Definition object.cc:5748
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
Set< Object * > delayed_extraction
eObjectMode object_mode
struct Lattice * latt
struct EditLatt * editlatt
struct MDeformVert * dvert
ListBaseT< struct bDeformGroup > vertex_group_names
bke::ObjectRuntime * runtime