Blender V4.3
overlay_sculpt.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "DRW_render.hh"
10
11#include "draw_cache_impl.hh"
12#include "overlay_private.hh"
13
14#include "BKE_attribute.hh"
15#include "BKE_mesh.hh"
16#include "BKE_paint.hh"
17#include "BKE_pbvh_api.hh"
18#include "BKE_subdiv_ccg.hh"
19
21
37
39{
40 using namespace blender::draw;
41 OVERLAY_PrivateData *pd = vedata->stl->pd;
42 const DRWContextState *draw_ctx = DRW_context_state_get();
43 blender::gpu::Batch *sculpt_overlays;
44 const SculptSession &ss = *ob->sculpt;
46
47 const bool use_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->rv3d);
48
49 if (!pbvh) {
50 /* It is possible to have SculptSession without pbvh::Tree. This happens, for example, when
51 * toggling object mode to sculpt then to edit mode. */
52 return;
53 }
54
55 /* Using the original object/geometry is necessary because we skip depsgraph updates in sculpt
56 * mode to improve performance. This means the evaluated mesh doesn't have the latest face set,
57 * visibility, and mask data. */
58 Object *object_orig = reinterpret_cast<Object *>(DEG_get_original_id(&ob->id));
59 if (!object_orig) {
61 return;
62 }
63
64 switch (pbvh->type()) {
66 const Mesh &mesh = *static_cast<const Mesh *>(object_orig->data);
67 if (!mesh.attributes().contains(".sculpt_face_set") &&
68 !mesh.attributes().contains(".sculpt_mask"))
69 {
70 return;
71 }
72 break;
73 }
75 const SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
76 const Mesh &base_mesh = *static_cast<const Mesh *>(object_orig->data);
77 if (subdiv_ccg.masks.is_empty() && !base_mesh.attributes().contains(".sculpt_face_set")) {
78 return;
79 }
80 break;
81 }
83 const BMesh &bm = *ss.bm;
84 if (!CustomData_has_layer_named(&bm.pdata, CD_PROP_FLOAT, ".sculpt_face_set") &&
86 {
87 return;
88 }
89 break;
90 }
91 }
92
93 if (use_pbvh) {
94 DRW_shgroup_call_sculpt(pd->sculpt_mask_grp, ob, false, true, true, false, false);
95 }
96 else {
97 sculpt_overlays = DRW_mesh_batch_cache_get_sculpt_overlays(*static_cast<Mesh *>(ob->data));
98 if (sculpt_overlays) {
99 DRW_shgroup_call(pd->sculpt_mask_grp, sculpt_overlays, ob);
100 }
101 }
102}
103
105{
106 OVERLAY_PassList *psl = vedata->psl;
107 OVERLAY_PrivateData *pd = vedata->stl->pd;
109
110 if (DRW_state_is_fbo()) {
112 }
113
115}
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, blender::StringRef name)
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2862
A BVH for high poly meshes.
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
ID * DEG_get_original_id(ID *id)
@ CD_PROP_FLOAT
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_call(shgroup, geom, ob)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
struct GPUShader GPUShader
ATTR_WARN_UNUSED_RESULT BMesh * bm
AttributeSet attributes
bool is_empty() const
Definition BLI_array.hh:253
DefaultFramebufferList * DRW_viewport_framebuffer_list_get()
const DRWContextState * DRW_context_state_get()
bool DRW_state_is_fbo()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup, Object *ob, bool use_wire, bool use_mask, bool use_fset, bool use_color, bool use_uv)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
@ DRW_STATE_BLEND_MUL
Definition draw_state.hh:60
static ulong state[N]
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:2846
GPUShader * OVERLAY_shader_sculpt_mask()
void OVERLAY_sculpt_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_sculpt_draw(OVERLAY_Data *vedata)
void OVERLAY_sculpt_cache_init(OVERLAY_Data *vedata)
CustomData vdata
CustomData pdata
RegionView3D * rv3d
GPUFrameBuffer * in_front_fb
GPUFrameBuffer * default_fb
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
struct OVERLAY_PrivateData::@235 painting
DRWShadingGroup * sculpt_mask_grp
OVERLAY_PrivateData * pd
struct SculptSession * sculpt
SubdivCCG * subdiv_ccg
Definition BKE_paint.hh:405
blender::Array< float > masks
float sculpt_mode_mask_opacity
float sculpt_mode_face_sets_opacity