Blender V4.3
overlay_viewer_attribute.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
9#include "DRW_render.hh"
10
11#include "DNA_mesh_types.h"
13
14#include "BLI_math_vector.hh"
15#include "BLI_span.hh"
16
17#include "GPU_batch.hh"
18
19#include "BKE_attribute.hh"
20#include "BKE_curves.hh"
21#include "BKE_customdata.hh"
22#include "BKE_duplilist.hh"
23#include "BKE_geometry_set.hh"
24
25#include "draw_cache_extract.hh"
26#include "draw_cache_impl.hh"
27#include "overlay_private.hh"
28
52
55 const DupliObject &dupli_object,
56 const float opacity)
57{
58 using namespace blender;
59 using namespace blender::bke;
60 using namespace blender::draw;
61
62 const GeometrySet &base_geometry = *dupli_object.preview_base_geometry;
63 const InstancesComponent &instances = *base_geometry.get_component<InstancesComponent>();
64 const AttributeAccessor instance_attributes = *instances.attributes();
65 const VArray attribute = *instance_attributes.lookup<ColorGeometry4f>(".viewer");
66 if (!attribute) {
67 return;
68 }
69 ColorGeometry4f color = attribute.get(dupli_object.preview_instance_index);
70 color.a *= opacity;
71 switch (object.type) {
72 case OB_MESH: {
73 {
75 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
76 blender::gpu::Batch *batch = DRW_cache_mesh_surface_get(&object);
77 DRW_shgroup_call(sub_grp, batch, &object);
78 }
79 if (blender::gpu::Batch *batch = DRW_cache_mesh_loose_edges_get(&object)) {
81 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
82 DRW_shgroup_call(sub_grp, batch, &object);
83 }
84 break;
85 }
86 case OB_POINTCLOUD: {
87 DRWShadingGroup *sub_grp = DRW_shgroup_pointcloud_create_sub(
88 &object, pd.viewer_attribute_pointcloud_grp, nullptr);
89 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
90 break;
91 }
92 case OB_CURVES_LEGACY: {
94 DRW_shgroup_uniform_vec4_copy(sub_grp, "ucolor", color);
95 blender::gpu::Batch *batch = DRW_cache_curve_edge_wire_get(&object);
96 DRW_shgroup_call_obmat(sub_grp, batch, object.object_to_world().ptr());
97 break;
98 }
99 case OB_CURVES: {
100 /* Not supported yet because instances of this type are currently drawn as legacy curves.
101 */
102 break;
103 }
104 }
105}
106
112
115 const float opacity)
116{
117 using namespace blender;
118 using namespace blender::bke;
119 using namespace blender::draw;
120
121 switch (object.type) {
122 case OB_MESH: {
123 Mesh *mesh = static_cast<Mesh *>(object.data);
124 if (const std::optional<bke::AttributeMetaData> meta_data =
125 mesh->attributes().lookup_meta_data(".viewer"))
126 {
127 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
128 blender::gpu::Batch *batch = DRW_cache_mesh_surface_viewer_attribute_get(&object);
131 }
132 }
133 break;
134 }
135 case OB_POINTCLOUD: {
136 PointCloud *pointcloud = static_cast<PointCloud *>(object.data);
137 if (const std::optional<bke::AttributeMetaData> meta_data =
138 pointcloud->attributes().lookup_meta_data(".viewer"))
139 {
140 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
141 gpu::VertBuf **vertbuf = DRW_pointcloud_evaluated_attribute(pointcloud, ".viewer");
142 DRWShadingGroup *grp = DRW_shgroup_pointcloud_create_sub(
143 &object, pd.viewer_attribute_pointcloud_grp, nullptr);
144 DRW_shgroup_uniform_float_copy(grp, "opacity", opacity);
145 DRW_shgroup_buffer_texture_ref(grp, "attribute_tx", vertbuf);
146 }
147 }
148 break;
149 }
150 case OB_CURVES_LEGACY: {
151 Curve *curve = static_cast<Curve *>(object.data);
152 if (curve->curve_eval) {
153 const bke::CurvesGeometry &curves = curve->curve_eval->geometry.wrap();
154 if (const std::optional<bke::AttributeMetaData> meta_data =
155 curves.attributes().lookup_meta_data(".viewer"))
156 {
157 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
158 blender::gpu::Batch *batch = DRW_cache_curve_edge_wire_viewer_attribute_get(&object);
161 pd.viewer_attribute_curve_grp, batch, object.object_to_world().ptr());
162 }
163 }
164 }
165 break;
166 }
167 case OB_CURVES: {
168 Curves *curves_id = static_cast<Curves *>(object.data);
169 const bke::CurvesGeometry &curves = curves_id->geometry.wrap();
170 if (const std::optional<bke::AttributeMetaData> meta_data =
171 curves.attributes().lookup_meta_data(".viewer"))
172 {
173 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
174 bool is_point_domain;
175 gpu::VertBuf **texture = DRW_curves_texture_for_evaluated_attribute(
176 curves_id, ".viewer", &is_point_domain);
177 DRWShadingGroup *grp = DRW_shgroup_curves_create_sub(
178 &object, pd.viewer_attribute_curves_grp, nullptr);
180 DRW_shgroup_uniform_bool_copy(grp, "is_point_domain", is_point_domain);
181 DRW_shgroup_buffer_texture(grp, "color_tx", *texture);
182 }
183 }
184 break;
185 }
186 }
187}
188
190{
191 OVERLAY_PrivateData *pd = vedata->stl->pd;
192 const float opacity = vedata->stl->pd->overlay.viewer_attribute_opacity;
193 DupliObject *dupli_object = DRW_object_get_dupli(object);
194
195 if (dupli_object->preview_instance_index >= 0) {
196 const auto &instances =
198 if (const std::optional<blender::bke::AttributeMetaData> meta_data =
199 instances.attributes()->lookup_meta_data(".viewer"))
200 {
201 if (attribute_type_supports_viewer_overlay(meta_data->data_type)) {
202 populate_cache_for_instance(*object, *pd, *dupli_object, opacity);
203 return;
204 }
205 }
206 }
207 populate_cache_for_geometry(*object, *pd, opacity);
208}
209
211{
212 OVERLAY_PassList *psl = vedata->psl;
214}
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
#define CD_TYPE_AS_MASK(_type)
#define CD_MASK_PROP_ALL
#define CD_MASK_PROP_QUATERNION
#define CD_MASK_PROP_FLOAT4X4
@ OB_MESH
@ OB_POINTCLOUD
@ OB_CURVES_LEGACY
@ OB_CURVES
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_call_obmat(shgroup, geom, obmat)
#define DRW_shgroup_call(shgroup, geom, ob)
struct GPUShader GPUShader
AttributeSet attributes
ChannelStorageType a
Definition BLI_color.hh:88
blender::gpu::Batch * DRW_cache_curve_edge_wire_viewer_attribute_get(Object *ob)
blender::gpu::Batch * DRW_cache_curve_edge_wire_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_loose_edges_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_viewer_attribute_get(Object *ob)
DupliObject * DRW_object_get_dupli(const Object *)
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_buffer_texture(DRWShadingGroup *shgroup, const char *name, blender::gpu::VertBuf *vertex_buffer)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
void DRW_shgroup_buffer_texture_ref(DRWShadingGroup *shgroup, const char *name, blender::gpu::VertBuf **vertex_buffer)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
struct @620::@622 batch
static ulong state[N]
GPUShader * OVERLAY_shader_uniform_color()
GPUShader * OVERLAY_shader_uniform_color_pointcloud()
GPUShader * OVERLAY_shader_viewer_attribute_curve()
GPUShader * OVERLAY_shader_viewer_attribute_pointcloud()
GPUShader * OVERLAY_shader_viewer_attribute_curves()
GPUShader * OVERLAY_shader_viewer_attribute_mesh()
static bool attribute_type_supports_viewer_overlay(const eCustomDataType data_type)
static void populate_cache_for_geometry(Object &object, OVERLAY_PrivateData &pd, const float opacity)
void OVERLAY_viewer_attribute_draw(OVERLAY_Data *vedata)
void OVERLAY_viewer_attribute_cache_populate(OVERLAY_Data *vedata, Object *object)
static void populate_cache_for_instance(Object &object, OVERLAY_PrivateData &pd, const DupliObject &dupli_object, const float opacity)
void OVERLAY_viewer_attribute_cache_init(OVERLAY_Data *vedata)
CurvesGeometry geometry
const blender::bke::GeometrySet * preview_base_geometry
int preview_instance_index
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
DRWShadingGroup * viewer_attribute_instance_grp
DRWShadingGroup * viewer_attribute_pointcloud_grp
DRWShadingGroup * viewer_attribute_curve_grp
DRWShadingGroup * viewer_attribute_instance_pointcloud_grp
DRWShadingGroup * viewer_attribute_mesh_grp
DRWShadingGroup * viewer_attribute_curves_grp
OVERLAY_PrivateData * pd
float viewer_attribute_opacity
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
PointerRNA * ptr
Definition wm_files.cc:4126