Blender V5.3
draw_cache_impl_mesh.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 <array>
12#include <optional>
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_index_range.hh"
17#include "BLI_listbase.hh"
18#include "BLI_span.hh"
19#include "BLI_string_ref.hh"
20
21#include "DNA_mesh_types.h"
22#include "DNA_object_types.h"
23#include "DNA_scene_types.h"
24#include "DNA_userdef_types.h"
25
26#include "BKE_attribute.hh"
27#include "BKE_customdata.hh"
28#include "BKE_editmesh.hh"
29#include "BKE_material.hh"
30#include "BKE_mesh.hh"
31#include "BKE_object.hh"
32#include "BKE_object_deform.h"
33#include "BKE_paint.hh"
34#include "BKE_paint_bvh.hh"
36
37#include "GPU_batch.hh"
38#include "GPU_material.hh"
39
40#include "DRW_render.hh"
41
42#include "draw_cache_extract.hh"
43#include "draw_cache_inline.hh"
44#include "draw_subdivision.hh"
45
46#include "draw_cache_impl.hh" /* own include */
48
50
51namespace blender::draw {
52
53/* ---------------------------------------------------------------------- */
56
57#define TRIS_PER_MAT_INDEX BUFFER_LEN
58
59static void mesh_batch_cache_clear(MeshBatchCache &cache);
60
62 const Span<VBOType> vbos,
63 const Span<IBOType> ibos)
64{
65 Set<const void *, 16> buffer_ptrs;
66 buffer_ptrs.reserve(vbos.size() + ibos.size());
67 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
68 for (const VBOType vbo : vbos) {
69 if (const auto *buffer = mbc->buff.vbos.lookup_ptr(vbo)) {
70 buffer_ptrs.add(buffer->get());
71 }
72 }
73 }
74 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
75 for (const IBOType ibo : ibos) {
76 if (const auto *buffer = mbc->buff.ibos.lookup_ptr(ibo)) {
77 buffer_ptrs.add(buffer->get());
78 }
79 }
80 }
81
82 const auto batch_contains_data = [&](gpu::Batch &batch) {
83 if (buffer_ptrs.contains(batch.elem)) {
84 return true;
85 }
86 if (std::any_of(batch.verts,
87 batch.verts + ARRAY_SIZE(batch.verts),
88 [&](gpu::VertBuf *vbo) { return vbo && buffer_ptrs.contains(vbo); }))
89 {
90 return true;
91 }
92 return false;
93 };
94
95 for (const int i : IndexRange(MBC_BATCH_LEN)) {
96 gpu::Batch *batch = (reinterpret_cast<gpu::Batch **>(&cache.batch))[i];
97 if (batch && batch_contains_data(*batch)) {
98 GPU_BATCH_DISCARD_SAFE(((gpu::Batch **)&cache.batch)[i]);
99 cache.batch_ready &= ~DRWBatchFlag(uint64_t(1u) << i);
100 }
101 }
102
103 if (!cache.surface_per_mat.is_empty()) {
104 if (cache.surface_per_mat.first() && batch_contains_data(*cache.surface_per_mat.first())) {
105 /* The format for all `surface_per_mat` batches is the same, discard them all. */
106 for (const int i : cache.surface_per_mat.index_range()) {
108 }
110 }
111 }
112
113 for (const VBOType vbo : vbos) {
114 cache.final.buff.vbos.remove(vbo);
115 cache.cage.buff.vbos.remove(vbo);
116 cache.uv_cage.buff.vbos.remove(vbo);
117 }
118 for (const IBOType ibo : ibos) {
119 cache.final.buff.ibos.remove(ibo);
120 cache.cage.buff.ibos.remove(ibo);
121 cache.uv_cage.buff.ibos.remove(ibo);
122 }
123}
124
126{
127 drw_attributes_merge(&a->uv, &b.uv);
128 drw_attributes_merge(&a->tan, &b.tan);
129 a->orco |= b.orco;
130 a->tan_orco |= b.tan_orco;
131 a->sculpt_overlays |= b.sculpt_overlays;
132 a->edit_uv |= b.edit_uv;
133}
134
135static void mesh_cd_calc_edit_uv_layer(const Mesh & /*mesh*/, DRW_MeshCDMask *cd_used)
136{
137 cd_used->edit_uv = true;
138}
139
140static void mesh_cd_calc_active_uv_layer(const Object &object,
141 const Mesh &mesh,
142 DRW_MeshCDMask &cd_used)
143{
144 const Mesh &me_final = editmesh_final_or_this(object, mesh);
145 const StringRef active_uv_map = me_final.active_or_default_uv_map_name();
146 if (!active_uv_map.is_empty()) {
147 cd_used.uv.add_as(active_uv_map);
148 }
149}
150
152 const Mesh &mesh,
153 DRW_MeshCDMask &cd_used)
154{
155 const Mesh &me_final = editmesh_final_or_this(object, mesh);
156 StringRef name = me_final.stencil_uv_map_attribute;
157 if (name.is_empty()) {
158 name = mesh.active_uv_map_name();
159 }
160 if (!name.is_empty()) {
161 cd_used.uv.add_as(name);
162 }
163}
164
165static bool attribute_exists(const Mesh &mesh, const StringRef name)
166{
167 if (const BMesh *bm = BKE_editmesh_bmesh_get(&mesh)) {
168 return bool(BM_data_layer_lookup(*bm, name));
169 }
170 return mesh.attributes().contains(name);
171};
172
173static std::optional<bke::AttributeMetaData> lookup_meta_data(const Mesh &mesh,
174 const StringRef name)
175{
176 if (mesh.runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
177 if (const BMesh *bm = BKE_editmesh_bmesh_get(&mesh)) {
178 if (const BMDataLayerLookup attr = BM_data_layer_lookup(*bm, name)) {
179 return bke::AttributeMetaData{attr.domain, attr.type};
180 }
181 return std::nullopt;
182 }
183 }
184 return mesh.attributes().lookup_meta_data(name);
185}
186
187static void mesh_cd_calc_used_gpu_layers(const Object &object,
188 const Mesh &mesh,
189 const Span<const GPUMaterial *> materials,
190 VectorSet<std::string> *r_attributes,
191 DRW_MeshCDMask *r_cd_used)
192{
194 const Mesh &me_final = editmesh_final_or_this(object, mesh);
195
196 for (const GPUMaterial *gpumat : materials) {
197 if (gpumat == nullptr) {
198 continue;
199 }
200 ListBaseT<GPUMaterialAttribute> gpu_attrs = GPU_material_attributes(gpumat);
201 for (GPUMaterialAttribute &gpu_attr : gpu_attrs) {
202
203 if (gpu_attr.is_default_color) {
204 const StringRef default_color_name = me_final.default_color_attribute;
205 if (attribute_exists(me_final, default_color_name)) {
206 drw_attributes_add_request(r_attributes, default_color_name);
207 }
208 continue;
209 }
210
211 if (gpu_attr.type == CD_ORCO) {
212 r_cd_used->orco = true;
213 continue;
214 }
215
216 StringRef name = gpu_attr.name;
217
218 if (gpu_attr.type == CD_TANGENT) {
219 if (name.is_empty()) {
220 const StringRef default_name = me_final.default_uv_map_name();
221 if (!default_name.is_empty()) {
222 name = default_name;
223 }
224 }
225 if (lookup_meta_data(mesh, name) == UV_METADATA) {
226 r_cd_used->tan.add(name);
227 }
228 else {
229 r_cd_used->tan_orco = true;
230 r_cd_used->orco = true;
231 }
232
233 continue;
234 }
235
236 if (name.is_empty()) {
237 const StringRef default_name = me_final.default_uv_map_name();
238 if (!default_name.is_empty()) {
239 if (lookup_meta_data(mesh, default_name) == UV_METADATA) {
240 r_cd_used->uv.add(default_name);
241 }
242 }
243 continue;
244 }
245
246 const std::optional<bke::AttributeMetaData> meta_data = lookup_meta_data(mesh, name);
247 if (!meta_data) {
248 continue;
249 }
250 if (meta_data == UV_METADATA) {
251 r_cd_used->uv.add(name);
252 continue;
253 }
254 drw_attributes_add_request(r_attributes, name);
255 }
256 }
257}
258
260
261/* ---------------------------------------------------------------------- */
264
267{
268 MEM_SAFE_DELETE(wstate->defgroup_sel);
269 MEM_SAFE_DELETE(wstate->defgroup_locked);
270 MEM_SAFE_DELETE(wstate->defgroup_unlocked);
271
272 memset(wstate, 0, sizeof(*wstate));
273
274 wstate->defgroup_active = -1;
275}
276
279 const DRW_MeshWeightState *wstate_src)
280{
281 MEM_SAFE_DELETE(wstate_dst->defgroup_sel);
282 MEM_SAFE_DELETE(wstate_dst->defgroup_locked);
283 MEM_SAFE_DELETE(wstate_dst->defgroup_unlocked);
284
285 memcpy(wstate_dst, wstate_src, sizeof(*wstate_dst));
286
287 if (wstate_src->defgroup_sel) {
288 wstate_dst->defgroup_sel = MEM_dupalloc(wstate_src->defgroup_sel);
289 }
290 if (wstate_src->defgroup_locked) {
291 wstate_dst->defgroup_locked = MEM_dupalloc(wstate_src->defgroup_locked);
292 }
293 if (wstate_src->defgroup_unlocked) {
294 wstate_dst->defgroup_unlocked = static_cast<bool *>(
295 MEM_dupalloc(wstate_src->defgroup_unlocked));
296 }
297}
298
299static bool drw_mesh_flags_equal(const bool *array1, const bool *array2, int size)
300{
301 return ((!array1 && !array2) ||
302 (array1 && array2 && memcmp(array1, array2, size * sizeof(bool)) == 0));
303}
304
307 const DRW_MeshWeightState *b)
308{
309 return a->defgroup_active == b->defgroup_active && a->defgroup_len == b->defgroup_len &&
310 a->flags == b->flags && a->alert_mode == b->alert_mode &&
311 a->defgroup_sel_count == b->defgroup_sel_count &&
312 drw_mesh_flags_equal(a->defgroup_sel, b->defgroup_sel, a->defgroup_len) &&
313 drw_mesh_flags_equal(a->defgroup_locked, b->defgroup_locked, a->defgroup_len) &&
314 drw_mesh_flags_equal(a->defgroup_unlocked, b->defgroup_unlocked, a->defgroup_len);
315}
316
318 Object &ob, Mesh &mesh, const ToolSettings &ts, bool paint_mode, DRW_MeshWeightState *wstate)
319{
320 /* Extract complete vertex weight group selection state and mode flags. */
321 memset(wstate, 0, sizeof(*wstate));
322
323 wstate->defgroup_active = mesh.vertex_group_active_index - 1;
324 wstate->defgroup_len = mesh.vertex_group_names.count();
325
326 wstate->alert_mode = ts.weightuser;
327
328 if (paint_mode && ts.multipaint) {
329 /* Multi-paint needs to know all selected bones, not just the active group.
330 * This is actually a relatively expensive operation, but caching would be difficult. */
332 &ob, wstate->defgroup_len, &wstate->defgroup_sel_count);
333
334 if (wstate->defgroup_sel_count > 1) {
337
340 wstate->defgroup_len,
341 wstate->defgroup_sel,
342 wstate->defgroup_sel,
343 &wstate->defgroup_sel_count);
344 }
345 }
346 /* With only one selected bone Multi-paint reverts to regular mode. */
347 else {
348 wstate->defgroup_sel_count = 0;
349 MEM_SAFE_DELETE(wstate->defgroup_sel);
350 }
351 }
352
353 if (paint_mode && ts.wpaint_lock_relative) {
354 /* Set of locked vertex groups for the lock relative mode. */
357
358 /* Check that a deform group is active, and none of selected groups are locked. */
360 wstate->defgroup_locked, wstate->defgroup_unlocked, wstate->defgroup_active) &&
362 wstate->defgroup_locked,
363 wstate->defgroup_sel,
364 wstate->defgroup_sel_count))
365 {
367
368 /* Compute the set of locked and unlocked deform vertex groups. */
370 wstate->defgroup_locked,
371 wstate->defgroup_unlocked,
372 wstate->defgroup_locked, /* out */
373 wstate->defgroup_unlocked);
374 }
375 else {
376 MEM_SAFE_DELETE(wstate->defgroup_unlocked);
377 MEM_SAFE_DELETE(wstate->defgroup_locked);
378 }
379 }
380}
381
383
384/* ---------------------------------------------------------------------- */
387
388/* gpu::Batch cache management. */
389
391{
392 MeshBatchCache *cache = mesh.runtime->batch_cache;
393
394 if (cache == nullptr) {
395 return false;
396 }
397
398 /* NOTE: bke::pbvh::Tree draw data should not be checked here. */
399
400 if (cache->is_editmode != (mesh.runtime->edit_mesh != nullptr)) {
401 return false;
402 }
403
404 if (cache->is_dirty) {
405 return false;
406 }
407
409 return false;
410 }
411
412 return true;
413}
414
416{
417 if (!mesh.runtime->batch_cache) {
418 mesh.runtime->batch_cache = MEM_new<MeshBatchCache>(__func__);
419 }
420 else {
421 *mesh.runtime->batch_cache = {};
422 }
423 MeshBatchCache *cache = mesh.runtime->batch_cache;
424
425 cache->is_editmode = mesh.runtime->edit_mesh != nullptr;
426
427 if (cache->is_editmode == false) {
428 // cache->edge_len = mesh_render_edges_len_get(mesh);
429 // cache->tri_len = mesh_render_corner_tris_len_get(mesh);
430 // cache->face_len = mesh_render_faces_len_get(mesh);
431 // cache->vert_len = mesh_render_verts_len_get(mesh);
432 }
433
435 cache->surface_per_mat = Array<gpu::Batch *>(cache->mat_len, nullptr);
436 cache->tris_per_mat.reinitialize(cache->mat_len);
437
438 cache->is_dirty = false;
439 cache->batch_ready = DRWBatchFlag(0);
440 cache->batch_requested = DRWBatchFlag(0);
441
443}
444
446{
448 if (mesh.runtime->batch_cache) {
449 mesh_batch_cache_clear(*mesh.runtime->batch_cache);
450 }
452 }
453}
454
456{
457 return mesh.runtime->batch_cache;
458}
459
461 const DRW_MeshWeightState *wstate)
462{
463 if (!drw_mesh_weight_state_compare(&cache.weight_state, wstate)) {
464 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
465 mbc->buff.vbos.remove(VBOType::VertexGroupWeight);
466 }
468
470
472 }
473}
474
476{
479
480 /* If there are only a few materials at most, just request batches for everything. However, if
481 * the maximum material index is large, detect the actually used material indices first and only
482 * request those. This reduces the overhead of dealing with all these batches down the line. */
483 if (cache.mat_len < 16) {
484 for (int i = 0; i < cache.mat_len; i++) {
486 }
487 }
488 else {
489 const VectorSet<int> &used_material_indices = mesh.material_indices_used();
490 for (const int i : used_material_indices) {
492 }
493 }
494}
495
501
503{
505
506 if (cache.surface_blas) {
508 cache.surface_blas = nullptr;
509 cache.surface_blas_ready = false;
510 }
511}
512
514{
515 discard_buffers(cache,
528
529 cache.tot_area = 0.0f;
530 cache.tot_uv_area = 0.0f;
531
532 /* We discarded the vbo.uv so we need to reset the cd_used flag. */
533 cache.cd_used.uv.clear();
534 cache.cd_used.edit_uv = false;
535}
536
548
550{
551 if (!mesh->runtime->batch_cache) {
552 return;
553 }
554 MeshBatchCache &cache = *mesh->runtime->batch_cache;
555 switch (mode) {
558
559 /* Because visible UVs depends on edit mode selection, discard topology. */
561 break;
564 break;
566 cache.is_dirty = true;
567 break;
571 break;
574 break;
577 break;
578 default:
579 BLI_assert(0);
580 }
581}
582
584{
585 mbc->buff.ibos.clear();
586 mbc->buff.vbos.clear();
587
588 mbc->loose_geom = {};
589 mbc->face_sorted = {};
590 mbc->corner_verts.reset();
591 mbc->corner_edges.reset();
592 mbc->face_offsets.reset();
593}
594
596{
597 if (cache.subdiv_cache) {
599 MEM_delete(cache.subdiv_cache);
600 cache.subdiv_cache = nullptr;
601 }
602}
603
605{
606 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
608 }
609
610 cache.tris_per_mat = {};
611
612 for (int i = 0; i < sizeof(cache.batch) / sizeof(void *); i++) {
613 gpu::Batch **batch = reinterpret_cast<gpu::Batch **>(&cache.batch);
614 GPU_BATCH_DISCARD_SAFE(batch[i]);
615 }
616 for (const int i : cache.surface_per_mat.index_range()) {
618 }
619
622 cache.surface_per_mat = {};
623 cache.mat_len = 0;
624
625 cache.batch_ready = DRWBatchFlag(0);
627
629
630 if (cache.surface_blas) {
632 cache.surface_blas = nullptr;
633 cache.surface_blas_ready = false;
634 }
635}
636
638{
639 mesh_batch_cache_clear(*batch_cache);
640 MEM_delete(batch_cache);
641}
642
644
645/* ---------------------------------------------------------------------- */
648
650{
652
653 BLI_assert(!cache.cd_needed.uv.is_empty() &&
654 "No uv layer available in texpaint, but batches requested anyway!");
655
657}
658
660 const Mesh &mesh,
661 VectorSet<std::string> &attributes)
662{
663 const Mesh &me_final = editmesh_final_or_this(object, mesh);
664
665 auto request_color_attribute = [&](const StringRef name) {
666 if (!name.is_empty()) {
667 if (attribute_exists(me_final, name)) {
668 drw_attributes_add_request(&attributes, name);
669 }
670 }
671 };
672
673 request_color_attribute(me_final.active_color_attribute);
674 request_color_attribute(me_final.default_color_attribute);
675}
676
683
690
697
705
713
720
722{
724 if (cache.no_loose_wire) {
725 return nullptr;
726 }
728 return DRW_batch_request(&cache.batch.loose_edges);
729}
730
737
738gpu::Batch *DRW_mesh_batch_cache_get_edge_detection(Mesh &mesh, bool *r_is_manifold)
739{
742 /* Even if is_manifold is not correct (not updated),
743 * the default (not manifold) is just the worst case. */
744 if (r_is_manifold) {
745 *r_is_manifold = cache.is_manifold;
746 }
748}
749
756
763
765 const Mesh &mesh,
766 const Span<const GPUMaterial *> materials,
767 VectorSet<std::string> *r_attrs,
768 DRW_MeshCDMask *r_cd_needed)
769{
770 mesh_cd_calc_used_gpu_layers(object, mesh, materials, r_attrs, r_cd_needed);
771}
772
774 Object &object, Mesh &mesh, const Span<const GPUMaterial *> materials)
775{
777 mesh_cd_calc_used_gpu_layers(object, mesh, materials, &cache.attr_needed, &cache.cd_needed);
778
779 BLI_assert(materials.size() == cache.mat_len);
780
782 return cache.surface_per_mat;
783}
784
792
800
802{
804
805 VectorSet<std::string> attrs_needed{};
807
808 drw_attributes_merge(&cache.attr_needed, &attrs_needed);
809
811 return cache.batch.surface;
812}
813
815{
817
818 VectorSet<std::string> attrs_needed{};
820
821 drw_attributes_merge(&cache.attr_needed, &attrs_needed);
822
824 return cache.batch.surface;
825}
826
837
847
849
850/* ---------------------------------------------------------------------- */
853
860
867
874
881
888
895
902
904
905/* ---------------------------------------------------------------------- */
908
915
922
929
936
938
939/* ---------------------------------------------------------------------- */
942
950
952 Mesh &mesh,
953 float **tot_area,
954 float **tot_uv_area)
955{
957 edituv_request_active_uv(cache, object, mesh);
959
960 if (tot_area != nullptr) {
961 *tot_area = &cache.tot_area;
962 }
963 if (tot_uv_area != nullptr) {
964 *tot_uv_area = &cache.tot_uv_area;
965 }
967}
968
976
984
992
1000
1008
1010{
1012 edituv_request_active_uv(cache, object, mesh);
1014 return DRW_batch_request(&cache.batch.uv_faces);
1015}
1016
1024
1032
1040
1047
1049
1050/* ---------------------------------------------------------------------- */
1053
1055{
1056 MeshBatchCache *cache = mesh->runtime->batch_cache;
1057
1058 if (cache == nullptr) {
1059 return;
1060 }
1061
1062 if (cache->cd_used_over_time == cache->cd_used) {
1063 cache->lastmatch = ctime;
1064 }
1065
1067 cache->lastmatch = ctime;
1068 }
1069
1070 if (ctime - cache->lastmatch > U.vbotimeout) {
1072 }
1073
1074 cache->cd_used_over_time.clear();
1075 cache->attr_used_over_time.clear();
1076}
1077
1078static void init_empty_dummy_batch(gpu::Batch &batch)
1079{
1080 /* The dummy batch is only used in cases with invalid edit mode mapping, so the overhead of
1081 * creating a vertex buffer shouldn't matter. */
1082 GPUVertFormat format{};
1083 GPU_vertformat_attr_add(&format, "dummy", gpu::VertAttrType::SFLOAT_32);
1084 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
1085 GPU_vertbuf_data_alloc(*vbo, 1);
1086 /* Avoid the batch being rendered at all. */
1087 GPU_vertbuf_data_len_set(*vbo, 0);
1088
1089 GPU_batch_vertbuf_add(&batch, vbo, true);
1090}
1091
1093 Object &ob,
1094 Mesh &mesh,
1095 const Scene &scene,
1096 const bool is_paint_mode,
1097 const bool use_hide)
1098{
1099 const ToolSettings *ts = scene.toolsettings;
1100
1102 bool cd_uv_update = false;
1103
1104 /* Early out */
1105 if (cache.batch_requested == 0 && !cache.surface_blas_requested) {
1106 return;
1107 }
1108
1109 /* Sanity check. */
1110 if ((mesh.runtime->edit_mesh != nullptr) && (ob.mode & OB_MODE_EDIT)) {
1112 }
1113
1114 const bool is_editmode = ob.mode == OB_MODE_EDIT;
1115
1116 DRWBatchFlag batch_requested = cache.batch_requested;
1117 cache.batch_requested = DRWBatchFlag(0);
1118
1119 if (batch_requested & MBC_SURFACE_WEIGHTS) {
1120 /* Check vertex weights. */
1121 if ((cache.batch.surface_weights != nullptr) && (ts != nullptr)) {
1122 DRW_MeshWeightState wstate;
1123 BLI_assert(ob.type == OB_MESH);
1124 drw_mesh_weight_state_extract(ob, mesh, *ts, is_paint_mode, &wstate);
1128 }
1129 }
1130
1131 if (batch_requested &
1135 {
1136 /* Modifiers will only generate an orco layer if the mesh is deformed. */
1137 if (cache.cd_needed.orco != 0) {
1138 /* Orco is always extracted from final mesh. */
1139 const Mesh *me_final = (mesh.runtime->edit_mesh) ? BKE_object_get_editmesh_eval_final(&ob) :
1140 &mesh;
1141 if (CustomData_get_layer(&me_final->vert_data, CD_ORCO) == nullptr) {
1142 /* Skip orco calculation */
1143 cache.cd_needed.orco = false;
1144 }
1145 }
1146
1147 /* Verify that all surface batches have needed attribute layers, i.e. that none of the shaders
1148 * need vertex buffers that aren't currently cached. */
1149 /* TODO(fclem): We could be a bit smarter here and only do it per
1150 * material. */
1151 const bool uvs_overlap = drw_attributes_overlap(&cache.cd_used.uv, &cache.cd_needed.uv);
1152 const bool tan_overlap = drw_attributes_overlap(&cache.cd_used.tan, &cache.cd_needed.tan);
1153 const bool attr_overlap = drw_attributes_overlap(&cache.attr_used, &cache.attr_needed);
1154 if (!uvs_overlap || !tan_overlap || !attr_overlap ||
1155 (cache.cd_needed.orco && !cache.cd_used.orco) ||
1156 (cache.cd_needed.tan_orco && !cache.cd_used.tan_orco) ||
1158 {
1159 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
1160 if (!uvs_overlap) {
1161 mbc->buff.vbos.remove(VBOType::UVs);
1162 cd_uv_update = true;
1163 }
1164 if (!tan_overlap || cache.cd_used.tan_orco != cache.cd_needed.tan_orco) {
1165 mbc->buff.vbos.remove(VBOType::Tangents);
1166 }
1167 if (cache.cd_used.orco != cache.cd_needed.orco) {
1168 mbc->buff.vbos.remove(VBOType::Orco);
1169 }
1170 if (cache.cd_used.sculpt_overlays != cache.cd_needed.sculpt_overlays) {
1171 mbc->buff.vbos.remove(VBOType::SculptData);
1172 }
1173 if (!attr_overlap) {
1174 for (int i = 0; i < GPU_MAX_ATTR; i++) {
1175 mbc->buff.vbos.remove(VBOType(int8_t(VBOType::Attr0) + i));
1176 }
1177 }
1178 }
1179 /* We can't discard batches at this point as they have been
1180 * referenced for drawing. Just clear them in place. */
1181 for (int i = 0; i < cache.mat_len; i++) {
1183 }
1187
1190 }
1192 cache.cd_needed.clear();
1193
1195 cache.attr_needed.clear();
1196 }
1197
1198 if ((batch_requested & MBC_EDITUV) || cd_uv_update) {
1199 /* Discard UV batches if sync_selection changes */
1200 const bool is_uvsyncsel = ts && (ts->uv_flag & UV_FLAG_SELECT_SYNC);
1201 if (cd_uv_update || (cache.is_uvsyncsel != is_uvsyncsel)) {
1202 cache.is_uvsyncsel = is_uvsyncsel;
1203 FOREACH_MESH_BUFFER_CACHE (cache, mbc) {
1204 mbc->buff.vbos.remove(VBOType::EditUVData);
1205 mbc->buff.vbos.remove(VBOType::FaceDotUV);
1206 mbc->buff.vbos.remove(VBOType::FaceDotEditUVData);
1207 mbc->buff.ibos.remove(IBOType::EditUVTris);
1208 mbc->buff.ibos.remove(IBOType::EditUVLines);
1209 mbc->buff.ibos.remove(IBOType::EditUVPoints);
1210 mbc->buff.ibos.remove(IBOType::EditUVFaceDots);
1211 }
1212 /* We only clear the batches as they may already have been
1213 * referenced. */
1224 cache.batch_ready &= ~MBC_EDITUV;
1225 }
1226 }
1227
1228 /* Second chance to early out */
1229 if ((batch_requested & ~cache.batch_ready) == 0 && !cache.surface_blas_requested) {
1230 return;
1231 }
1232
1233 /* TODO(pablodp606): This always updates the sculpt normals for regular drawing (non-pbvh::Tree).
1234 * This makes tools that sample the surface per step get wrong normals until a redraw happens.
1235 * Normal updates should be part of the brush loop and only run during the stroke when the
1236 * brush needs to sample the surface. The drawing code should only update the normals
1237 * per redraw when smooth shading is enabled. */
1240 }
1241
1242 /* This is the mesh before modifier evaluation, used to test how the mesh changed during
1243 * evaluation to decide which data is valid to extract. */
1244 const Mesh *orig_edit_mesh = is_editmode ? BKE_object_get_pre_modified_mesh(&ob) : nullptr;
1245
1246 bool do_cage = false;
1247 const Mesh *edit_data_mesh = nullptr;
1248 if (is_editmode) {
1249 const Mesh *eval_cage = DRW_object_get_editmesh_cage_for_drawing(ob);
1250 if (eval_cage && eval_cage != &mesh) {
1251 /* Extract "cage" data separately when it exists and it's not just the same mesh as the
1252 * regular evaluated mesh. Otherwise edit data will be extracted from the final evaluated
1253 * mesh. */
1254 do_cage = true;
1255 edit_data_mesh = eval_cage;
1256 }
1257 else {
1258 edit_data_mesh = &mesh;
1259 }
1260 }
1261
1262 bool do_uvcage = false;
1263 if (is_editmode) {
1264 /* Currently we don't extract UV data from the evaluated mesh unless it's the same mesh as the
1265 * original edit mesh. */
1266 do_uvcage = !(mesh.runtime->is_original_bmesh &&
1267 mesh.runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH);
1268 }
1269
1270 const DRWBatchFlag batches_to_create = batch_requested & ~cache.batch_ready;
1271
1272 const bool do_subdivision = BKE_subsurf_modifier_has_gpu_subdiv(&mesh);
1273
1274 enum class BufferList : int8_t { Final, Cage, UVCage };
1275
1276 struct BatchCreateData {
1277 gpu::Batch &batch;
1278 GPUPrimType prim_type;
1279 BufferList list;
1280 std::optional<IBOType> ibo;
1281 Vector<VBOType> vbos;
1282 };
1283 Vector<BatchCreateData> batch_info;
1284
1285 {
1286 const BufferList list = BufferList::Final;
1287 if (batches_to_create & MBC_SURFACE) {
1288 BatchCreateData batch{*cache.batch.surface,
1290 list,
1293 if (!cache.cd_used.uv.is_empty()) {
1294 batch.vbos.append(VBOType::UVs);
1295 }
1296 for (const int i : cache.attr_used.index_range()) {
1297 batch.vbos.append(VBOType(int8_t(VBOType::Attr0) + i));
1298 }
1299 batch_info.append(std::move(batch));
1300 }
1301 if (batches_to_create & MBC_PAINT_OVERLAY_SURFACE) {
1302 BatchCreateData batch{*cache.batch.paint_overlay_surface,
1304 list,
1307 batch_info.append(std::move(batch));
1308 }
1309 if (batches_to_create & MBC_VIEWER_ATTRIBUTE_OVERLAY) {
1310 batch_info.append({*cache.batch.surface_viewer_attribute,
1312 list,
1315 }
1316 if (batches_to_create & MBC_ALL_VERTS) {
1317 batch_info.append(
1318 {*cache.batch.all_verts, GPU_PRIM_POINTS, list, std::nullopt, {VBOType::Position}});
1319 }
1320 if (batches_to_create & MBC_PAINT_OVERLAY_VERTS) {
1321 batch_info.append({*cache.batch.paint_overlay_verts,
1323 list,
1324 std::nullopt,
1326 }
1327 if (batches_to_create & MBC_SCULPT_OVERLAYS) {
1328 batch_info.append({*cache.batch.sculpt_overlays,
1330 list,
1333 }
1334 if (batches_to_create & MBC_ALL_EDGES) {
1335 batch_info.append(
1337 }
1338 if (batches_to_create & MBC_LOOSE_EDGES) {
1339 batch_info.append({*cache.batch.loose_edges,
1341 list,
1344 }
1345 if (batches_to_create & MBC_EDGE_DETECTION) {
1346 batch_info.append({*cache.batch.edge_detection,
1348 list,
1351 }
1352 if (batches_to_create & MBC_SURFACE_WEIGHTS) {
1353 batch_info.append({*cache.batch.surface_weights,
1355 list,
1358 }
1359 if (batches_to_create & MBC_PAINT_OVERLAY_WIRE_LOOPS) {
1360 batch_info.append({*cache.batch.paint_overlay_wire_loops,
1362 list,
1365 }
1366 if (batches_to_create & MBC_WIRE_EDGES) {
1367 batch_info.append({*cache.batch.wire_edges,
1369 list,
1372 }
1373 if (batches_to_create & MBC_WIRE_LOOPS_ALL_UVS) {
1374 BatchCreateData batch{
1376 if (!cache.cd_used.uv.is_empty()) {
1377 batch.vbos.append(VBOType::UVs);
1378 }
1379 batch_info.append(std::move(batch));
1380 }
1381 if (batches_to_create & MBC_WIRE_LOOPS_UVS) {
1382 BatchCreateData batch{
1384 if (!cache.cd_used.uv.is_empty()) {
1385 batch.vbos.append(VBOType::UVs);
1386 }
1387 batch_info.append(std::move(batch));
1388 }
1389 if (batches_to_create & MBC_WIRE_LOOPS_EDITUVS) {
1390 BatchCreateData batch{
1392 if (!cache.cd_used.uv.is_empty()) {
1393 batch.vbos.append(VBOType::UVs);
1394 }
1395 batch_info.append(std::move(batch));
1396 }
1397 if (batches_to_create & MBC_UV_FACES) {
1398 const bool use_face_selection = (mesh.editflag & ME_EDIT_PAINT_FACE_SEL);
1399 /* Sculpt mode does not support selection, therefore the generic `is_paint_mode` check cannot
1400 * be used */
1401 const bool is_face_selectable =
1403 use_face_selection;
1404
1405 const IBOType ibo = is_face_selectable || is_editmode ? IBOType::UVTris : IBOType::Tris;
1406 BatchCreateData batch{*cache.batch.uv_faces, GPU_PRIM_TRIS, list, ibo, {}};
1407 if (!cache.cd_used.uv.is_empty()) {
1408 batch.vbos.append(VBOType::UVs);
1409 }
1410 batch_info.append(std::move(batch));
1411 }
1412 if (batches_to_create & MBC_EDIT_MESH_ANALYSIS) {
1413 batch_info.append({*cache.batch.edit_mesh_analysis,
1415 list,
1418 }
1419 }
1420
1421 /* When the mesh doesn't correspond to the object's original mesh (i.e. the mesh was replaced by
1422 * another with the object info node during evaluation), don't extract edit mode data for it.
1423 * That data can be invalid because any original indices (#CD_ORIGINDEX) on the evaluated mesh
1424 * won't correspond to the correct mesh. */
1425 const bool edit_mapping_valid = is_editmode && BKE_editmesh_eval_orig_map_available(
1426 *edit_data_mesh, orig_edit_mesh);
1427
1428 {
1429 const BufferList list = do_cage ? BufferList::Cage : BufferList::Final;
1430 if (batches_to_create & MBC_EDIT_TRIANGLES) {
1431 if (edit_mapping_valid) {
1432 batch_info.append({*cache.batch.edit_triangles,
1434 list,
1437 }
1438 else {
1440 }
1441 }
1442 if (batches_to_create & MBC_EDIT_VERTICES) {
1443 if (edit_mapping_valid) {
1444 BatchCreateData batch{*cache.batch.edit_vertices,
1446 list,
1449 if (!do_subdivision || do_cage) {
1450 batch.vbos.append(VBOType::CornerNormal);
1451 }
1452 batch_info.append(std::move(batch));
1453 }
1454 else {
1456 }
1457 }
1458 if (batches_to_create & MBC_EDIT_EDGES) {
1459 if (edit_mapping_valid) {
1460 BatchCreateData batch{*cache.batch.edit_edges,
1462 list,
1465 batch_info.append(std::move(batch));
1466 }
1467 else {
1469 }
1470 }
1471 if (batches_to_create & MBC_EDIT_VNOR) {
1472 if (edit_mapping_valid) {
1473 batch_info.append({*cache.batch.edit_vnor,
1475 list,
1478 }
1479 else {
1481 }
1482 }
1483 if (batches_to_create & MBC_EDIT_LNOR) {
1484 if (edit_mapping_valid) {
1485 batch_info.append({*cache.batch.edit_lnor,
1487 list,
1490 }
1491 else {
1493 }
1494 }
1495 if (batches_to_create & MBC_EDIT_FACEDOTS) {
1496 if (edit_mapping_valid) {
1497 batch_info.append({*cache.batch.edit_fdots,
1499 list,
1502 }
1503 else {
1505 }
1506 }
1507 if (batches_to_create & MBC_SKIN_ROOTS) {
1508 if (edit_mapping_valid) {
1509 batch_info.append({*cache.batch.edit_skin_roots,
1511 list,
1512 std::nullopt,
1514 }
1515 else {
1517 }
1518 }
1519 if (batches_to_create & MBC_EDIT_SELECTION_VERTS) {
1520 if (is_editmode && !edit_mapping_valid) {
1522 }
1523 else {
1524 batch_info.append({*cache.batch.edit_selection_verts,
1526 list,
1529 }
1530 }
1531 if (batches_to_create & MBC_EDIT_SELECTION_EDGES) {
1532 if (is_editmode && !edit_mapping_valid) {
1534 }
1535 else {
1536 batch_info.append({*cache.batch.edit_selection_edges,
1538 list,
1541 }
1542 }
1543 if (batches_to_create & MBC_EDIT_SELECTION_FACES) {
1544 if (is_editmode && !edit_mapping_valid) {
1546 }
1547 else {
1548 batch_info.append({*cache.batch.edit_selection_faces,
1550 list,
1553 }
1554 }
1555 if (batches_to_create & MBC_EDIT_SELECTION_FACEDOTS) {
1556 if (is_editmode && !edit_mapping_valid) {
1558 }
1559 else {
1560 batch_info.append({*cache.batch.edit_selection_fdots,
1562 list,
1565 }
1566 }
1567 }
1568
1569 {
1575 const BufferList list = do_uvcage ? BufferList::UVCage : BufferList::Final;
1576
1577 if (batches_to_create & MBC_EDITUV_FACES) {
1578 if (edit_mapping_valid) {
1579 batch_info.append({*cache.batch.edituv_faces,
1581 list,
1584 }
1585 else {
1587 }
1588 }
1589 if (batches_to_create & MBC_EDITUV_FACES_STRETCH_AREA) {
1590 if (edit_mapping_valid) {
1591 batch_info.append({*cache.batch.edituv_faces_stretch_area,
1593 list,
1596 }
1597 else {
1599 }
1600 }
1601 if (batches_to_create & MBC_EDITUV_FACES_STRETCH_ANGLE) {
1602 if (edit_mapping_valid) {
1603 batch_info.append({*cache.batch.edituv_faces_stretch_angle,
1605 list,
1608 }
1609 else {
1611 }
1612 }
1613 if (batches_to_create & MBC_EDITUV_EDGES) {
1614 if (edit_mapping_valid) {
1615 batch_info.append({*cache.batch.edituv_edges,
1617 list,
1620 }
1621 else {
1623 }
1624 }
1625 if (batches_to_create & MBC_EDITUV_VERTS) {
1626 if (edit_mapping_valid) {
1627 batch_info.append({*cache.batch.edituv_verts,
1629 list,
1632 }
1633 else {
1635 }
1636 }
1637 if (batches_to_create & MBC_EDITUV_FACEDOTS) {
1638 if (edit_mapping_valid) {
1639 batch_info.append({*cache.batch.edituv_fdots,
1641 list,
1644 }
1645 else {
1647 }
1648 }
1649 }
1650
1651 std::array<VectorSet<IBOType>, 3> ibo_requests;
1652 std::array<VectorSet<VBOType>, 3> vbo_requests;
1653 for (const BatchCreateData &batch : batch_info) {
1654 if (batch.ibo) {
1655 ibo_requests[int(batch.list)].add(*batch.ibo);
1656 }
1657 vbo_requests[int(batch.list)].add_multiple(batch.vbos);
1658 }
1659
1660 if (batches_to_create & MBC_SURFACE_PER_MAT) {
1661 ibo_requests[int(BufferList::Final)].add(IBOType::Tris);
1662 vbo_requests[int(BufferList::Final)].add(VBOType::CornerNormal);
1663 vbo_requests[int(BufferList::Final)].add(VBOType::Position);
1664 for (const int i : cache.attr_used.index_range()) {
1665 vbo_requests[int(BufferList::Final)].add(VBOType(int8_t(VBOType::Attr0) + i));
1666 }
1667 if (!cache.cd_used.uv.is_empty()) {
1668 vbo_requests[int(BufferList::Final)].add(VBOType::UVs);
1669 }
1670 if (!cache.cd_used.tan.is_empty() || cache.cd_used.tan_orco) {
1671 vbo_requests[int(BufferList::Final)].add(VBOType::Tangents);
1672 }
1673 if (cache.cd_used.orco) {
1674 vbo_requests[int(BufferList::Final)].add(VBOType::Orco);
1675 }
1676 }
1677
1678 if (do_uvcage) {
1680 scene,
1681 cache,
1682 cache.uv_cage,
1683 ibo_requests[int(BufferList::UVCage)],
1684 vbo_requests[int(BufferList::UVCage)],
1685 ob,
1686 mesh,
1687 is_editmode,
1688 is_paint_mode,
1689 false,
1690 true,
1691 true);
1692 }
1693
1694 if (do_cage) {
1696 scene,
1697 cache,
1698 cache.cage,
1699 ibo_requests[int(BufferList::Cage)],
1700 vbo_requests[int(BufferList::Cage)],
1701 ob,
1702 mesh,
1703 is_editmode,
1704 is_paint_mode,
1705 false,
1706 false,
1707 true);
1708 }
1709
1710 if (do_subdivision) {
1712 mesh,
1713 cache,
1714 cache.final,
1715 ibo_requests[int(BufferList::Final)],
1716 vbo_requests[int(BufferList::Final)],
1717 is_editmode,
1718 is_paint_mode,
1719 true,
1720 false,
1721 do_cage,
1722 ts,
1723 use_hide);
1724 }
1725 else {
1726 /* The subsurf modifier may have been recently removed, or another modifier was added after it,
1727 * so free any potential subdivision cache as it is not needed anymore. */
1729 }
1730
1732 scene,
1733 cache,
1734 cache.final,
1735 ibo_requests[int(BufferList::Final)],
1736 vbo_requests[int(BufferList::Final)],
1737 ob,
1738 mesh,
1739 is_editmode,
1740 is_paint_mode,
1741 true,
1742 false,
1743 use_hide);
1744
1745 std::array<MeshBufferCache *, 3> caches{&cache.final, &cache.cage, &cache.uv_cage};
1746 for (const BatchCreateData &batch : batch_info) {
1747 MeshBufferCache &cache_for_batch = *caches[int(batch.list)];
1748 gpu::IndexBuf *ibo = batch.ibo ? caches[int(batch.list)]->buff.ibos.lookup(*batch.ibo).get() :
1749 nullptr;
1750 GPU_batch_init(&batch.batch, batch.prim_type, nullptr, ibo);
1751 for (const VBOType vbo_request : batch.vbos) {
1753 &batch.batch, cache_for_batch.buff.vbos.lookup(vbo_request).get(), false);
1754 }
1755 }
1756
1757 if (batches_to_create & MBC_SURFACE_PER_MAT) {
1758 MeshBufferList &buffers = cache.final.buff;
1759 gpu::IndexBuf &tris_ibo = *buffers.ibos.lookup(IBOType::Tris);
1761 for (const int material : IndexRange(cache.mat_len)) {
1762 gpu::Batch *batch = cache.surface_per_mat[material];
1763 if (!batch) {
1764 continue;
1765 }
1766 GPU_batch_init(batch, GPU_PRIM_TRIS, nullptr, cache.tris_per_mat[material].get());
1767 GPU_batch_vertbuf_add(batch, buffers.vbos.lookup(VBOType::CornerNormal).get(), false);
1768 GPU_batch_vertbuf_add(batch, buffers.vbos.lookup(VBOType::Position).get(), false);
1769 if (!cache.cd_used.uv.is_empty()) {
1770 GPU_batch_vertbuf_add(batch, buffers.vbos.lookup(VBOType::UVs).get(), false);
1771 }
1772 if (!cache.cd_used.tan.is_empty() || cache.cd_used.tan_orco) {
1773 GPU_batch_vertbuf_add(batch, buffers.vbos.lookup(VBOType::Tangents).get(), false);
1774 }
1775 if (cache.cd_used.orco) {
1776 GPU_batch_vertbuf_add(batch, buffers.vbos.lookup(VBOType::Orco).get(), false);
1777 }
1778 for (const int i : cache.attr_used.index_range()) {
1780 batch, buffers.vbos.lookup(VBOType(int8_t(VBOType::Attr0) + i)).get(), false);
1781 }
1782 }
1783 }
1784
1785 cache.batch_ready |= batch_requested;
1786
1787 if (cache.surface_blas_requested && !cache.surface_blas_ready) {
1788 cache.surface_blas->add_geometry(*cache.final.buff.ibos.lookup(IBOType::Tris),
1789 *cache.final.buff.vbos.lookup(VBOType::Position));
1790 cache.surface_blas->build();
1791 cache.surface_blas_ready = true;
1792 }
1793 cache.surface_blas_requested = false;
1794}
1795
1797
1798} // namespace blender::draw
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
A BVH for high poly meshes.
#define ME_USING_MIRROR_X_VERTEX_GROUPS(_me)
Object is a sort of wrapper for general info.
#define GPU_BATCH_CLEAR_SAFE(batch)
Definition GPU_batch.hh:185
#define GPU_batch_init(batch, primitive_type, vertex_buf, index_buf)
Definition GPU_batch.hh:161
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition GPU_batch.hh:199
void GPU_ray_tracing_blas_discard(blender::gpu::BottomLevelAS *blas)
Read Blender memory allocation and freeing.
#define BLI_INLINE
#define ELEM(...)
IndexRange index_range() const
Definition BLI_array.hh:371
const T & first() const
Definition BLI_array.hh:292
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
bool is_empty() const
Definition BLI_array.hh:275
constexpr IndexRange()=default
void reserve(const int64_t n)
Definition BLI_set.hh:656
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr int64_t size() const
Definition BLI_span.hh:256
bool add(const Key &key)
bool add_as(ForwardKey &&key)
IndexRange index_range() const
void append(const T &value)
constexpr bool is_empty() const
virtual void add_geometry(IndexBuf &index_buffer, VertBuf &vertex_buffer)=0
#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc)
#define MBC_BATCH_LEN
#define MBC_EDITUV
Extraction of Mesh data into VBO to feed to GPU.
pbvh::Tree * pbvh_get(Object &object)
void update_normals_from_eval(Object &object_eval, Tree &pbvh)
Definition pbvh.cc:1186
static bool attribute_exists(const Mesh &mesh, const StringRef name)
void DRW_mesh_batch_cache_validate(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(Object &object, Mesh &mesh)
void drw_attributes_add_request(VectorSet< std::string > *attrs, const StringRef name)
static void drw_mesh_weight_state_extract(Object &ob, Mesh &mesh, const ToolSettings &ts, bool paint_mode, DRW_MeshWeightState *wstate)
static void init_empty_dummy_batch(gpu::Batch &batch)
gpu::Batch * DRW_mesh_batch_cache_get_loose_edges(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_edges(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface_texpaint_single(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_edges(Mesh &mesh)
static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_facedots(Object &object, Mesh &mesh)
static bool drw_mesh_flags_equal(const bool *array1, const bool *array2, int size)
gpu::Batch * DRW_mesh_batch_cache_get_facedots_with_select_id(Mesh &mesh)
static void mesh_cd_calc_active_uv_layer(const Object &object, const Mesh &mesh, DRW_MeshCDMask &cd_used)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_wireframe(Object &object, Mesh &mesh)
void DRW_mesh_batch_cache_free(draw::MeshBatchCache *batch_cache)
gpu::Batch * DRW_mesh_batch_cache_get_edit_facedots(Mesh &mesh)
void draw_subdiv_cache_free(DRWSubdivCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_verts(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface(Mesh &mesh)
static void texpaint_request_active_uv(MeshBatchCache &cache, Object &object, Mesh &mesh)
static void mesh_cd_calc_edit_uv_layer(const Mesh &, DRW_MeshCDMask *cd_used)
static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_surface_weights(Mesh &mesh)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_shaded(Object &object, Mesh &mesh, Span< const GPUMaterial * > materials)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces(Object &object, Mesh &mesh)
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)
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_edit_loop_normals(Mesh &mesh)
static bool drw_mesh_weight_state_compare(const DRW_MeshWeightState *a, const DRW_MeshWeightState *b)
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)
static std::optional< bke::AttributeMetaData > lookup_meta_data(const Mesh &mesh, const StringRef name)
gpu::Batch * DRW_mesh_batch_cache_get_edit_triangles(Mesh &mesh)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_vertices(Mesh &mesh)
static void mesh_cd_calc_used_gpu_layers(const Object &object, const Mesh &mesh, const Span< const GPUMaterial * > materials, VectorSet< std::string > *r_attributes, DRW_MeshCDMask *r_cd_used)
static void mesh_batch_cache_init(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_all_uv_wireframe(Object &object, Mesh &mesh)
static void mesh_batch_cache_clear(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_triangles_with_select_id(Mesh &mesh)
static void mesh_buffer_cache_clear(MeshBufferCache *mbc)
static void mesh_batch_cache_discard_uvedit(MeshBatchCache &cache)
static void mesh_batch_cache_check_vertex_group(MeshBatchCache &cache, const DRW_MeshWeightState *wstate)
static void drw_mesh_weight_state_copy(DRW_MeshWeightState *wstate_dst, const DRW_MeshWeightState *wstate_src)
const Mesh & editmesh_final_or_this(const Object &object, const Mesh &mesh)
static void mesh_cd_calc_active_mask_uv_layer(const Object &object, const Mesh &mesh, DRW_MeshCDMask &cd_used)
bool drw_attributes_overlap(const VectorSet< std::string > *a, const VectorSet< std::string > *b)
static void mesh_batch_cache_request_surface_batches(Mesh &mesh, MeshBatchCache &cache)
void DRW_create_subdivision(Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const Span< IBOType > ibo_requests, const Span< VBOType > vbo_requests, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
static void mesh_batch_cache_request_surface_blas(MeshBatchCache &cache)
static void request_active_and_default_color_attributes(const Object &object, const Mesh &mesh, VectorSet< std::string > &attributes)
gpu::Batch * DRW_mesh_batch_cache_get_verts_with_select_id(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_sculpt_overlays(Mesh &mesh)
static void discard_buffers(MeshBatchCache &cache, const Span< VBOType > vbos, const Span< IBOType > ibos)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_surface(Mesh &mesh)
void DRW_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
gpu::Batch * DRW_mesh_batch_cache_get_surface_viewer_attribute(Mesh &mesh)
void DRW_mesh_batch_cache_create_requested(TaskGraph &task_graph, Object &ob, Mesh &mesh, const Scene &scene, bool is_paint_mode, bool use_hide)
BLI_INLINE void mesh_cd_layers_type_merge(DRW_MeshCDMask *a, const DRW_MeshCDMask &b)
void DRW_mesh_get_attributes(const Object &object, const Mesh &mesh, const Span< const GPUMaterial * > materials, VectorSet< std::string > *r_attrs, DRW_MeshCDMask *r_cd_needed)
static void mesh_batch_cache_free_subdiv_cache(MeshBatchCache &cache)
void mesh_buffer_cache_create_requested(TaskGraph &task_graph, const Scene &scene, MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, Object &object, Mesh &mesh, bool is_editmode, bool is_paint_mode, bool do_final, bool do_uvedit, bool use_hide)
gpu::Batch * DRW_mesh_batch_cache_get_edit_vert_normals(Mesh &mesh)
static MeshBatchCache * mesh_batch_cache_get(Mesh &mesh)
static void drw_mesh_weight_state_clear(DRW_MeshWeightState *wstate)
void drw_attributes_merge(VectorSet< std::string > *dst, const VectorSet< std::string > *src)
gpu::Batch * DRW_mesh_batch_cache_get_uv_faces(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edges_with_select_id(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Object &object, Mesh &mesh, float **tot_area, float **tot_uv_area)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_edges(Mesh &mesh)
static void edituv_request_active_uv(MeshBatchCache &cache, Object &object, Mesh &mesh)
static bool mesh_batch_cache_valid(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_all_verts(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_uv_wireframe(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_skin_roots(Mesh &mesh)
gpu::BottomLevelAS * DRW_mesh_batch_cache_get_surface_blas(Mesh &mesh)
void create_material_subranges(const SortedFaceData &face_sorted, gpu::IndexBuf &tris_ibo, MutableSpan< gpu::IndexBufPtr > ibos)
UserDef U
Definition blender.cc:58
const Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
Definition object.cc:4444
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
bool BKE_subsurf_modifier_has_gpu_subdiv(const Mesh *mesh)
void BKE_object_defgroup_mirror_selection(struct Object *ob, int defbase_tot, const bool *selection, bool *dg_flags_sel, int *r_dg_flags_sel_tot)
bool * BKE_object_defgroup_validmap_get(struct Object *ob, int defbase_tot)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition object.cc:4477
void DRW_blas_request(gpu::BottomLevelAS **blas)
@ GPU_PRIM_LINES_ADJ
void BKE_object_defgroup_split_locked_validmap(int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
int BKE_id_material_used_with_fallback_eval(const ID &id)
bool * BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
@ ME_EDIT_PAINT_FACE_SEL
@ OB_MODE_TEXTURE_PAINT
ListBaseT< GPUMaterialAttribute > GPU_material_attributes(const GPUMaterial *material)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
BMDataLayerLookup BM_data_layer_lookup(const BMesh &bm, const StringRef name)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
bool BKE_editmesh_eval_orig_map_available(const Mesh &mesh_eval, const Mesh *mesh_orig)
Definition editmesh.cc:93
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
bool * BKE_object_defgroup_lock_flags_get(struct Object *ob, int defbase_tot)
bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot, const bool *lock_flags, const bool *selected, int sel_tot)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
const Mesh * DRW_object_get_editmesh_cage_for_drawing(const Object &object)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
@ ME_WRAPPER_TYPE_BMESH
bool BKE_object_defgroup_check_lock_relative(const bool *lock_flags, const bool *validmap, int index)
eMeshBatchDirtyMode
Definition BKE_mesh.h:47
@ BKE_MESH_BATCH_DIRTY_UVEDIT_ALL
Definition BKE_mesh.h:52
@ BKE_MESH_BATCH_DIRTY_UVEDIT_SELECT
Definition BKE_mesh.h:53
@ BKE_MESH_BATCH_DIRTY_ALL
Definition BKE_mesh.h:48
@ BKE_MESH_BATCH_DIRTY_SHADING
Definition BKE_mesh.h:51
@ BKE_MESH_BATCH_DIRTY_SELECT
Definition BKE_mesh.h:49
@ BKE_MESH_BATCH_DIRTY_SELECT_PAINT
Definition BKE_mesh.h:50
void GPU_vertbuf_data_len_set(gpu::VertBuf &verts, uint v_len)
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
signed char int8_t
Definition BKE_text.h:76
char * stencil_uv_map_attribute
char * active_color_attribute
char * default_color_attribute
CustomData vert_data
struct ToolSettings * toolsettings
eTool_WeightUser weightuser
VectorSet< std::string > tan
VectorSet< std::string > uv
VectorSet< std::string > attr_used_over_time
Array< gpu::IndexBufPtr > tris_per_mat
VectorSet< std::string > attr_used
Array< gpu::Batch * > surface_per_mat
VectorSet< std::string > attr_needed
Map< IBOType, std::unique_ptr< gpu::IndexBuf, gpu::IndexBufDeleter > > ibos
Map< VBOType, std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > > vbos