Blender V4.5
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.h"
22#include "BLI_listbase.h"
23#include "BLI_string.h"
24#include "BLI_utildefines.h"
25
26#include "BKE_context.hh"
27#include "BKE_mesh_wrapper.hh"
28#include "BKE_object.hh"
30
31#include "DRW_render.hh"
32#include "GPU_batch.hh"
33#include "GPU_batch_utils.hh"
34#include "GPU_capabilities.hh"
35
36#include "draw_cache.hh"
37#include "draw_cache_impl.hh"
39
40/* -------------------------------------------------------------------- */
43
44#define VCLASS_LIGHT_AREA_SHAPE (1 << 0)
45#define VCLASS_LIGHT_SPOT_SHAPE (1 << 1)
46#define VCLASS_LIGHT_SPOT_BLEND (1 << 2)
47#define VCLASS_LIGHT_SPOT_CONE (1 << 3)
48#define VCLASS_LIGHT_DIST (1 << 4)
49
50#define VCLASS_CAMERA_FRAME (1 << 5)
51#define VCLASS_CAMERA_DIST (1 << 6)
52#define VCLASS_CAMERA_VOLUME (1 << 7)
53
54#define VCLASS_SCREENSPACE (1 << 8)
55#define VCLASS_SCREENALIGNED (1 << 9)
56
57#define VCLASS_EMPTY_SCALED (1 << 10)
58#define VCLASS_EMPTY_AXES (1 << 11)
59#define VCLASS_EMPTY_AXES_NAME (1 << 12)
60#define VCLASS_EMPTY_AXES_SHADOW (1 << 13)
61#define VCLASS_EMPTY_SIZE (1 << 14)
62
64
65/* -------------------------------------------------------------------- */
68
69namespace blender::draw {
70
71void DRW_vertbuf_create_wiredata(gpu::VertBuf *vbo, const int vert_len)
72{
76 GPU_vertbuf_data_alloc(*vbo, vert_len);
77 vbo->data<float>().fill(1.0f);
78}
79
81
82/* -------------------------------------------------------------------- */
89
91{
92 switch (ob->type) {
93 case OB_MESH:
95 /* TODO: should match #DRW_cache_object_surface_get. */
96 default:
97 return nullptr;
98 }
99}
100
101gpu::Batch *DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold)
102{
103 switch (ob->type) {
104 case OB_MESH:
105 return DRW_cache_mesh_edge_detection_get(ob, r_is_manifold);
106 default:
107 return nullptr;
108 }
109}
110
112{
113 switch (ob->type) {
114 case OB_MESH:
116 case OB_POINTCLOUD:
118 case OB_VOLUME:
120 case OB_GREASE_PENCIL:
122 default:
123 return nullptr;
124 }
125}
126
128{
129 switch (ob->type) {
130 case OB_MESH:
132 default:
133 return nullptr;
134 }
135}
136
138{
139 switch (ob->type) {
140 case OB_MESH:
142 default:
143 return nullptr;
144 }
145}
146
148 const Span<const GPUMaterial *> materials)
149{
150 switch (ob->type) {
151 case OB_MESH:
152 return DRW_cache_mesh_surface_shaded_get(ob, materials);
153 default:
154 return {};
155 }
156}
157
159
160/* -------------------------------------------------------------------- */
163
169
175
181
182gpu::Batch *DRW_cache_mesh_edge_detection_get(Object *ob, bool *r_is_manifold)
183{
184 BLI_assert(ob->type == OB_MESH);
186 r_is_manifold);
187}
188
194
200
208
215
222
229
235
241
247
253
260
262
263/* -------------------------------------------------------------------- */
266
273
280
287
295
303
305
306/* -------------------------------------------------------------------- */
309
316
318
319/* -------------------------------------------------------------------- */
322
329
331
332/* -------------------------------------------------------------------- */
335
343
344gpu::Batch *DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
345{
346 BLI_assert(ob->type == OB_LATTICE);
347
349 int actdef = -1;
350
351 if (use_weight && !BLI_listbase_is_empty(&lt.vertex_group_names) && lt.editlatt &&
352 lt.editlatt->latt->dvert)
353 {
354 actdef = lt.vertex_group_active_index - 1;
355 }
356
357 return DRW_lattice_batch_cache_get_all_edges(&lt, use_weight, actdef);
358}
359
367
369
370/* -------------------------------------------------------------------- */
373
381
383
384/* -------------------------------------------------------------------- */
387
393
400
402
403/* -------------------------------------------------------------------- */
406
408{
409 return DRW_particles_batch_cache_get_hair(object, psys, md);
410}
411
413{
414 return DRW_particles_batch_cache_get_dots(object, psys);
415}
416
418 ParticleSystem *psys,
419 PTCacheEdit *edit,
420 bool use_weight)
421{
422 return DRW_particles_batch_cache_get_edit_strands(object, psys, edit, use_weight);
423}
424
426 ParticleSystem *psys,
427 PTCacheEdit *edit)
428{
429 return DRW_particles_batch_cache_get_edit_inner_points(object, psys, edit);
430}
431
433 ParticleSystem *psys,
434 PTCacheEdit *edit)
435{
436 return DRW_particles_batch_cache_get_edit_tip_points(object, psys, edit);
437}
438
440
441/* -------------------------------------------------------------------- */
444
474
476{
477 const DRWContext *draw_ctx = DRW_context_get();
478 const Scene *scene = draw_ctx->scene;
480 draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
481 const bool is_paint_mode = ELEM(
483
484 const bool use_hide = ((ob->type == OB_MESH) &&
485 ((is_paint_mode && (ob == draw_ctx->obact) &&
487 ((mode == CTX_MODE_EDIT_MESH) && (ob->mode == OB_MODE_EDIT))));
488
489 switch (ob->type) {
490 case OB_MESH:
492 *ob,
494 *scene,
495 is_paint_mode,
496 use_hide);
497 break;
498 case OB_CURVES_LEGACY:
499 case OB_FONT:
500 case OB_SURF:
502 break;
503 case OB_CURVES:
505 break;
506 case OB_POINTCLOUD:
508 break;
509 /* TODO: all cases. */
510 default:
511 break;
512 }
513}
514
516{
517 /* NOTE: Logic here is duplicated from #drw_batch_cache_generate_requested. */
518
519 const DRWContext *draw_ctx = DRW_context_get();
520 const Scene *scene = draw_ctx->scene;
522 draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
523 const bool is_paint_mode = ELEM(
525
526 const bool use_hide = ((ob->type == OB_MESH) &&
527 ((is_paint_mode && (ob == draw_ctx->obact) &&
529 ((mode == CTX_MODE_EDIT_MESH) && (ob->mode == OB_MODE_EDIT))));
530
532 /* Try getting the mesh first and if that fails, try getting the curve data.
533 * If the curves are surfaces or have certain modifiers applied to them, the will have mesh data
534 * of the final result.
535 */
536 if (mesh != nullptr) {
537 DRW_mesh_batch_cache_create_requested(task_graph, *ob, *mesh, *scene, is_paint_mode, use_hide);
538 }
539 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
541 }
542}
543
545{
546 DRWContext &draw_ctx = drw_get();
547 if (draw_ctx.delayed_extraction == nullptr) {
548 draw_ctx.delayed_extraction = BLI_gset_ptr_new(__func__);
549 }
550 BLI_gset_add(draw_ctx.delayed_extraction, ob);
551}
552
554{
555 switch (ob->type) {
556 case OB_MESH:
558 break;
559 case OB_CURVES:
561 break;
562 case OB_POINTCLOUD:
564 ctime);
565 break;
566 default:
567 break;
568 }
569}
570
572
574 const char *base_name,
575 const int data_type,
576 const StringRef layer_name,
577 bool is_active_render,
578 bool is_active_layer)
579{
580 char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
581 GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
582
583 /* Attribute layer name. */
584 SNPRINTF(attr_name, "%s%s", base_name, attr_safe_name);
586
587 /* Auto layer name. */
588 SNPRINTF(attr_name, "a%s", attr_safe_name);
590
591 /* Active render layer name. */
592 if (is_active_render) {
593 GPU_vertformat_alias_add(format, data_type == CD_PROP_FLOAT2 ? "a" : base_name);
594 }
595
596 /* Active display layer name. */
597 if (is_active_layer) {
598 SNPRINTF(attr_name, "a%s", base_name);
600 }
601}
602
603} // namespace blender::draw
eContextObjectMode
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_SCULPT
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_PAINT_WEIGHT
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh_no_subsurf_unchecked(const Object *object)
#define BLI_assert(a)
Definition BLI_assert.h:46
GSet * BLI_gset_ptr_new(const char *info)
bool BLI_gset_add(GSet *gs, void *key)
Definition BLI_ghash.cc:966
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
#define ELEM(...)
@ CD_PROP_FLOAT2
@ OB_MODE_EDIT
Object is a sort of wrapper for general info.
@ OB_LATTICE
@ OB_SURF
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
#define GPU_vertbuf_init_with_format(verts, format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_FETCH_FLOAT
void GPU_vertformat_alias_add(GPUVertFormat *, blender::StringRef alias)
void GPU_vertformat_safe_attr_name(blender::StringRef attr_name, char *r_safe_name, uint max_len)
static constexpr int GPU_MAX_SAFE_ATTR_NAME
GPUVertFormat GPU_vertformat_from_attribute(blender::StringRef name, const GPUVertCompType comp_type, const uint comp_len, const GPUVertFetchMode fetch_mode)
@ GPU_COMP_F32
MutableSpan< T > data()
const DRWContext * DRW_context_get()
bool DRW_object_use_hide_faces(const Object *ob)
Mesh & DRW_object_get_data_for_drawing(const Object &object)
DRWContext & drw_get()
format
void DRW_mesh_batch_cache_validate(Mesh &mesh)
gpu::Batch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
blender::gpu::Batch * DRW_lattice_batch_cache_get_all_verts(Lattice *lt)
void DRW_curves_batch_cache_validate(Curves *curves)
blender::gpu::Batch * DRW_mesh_batch_cache_get_loose_edges(Mesh &mesh)
void DRW_grease_pencil_batch_cache_validate(GreasePencil *grease_pencil)
gpu::Batch * DRW_cache_text_edge_wire_get(Object *ob)
void DRW_lattice_batch_cache_validate(Lattice *lt)
blender::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:71
gpu::Batch * DRW_cache_mesh_all_verts_get(Object *ob)
blender::gpu::Batch * DRW_lattice_batch_cache_get_all_edges(Lattice *lt, bool use_weight, int actdef)
blender::gpu::Batch * DRW_particles_batch_cache_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
blender::gpu::Batch * DRW_curve_batch_cache_get_wire_edge(Curve *cu)
blender::gpu::Batch * DRW_lattice_batch_cache_get_edit_verts(Lattice *lt)
blender::gpu::Batch * DRW_curve_batch_cache_get_edit_verts(Curve *cu)
void DRW_curves_batch_cache_free_old(Curves *curves, int ctime)
blender::gpu::Batch * DRW_mesh_batch_cache_get_surface_edges(Mesh &mesh)
blender::gpu::Batch * DRW_particles_batch_cache_get_edit_tip_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
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)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh &mesh)
blender::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)
blender::gpu::Batch * DRW_curve_batch_cache_get_edit_edges(Curve *cu)
void DRW_curve_batch_cache_validate(Curve *cu)
blender::gpu::Batch * DRW_mesh_batch_cache_get_surface(Mesh &mesh)
blender::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)
blender::gpu::Batch * DRW_mesh_batch_cache_get_surface_weights(Mesh &mesh)
blender::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:90
void DRW_curve_batch_cache_create_requested(Object *ob, const Scene *scene)
blender::gpu::Batch * DRW_mesh_batch_cache_get_surface_vertpaint(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_wireframes_face(Mesh &mesh)
gpu::Batch * DRW_cache_mesh_surface_edges_get(Object *ob)
blender::gpu::Batch * DRW_mesh_batch_cache_get_surface_sculpt(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_all_edges(Mesh &mesh)
blender::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)
blender::gpu::Batch * DRW_pointcloud_batch_cache_get_dots(Object *ob)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
blender::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)
blender::gpu::Batch * DRW_volume_batch_cache_get_wireframes_face(Volume *volume)
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)
blender::gpu::Batch * DRW_pointcloud_batch_cache_get_edit_dots(PointCloud *pointcloud)
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)
void DRW_cdlayer_attr_aliases_add(GPUVertFormat *format, const char *base_name, int data_type, blender::StringRef layer_name, bool is_active_render, bool is_active_layer)
blender::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_particles_get_hair(Object *object, ParticleSystem *psys, ModifierData *md)
Span< gpu::Batch * > DRW_cache_object_surface_material_get(Object *ob, const Span< const GPUMaterial * > materials)
blender::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_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)
blender::gpu::Batch * DRW_mesh_batch_cache_get_all_verts(Mesh &mesh)
blender::gpu::Batch * DRW_curve_batch_cache_get_wire_edge_viewer_attribute(Curve *cu)
void DRW_curves_batch_cache_create_requested(Object *ob)
gpu::Batch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, PTCacheEdit *edit, bool use_weight)
gpu::Batch * DRW_cache_mesh_surface_mesh_analysis_get(Object *ob)
Object * object_edit
GSet * delayed_extraction
Object * obact
Scene * scene
eObjectMode object_mode
struct Lattice * latt
ListBase vertex_group_names
struct MDeformVert * dvert
int vertex_group_active_index
struct EditLatt * editlatt