Blender V4.5
overlay_instance.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 "BKE_colorband.hh"
11
12#include "ED_view3d.hh"
13
14#include "BKE_paint.hh"
15
16#include "draw_debug.hh"
17#include "overlay_instance.hh"
18
19namespace blender::draw::overlay {
20
22{
23 /* TODO(fclem): Remove DRW global usage. */
24 const DRWContext *ctx = DRW_context_get();
25 /* Was needed by `object_wire_theme_id()` when doing the port. Not sure if needed nowadays. */
27
28 clipping_enabled_ = RV3D_CLIPPING_ENABLED(ctx->v3d, ctx->rv3d);
29
30 resources.init(clipping_enabled_);
31
32 state.depsgraph = ctx->depsgraph;
33 state.view_layer = ctx->view_layer;
34 state.space_data = ctx->space_data;
35 state.scene = ctx->scene;
36 state.v3d = ctx->v3d;
37 state.region = ctx->region;
38 state.rv3d = ctx->rv3d;
40 state.object_mode = ctx->object_mode;
41 state.cfra = DEG_get_ctime(state.depsgraph);
42 state.is_viewport_image_render = ctx->is_viewport_image_render();
43 state.is_image_render = ctx->is_image_render();
44 state.is_depth_only_drawing = ctx->is_depth();
45 state.skip_particles = ctx->mode == DRWContext::DEPTH_ACTIVE_OBJECT;
46 state.is_material_select = ctx->is_material_select();
47 state.draw_background = ctx->options.draw_background;
48 state.show_text = ctx->options.draw_text;
49
50 /* Note there might be less than 6 planes, but we always compute the 6 of them for simplicity. */
51 state.clipping_plane_count = clipping_enabled_ ? 6 : 0;
52
53 state.ctx_mode = CTX_data_mode_enum_ex(ctx->object_edit, ctx->obact, ctx->object_mode);
54 state.space_data = ctx->space_data;
55 state.space_type = state.v3d != nullptr ? SPACE_VIEW3D : eSpace_Type(ctx->space_data->spacetype);
56 if (state.v3d != nullptr) {
57 state.clear_in_front = (state.v3d->shading.type != OB_SOLID);
58 /* TODO(pragma37): Check with @fclem if this was intentional. */
59 // state.use_in_front = (state.v3d->shading.type <= OB_SOLID) ||
60 // BKE_scene_uses_blender_workbench(state.scene);
61 state.use_in_front = true;
62 state.is_wireframe_mode = (state.v3d->shading.type == OB_WIRE);
63 state.hide_overlays = (state.v3d->flag2 & V3D_HIDE_OVERLAYS) != 0;
64 state.xray_enabled = XRAY_ACTIVE(state.v3d) && !state.is_depth_only_drawing;
65 state.xray_enabled_and_not_wire = state.xray_enabled && (state.v3d->shading.type > OB_WIRE);
66 state.xray_opacity = state.xray_enabled ? XRAY_ALPHA(state.v3d) : 1.0f;
67 state.xray_flag_enabled = SHADING_XRAY_FLAG_ENABLED(state.v3d->shading) &&
68 !state.is_depth_only_drawing;
69
70 const bool viewport_uses_workbench = state.v3d->shading.type <= OB_SOLID ||
72 const bool viewport_uses_eevee = STREQ(
73 ED_view3d_engine_type(state.scene, state.v3d->shading.type)->idname,
75 const bool use_resolution_scaling = BKE_render_preview_pixel_size(&state.scene->r) != 1;
76 /* Only workbench ensures the depth buffer is matching overlays.
77 * Force depth prepass for other render engines.
78 * EEVEE is an exception (if not using mixed resolution) to avoid a significant overhead. */
79 state.is_render_depth_available = viewport_uses_workbench ||
80 (viewport_uses_eevee && !use_resolution_scaling);
81
82 /* For depth only drawing, no other render engine is expected. Except for Grease Pencil which
83 * outputs valid depth. Otherwise depth is cleared and is valid. */
84 state.is_render_depth_available |= state.is_depth_only_drawing;
85
86 if (!state.hide_overlays) {
87 state.overlay = state.v3d->overlay;
88 state.v3d_flag = state.v3d->flag;
89 state.v3d_gridflag = state.v3d->gridflag;
90 }
91 else {
92 memset(&state.overlay, 0, sizeof(state.overlay));
93 state.v3d_flag = 0;
94 state.v3d_gridflag = 0;
98 state.overlay.wireframe_threshold = state.v3d->overlay.wireframe_threshold;
99 state.overlay.wireframe_opacity = state.v3d->overlay.wireframe_opacity;
100 }
101
102 state.do_pose_xray = state.show_bone_selection();
103 state.do_pose_fade_geom = state.do_pose_xray && !(state.object_mode & OB_MODE_WEIGHT_PAINT) &&
104 ctx->object_pose != nullptr;
105 }
106 else if (state.is_space_image()) {
107 SpaceImage *space_image = (SpaceImage *)state.space_data;
108
109 state.clear_in_front = false;
110 state.use_in_front = false;
111 state.is_wireframe_mode = false;
112 state.hide_overlays = (space_image->overlay.flag & SI_OVERLAY_SHOW_OVERLAYS) == 0;
113 state.xray_enabled = false;
114 /* Avoid triggering the depth prepass. */
115 state.is_render_depth_available = true;
116
117 /* During engine initialization phase the `space_image` isn't locked and we are able to
118 * retrieve the needed data. During cache_init the image engine locks the `space_image` and
119 * makes it impossible to retrieve the data. */
120 state.is_image_valid = bool(space_image->image);
121 ED_space_image_get_uv_aspect(space_image, &state.image_uv_aspect.x, &state.image_uv_aspect.y);
122 ED_space_image_get_size(space_image, &state.image_size.x, &state.image_size.y);
123 ED_space_image_get_aspect(space_image, &state.image_aspect.x, &state.image_aspect.y);
124 }
125
126 resources.update_theme_settings(ctx, state);
127 resources.update_clip_planes(state);
128
129 ensure_weight_ramp_texture();
130
131 {
133 if (resources.dummy_depth_tx.ensure_2d(GPU_DEPTH_COMPONENT32F, int2(1, 1), usage)) {
134 float data = 1.0f;
135 GPU_texture_update_sub(resources.dummy_depth_tx, GPU_DATA_FLOAT, &data, 0, 0, 0, 1, 1, 1);
136 }
137 }
138}
139
140void Instance::ensure_weight_ramp_texture()
141{
142 /* Weight Painting color ramp texture */
143 bool user_weight_ramp = (U.flag & USER_CUSTOM_RANGE) != 0;
144
145 auto is_equal = [](const ColorBand &a, const ColorBand &b) {
146 if (a.tot != b.tot || a.cur != b.cur || a.ipotype != b.ipotype ||
147 a.ipotype_hue != b.ipotype_hue || a.color_mode != b.color_mode)
148 {
149 return false;
150 }
151
152 auto is_equal_cbd = [](const CBData &a, const CBData &b) {
153 return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a && a.pos == b.pos &&
154 a.cur == b.cur;
155 };
156
157 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
158 if (!is_equal_cbd(a.data[i], b.data[i])) {
159 return false;
160 }
161 }
162 return true;
163 };
164
165 if (assign_if_different(resources.weight_ramp_custom, user_weight_ramp)) {
166 resources.weight_ramp_tx.free();
167 }
168
169 if (user_weight_ramp && !is_equal(resources.weight_ramp_copy, U.coba_weight)) {
170 resources.weight_ramp_copy = U.coba_weight;
171 resources.weight_ramp_tx.free();
172 }
173
174 if (resources.weight_ramp_tx.is_valid()) {
175 /* Only recreate on updates. */
176 return;
177 }
178
179 auto evaluate_weight_to_color = [&](const float weight, float result[4]) {
180 if (user_weight_ramp) {
181 BKE_colorband_evaluate(&U.coba_weight, weight, result);
182 }
183 else {
184 /* Use gamma correction to even out the color bands:
185 * increasing widens yellow/cyan vs red/green/blue.
186 * Gamma 1.0 produces the original 2.79 color ramp. */
187 const float gamma = 1.5f;
188 const float hsv[3] = {
189 (2.0f / 3.0f) * (1.0f - weight), 1.0f, pow(0.5f + 0.5f * weight, gamma)};
190
191 hsv_to_rgb_v(hsv, result);
192
193 for (int i = 0; i < 3; i++) {
194 result[i] = pow(result[i], 1.0f / gamma);
195 }
196 }
197 };
198
199 constexpr int res = 256;
200
201 float pixels[res][4];
202 for (int i = 0; i < res; i++) {
203 evaluate_weight_to_color(i / 255.0f, pixels[i]);
204 pixels[i][3] = 1.0f;
205 }
206
207 uchar4 pixels_ubyte[res];
208 for (int i = 0; i < res; i++) {
209 unit_float_to_uchar_clamp_v4(pixels_ubyte[i], pixels[i]);
210 }
211
212 resources.weight_ramp_tx.ensure_1d(GPU_SRGB8_A8, res, GPU_TEXTURE_USAGE_SHADER_READ);
213 GPU_texture_update(resources.weight_ramp_tx, GPU_DATA_UBYTE, pixels_ubyte);
214}
215
217{
218 if (!state.is_space_v3d() || state.clipping_plane_count == 0) {
219 /* Unused, do not care about content but still fulfill the bindings. */
220 clip_planes_buf.push_update();
221 return;
222 }
223
224 for (int i : IndexRange(6)) {
226 }
227
228 int plane_len = (RV3D_LOCK_FLAGS(state.rv3d) & RV3D_BOXCLIP) ? 4 : 6;
229 for (int i : IndexRange(plane_len)) {
230 clip_planes_buf[i] = float4(state.rv3d->clip[i]);
231 }
232
233 clip_planes_buf.push_update();
234}
235
237{
238 using namespace math;
239 UniformData &gb = theme;
240
241 auto rgba_uchar_to_float = [](uchar r, uchar g, uchar b, uchar a) {
242 return float4(r, g, b, a) / 255.0f;
243 };
244
245 UI_GetThemeColor4fv(TH_WIRE, gb.colors.wire);
246 UI_GetThemeColor4fv(TH_WIRE_EDIT, gb.colors.wire_edit);
247 UI_GetThemeColor4fv(TH_ACTIVE, gb.colors.active_object);
248 UI_GetThemeColor4fv(TH_SELECT, gb.colors.object_select);
249 gb.colors.library_select = rgba_uchar_to_float(0x88, 0xFF, 0xFF, 155);
250 gb.colors.library = rgba_uchar_to_float(0x55, 0xCC, 0xCC, 155);
251 UI_GetThemeColor4fv(TH_TRANSFORM, gb.colors.transform);
252 UI_GetThemeColor4fv(TH_LIGHT, gb.colors.light);
253 UI_GetThemeColor4fv(TH_SPEAKER, gb.colors.speaker);
255 UI_GetThemeColor4fv(TH_CAMERA_PATH, gb.colors.camera_path);
256 UI_GetThemeColor4fv(TH_EMPTY, gb.colors.empty);
257 UI_GetThemeColor4fv(TH_VERTEX, gb.colors.vert);
258 UI_GetThemeColor4fv(TH_VERTEX_SELECT, gb.colors.vert_select);
259 UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, gb.colors.vert_unreferenced);
260 gb.colors.vert_missing_data = rgba_uchar_to_float(0xB0, 0x00, 0xB0, 0xFF);
261 UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, gb.colors.edit_mesh_active);
262 UI_GetThemeColor4fv(TH_EDGE_SELECT, gb.colors.edge_select);
263 UI_GetThemeColor4fv(TH_EDGE_MODE_SELECT, gb.colors.edge_mode_select);
264 UI_GetThemeColor4fv(TH_GP_VERTEX, gb.colors.gpencil_vertex);
265 UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, gb.colors.gpencil_vertex_select);
266
267 UI_GetThemeColor4fv(TH_EDGE_SEAM, gb.colors.edge_seam);
268 UI_GetThemeColor4fv(TH_EDGE_SHARP, gb.colors.edge_sharp);
269 UI_GetThemeColor4fv(TH_EDGE_CREASE, gb.colors.edge_crease);
270 UI_GetThemeColor4fv(TH_EDGE_BEVEL, gb.colors.edge_bweight);
271 UI_GetThemeColor4fv(TH_EDGE_FACESEL, gb.colors.edge_face_select);
272 UI_GetThemeColor4fv(TH_FACE, gb.colors.face);
273 UI_GetThemeColor4fv(TH_FACE_SELECT, gb.colors.face_select);
274 UI_GetThemeColor4fv(TH_FACE_MODE_SELECT, gb.colors.face_mode_select);
275 UI_GetThemeColor4fv(TH_FACE_RETOPOLOGY, gb.colors.face_retopology);
276 UI_GetThemeColor4fv(TH_FACE_BACK, gb.colors.face_back);
277 UI_GetThemeColor4fv(TH_FACE_FRONT, gb.colors.face_front);
278 UI_GetThemeColor4fv(TH_NORMAL, gb.colors.normal);
279 UI_GetThemeColor4fv(TH_VNORMAL, gb.colors.vnormal);
280 UI_GetThemeColor4fv(TH_LNORMAL, gb.colors.lnormal);
281 UI_GetThemeColor4fv(TH_FACE_DOT, gb.colors.facedot);
282 UI_GetThemeColor4fv(TH_SKIN_ROOT, gb.colors.skinroot);
283 UI_GetThemeColor4fv(TH_BACK, gb.colors.background);
284 UI_GetThemeColor4fv(TH_BACK_GRAD, gb.colors.background_gradient);
285 UI_GetThemeColor4fv(TH_TRANSPARENT_CHECKER_PRIMARY, gb.colors.checker_primary);
286 UI_GetThemeColor4fv(TH_TRANSPARENT_CHECKER_SECONDARY, gb.colors.checker_secondary);
288 gb.fresnel_mix_edit = ((U.gpu_flag & USER_GPU_FLAG_FRESNEL_EDIT) == 0) ? 0.0f : 1.0f;
289 UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, gb.colors.clipping_border);
290
291 /* Custom median color to slightly affect the edit mesh colors. */
292 gb.colors.edit_mesh_middle = interpolate(gb.colors.vert_select, gb.colors.wire_edit, 0.35f);
293 /* Desaturate. */
294 gb.colors.edit_mesh_middle = float4(
295 float3(dot(gb.colors.edit_mesh_middle.xyz(), float3(0.3333f))),
296 gb.colors.edit_mesh_middle.w);
297
298#ifdef WITH_FREESTYLE
299 UI_GetThemeColor4fv(TH_FREESTYLE_EDGE_MARK, gb.colors.edge_freestyle);
300 UI_GetThemeColor4fv(TH_FREESTYLE_FACE_MARK, gb.colors.face_freestyle);
301#else
302 gb.colors.edge_freestyle = float4(0.0f);
303 gb.colors.face_freestyle = float4(0.0f);
304#endif
305
306 UI_GetThemeColor4fv(TH_TEXT, gb.colors.text);
307 UI_GetThemeColor4fv(TH_TEXT_HI, gb.colors.text_hi);
308
309 /* Bone colors */
310 UI_GetThemeColor4fv(TH_BONE_POSE, gb.colors.bone_pose);
311 UI_GetThemeColor4fv(TH_BONE_POSE_ACTIVE, gb.colors.bone_pose_active);
312 UI_GetThemeColorShade4fv(TH_EDGE_SELECT, 60, gb.colors.bone_active);
313 UI_GetThemeColorShade4fv(TH_EDGE_SELECT, -20, gb.colors.bone_select);
314 UI_GetThemeColorBlendShade4fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, gb.colors.bone_pose_active_unsel);
316 TH_WIRE_EDIT, TH_EDGE_SELECT, 0.15f, 0, gb.colors.bone_active_unsel);
317 gb.colors.bone_pose_no_target = rgba_uchar_to_float(255, 150, 0, 80);
318 gb.colors.bone_pose_ik = rgba_uchar_to_float(255, 255, 0, 80);
319 gb.colors.bone_pose_spline_ik = rgba_uchar_to_float(200, 255, 0, 80);
320 gb.colors.bone_pose_constraint = rgba_uchar_to_float(0, 255, 120, 80);
321 UI_GetThemeColor4fv(TH_BONE_SOLID, gb.colors.bone_solid);
322 UI_GetThemeColor4fv(TH_BONE_LOCKED_WEIGHT, gb.colors.bone_locked);
323 gb.colors.bone_ik_line = float4(0.8f, 0.8f, 0.0f, 1.0f);
324 gb.colors.bone_ik_line_no_target = float4(0.8f, 0.5f, 0.2f, 1.0f);
325 gb.colors.bone_ik_line_spline = float4(0.8f, 0.8f, 0.2f, 1.0f);
326
327 /* Curve */
328 UI_GetThemeColor4fv(TH_HANDLE_FREE, gb.colors.handle_free);
329 UI_GetThemeColor4fv(TH_HANDLE_AUTO, gb.colors.handle_auto);
330 UI_GetThemeColor4fv(TH_HANDLE_VECT, gb.colors.handle_vect);
331 UI_GetThemeColor4fv(TH_HANDLE_ALIGN, gb.colors.handle_align);
332 UI_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, gb.colors.handle_autoclamp);
333 UI_GetThemeColor4fv(TH_HANDLE_SEL_FREE, gb.colors.handle_sel_free);
334 UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, gb.colors.handle_sel_auto);
335 UI_GetThemeColor4fv(TH_HANDLE_SEL_VECT, gb.colors.handle_sel_vect);
336 UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, gb.colors.handle_sel_align);
337 UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, gb.colors.handle_sel_autoclamp);
338 UI_GetThemeColor4fv(TH_NURB_ULINE, gb.colors.nurb_uline);
339 UI_GetThemeColor4fv(TH_NURB_VLINE, gb.colors.nurb_vline);
340 UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, gb.colors.nurb_sel_uline);
341 UI_GetThemeColor4fv(TH_NURB_SEL_VLINE, gb.colors.nurb_sel_vline);
342 UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, gb.colors.active_spline);
343
344 UI_GetThemeColor4fv(TH_CFRAME, gb.colors.current_frame);
345 UI_GetThemeColor4fv(TH_FRAME_BEFORE, gb.colors.before_frame);
346 UI_GetThemeColor4fv(TH_FRAME_AFTER, gb.colors.after_frame);
347
348 /* Meta-ball. */
349 gb.colors.mball_radius = rgba_uchar_to_float(0xA0, 0x30, 0x30, 0xFF);
350 gb.colors.mball_radius_select = rgba_uchar_to_float(0xF0, 0xA0, 0xA0, 0xFF);
351 gb.colors.mball_stiffness = rgba_uchar_to_float(0x30, 0xA0, 0x30, 0xFF);
352 gb.colors.mball_stiffness_select = rgba_uchar_to_float(0xA0, 0xF0, 0xA0, 0xFF);
353
354 /* Grid */
355 UI_GetThemeColorShade4fv(TH_GRID, 10, gb.colors.grid);
356 /* Emphasize division lines lighter instead of darker, if background is darker than grid. */
357 const bool is_bg_darker = reduce_add(gb.colors.grid.xyz()) + 0.12f >
358 reduce_add(gb.colors.background.xyz());
359 UI_GetThemeColorShade4fv(TH_GRID, (is_bg_darker) ? 20 : -10, gb.colors.grid_emphasis);
360 /* Grid Axis */
361 UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, gb.colors.grid_axis_x);
362 UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, gb.colors.grid_axis_y);
363 UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, gb.colors.grid_axis_z);
364
365 UI_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, 0, -80, gb.colors.deselect);
366 UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, gb.colors.outline);
367 UI_GetThemeColorShadeAlpha4fv(TH_LIGHT, 0, 255, gb.colors.light_no_alpha);
368
369 /* UV colors */
370 UI_GetThemeColor4fv(TH_UV_SHADOW, gb.colors.uv_shadow);
371
372 /* Color management. */
373 {
374 float4 *color = reinterpret_cast<float4 *>(&gb.colors);
375 float4 *color_end = color + (sizeof(gb.colors) / sizeof(float4));
376 do {
377 /* TODO: more accurate transform. */
379 } while (++color <= color_end);
380 }
381
382 gb.sizes.pixel = 1.0f;
383 gb.sizes.object_center = UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.0f;
384 gb.sizes.light_center = UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.5f;
385 gb.sizes.light_circle = 9.0f;
386 gb.sizes.light_circle_shadow = (gb.sizes.light_circle + 3.0f);
387
388 /* M_SQRT2 to be at least the same size of the old square */
389 gb.sizes.vert = vertex_size_get();
390 gb.sizes.vertex_gpencil = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
391 gb.sizes.face_dot = UI_GetThemeValuef(TH_FACEDOT_SIZE);
392 gb.sizes.edge = max_ff(1.0f, UI_GetThemeValuef(TH_EDGE_WIDTH)) / 2.0f;
393
394 /* Pixel size. */
395 {
396 float *size = reinterpret_cast<float *>(&gb.sizes);
397 float *size_end = size + (sizeof(gb.sizes) / sizeof(float));
398 do {
399 *size *= U.pixelsize;
400 } while (++size <= size_end);
401 }
402
403 gb.pixel_fac = (state.rv3d) ? state.rv3d->pixsize : 1.0f;
404 gb.size_viewport = ctx->viewport_size_get();
405 gb.size_viewport_inv = 1.0f / gb.size_viewport;
406
407 if (state.v3d) {
408 const View3DShading &shading = state.v3d->shading;
409 gb.backface_culling = (shading.type == OB_SOLID) &&
411
412 if (is_selection() || state.is_depth_only_drawing) {
413 /* This is bad as this makes a solid mode setting affect material preview / render mode
414 * selection and auto-depth. But users are relying on this to work in scene using backface
415 * culling in shading (see #136335 and #136418). */
416 gb.backface_culling = (shading.flag & V3D_SHADING_BACKFACE_CULLING);
417 }
418 }
419 else {
420 gb.backface_culling = false;
421 }
422
423 globals_buf.push_update();
424}
425
427{
428 /* TODO(fclem): Against design. Should not sync depending on view. */
431 state.camera_position = view.viewinv().location();
432 state.camera_forward = view.viewinv().z_axis();
433
434 resources.begin_sync(state.clipping_plane_count);
435
436 background.begin_sync(resources, state);
437 cursor.begin_sync(resources, state);
438 image_prepass.begin_sync(resources, state);
439 motion_paths.begin_sync(resources, state);
440 origins.begin_sync(resources, state);
441 outline.begin_sync(resources, state);
442
443 auto begin_sync_layer = [&](OverlayLayer &layer) {
444 layer.armatures.begin_sync(resources, state);
445 layer.attribute_viewer.begin_sync(resources, state);
446 layer.attribute_texts.begin_sync(resources, state);
447 layer.axes.begin_sync(resources, state);
448 layer.bounds.begin_sync(resources, state);
449 layer.cameras.begin_sync(resources, state);
450 layer.curves.begin_sync(resources, state);
451 layer.text.begin_sync(resources, state);
452 layer.empties.begin_sync(resources, state);
453 layer.facing.begin_sync(resources, state);
454 layer.fade.begin_sync(resources, state);
455 layer.force_fields.begin_sync(resources, state);
456 layer.fluids.begin_sync(resources, state);
457 layer.grease_pencil.begin_sync(resources, state);
458 layer.lattices.begin_sync(resources, state);
459 layer.lights.begin_sync(resources, state);
460 layer.light_probes.begin_sync(resources, state);
461 layer.metaballs.begin_sync(resources, state);
462 layer.meshes.begin_sync(resources, state);
463 layer.mesh_uvs.begin_sync(resources, state);
464 layer.mode_transfer.begin_sync(resources, state);
465 layer.names.begin_sync(resources, state);
466 layer.paints.begin_sync(resources, state);
467 layer.particles.begin_sync(resources, state);
468 layer.pointclouds.begin_sync(resources, state);
469 layer.prepass.begin_sync(resources, state);
470 layer.relations.begin_sync(resources, state);
471 layer.speakers.begin_sync(resources, state);
472 layer.sculpts.begin_sync(resources, state);
473 layer.wireframe.begin_sync(resources, state);
474 };
475 begin_sync_layer(regular);
476 begin_sync_layer(infront);
477
478 grid.begin_sync(resources, state);
479
480 anti_aliasing.begin_sync(resources, state);
481 xray_fade.begin_sync(resources, state);
482}
483
485{
486 const bool in_object_mode = ob_ref.object->mode == OB_MODE_OBJECT;
487 const bool in_edit_mode = ob_ref.object->mode == OB_MODE_EDIT;
488 const bool in_paint_mode = object_is_paint_mode(ob_ref.object);
489 const bool in_sculpt_mode = object_is_sculpt_mode(ob_ref);
490 const bool in_particle_edit_mode = object_is_particle_edit_mode(ob_ref);
491 const bool in_edit_paint_mode = object_is_edit_paint_mode(
492 ob_ref, in_edit_mode, in_paint_mode, in_sculpt_mode);
493 const bool needs_prepass = object_needs_prepass(ob_ref, in_paint_mode);
494
495 OverlayLayer &layer = object_is_in_front(ob_ref.object, state) ? infront : regular;
496
497 layer.mode_transfer.object_sync(manager, ob_ref, resources, state);
498
499 if (needs_prepass) {
500 layer.prepass.object_sync(manager, ob_ref, resources, state);
501 }
502
503 if (in_particle_edit_mode) {
504 layer.particles.edit_object_sync(manager, ob_ref, resources, state);
505 }
506
507 /* For 2D UV overlays. */
508 if (!state.hide_overlays && state.is_space_image()) {
509 switch (ob_ref.object->type) {
510 case OB_MESH:
511 if (in_edit_paint_mode) {
512 /* TODO(fclem): Find a better place / condition. */
513 layer.mesh_uvs.edit_object_sync(manager, ob_ref, resources, state);
514 }
515 else if (in_object_mode) {
516 layer.mesh_uvs.object_sync(manager, ob_ref, resources, state);
517 }
518 default:
519 break;
520 }
521 }
522
523 if (in_paint_mode && !state.hide_overlays) {
524 switch (ob_ref.object->type) {
525 case OB_MESH:
526 /* TODO(fclem): Make it part of a #Meshes. */
527 layer.paints.object_sync(manager, ob_ref, resources, state);
528 break;
529 case OB_GREASE_PENCIL:
530 layer.grease_pencil.paint_object_sync(manager, ob_ref, resources, state);
531 break;
532 default:
533 break;
534 }
535 }
536
537 if (in_sculpt_mode) {
538 switch (ob_ref.object->type) {
539 case OB_MESH:
540 case OB_CURVES:
541 /* TODO(fclem): Make it part of a #Meshes. */
542 layer.sculpts.object_sync(manager, ob_ref, resources, state);
543 break;
544 case OB_GREASE_PENCIL:
545 layer.grease_pencil.sculpt_object_sync(manager, ob_ref, resources, state);
546 break;
547 default:
548 break;
549 }
550 }
551
552 if (in_edit_mode && !state.hide_overlays) {
553 switch (ob_ref.object->type) {
554 case OB_MESH:
555 layer.meshes.edit_object_sync(manager, ob_ref, resources, state);
556 break;
557 case OB_ARMATURE:
558 layer.armatures.edit_object_sync(manager, ob_ref, resources, state);
559 break;
560 case OB_SURF:
561 case OB_CURVES_LEGACY:
562 layer.curves.edit_object_sync_legacy(manager, ob_ref, resources);
563 break;
564 case OB_CURVES:
565 layer.curves.edit_object_sync(manager, ob_ref, resources, state);
566 break;
567 case OB_LATTICE:
568 layer.lattices.edit_object_sync(manager, ob_ref, resources, state);
569 break;
570 case OB_MBALL:
571 layer.metaballs.edit_object_sync(manager, ob_ref, resources, state);
572 break;
573 case OB_POINTCLOUD:
574 layer.pointclouds.edit_object_sync(manager, ob_ref, resources, state);
575 break;
576 case OB_FONT:
577 layer.text.edit_object_sync(manager, ob_ref, resources, state);
578 break;
579 case OB_GREASE_PENCIL:
580 layer.grease_pencil.edit_object_sync(manager, ob_ref, resources, state);
581 break;
582 }
583 }
584
585 if (state.is_wireframe_mode || !state.hide_overlays) {
587 manager, ob_ref, resources, state, in_edit_paint_mode, in_edit_mode);
588 }
589
590 if (!state.hide_overlays) {
591 switch (ob_ref.object->type) {
592 case OB_EMPTY:
593 layer.empties.object_sync(manager, ob_ref, resources, state);
594 break;
595 case OB_CAMERA:
596 layer.cameras.object_sync(manager, ob_ref, resources, state);
597 break;
598 case OB_ARMATURE:
599 if (!in_edit_mode) {
600 layer.armatures.object_sync(manager, ob_ref, resources, state);
601 }
602 break;
603 case OB_LATTICE:
604 if (!in_edit_mode) {
605 layer.lattices.object_sync(manager, ob_ref, resources, state);
606 }
607 break;
608 case OB_LAMP:
609 layer.lights.object_sync(manager, ob_ref, resources, state);
610 break;
611 case OB_LIGHTPROBE:
612 layer.light_probes.object_sync(manager, ob_ref, resources, state);
613 break;
614 case OB_MBALL:
615 if (!in_edit_mode) {
616 layer.metaballs.object_sync(manager, ob_ref, resources, state);
617 }
618 break;
619 case OB_GREASE_PENCIL:
620 layer.grease_pencil.object_sync(manager, ob_ref, resources, state);
621 break;
622 case OB_SPEAKER:
623 layer.speakers.object_sync(manager, ob_ref, resources, state);
624 break;
625 }
626 layer.attribute_viewer.object_sync(manager, ob_ref, resources, state);
627 layer.attribute_texts.object_sync(manager, ob_ref, resources, state);
628 layer.bounds.object_sync(manager, ob_ref, resources, state);
629 layer.facing.object_sync(manager, ob_ref, resources, state);
630 layer.fade.object_sync(manager, ob_ref, resources, state);
631 layer.force_fields.object_sync(manager, ob_ref, resources, state);
632 layer.fluids.object_sync(manager, ob_ref, resources, state);
633 layer.particles.object_sync(manager, ob_ref, resources, state);
634 layer.relations.object_sync(manager, ob_ref, resources, state);
635 layer.axes.object_sync(manager, ob_ref, resources, state);
636 layer.names.object_sync(manager, ob_ref, resources, state);
637
638 motion_paths.object_sync(manager, ob_ref, resources, state);
639 origins.object_sync(manager, ob_ref, resources, state);
640
641 if (object_is_selected(ob_ref) && !in_edit_paint_mode) {
642 outline.object_sync(manager, ob_ref, resources, state);
643 }
644 }
645}
646
648{
649 origins.end_sync(resources, state);
650 resources.end_sync();
651
652 auto end_sync_layer = [&](OverlayLayer &layer) {
653 layer.armatures.end_sync(resources, state);
654 layer.axes.end_sync(resources, state);
655 layer.bounds.end_sync(resources, state);
656 layer.cameras.end_sync(resources, state);
657 layer.text.end_sync(resources, state);
658 layer.empties.end_sync(resources, state);
659 layer.force_fields.end_sync(resources, state);
660 layer.lights.end_sync(resources, state);
661 layer.light_probes.end_sync(resources, state);
662 layer.mesh_uvs.end_sync(resources, state);
663 layer.metaballs.end_sync(resources, state);
664 layer.relations.end_sync(resources, state);
665 layer.fluids.end_sync(resources, state);
666 layer.speakers.end_sync(resources, state);
667 };
668 end_sync_layer(regular);
669 end_sync_layer(infront);
670
671 /* WORKAROUND: This prevents bad frame-buffer config inside workbench when xray is enabled.
672 * Better find a solution to this chicken-egg problem. */
673 {
674 const DRWContext *draw_ctx = DRW_context_get();
675 /* HACK we allocate the in front depth here to avoid the overhead when if is not needed. */
678
679 if (dtxl->depth_in_front == nullptr) {
680 int2 size = int2(draw_ctx->viewport_size_get());
681
682 dtxl->depth_in_front = GPU_texture_create_2d("txl.depth_in_front",
683 size.x,
684 size.y,
685 1,
688 nullptr);
689 }
690
692 &dfbl->in_front_fb,
693 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
694 }
695}
696
698{
699 /* TODO(fclem): Remove global access. */
701
702 static gpu::DebugScope select_scope = {"Selection"};
703 static gpu::DebugScope draw_scope = {"Overlay"};
704 static gpu::DebugScope depth_scope = {"DepthOnly"};
705
706 if (state.is_depth_only_drawing) {
707 depth_scope.begin_capture();
708 }
709 else if (resources.is_selection()) {
710 select_scope.begin_capture();
711 }
712 else {
713 draw_scope.begin_capture();
714 }
715
716 /* TODO(fclem): To be moved to overlay UBO. */
717 state.ndc_offset_factor = state.offset_data_get().polygon_offset_factor(view.winmat());
718
719 resources.pre_draw();
720
721 outline.flat_objects_pass_sync(manager, view, resources, state);
722 GreasePencil::compute_depth_planes(manager, view, resources, state);
723
724 /* Pre-Draw: Run the compute steps of all passes up-front
725 * to avoid constant GPU compute/raster context switching. */
726 {
727 manager.ensure_visibility(view);
728
729 auto pre_draw = [&](OverlayLayer &layer) {
730 layer.attribute_viewer.pre_draw(manager, view);
731 layer.cameras.pre_draw(manager, view);
732 layer.empties.pre_draw(manager, view);
733 layer.facing.pre_draw(manager, view);
734 layer.fade.pre_draw(manager, view);
735 layer.lattices.pre_draw(manager, view);
736 layer.light_probes.pre_draw(manager, view);
737 layer.particles.pre_draw(manager, view);
738 layer.pointclouds.pre_draw(manager, view);
739 layer.prepass.pre_draw(manager, view);
740 layer.wireframe.pre_draw(manager, view);
741 };
742
743 pre_draw(regular);
744 pre_draw(infront);
745
746 outline.pre_draw(manager, view);
747 }
748
749 resources.acquire(DRW_context_get(), this->state);
750
752
753 /* TODO(fclem): Would be better to have a v2d overlay class instead of these conditions. */
754 switch (state.space_type) {
755 case SPACE_NODE:
756 draw_node(manager, view);
757 break;
758 case SPACE_IMAGE:
759 draw_v2d(manager, view);
760 break;
761 case SPACE_VIEW3D:
762 draw_v3d(manager, view);
763 break;
764 default:
766 }
767
769
770 resources.release();
771
772 resources.read_result();
773
774 if (state.is_depth_only_drawing) {
775 depth_scope.end_capture();
776 }
777 else if (resources.is_selection()) {
778 select_scope.end_capture();
779 }
780 else {
781 draw_scope.end_capture();
782 }
783}
784
785void Instance::draw_node(Manager &manager, View &view)
786{
787 /* Don't clear background for the node editor. The node editor draws the background and we
788 * need to mask out the image from the already drawn overlay color buffer. */
790}
791
792void Instance::draw_v2d(Manager &manager, View &view)
793{
795 regular.mesh_uvs.draw_on_render(resources.render_fb, manager, view);
796
799
802 regular.mesh_uvs.draw(resources.overlay_output_fb, manager, view);
803
805}
806
807void Instance::draw_v3d(Manager &manager, View &view)
808{
809 float4 clear_color(0.0f);
810
811 auto draw = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
812 /* TODO(fclem): Depth aware outlines (see #130751). */
813 // layer.facing.draw(framebuffer, manager, view);
814 layer.fade.draw(framebuffer, manager, view);
815 layer.mode_transfer.draw(framebuffer, manager, view);
816 layer.text.draw(framebuffer, manager, view);
817 layer.paints.draw(framebuffer, manager, view);
818 layer.particles.draw(framebuffer, manager, view);
819 };
820
821 auto draw_line = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
822 layer.bounds.draw_line(framebuffer, manager, view);
823 layer.wireframe.draw_line(framebuffer, manager, view);
824 layer.cameras.draw_line(framebuffer, manager, view);
825 layer.empties.draw_line(framebuffer, manager, view);
826 layer.axes.draw_line(framebuffer, manager, view);
827 layer.force_fields.draw_line(framebuffer, manager, view);
828 layer.lights.draw_line(framebuffer, manager, view);
829 layer.light_probes.draw_line(framebuffer, manager, view);
830 layer.speakers.draw_line(framebuffer, manager, view);
831 layer.lattices.draw_line(framebuffer, manager, view);
832 layer.metaballs.draw_line(framebuffer, manager, view);
833 layer.pointclouds.draw_line(framebuffer, manager, view);
834 layer.relations.draw_line(framebuffer, manager, view);
835 layer.fluids.draw_line(framebuffer, manager, view);
836 layer.particles.draw_line(framebuffer, manager, view);
837 layer.attribute_viewer.draw_line(framebuffer, manager, view);
838 layer.armatures.draw_line(framebuffer, manager, view);
839 layer.sculpts.draw_line(framebuffer, manager, view);
840 layer.grease_pencil.draw_line(framebuffer, manager, view);
841 /* NOTE: Temporarily moved after grid drawing (See #136764). */
842 // layer.meshes.draw_line(framebuffer, manager, view);
843 layer.curves.draw_line(framebuffer, manager, view);
844 };
845
846 auto draw_color_only = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
847 layer.light_probes.draw_color_only(framebuffer, manager, view);
848 layer.meshes.draw_color_only(framebuffer, manager, view);
849 layer.curves.draw_color_only(framebuffer, manager, view);
850 layer.grease_pencil.draw_color_only(framebuffer, manager, view);
851 };
852
853 {
854 /* Render pass. Draws directly on render result (instead of overlay result). */
855 /* TODO(fclem): Split overlay and rename draw functions. */
856 regular.cameras.draw_scene_background_images(resources.render_fb, manager, view);
857 infront.cameras.draw_scene_background_images(resources.render_in_front_fb, manager, view);
858
859 regular.sculpts.draw_on_render(resources.render_fb, manager, view);
860 infront.sculpts.draw_on_render(resources.render_in_front_fb, manager, view);
861 }
862 {
863 /* Overlay Line prepass. */
864 GPU_framebuffer_bind(resources.overlay_line_fb);
865 if (state.xray_enabled) {
866 /* Rendering to a new depth buffer that needs to be cleared. */
867 GPU_framebuffer_clear_color_depth(resources.overlay_line_fb, clear_color, 1.0f);
868 }
869 else {
870 if (!state.is_render_depth_available) {
871 /* If the render engine is not outputting correct depth,
872 * clear the depth and render a depth prepass. */
873 GPU_framebuffer_clear_color_depth(resources.overlay_line_fb, clear_color, 1.0f);
874 }
875 else {
876 GPU_framebuffer_clear_color(resources.overlay_line_fb, clear_color);
877 }
878 }
879
880 if (BLI_thread_is_main() && !state.hide_overlays) {
882 }
883
884 regular.prepass.draw_line(resources.overlay_line_fb, manager, view);
885
886 /* TODO(fclem): Split overlay and rename draw functions. */
887 /* TODO(fclem): Draw on line framebuffer. */
888 regular.empties.draw_images(resources.overlay_fb, manager, view);
889
890 if (state.xray_enabled || (state.v3d && state.v3d->shading.type > OB_SOLID)) {
891 /* If workbench is not enabled, the infront buffer might contain garbage. */
892 GPU_framebuffer_bind(resources.overlay_line_in_front_fb);
893 GPU_framebuffer_clear_depth(resources.overlay_line_in_front_fb, 1.0f);
894 }
895
896 infront.prepass.draw_line(resources.overlay_line_in_front_fb, manager, view);
897 }
898 {
899 /* Copy depth at the end of the prepass to avoid splitting the main render pass. */
900 /* TODO(fclem): Better get rid of it. */
901 regular.wireframe.copy_depth(resources.depth_target_tx);
902 infront.wireframe.copy_depth(resources.depth_target_in_front_tx);
903 }
904 {
905 /* TODO(fclem): This is really bad for performance as the outline pass will then split the
906 * render pass and do a framebuffer switch. This also only fix the issue for non-infront
907 * objects.
908 * We need to figure a way to merge the outline with correct depth awareness (see #130751). */
909 regular.facing.draw(resources.overlay_fb, manager, view);
910
911 /* Line only pass. */
912 outline.draw_line_only_ex(resources.overlay_line_only_fb, resources, manager, view);
913 }
914 {
915 /* Overlay (+Line) pass. */
916 draw(regular, resources.overlay_fb);
917 draw_line(regular, resources.overlay_line_fb);
918
919 /* Here because of custom order of regular.facing. */
920 infront.facing.draw(resources.overlay_fb, manager, view);
921
922 draw(infront, resources.overlay_in_front_fb);
923 draw_line(infront, resources.overlay_line_in_front_fb);
924 }
925 {
926 /* Color only pass. */
927 motion_paths.draw_color_only(resources.overlay_color_only_fb, manager, view);
928 xray_fade.draw_color_only(resources.overlay_color_only_fb, manager, view);
929 grid.draw_color_only(resources.overlay_color_only_fb, manager, view);
930
931 regular.meshes.draw_line(resources.overlay_line_fb, manager, view);
932 infront.meshes.draw_line(resources.overlay_line_in_front_fb, manager, view);
933
934 draw_color_only(regular, resources.overlay_color_only_fb);
935 draw_color_only(infront, resources.overlay_color_only_fb);
936
937 /* TODO(fclem): Split overlay and rename draw functions. */
938 regular.empties.draw_in_front_images(resources.overlay_color_only_fb, manager, view);
939 infront.empties.draw_in_front_images(resources.overlay_color_only_fb, manager, view);
940 regular.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view);
941 infront.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view);
942
943 origins.draw_color_only(resources.overlay_color_only_fb, manager, view);
944 }
945
946 if (state.is_depth_only_drawing == false) {
947 /* Output pass. */
948 GPU_framebuffer_bind(resources.overlay_output_color_only_fb);
949 GPU_framebuffer_clear_color(resources.overlay_output_color_only_fb, clear_color);
950
951 /* TODO(fclem): Split overlay and rename draw functions. */
952 regular.cameras.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
953 infront.cameras.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
954 regular.empties.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
955
956 background.draw_output(resources.overlay_output_color_only_fb, manager, view);
957 anti_aliasing.draw_output(resources.overlay_output_color_only_fb, manager, view);
958 cursor.draw_output(resources.overlay_output_color_only_fb, manager, view);
959 }
960}
961
962bool Instance::object_is_selected(const ObjectRef &ob_ref)
963{
964 return (ob_ref.object->base_flag & BASE_SELECTED);
965}
966
967bool Instance::object_is_paint_mode(const Object *object)
968{
969 return (object == state.object_active) &&
971}
972
973bool Instance::object_is_sculpt_mode(const ObjectRef &ob_ref)
974{
975 if (state.object_mode == OB_MODE_SCULPT_CURVES) {
976 const Object *active_object = state.object_active;
977 const bool is_active_object = ob_ref.object == active_object;
978
979 bool is_geonode_preview = ob_ref.dupli_object && ob_ref.dupli_object->preview_base_geometry;
980 bool is_active_dupli_parent = ob_ref.dupli_parent == active_object;
981 return is_active_object || (is_active_dupli_parent && is_geonode_preview);
982 }
983
984 if (state.object_mode == OB_MODE_SCULPT) {
985 const Object *active_object = state.object_active;
986 const bool is_active_object = ob_ref.object == active_object;
987 return is_active_object;
988 }
989
990 return false;
991}
992
993bool Instance::object_is_particle_edit_mode(const ObjectRef &ob_ref)
994{
995 return (ob_ref.object->mode == OB_MODE_PARTICLE_EDIT) && (state.ctx_mode == CTX_MODE_PARTICLE);
996}
997
998bool Instance::object_is_sculpt_mode(const Object *object)
999{
1000 if (object->sculpt && (object->sculpt->mode_type == OB_MODE_SCULPT)) {
1001 return object == state.object_active;
1002 }
1003 return false;
1004}
1005
1006bool Instance::object_is_edit_paint_mode(const ObjectRef &ob_ref,
1007 bool in_edit_mode,
1008 bool in_paint_mode,
1009 bool in_sculpt_mode)
1010{
1011 bool in_edit_paint_mode = in_edit_mode || in_paint_mode || in_sculpt_mode;
1012 if (ob_ref.object->base_flag & BASE_FROM_DUPLI) {
1013 /* Disable outlines for objects instanced by an object in sculpt, paint or edit mode. */
1014 in_edit_paint_mode |= ob_ref.dupli_parent && (object_is_edit_mode(ob_ref.dupli_parent) ||
1015 object_is_sculpt_mode(ob_ref.dupli_parent) ||
1016 object_is_paint_mode(ob_ref.dupli_parent));
1017 }
1018 return in_edit_paint_mode;
1019}
1020
1021bool Instance::object_is_edit_mode(const Object *object)
1022{
1023 if (DRW_object_is_in_edit_mode(object)) {
1024 /* Also check for context mode as the object mode is not 100% reliable. (see T72490) */
1025 switch (object->type) {
1026 case OB_MESH:
1027 return state.ctx_mode == CTX_MODE_EDIT_MESH;
1028 case OB_ARMATURE:
1029 return state.ctx_mode == CTX_MODE_EDIT_ARMATURE;
1030 case OB_CURVES_LEGACY:
1031 return state.ctx_mode == CTX_MODE_EDIT_CURVE;
1032 case OB_SURF:
1033 return state.ctx_mode == CTX_MODE_EDIT_SURFACE;
1034 case OB_LATTICE:
1035 return state.ctx_mode == CTX_MODE_EDIT_LATTICE;
1036 case OB_MBALL:
1037 return state.ctx_mode == CTX_MODE_EDIT_METABALL;
1038 case OB_FONT:
1039 return state.ctx_mode == CTX_MODE_EDIT_TEXT;
1040 case OB_CURVES:
1041 return state.ctx_mode == CTX_MODE_EDIT_CURVES;
1042 case OB_POINTCLOUD:
1043 return state.ctx_mode == CTX_MODE_EDIT_POINTCLOUD;
1044 case OB_GREASE_PENCIL:
1045 return state.ctx_mode == CTX_MODE_EDIT_GREASE_PENCIL;
1046 case OB_VOLUME:
1047 /* No edit mode yet. */
1048 return false;
1049 }
1050 }
1051 return false;
1052}
1053
1054bool Instance::object_is_in_front(const Object *object, const State &state)
1055{
1056 switch (object->type) {
1057 case OB_ARMATURE:
1058 return (object->dtx & OB_DRAW_IN_FRONT) ||
1059 (state.do_pose_xray && Armatures::is_pose_mode(object, state));
1060 default:
1061 return state.use_in_front && (object->dtx & OB_DRAW_IN_FRONT);
1062 }
1063}
1064
1065bool Instance::object_needs_prepass(const ObjectRef &ob_ref, bool in_paint_mode)
1066{
1067 if (resources.is_selection() && state.is_wireframe_mode && !state.is_solid()) {
1068 /* Selection in wireframe mode only use wires unless xray opacity is 1. */
1069 return false;
1070 }
1071
1072 if (resources.is_selection() || state.is_depth_only_drawing) {
1073 /* Selection and depth picking always need a prepass.
1074 * Note that depth writing and depth test might be disable for certain selection mode. */
1075 return true;
1076 }
1077
1078 if (in_paint_mode) {
1079 /* Allow paint overlays to draw with depth equal test. */
1080 if (object_is_rendered_transparent(ob_ref.object, state)) {
1081 return true;
1082 }
1083 }
1084
1085 if (!state.xray_enabled) {
1086 /* Force depth prepass if depth buffer form render engine is not available. */
1087 if (!state.is_render_depth_available && (ob_ref.object->dt >= OB_SOLID)) {
1088 return true;
1089 }
1090 }
1091
1092 return false;
1093}
1094
1095bool Instance::object_is_rendered_transparent(const Object *object, const State &state)
1096{
1097 if (state.v3d == nullptr) {
1098 return false;
1099 }
1100
1101 if (!state.is_solid()) {
1102 return true;
1103 }
1104
1105 if (ELEM(object->dt, OB_WIRE, OB_BOUNDBOX)) {
1106 return true;
1107 }
1108
1109 const View3DShading &shading = state.v3d->shading;
1110
1111 if (shading.type == OB_WIRE) {
1112 return true;
1113 }
1114
1115 if (shading.type > OB_SOLID) {
1116 return false;
1117 }
1118
1119 if (shading.color_type == V3D_SHADING_OBJECT_COLOR) {
1120 return object->color[3] < 1.0f;
1121 }
1122
1123 if (shading.color_type == V3D_SHADING_MATERIAL_COLOR) {
1124 if (object->type == OB_MESH) {
1125 const int materials_num = BKE_object_material_used_with_fallback_eval(*object);
1126 for (int i = 0; i < materials_num; i++) {
1127 Material *mat = BKE_object_material_get_eval(const_cast<Object *>(object), i + 1);
1128 if (mat && mat->a < 1.0f) {
1129 return true;
1130 }
1131 }
1132 }
1133 }
1134
1135 return false;
1136}
1137
1138} // namespace blender::draw::overlay
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
Definition colorband.cc:395
@ CTX_MODE_EDIT_CURVE
@ CTX_MODE_EDIT_SURFACE
@ CTX_MODE_PARTICLE
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_EDIT_POINTCLOUD
@ CTX_MODE_EDIT_GREASE_PENCIL
@ CTX_MODE_EDIT_TEXT
@ CTX_MODE_EDIT_CURVES
@ CTX_MODE_EDIT_ARMATURE
@ CTX_MODE_EDIT_LATTICE
@ CTX_MODE_EDIT_METABALL
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Material * BKE_object_material_get_eval(Object *ob, short act)
int BKE_object_material_used_with_fallback_eval(const Object &ob)
int BKE_render_preview_pixel_size(const RenderData *r)
Definition scene.cc:2942
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:2827
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
MINLINE float max_ff(float a, float b)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
unsigned char uchar
int BLI_thread_is_main(void)
Definition threads.cc:179
#define ARRAY_SIZE(arr)
#define ELEM(...)
#define STREQ(a, b)
float DEG_get_ctime(const Depsgraph *graph)
@ BASE_FROM_DUPLI
struct Material Material
#define OB_MODE_ALL_PAINT
@ OB_WIRE
@ OB_BOUNDBOX
@ OB_SOLID
#define OB_MODE_ALL_PAINT_GPENCIL
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_SCULPT
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_OBJECT
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_LIGHTPROBE
struct Object Object
@ OB_DRAW_IN_FRONT
#define BASE_SELECTED(v3d, base)
@ SI_OVERLAY_SHOW_OVERLAYS
eSpace_Type
@ SPACE_NODE
@ SPACE_IMAGE
@ SPACE_VIEW3D
@ USER_GPU_FLAG_FRESNEL_EDIT
@ USER_CUSTOM_RANGE
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_OBJECT_COLOR
@ RV3D_BOXCLIP
#define RV3D_LOCK_FLAGS(rv3d)
@ V3D_HIDE_OVERLAYS
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
struct View3DShading View3DShading
@ V3D_SHADING_BACKFACE_CULLING
@ V3D_OVERLAY_HIDE_OBJECT_ORIGINS
@ V3D_OVERLAY_HIDE_BONES
@ V3D_OVERLAY_HIDE_MOTION_PATHS
@ V3D_OVERLAY_HIDE_OBJECT_XTRAS
@ V3D_OVERLAY_HIDE_TEXT
void DRW_submission_end()
void DRW_submission_start()
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
#define XRAY_ACTIVE(v3d)
#define SHADING_XRAY_FLAG_ENABLED(shading)
#define XRAY_ALPHA(v3d)
RenderEngineType * ED_view3d_engine_type(const Scene *scene, int drawtype)
static AppView * view
static void View(GHOST_IWindow *window, bool stereo, int eye=0)
void GPU_framebuffer_clear_color_depth(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_framebuffer_clear_color(GPUFrameBuffer *fb, const float clear_col[4])
#define GPU_framebuffer_ensure_config(_fb,...)
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
@ GPU_DATA_UBYTE
@ GPU_DATA_FLOAT
eGPUTextureUsage
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_texture_update_sub(GPUTexture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
@ GPU_SRGB8_A8
@ GPU_DEPTH24_STENCIL8
@ GPU_DEPTH_COMPONENT32F
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
@ TH_EDGE_SHARP
@ TH_BONE_SOLID
@ TH_HANDLE_ALIGN
@ TH_NORMAL
@ TH_LIGHT
@ TH_FACE_BACK
@ TH_BACK_GRAD
@ TH_LNORMAL
@ TH_EDGE_FACESEL
@ TH_NURB_SEL_VLINE
@ TH_FRAME_AFTER
@ TH_TRANSPARENT_CHECKER_PRIMARY
@ TH_BONE_POSE_ACTIVE
@ TH_FREESTYLE_FACE_MARK
@ TH_FREESTYLE_EDGE_MARK
@ TH_GRID
@ TH_BACK
@ TH_WIRE
@ TH_BONE_LOCKED_WEIGHT
@ TH_FACEDOT_SIZE
@ TH_BONE_POSE
@ TH_HANDLE_SEL_AUTO
@ TH_SKIN_ROOT
@ TH_EDGE_SELECT
@ TH_TRANSPARENT_CHECKER_SECONDARY
@ TH_HANDLE_SEL_AUTOCLAMP
@ TH_ACTIVE_SPLINE
@ TH_CAMERA
@ TH_TRANSFORM
@ TH_EDGE_BEVEL
@ TH_HANDLE_AUTO
@ TH_NURB_VLINE
@ TH_SPEAKER
@ TH_VERTEX
@ TH_HANDLE_SEL_ALIGN
@ TH_GP_VERTEX_SELECT
@ TH_OBCENTER_DIA
@ TH_UV_SHADOW
@ TH_FACE_RETOPOLOGY
@ TH_HANDLE_SEL_FREE
@ TH_FACE_SELECT
@ TH_CFRAME
@ TH_NURB_ULINE
@ TH_EDGE_SEAM
@ TH_AXIS_Y
@ TH_AXIS_X
@ TH_HANDLE_SEL_VECT
@ TH_VERTEX_SELECT
@ TH_EMPTY
@ TH_FACE_FRONT
@ TH_VERTEX_UNREFERENCED
@ TH_TRANSPARENT_CHECKER_SIZE
@ TH_V3D_CLIPPING_BORDER
@ TH_AXIS_Z
@ TH_EDGE_WIDTH
@ TH_EDITMESH_ACTIVE
@ TH_GP_VERTEX_SIZE
@ TH_GP_VERTEX
@ TH_FRAME_BEFORE
@ TH_FACE_DOT
@ TH_EDGE_MODE_SELECT
@ TH_FACE_MODE_SELECT
@ TH_CAMERA_PATH
@ TH_SELECT
@ TH_HANDLE_FREE
@ TH_HANDLE_AUTOCLAMP
@ TH_EDGE_CREASE
@ TH_HANDLE_VECT
@ TH_TEXT
@ TH_WIRE_EDIT
@ TH_NURB_SEL_ULINE
@ TH_ACTIVE
@ TH_FACE
@ TH_VNORMAL
@ TH_TEXT_HI
void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
float UI_GetThemeValuef(int colorid)
#define U
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void display_to_view(View &view)
static DebugDraw & get()
void ensure_visibility(View &view)
static View & default_get()
Definition draw_view.cc:317
static bool is_pose_mode(const Object *armature_ob, const State &state)
void edit_object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void draw_output(Framebuffer &framebuffer, Manager &manager, View &view) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void draw_output(Framebuffer &framebuffer, Manager &manager, View &) final
void edit_object_sync_legacy(Manager &manager, const ObjectRef &ob_ref, Resources &)
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void sculpt_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void paint_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
void draw_on_render(GPUFrameBuffer *framebuffer, Manager &manager, View &view) final
void draw(Manager &manager) final
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void edit_object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &) final
void object_sync_ex(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state, const bool in_edit_paint_mode, const bool in_edit_mode)
const DRWContext * DRW_context_get()
bool DRW_object_is_in_edit_mode(const Object *ob)
DRWTextStore * DRW_text_cache_ensure()
Simple API to draw debug shapes and log in the viewport.
#define pow
#define unit_float_to_uchar_clamp_v4(v1, v2)
static ulong state[N]
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T interpolate(const T &a, const T &b, const FactorT &t)
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T reduce_add(const VecBase< T, Size > &a)
bool assign_if_different(T &old_value, T new_value)
blender::VecBase< uint8_t, 4 > uchar4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
const char * RE_engine_id_BLENDER_EEVEE_NEXT
Definition scene.cc:1626
bool is_image_render() const
Object * object_edit
bool draw_background
DefaultFramebufferList * viewport_framebuffer_list_get() const
View3D * v3d
Depsgraph * depsgraph
struct DRWContext::@104106145204363037226002274050347030264243156307 options
RegionView3D * rv3d
@ DEPTH_ACTIVE_OBJECT
Object * obact
enum DRWContext::Mode mode
blender::float2 viewport_size_get() const
Scene * scene
Object * object_pose
bool is_depth() const
bool is_viewport_image_render() const
eObjectMode object_mode
ARegion * region
SpaceLink * space_data
DefaultTextureList * viewport_texture_list_get() const
ViewLayer * view_layer
bool is_material_select() const
GPUFrameBuffer * in_front_fb
GPUTexture * depth_in_front
struct SculptSession * sculpt
char idname[64]
Definition RE_engine.h:74
eObjectMode mode_type
Definition BKE_paint.hh:511
SpaceImageOverlay overlay
struct Image * image
void update_theme_settings(const DRWContext *ctx, const State &state)
draw::UniformArrayBuffer< float4, 6 > clip_planes_buf
draw::UniformBuffer< UniformData > globals_buf
void update_clip_planes(const State &state)
i
Definition text_draw.cc:230