Blender V5.3
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_common_c.hh"
17#include "draw_debug.hh"
18#include "overlay_instance.hh"
19
20namespace blender::draw::overlay {
21
23{
24 /* TODO(fclem): Remove DRW global usage. */
25 const DRWContext *ctx = DRW_context_get();
26 /* Was needed by `object_wire_theme_id()` when doing the port. Not sure if needed nowadays. */
28
29 clipping_enabled_ = RV3D_CLIPPING_ENABLED(ctx->v3d, ctx->rv3d);
30
31 resources.init(clipping_enabled_);
32
36 state.scene = ctx->scene;
37 state.v3d = ctx->v3d;
38 state.region = ctx->region;
39 state.rv3d = ctx->rv3d;
49 state.draw_background = ctx->options.draw_background;
50 state.show_text = false;
51
52 /* Note there might be less than 6 planes, but we always compute the 6 of them for simplicity. */
53 state.clipping_plane_count = clipping_enabled_ ? 6 : 0;
54
58 if (state.v3d != nullptr) {
60 /* TODO(pragma37): Check with @fclem if this was intentional. */
61 // state.use_in_front = (state.v3d->shading.type <= OB_SOLID) ||
62 // BKE_scene_uses_blender_workbench(state.scene);
63 state.use_in_front = true;
73
74 const bool viewport_uses_workbench = state.v3d->shading.type <= OB_SOLID ||
78 const bool viewport_uses_eevee = STREQ(engine_type->idname, RE_engine_id_BLENDER_EEVEE);
79 const bool viewport_engine_provides_depth = engine_type->flag & RE_WRITE_VIEWPORT_DEPTH;
80 const bool use_resolution_scaling = BKE_render_preview_pixel_size(&state.scene->r) != 1;
81 /* Only workbench ensures the depth buffer is matching overlays.
82 * Force depth prepass for other render engines,
83 * unless they declared their depth information should be used.
84 * EEVEE is an exception (if not using mixed resolution) to avoid a significant overhead. */
85 state.is_render_depth_available = viewport_uses_workbench ||
86 (viewport_uses_eevee && !use_resolution_scaling) ||
87 viewport_engine_provides_depth;
88
89 /* For depth only drawing, no other render engine is expected. Except for Grease Pencil which
90 * outputs valid depth. Otherwise depth is cleared and is valid. */
92
93 if (!state.hide_overlays) {
99 }
100 else {
102 state.v3d_flag = 0;
109 }
110
113 ctx->object_pose != nullptr;
114 }
115 else if (state.is_space_image()) {
116 SpaceImage *space_image = reinterpret_cast<SpaceImage *>(
117 const_cast<SpaceLink *>(state.space_data));
118
119 state.clear_in_front = false;
120 state.use_in_front = false;
121 state.is_wireframe_mode = false;
124 state.xray_enabled = false;
125 /* Avoid triggering the depth prepass. */
127
128 /* During engine initialization phase the `space_image` isn't locked and we are able to
129 * retrieve the needed data. During cache_init the image engine locks the `space_image` and
130 * makes it impossible to retrieve the data. */
131 state.is_image_valid = bool(space_image->image);
135 }
136
139
140 ensure_weight_ramp_texture();
141
142 {
144 if (resources.dummy_depth_tx.ensure_2d(gpu::TextureFormat::SFLOAT_32_DEPTH, int2(1, 1), usage))
145 {
146 float data = 1.0f;
148 }
149 }
150}
151
152void Instance::ensure_weight_ramp_texture()
153{
154 /* Weight Painting color ramp texture */
155 bool user_weight_ramp = (U.flag & USER_CUSTOM_RANGE) != 0;
156
157 auto is_equal = [](const ColorBand &a, const ColorBand &b) {
158 if (a.tot != b.tot || a.cur != b.cur || a.ipotype != b.ipotype ||
159 a.ipotype_hue != b.ipotype_hue || a.color_mode != b.color_mode)
160 {
161 return false;
162 }
163
164 auto is_equal_cbd = [](const CBData &a, const CBData &b) {
165 return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a && a.pos == b.pos &&
166 a.cur == b.cur;
167 };
168
169 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
170 if (!is_equal_cbd(a.data[i], b.data[i])) {
171 return false;
172 }
173 }
174 return true;
175 };
176
177 if (assign_if_different(resources.weight_ramp_custom, user_weight_ramp)) {
179 }
180
181 if (user_weight_ramp && !is_equal(resources.weight_ramp_copy, U.coba_weight)) {
184 }
185
187 /* Only recreate on updates. */
188 return;
189 }
190
191 auto evaluate_weight_to_color = [&](const float weight, float result[4]) {
192 if (user_weight_ramp) {
194 }
195 else {
196 /* Use gamma correction to even out the color bands:
197 * increasing widens yellow/cyan vs red/green/blue.
198 * Gamma 1.0 produces the original 2.79 color ramp. */
199 const float gamma = 1.5f;
200 const float hsv[3] = {
201 (2.0f / 3.0f) * (1.0f - weight), 1.0f, pow(0.5f + 0.5f * weight, gamma)};
202
203 hsv_to_rgb_v(hsv, result);
204
205 for (int i = 0; i < 3; i++) {
206 result[i] = pow(result[i], 1.0f / gamma);
207 }
208 }
209 };
210
211 constexpr int res = 256;
212
213 float pixels[res][4];
214 for (int i = 0; i < res; i++) {
215 evaluate_weight_to_color(i / 255.0f, pixels[i]);
216 pixels[i][3] = 1.0f;
217 }
218
219 uchar4 pixels_ubyte[res];
220 for (int i = 0; i < res; i++) {
221 unit_float_to_uchar_clamp_v4(pixels_ubyte[i], pixels[i]);
222 }
223
225 gpu::TextureFormat::SRGBA_8_8_8_8, res, GPU_TEXTURE_USAGE_SHADER_READ);
227}
228
230{
231 if (!state.is_space_v3d() || state.clipping_plane_count == 0) {
232 /* Unused, do not care about content but still fulfill the bindings. */
233 clip_planes_buf.push_update();
234 return;
235 }
236
237 for (int i : IndexRange(6)) {
238 clip_planes_buf[i] = float4(0);
239 }
240
241 int plane_len = (RV3D_LOCK_FLAGS(state.rv3d) & RV3D_BOXCLIP) ? 4 : 6;
242 for (int i : IndexRange(plane_len)) {
243 clip_planes_buf[i] = float4(state.rv3d->clip[i]);
244 }
245
246 clip_planes_buf.push_update();
247}
248
250{
251 using namespace math;
252 UniformData &gb = theme;
253
254 auto rgba_uchar_to_float = [](uchar r, uchar g, uchar b, uchar a) {
255 return float4(r, g, b, a) / 255.0f;
256 };
257
258 ui::theme::get_color_4fv(TH_WIRE, gb.colors.wire);
259 ui::theme::get_color_4fv(TH_WIRE_EDIT, gb.colors.wire_edit);
260 ui::theme::get_color_4fv(TH_ACTIVE, gb.colors.active_object);
261 ui::theme::get_color_4fv(TH_SELECT, gb.colors.object_select);
262 gb.colors.library_select = rgba_uchar_to_float(0x88, 0xFF, 0xFF, 155);
263 gb.colors.library = rgba_uchar_to_float(0x55, 0xCC, 0xCC, 155);
264 ui::theme::get_color_4fv(TH_TRANSFORM, gb.colors.transform);
265 ui::theme::get_color_4fv(TH_LIGHT, gb.colors.light);
266 ui::theme::get_color_4fv(TH_SPEAKER, gb.colors.speaker);
268 ui::theme::get_color_4fv(TH_CAMERA_PATH, gb.colors.camera_path);
269 ui::theme::get_color_4fv(TH_EMPTY, gb.colors.empty);
270 ui::theme::get_color_4fv(TH_VERTEX, gb.colors.vert);
271 ui::theme::get_color_4fv(TH_VERTEX_SELECT, gb.colors.vert_select);
272 ui::theme::get_color_4fv(TH_VERTEX_UNREFERENCED, gb.colors.vert_unreferenced);
273 gb.colors.vert_missing_data = rgba_uchar_to_float(0xB0, 0x00, 0xB0, 0xFF);
274 ui::theme::get_color_4fv(TH_EDITMESH_ACTIVE, gb.colors.edit_mesh_active);
275 ui::theme::get_color_4fv(TH_EDGE_SELECT, gb.colors.edge_select);
276 ui::theme::get_color_4fv(TH_EDGE_MODE_SELECT, gb.colors.edge_mode_select);
277 ui::theme::get_color_4fv(TH_GP_WIRE_EDIT, gb.colors.gpencil_wire_edit);
278 ui::theme::get_color_4fv(TH_GP_VERTEX, gb.colors.gpencil_vertex);
279 ui::theme::get_color_4fv(TH_GP_VERTEX_SELECT, gb.colors.gpencil_vertex_select);
280
281 ui::theme::get_color_4fv(TH_SEAM, gb.colors.edge_seam);
282 ui::theme::get_color_4fv(TH_SHARP, gb.colors.edge_sharp);
283 ui::theme::get_color_4fv(TH_CREASE, gb.colors.edge_crease);
284 ui::theme::get_color_4fv(TH_BEVEL, gb.colors.edge_bweight);
285 ui::theme::get_color_4fv(TH_FACE, gb.colors.face);
286 ui::theme::get_color_4fv(TH_FACE_SELECT, gb.colors.face_select);
287 ui::theme::get_color_4fv(TH_FACE_MODE_SELECT, gb.colors.face_mode_select);
288 ui::theme::get_color_4fv(TH_FACE_RETOPOLOGY, gb.colors.face_retopology);
289 ui::theme::get_color_4fv(TH_FACE_BACK, gb.colors.face_back);
290 ui::theme::get_color_4fv(TH_FACE_FRONT, gb.colors.face_front);
291 ui::theme::get_color_4fv(TH_NORMAL, gb.colors.normal);
292 ui::theme::get_color_4fv(TH_VNORMAL, gb.colors.vnormal);
293 ui::theme::get_color_4fv(TH_LNORMAL, gb.colors.lnormal);
294 ui::theme::get_color_4fv(TH_FACE_SELECT, gb.colors.facedot), gb.colors.facedot[3] = 1.0f;
295 ui::theme::get_color_4fv(TH_SKIN_ROOT, gb.colors.skinroot);
296 ui::theme::get_color_4fv(TH_BACK, gb.colors.background);
297 ui::theme::get_color_4fv(TH_BACK_GRAD, gb.colors.background_gradient);
301 gb.fresnel_mix_edit = ((U.gpu_flag & USER_GPU_FLAG_FRESNEL_EDIT) == 0) ? 0.0f : 1.0f;
302 ui::theme::get_color_4fv(TH_V3D_CLIPPING_BORDER, gb.colors.clipping_border);
303
304 /* Custom median color to slightly affect the edit mesh colors. */
305 gb.colors.edit_mesh_middle = interpolate(gb.colors.vert_select, gb.colors.wire_edit, 0.35f);
306 /* Desaturate. */
307 gb.colors.edit_mesh_middle = float4(
308 float3(dot(gb.colors.edit_mesh_middle.xyz(), float3(0.3333f))),
309 gb.colors.edit_mesh_middle.w);
310
311#ifdef WITH_FREESTYLE
312 ui::theme::get_color_4fv(TH_FREESTYLE, gb.colors.edge_freestyle),
313 gb.colors.edge_freestyle[3] = 1.0f;
314 ui::theme::get_color_4fv(TH_FREESTYLE, gb.colors.face_freestyle);
315#else
316 gb.colors.edge_freestyle = float4(0.0f);
317 gb.colors.face_freestyle = float4(0.0f);
318#endif
319
320 ui::theme::get_color_4fv(TH_TEXT, gb.colors.text);
321 ui::theme::get_color_4fv(TH_TEXT_HI, gb.colors.text_hi);
322
323 /* Bone colors */
324 ui::theme::get_color_4fv(TH_BONE_POSE, gb.colors.bone_pose);
325 ui::theme::get_color_4fv(TH_BONE_POSE_ACTIVE, gb.colors.bone_pose_active);
326 ui::theme::get_color_shade_4fv(TH_EDGE_SELECT, 60, gb.colors.bone_active);
327 ui::theme::get_color_shade_4fv(TH_EDGE_SELECT, -20, gb.colors.bone_select);
329 TH_WIRE, TH_BONE_POSE, 0.15f, 0, gb.colors.bone_pose_active_unsel);
331 TH_WIRE_EDIT, TH_EDGE_SELECT, 0.15f, 0, gb.colors.bone_active_unsel);
332 gb.colors.bone_pose_no_target = rgba_uchar_to_float(255, 150, 0, 80);
333 gb.colors.bone_pose_ik = rgba_uchar_to_float(255, 255, 0, 80);
334 gb.colors.bone_pose_spline_ik = rgba_uchar_to_float(200, 255, 0, 80);
335 gb.colors.bone_pose_constraint = rgba_uchar_to_float(0, 255, 120, 80);
336 ui::theme::get_color_4fv(TH_BONE_SOLID, gb.colors.bone_solid);
337 ui::theme::get_color_4fv(TH_BONE_LOCKED_WEIGHT, gb.colors.bone_locked);
338 gb.colors.bone_ik_line = float4(0.8f, 0.8f, 0.0f, 1.0f);
339 gb.colors.bone_ik_line_no_target = float4(0.8f, 0.5f, 0.2f, 1.0f);
340 gb.colors.bone_ik_line_spline = float4(0.8f, 0.8f, 0.2f, 1.0f);
341
342 /* Curve */
343 ui::theme::get_color_4fv(TH_HANDLE_FREE, gb.colors.handle_free);
344 ui::theme::get_color_4fv(TH_HANDLE_AUTO, gb.colors.handle_auto);
345 ui::theme::get_color_4fv(TH_HANDLE_VECT, gb.colors.handle_vect);
346 ui::theme::get_color_4fv(TH_HANDLE_ALIGN, gb.colors.handle_align);
347 ui::theme::get_color_4fv(TH_HANDLE_AUTOCLAMP, gb.colors.handle_autoclamp);
348 ui::theme::get_color_4fv(TH_HANDLE_SEL_FREE, gb.colors.handle_sel_free);
349 ui::theme::get_color_4fv(TH_HANDLE_SEL_AUTO, gb.colors.handle_sel_auto);
350 ui::theme::get_color_4fv(TH_HANDLE_SEL_VECT, gb.colors.handle_sel_vect);
351 ui::theme::get_color_4fv(TH_HANDLE_SEL_ALIGN, gb.colors.handle_sel_align);
352 ui::theme::get_color_4fv(TH_HANDLE_SEL_AUTOCLAMP, gb.colors.handle_sel_autoclamp);
353 ui::theme::get_color_4fv(TH_NURB_ULINE, gb.colors.nurb_uline);
354 ui::theme::get_color_4fv(TH_NURB_VLINE, gb.colors.nurb_vline);
355 ui::theme::get_color_4fv(TH_NURB_SEL_ULINE, gb.colors.nurb_sel_uline);
356 ui::theme::get_color_4fv(TH_NURB_SEL_VLINE, gb.colors.nurb_sel_vline);
357
358 ui::theme::get_color_4fv(TH_CFRAME, gb.colors.current_frame);
359 ui::theme::get_color_4fv(TH_FRAME_BEFORE, gb.colors.before_frame);
360 ui::theme::get_color_4fv(TH_FRAME_AFTER, gb.colors.after_frame);
361
362 /* Meta-ball. */
363 gb.colors.mball_radius = rgba_uchar_to_float(0xA0, 0x30, 0x30, 0xFF);
364 gb.colors.mball_radius_select = rgba_uchar_to_float(0xF0, 0xA0, 0xA0, 0xFF);
365 gb.colors.mball_stiffness = rgba_uchar_to_float(0x30, 0xA0, 0x30, 0xFF);
366 gb.colors.mball_stiffness_select = rgba_uchar_to_float(0xA0, 0xF0, 0xA0, 0xFF);
367
368 /* Grid */
369 ui::theme::get_color_shade_4fv(TH_GRID, 10, gb.colors.grid);
370 /* Emphasize division lines lighter instead of darker, if background is darker than grid. */
371 const bool is_bg_darker = reduce_add(gb.colors.grid.xyz()) + 0.12f >
372 reduce_add(gb.colors.background.xyz());
374 state.rv3d ? TH_GRID_MAJOR : TH_GRID, is_bg_darker ? 20 : -10, gb.colors.grid_emphasis);
375
376 /* Grid axes */
377 const bTheme *btheme = ui::theme::theme_get();
378 const float grid_axis_brightness = btheme->space_view3d.grid_axis_brightness;
379 const int grid_axis_offset_i = int((grid_axis_brightness * 2.0f - 1.0f) * 255.0f);
381 TH_GRID, TH_AXIS_X, 0.85, grid_axis_offset_i, gb.colors.grid_axis_x);
383 TH_GRID, TH_AXIS_Y, 0.85, grid_axis_offset_i, gb.colors.grid_axis_y);
385 TH_GRID, TH_AXIS_Z, 0.85, grid_axis_offset_i, gb.colors.grid_axis_z);
386
387 ui::theme::get_color_shade_alpha_4fv(TH_TRANSFORM, 0, -80, gb.colors.deselect);
388 ui::theme::get_color_shade_alpha_4fv(TH_WIRE, 0, -30, gb.colors.outline);
389 ui::theme::get_color_shade_alpha_4fv(TH_LIGHT, 0, 255, gb.colors.light_no_alpha);
390
391 /* UV colors */
392 ui::theme::get_color_4fv(TH_UV_SHADOW, gb.colors.uv_shadow);
393
394 /* Color management. */
395 {
396 float4 *color = reinterpret_cast<float4 *>(&gb.colors);
397 float4 *color_end = color + (sizeof(gb.colors) / sizeof(float4));
398 do {
399 /* TODO: more accurate transform. */
401 } while (++color <= color_end);
402 }
403
404 gb.sizes.pixel = 1.0f;
405 gb.sizes.object_center = ui::theme::get_value_f(TH_OBCENTER_DIA) + 1.0f;
406 gb.sizes.light_center = ui::theme::get_value_f(TH_OBCENTER_DIA) + 1.5f;
407 gb.sizes.light_circle = 9.0f;
408 gb.sizes.light_circle_shadow = (gb.sizes.light_circle + 3.0f);
409
410 /* M_SQRT2 to be at least the same size of the old square */
411 gb.sizes.vert = vertex_size_get();
412 gb.sizes.vertex_gpencil = ui::theme::get_value_f(TH_GP_VERTEX_SIZE);
413 gb.sizes.face_dot = ui::theme::get_value_f(TH_FACEDOT_SIZE);
414 gb.sizes.edge = max_ff(1.0f, ui::theme::get_value_f(TH_EDGE_WIDTH)) / 2.0f;
415
416 /* Pixel size. */
417 {
418 float *size = reinterpret_cast<float *>(&gb.sizes);
419 float *size_end = size + (sizeof(gb.sizes) / sizeof(float));
420 do {
421 *size *= U.pixelsize;
422 } while (++size <= size_end);
423 }
424
425 /* Pixel fraction. Use orthographic size in 3d, visible region size in 2D. */
426 if (state.rv3d) {
427 gb.pixel_fac = state.rv3d->pixsize;
428 }
429 else if (state.region) {
430 const View2D *v2d = &state.region->v2d;
431 gb.pixel_fac = (v2d->cur.xmax - v2d->cur.xmin) / float(v2d->mask.xmax - v2d->mask.xmin);
432 }
433 else {
434 gb.pixel_fac = 1.0f;
435 }
436
437 gb.size_viewport = ctx->viewport_size_get();
438 gb.size_viewport_inv = 1.0f / gb.size_viewport;
439
440 if (state.v3d) {
441 const View3DShading &shading = state.v3d->shading;
442 gb.backface_culling = (shading.type == OB_SOLID) &&
444
445 if (is_selection() || state.is_depth_only_drawing) {
446 /* This is bad as this makes a solid mode setting affect material preview / render mode
447 * selection and auto-depth. But users are relying on this to work in scene using backface
448 * culling in shading (see #136335 and #136418). */
449 gb.backface_culling = (shading.flag & V3D_SHADING_BACKFACE_CULLING);
450 }
451 }
452 else {
453 gb.backface_culling = false;
454 }
455
457}
458
460{
461 /* TODO(fclem): Against design. Should not sync depending on view. */
462 View &view = View::default_get();
465
468
470
477
478 auto begin_sync_layer = [&](OverlayLayer &layer) {
479 layer.armatures.begin_sync(resources, state);
480 layer.attribute_viewer.begin_sync(resources, state);
481 layer.attribute_texts.begin_sync(resources, state);
482 layer.axes.begin_sync(resources, state);
483 layer.bounds.begin_sync(resources, state);
484 layer.cameras.begin_sync(resources, state);
485 layer.curves.begin_sync(resources, state);
486 layer.text.begin_sync(resources, state);
487 layer.empties.begin_sync(resources, state);
488 layer.facing.begin_sync(resources, state);
489 layer.fade.begin_sync(resources, state);
490 layer.force_fields.begin_sync(resources, state);
491 layer.fluids.begin_sync(resources, state);
492 layer.grease_pencil.begin_sync(resources, state);
493 layer.gsplats.begin_sync(resources, state);
494 layer.lattices.begin_sync(resources, state);
495 layer.lights.begin_sync(resources, state);
496 layer.light_probes.begin_sync(resources, state);
497 layer.metaballs.begin_sync(resources, state);
498 layer.meshes.begin_sync(resources, state);
499 layer.mesh_uvs.begin_sync(resources, state);
500 layer.mode_transfer.begin_sync(resources, state);
501 layer.names.begin_sync(resources, state);
502 layer.paints.begin_sync(resources, state);
503 layer.particles.begin_sync(resources, state);
504 layer.pointclouds.begin_sync(resources, state);
505 layer.prepass.begin_sync(resources, state);
506 layer.relations.begin_sync(resources, state);
507 layer.speakers.begin_sync(resources, state);
508 layer.sculpts.begin_sync(resources, state);
509 layer.wireframe.begin_sync(resources, state);
510 };
511 begin_sync_layer(regular);
512 begin_sync_layer(infront);
513
517}
518
520{
521 const bool in_object_mode = ob_ref.object->mode == OB_MODE_OBJECT;
522 const bool in_edit_mode = ob_ref.object->mode == OB_MODE_EDIT;
523 const bool in_paint_mode = object_is_paint_mode(ob_ref.object);
524 const bool in_sculpt_mode = object_is_sculpt_mode(ob_ref);
525 const bool in_particle_edit_mode = object_is_particle_edit_mode(ob_ref);
526 const bool in_edit_paint_mode = object_is_edit_paint_mode(
527 ob_ref, in_edit_mode, in_paint_mode, in_sculpt_mode);
528 const bool needs_prepass = object_needs_prepass(ob_ref, in_paint_mode);
529
530 OverlayLayer &layer = object_is_in_front(ob_ref.object, state) ? infront : regular;
531
532 layer.mode_transfer.object_sync(manager, ob_ref, resources, state);
533
534 if (needs_prepass) {
535 layer.prepass.object_sync(manager, ob_ref, resources, state);
536 }
537
538 if (in_particle_edit_mode) {
539 layer.particles.edit_object_sync(manager, ob_ref, resources, state);
540 }
541
542 /* For 2D UV overlays. */
544 switch (ob_ref.object->type) {
545 case OB_MESH:
546 if (in_edit_paint_mode) {
547 /* TODO(fclem): Find a better place / condition. */
548 layer.mesh_uvs.edit_object_sync(manager, ob_ref, resources, state);
549 }
550 else if (in_object_mode) {
551 layer.mesh_uvs.object_sync(manager, ob_ref, resources, state);
552 }
553 default:
554 break;
555 }
556 }
557
558 if (in_paint_mode && !state.hide_overlays) {
559 switch (ob_ref.object->type) {
560 case OB_MESH:
561 /* TODO(fclem): Make it part of a #Meshes. */
562 layer.paints.object_sync(manager, ob_ref, resources, state);
563 break;
564 case OB_GREASE_PENCIL:
565 layer.grease_pencil.paint_object_sync(manager, ob_ref, resources, state);
566 break;
567 default:
568 break;
569 }
570 }
571
572 if (in_sculpt_mode) {
573 switch (ob_ref.object->type) {
574 case OB_MESH:
575 case OB_CURVES:
576 /* TODO(fclem): Make it part of a #Meshes. */
577 layer.sculpts.object_sync(manager, ob_ref, resources, state);
578 break;
579 case OB_GREASE_PENCIL:
580 layer.grease_pencil.sculpt_object_sync(manager, ob_ref, resources, state);
581 break;
582 default:
583 break;
584 }
585 }
586
587 if (in_edit_mode && !state.hide_overlays) {
588 switch (ob_ref.object->type) {
589 case OB_MESH:
590 layer.meshes.edit_object_sync(manager, ob_ref, resources, state);
591 break;
592 case OB_ARMATURE:
593 layer.armatures.edit_object_sync(manager, ob_ref, resources, state);
594 break;
595 case OB_SURF:
596 case OB_CURVES_LEGACY:
597 layer.curves.edit_object_sync_legacy(manager, ob_ref, resources);
598 break;
599 case OB_CURVES:
600 layer.curves.edit_object_sync(manager, ob_ref, resources, state);
601 break;
602 case OB_LATTICE:
603 layer.lattices.edit_object_sync(manager, ob_ref, resources, state);
604 break;
605 case OB_MBALL:
606 layer.metaballs.edit_object_sync(manager, ob_ref, resources, state);
607 break;
608 case OB_POINTCLOUD: {
610 if (pointcloud.type == PointCloudType::GSplat) {
611 layer.gsplats.edit_object_sync(manager, ob_ref, resources, state);
612 }
613 else {
614 layer.pointclouds.edit_object_sync(manager, ob_ref, resources, state);
615 }
616 } break;
617 case OB_FONT:
618 layer.text.edit_object_sync(manager, ob_ref, resources, state);
619 break;
620 case OB_GREASE_PENCIL:
621 layer.grease_pencil.edit_object_sync(manager, ob_ref, resources, state);
622 break;
623 default:
624 break;
625 }
626 }
627
629 layer.wireframe.object_sync_ex(
630 manager, ob_ref, resources, state, in_edit_paint_mode, in_edit_mode);
631 }
632
633 if (!state.hide_overlays) {
634 switch (ob_ref.object->type) {
635 case OB_EMPTY:
636 layer.empties.object_sync(manager, ob_ref, resources, state);
637 break;
638 case OB_CAMERA:
639 layer.cameras.object_sync(manager, ob_ref, resources, state);
640 break;
641 case OB_ARMATURE:
642 if (!in_edit_mode) {
643 layer.armatures.object_sync(manager, ob_ref, resources, state);
644 }
645 break;
646 case OB_LATTICE:
647 if (!in_edit_mode) {
648 layer.lattices.object_sync(manager, ob_ref, resources, state);
649 }
650 break;
651 case OB_LAMP:
652 layer.lights.object_sync(manager, ob_ref, resources, state);
653 break;
654 case OB_LIGHTPROBE:
655 layer.light_probes.object_sync(manager, ob_ref, resources, state);
656 break;
657 case OB_MBALL:
658 if (!in_edit_mode) {
659 layer.metaballs.object_sync(manager, ob_ref, resources, state);
660 }
661 break;
662 case OB_GREASE_PENCIL:
663 layer.grease_pencil.object_sync(manager, ob_ref, resources, state);
664 break;
665 case OB_SPEAKER:
666 layer.speakers.object_sync(manager, ob_ref, resources, state);
667 break;
668 default:
669 break;
670 }
671 layer.attribute_viewer.object_sync(manager, ob_ref, resources, state);
672 layer.attribute_texts.object_sync(manager, ob_ref, resources, state);
673 layer.bounds.object_sync(manager, ob_ref, resources, state);
674 layer.facing.object_sync(manager, ob_ref, resources, state);
675 layer.fade.object_sync(manager, ob_ref, resources, state);
676 layer.force_fields.object_sync(manager, ob_ref, resources, state);
677 layer.fluids.object_sync(manager, ob_ref, resources, state);
678 layer.particles.object_sync(manager, ob_ref, resources, state);
679 layer.relations.object_sync(manager, ob_ref, resources, state);
680 layer.axes.object_sync(manager, ob_ref, resources, state);
681 layer.names.object_sync(manager, ob_ref, resources, state);
682
683 motion_paths.object_sync(manager, ob_ref, resources, state);
684 origins.object_sync(manager, ob_ref, resources, state);
685
686 if (object_is_selected(ob_ref) && !in_edit_paint_mode) {
687 outline.object_sync(manager, ob_ref, resources, state);
688 }
689 }
690}
691
693{
696
697 auto end_sync_layer = [&](OverlayLayer &layer) {
698 layer.armatures.end_sync(resources, state);
699 layer.axes.end_sync(resources, state);
700 layer.bounds.end_sync(resources, state);
701 layer.cameras.end_sync(resources, state);
702 layer.text.end_sync(resources, state);
703 layer.empties.end_sync(resources, state);
704 layer.force_fields.end_sync(resources, state);
705 layer.lights.end_sync(resources, state);
706 layer.light_probes.end_sync(resources, state);
707 layer.mesh_uvs.end_sync(resources, state);
708 layer.metaballs.end_sync(resources, state);
709 layer.relations.end_sync(resources, state);
710 layer.fluids.end_sync(resources, state);
711 layer.speakers.end_sync(resources, state);
712 };
713 end_sync_layer(regular);
714 end_sync_layer(infront);
715
716 /* WORKAROUND: This prevents bad frame-buffer config inside workbench when xray is enabled.
717 * Better find a solution to this chicken-egg problem. */
718 {
719 const DRWContext *draw_ctx = DRW_context_get();
720 /* HACK we allocate the in front depth here to avoid the overhead when if is not needed. */
723
724 if (dtxl->depth_in_front == nullptr) {
725 int2 size = int2(draw_ctx->viewport_size_get());
726
727 dtxl->depth_in_front = GPU_texture_create_2d("txl.depth_in_front",
728 size.x,
729 size.y,
730 1,
731 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
733 nullptr);
734 }
735
737 &dfbl->in_front_fb,
738 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
739 }
740}
741
743{
744 /* TODO(fclem): Remove global access. */
745 View &view = View::default_get();
746
747 static gpu::DebugScope select_scope = {"Selection"};
748 static gpu::DebugScope draw_scope = {"Overlay"};
749 static gpu::DebugScope depth_scope = {"DepthOnly"};
750
752 depth_scope.begin_capture();
753 }
754 else if (resources.is_selection()) {
755 select_scope.begin_capture();
756 }
757 else {
758 draw_scope.begin_capture();
759 }
760
761 /* TODO(fclem): To be moved to overlay UBO. */
763
765
768
769 /* Hand off gsplat compute workload before draws. */
770 /* TODO(not_mark): Disabled compute pass for now, due to incompatibility with instancing. */
771 /* DRW_gsplat_ensure_ellipses(manager, view); */
772
773 /* Pre-Draw: Run the compute steps of all passes up-front
774 * to avoid constant GPU compute/raster context switching. */
775 {
776 manager.ensure_visibility(view);
777
778 auto pre_draw = [&](OverlayLayer &layer) {
779 layer.attribute_viewer.pre_draw(manager, view);
780 layer.cameras.pre_draw(manager, view);
781 layer.empties.pre_draw(manager, view);
782 layer.facing.pre_draw(manager, view);
783 layer.fade.pre_draw(manager, view);
784 layer.lattices.pre_draw(manager, view);
785 layer.gsplats.pre_draw(manager, view);
786 layer.light_probes.pre_draw(manager, view);
787 layer.particles.pre_draw(manager, view);
788 layer.pointclouds.pre_draw(manager, view);
789 layer.prepass.pre_draw(manager, view);
790 layer.wireframe.pre_draw(manager, view);
791 };
792
793 pre_draw(regular);
794 pre_draw(infront);
795
796 outline.pre_draw(manager, view);
797 }
798
800
802
803 /* TODO(fclem): Would be better to have a v2d overlay class instead of these conditions. */
804 switch (state.space_type) {
805 case SPACE_NODE:
806 draw_node(manager, view);
807 break;
808 case SPACE_IMAGE:
809 draw_v2d(manager, view);
810 break;
811 case SPACE_VIEW3D:
812 draw_v3d(manager, view);
813 break;
814 default:
816 }
817
819
821
823
825 depth_scope.end_capture();
826 }
827 else if (resources.is_selection()) {
828 select_scope.end_capture();
829 }
830 else {
831 draw_scope.end_capture();
832 }
833}
834
835void Instance::draw_node(Manager &manager, View &view)
836{
837 /* Don't clear background for the node editor. The node editor draws the background and we
838 * need to mask out the image from the already drawn overlay color buffer. */
840}
841
842void Instance::draw_v2d(Manager &manager, View &view)
843{
845 regular.mesh_uvs.draw_on_render(resources.render_fb, manager, view);
846
849
852 regular.mesh_uvs.draw(resources.overlay_output_fb, manager, view);
853
855
857}
858
859void Instance::draw_v3d(Manager &manager, View &view)
860{
861 double4 clear_color(0.0f);
862
863 auto draw = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
864 /* TODO(fclem): Depth aware outlines (see #130751). */
865 // layer.facing.draw(framebuffer, manager, view);
866 layer.fade.draw(framebuffer, manager, view);
867 layer.mode_transfer.draw(framebuffer, manager, view);
868 layer.text.draw(framebuffer, manager, view);
869 layer.paints.draw(framebuffer, manager, view);
870 layer.particles.draw(framebuffer, manager, view);
871 };
872
873 auto draw_line = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
874 layer.bounds.draw_line(framebuffer, manager, view);
875 layer.wireframe.draw_line(framebuffer, manager, view);
876 layer.cameras.draw_line(framebuffer, manager, view);
877 layer.empties.draw_line(framebuffer, manager, view);
878 layer.axes.draw_line(framebuffer, manager, view);
879 layer.force_fields.draw_line(framebuffer, manager, view);
880 layer.gsplats.draw_line(framebuffer, manager, view);
881 layer.lights.draw_line(framebuffer, manager, view);
882 layer.light_probes.draw_line(framebuffer, manager, view);
883 layer.speakers.draw_line(framebuffer, manager, view);
884 layer.lattices.draw_line(framebuffer, manager, view);
885 layer.metaballs.draw_line(framebuffer, manager, view);
886 layer.pointclouds.draw_line(framebuffer, manager, view);
887 layer.relations.draw_line(framebuffer, manager, view);
888 layer.fluids.draw_line(framebuffer, manager, view);
889 layer.particles.draw_line(framebuffer, manager, view);
890 layer.attribute_viewer.draw_line(framebuffer, manager, view);
891 layer.armatures.draw_line(framebuffer, manager, view);
892 layer.sculpts.draw_line(framebuffer, manager, view);
893 layer.grease_pencil.draw_line(framebuffer, manager, view);
894 /* NOTE: Temporarily moved after grid drawing (See #136764). */
895 // layer.meshes.draw_line(framebuffer, manager, view);
896 layer.curves.draw_line(framebuffer, manager, view);
897 };
898
899 auto draw_line_only = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
900 layer.meshes.draw_line_only(framebuffer, manager, view);
901 };
902
903 auto draw_color_only = [&](OverlayLayer &layer, Framebuffer &framebuffer) {
904 layer.light_probes.draw_color_only(framebuffer, manager, view);
905 layer.curves.draw_color_only(framebuffer, manager, view);
906 layer.grease_pencil.draw_color_only(framebuffer, manager, view);
907 };
908
909 {
910 /* Render pass. Draws directly on render result (instead of overlay result). */
911 /* TODO(fclem): Split overlay and rename draw functions. */
912 regular.cameras.draw_scene_background_images(resources.render_fb, manager, view);
913 infront.cameras.draw_scene_background_images(resources.render_in_front_fb, manager, view);
914
915 regular.sculpts.draw_on_render(resources.render_fb, manager, view);
916 infront.sculpts.draw_on_render(resources.render_in_front_fb, manager, view);
917 }
918 {
919 /* Overlay Line prepass. */
921 if (state.xray_enabled) {
922 /* Rendering to a new depth buffer that needs to be cleared. */
924 }
925 else {
927 /* If the render engine is not outputting correct depth,
928 * clear the depth and render a depth prepass. */
930 }
931 else {
933 }
934 }
935
938 }
939
940 regular.prepass.draw_line(resources.overlay_line_fb, manager, view);
941
942 /* TODO(fclem): Split overlay and rename draw functions. */
943 /* TODO(fclem): Draw on line framebuffer. */
944 regular.empties.draw_images(resources.overlay_fb, manager, view);
945
947 /* If workbench is not enabled, the infront buffer might contain garbage. */
950 }
951
952 infront.prepass.draw_line(resources.overlay_line_in_front_fb, manager, view);
953 }
954 {
955 /* Copy depth at the end of the prepass to avoid splitting the main render pass. */
956 /* TODO(fclem): Better get rid of it. */
957 regular.wireframe.copy_depth(resources.depth_target_tx);
958 infront.wireframe.copy_depth(resources.depth_target_in_front_tx);
959 }
960 {
961 /* TODO(fclem): This is really bad for performance as the outline pass will then split the
962 * render pass and do a framebuffer switch. This also only fix the issue for non-infront
963 * objects.
964 * We need to figure a way to merge the outline with correct depth awareness (see #130751). */
965 regular.facing.draw(resources.overlay_fb, manager, view);
966
967 /* Line only pass. */
969 }
970 {
971 /* Overlay (+Line) pass. */
972 draw(regular, resources.overlay_fb);
973 draw_line(regular, resources.overlay_line_fb);
974
975 /* Here as it does depth+blending, and should draw after most overlay line passes.. */
977 grid.draw_line(resources.overlay_line_fb, manager, view);
978 }
979
980 /* Here because of custom order of regular.facing. */
981 infront.facing.draw(resources.overlay_fb, manager, view);
982
984 draw_line(infront, resources.overlay_line_in_front_fb);
985 }
986 {
987 /* Color only pass. */
990
991 regular.meshes.draw_line(resources.overlay_line_fb, manager, view);
992 infront.meshes.draw_line(resources.overlay_line_in_front_fb, manager, view);
993
994 draw_color_only(regular, resources.overlay_color_only_fb);
995 draw_color_only(infront, resources.overlay_color_only_fb);
996 draw_line_only(regular, resources.overlay_line_only_fb);
997 draw_line_only(infront, resources.overlay_line_only_fb);
998
999 /* TODO(fclem): Split overlay and rename draw functions. */
1000 regular.empties.draw_in_front_images(resources.overlay_color_only_fb, manager, view);
1001 infront.empties.draw_in_front_images(resources.overlay_color_only_fb, manager, view);
1002 regular.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view);
1003 infront.cameras.draw_in_front(resources.overlay_color_only_fb, manager, view);
1004
1006 }
1007
1008 if (state.is_depth_only_drawing == false) {
1009 /* Output pass. */
1012
1013 /* TODO(fclem): Split overlay and rename draw functions. */
1014 regular.cameras.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
1015 infront.cameras.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
1016 regular.empties.draw_background_images(resources.overlay_output_color_only_fb, manager, view);
1017
1021
1023
1024 if (state.vignette_enabled) {
1026 }
1027 }
1028}
1029
1030void Instance::draw_text(Framebuffer &framebuffer)
1031{
1032 if (state.show_text == false) {
1033 return;
1034 }
1035 GPU_framebuffer_bind(framebuffer);
1036
1039}
1040
1041bool Instance::object_is_selected(const ObjectRef &ob_ref)
1042{
1043 return (ob_ref.object->base_flag & BASE_SELECTED);
1044}
1045
1046bool Instance::object_is_paint_mode(const Object *object)
1047{
1048 return (object == state.object_active) &&
1050}
1051
1052bool Instance::object_is_sculpt_mode(const ObjectRef &ob_ref)
1053{
1055 const Object *active_object = state.object_active;
1056 const bool is_active_object = ob_ref.object == active_object;
1057
1058 bool is_active_geonode_preview = ob_ref.preview_base_geometry() != nullptr &&
1059 ob_ref.is_active(state.object_active);
1060 return is_active_object || is_active_geonode_preview;
1061 }
1062
1064 const Object *active_object = state.object_active;
1065 const bool is_active_object = ob_ref.object == active_object;
1066 return is_active_object;
1067 }
1068
1069 return false;
1070}
1071
1072bool Instance::object_is_particle_edit_mode(const ObjectRef &ob_ref)
1073{
1074 return (ob_ref.object->mode == OB_MODE_PARTICLE_EDIT) && (state.ctx_mode == CTX_MODE_PARTICLE);
1075}
1076
1077bool Instance::object_is_sculpt_mode(const Object *object)
1078{
1079 if (object->runtime->sculpt_session &&
1080 (object->runtime->sculpt_session->mode_type == OB_MODE_SCULPT))
1081 {
1082 return object == state.object_active;
1083 }
1084 return false;
1085}
1086
1087bool Instance::object_is_edit_paint_mode(const ObjectRef &ob_ref,
1088 bool in_edit_mode,
1089 bool in_paint_mode,
1090 bool in_sculpt_mode)
1091{
1092 bool in_edit_paint_mode = in_edit_mode || in_paint_mode || in_sculpt_mode;
1093 /* Disable outlines for objects instanced by an object in sculpt, paint or edit mode. */
1094 return in_edit_paint_mode || ob_ref.parent_is_in_edit_paint_mode(
1096}
1097
1098bool Instance::object_is_edit_mode(const Object *object)
1099{
1100 if (DRW_object_is_in_edit_mode(object)) {
1101 /* Also check for context mode as the object mode is not 100% reliable. (see T72490) */
1102 switch (object->type) {
1103 case OB_MESH:
1105 case OB_ARMATURE:
1107 case OB_CURVES_LEGACY:
1109 case OB_SURF:
1111 case OB_LATTICE:
1113 case OB_MBALL:
1115 case OB_FONT:
1117 case OB_CURVES:
1119 case OB_POINTCLOUD:
1121 case OB_GREASE_PENCIL:
1123 case OB_VOLUME:
1124 /* No edit mode yet. */
1125 return false;
1126 default:
1127 break;
1128 }
1129 }
1130 return false;
1131}
1132
1133bool Instance::object_is_in_front(const Object *object, const State &state)
1134{
1135 switch (object->type) {
1136 case OB_ARMATURE:
1137 return (object->dtx & OB_DRAW_IN_FRONT) ||
1138 (state.do_pose_xray && Armatures::is_pose_mode(object, state));
1139 default:
1140 return state.use_in_front && (object->dtx & OB_DRAW_IN_FRONT);
1141 }
1142}
1143
1144bool Instance::object_needs_prepass(const ObjectRef &ob_ref, bool in_paint_mode)
1145{
1146 if (resources.is_selection() && state.is_wireframe_mode && !state.is_solid()) {
1147 /* Selection in wireframe mode only use wires unless xray opacity is 1. */
1148 return false;
1149 }
1150
1151 if (resources.is_selection() || state.is_depth_only_drawing) {
1152 if (ob_ref.object->visibility_flag & OB_HIDE_SURFACE_PICK) {
1153 /* Special flag to avoid surfaces to contribute to depth picking and selection. */
1154 return false;
1155 }
1156 /* Selection and depth picking always need a prepass.
1157 * Note that depth writing and depth test might be disable for certain selection mode. */
1158 return true;
1159 }
1160
1161 if (in_paint_mode) {
1162 /* Allow paint overlays to draw with depth equal test. */
1163 if (object_is_rendered_transparent(ob_ref.object, state) ||
1164 object_is_in_front(ob_ref.object, state))
1165 {
1166 return true;
1167 }
1168 }
1169
1170 if (!state.xray_enabled) {
1171 /* Force depth prepass if depth buffer form render engine is not available. */
1172 if (!state.is_render_depth_available && (ob_ref.object->dt >= OB_SOLID)) {
1173 return true;
1174 }
1175 }
1176
1177 return false;
1178}
1179
1180bool Instance::object_is_rendered_transparent(const Object *object, const State &state)
1181{
1182 if (state.v3d == nullptr) {
1183 return false;
1184 }
1185
1186 if (!state.is_solid()) {
1187 return true;
1188 }
1189
1190 if (ELEM(object->dt, OB_WIRE, OB_BOUNDBOX)) {
1191 return true;
1192 }
1193
1194 const View3DShading &shading = state.v3d->shading;
1195
1196 if (shading.type == OB_WIRE) {
1197 return true;
1198 }
1199
1200 if (shading.type > OB_SOLID) {
1201 return false;
1202 }
1203
1204 if (shading.color_type == V3D_SHADING_OBJECT_COLOR) {
1205 return object->color[3] < 1.0f;
1206 }
1207
1208 if (shading.color_type == V3D_SHADING_MATERIAL_COLOR) {
1209 if (object->type == OB_MESH) {
1210 const int materials_num = BKE_object_material_used_with_fallback_eval(*object);
1211 for (int i = 0; i < materials_num; i++) {
1212 Material *mat = BKE_object_material_get_eval(const_cast<Object *>(object), i + 1);
1213 if (mat && mat->a < 1.0f) {
1214 return true;
1215 }
1216 }
1217 }
1218 }
1219
1220 return false;
1221}
1222
1223} // namespace blender::draw::overlay
#define M_SQRT1_2
#define OB_MODE_ALL_PAINT_MESH
#define OB_MODE_ALL_PAINT_GPENCIL
#define RV3D_LOCK_FLAGS(rv3d)
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
#define XRAY_ACTIVE(v3d)
#define SHADING_XRAY_FLAG_ENABLED(shading)
#define XRAY_ALPHA(v3d)
#define GPU_framebuffer_ensure_config(_fb,...)
#define BLI_assert_unreachable()
#define ELEM(...)
#define STREQ(a, b)
constexpr IndexRange()=default
static DebugDraw & get()
void display_to_view(View &view)
void ensure_visibility(View &view)
bool ensure_2d(gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
bool ensure_1d(gpu::TextureFormat format, int extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
const float4x4 & winmat(int view_id=0) const
Definition draw_view.hh:148
static View & default_get()
Definition draw_view.cc:317
const float4x4 & viewinv(int view_id=0) const
Definition draw_view.hh:142
void begin_sync(Resources &res, const State &state) final
void draw_output(Framebuffer &framebuffer, Manager &manager, View &) final
static bool is_pose_mode(const Object *armature_ob, const State &state)
void draw_vignette(Framebuffer &framebuffer, Manager &manager, View &view)
void draw_output(Framebuffer &framebuffer, Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
void begin_sync(Resources &res, const State &state) final
void draw_output(Framebuffer &framebuffer, Manager &manager, View &) final
static void compute_depth_planes(Manager &manager, View &view, Resources &res, const State &)
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
void begin_sync(Resources &res, const State &state) final
void draw_on_render(gpu::FrameBuffer *framebuffer, Manager &manager, View &view) final
void draw(Manager &manager) final
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &, const State &state) final
void begin_sync(Resources &res, const State &state) final
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
void begin_sync(Resources &, const State &state) final
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void end_sync(Resources &res, const State &state) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) final
void flat_objects_pass_sync(Manager &manager, View &view, Resources &res, const State &state)
void pre_draw(Manager &manager, View &view) final
void begin_sync(Resources &res, const State &state) final
void draw_line_only_ex(Framebuffer &framebuffer, Resources &res, Manager &manager, View &view)
void begin_sync(Resources &res, const State &state) final
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &) final
Simple API to draw debug shapes and log in the viewport.
#define layer
#define pow
float dot(VecOp< float, D >, VecOp< float, D >) RET
bool is_equal(float a, float b, const float epsilon)
Quaternion interpolate(Quaternion a, Quaternion b, float t)
float reduce_add(float2 a)
const int state
#define unit_float_to_uchar_clamp_v4(v1, v2)
void get_color_4fv(int colorid, float col[4])
void get_color_blend_shade_3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
float get_value_f(int colorid)
void get_color_shade_4fv(int colorid, int offset, float col[4])
const bTheme * theme_get()
void get_color_blend_shade_4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
void get_color_shade_alpha_4fv(int colorid, int coloffset, int alphaoffset, float col[4])
@ V3D_OVERLAY_HIDE_OBJECT_ORIGINS
@ V3D_OVERLAY_HIDE_MOTION_PATHS
@ V3D_OVERLAY_HIDE_OBJECT_XTRAS
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
UserDef U
Definition blender.cc:58
int BKE_render_preview_pixel_size(const RenderData *r)
Definition scene.cc:3183
VecBase< uint8_t, 4 > uchar4
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
int BKE_object_material_used_with_fallback_eval(const Object &ob)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
bool assign_if_different(T &old_value, T &&new_value)
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
@ RE_WRITE_VIEWPORT_DEPTH
Definition RE_engine.h:58
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
void DRW_text_cache_destroy(DRWTextStore *dt)
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
RenderEngineType * ED_view3d_engine_type(const Scene *scene, int drawtype)
@ TH_HANDLE_SEL_FREE
@ TH_VERTEX_SELECT
@ TH_HANDLE_SEL_VECT
@ TH_EDITMESH_ACTIVE
@ TH_FACE_MODE_SELECT
@ TH_GP_VERTEX_SELECT
@ TH_HANDLE_SEL_AUTO
@ TH_NURB_SEL_VLINE
@ TH_TRANSPARENT_CHECKER_SIZE
@ TH_HANDLE_SEL_AUTOCLAMP
@ TH_EDGE_MODE_SELECT
@ TH_TRANSPARENT_CHECKER_SECONDARY
@ TH_BONE_POSE_ACTIVE
@ TH_HANDLE_AUTOCLAMP
@ TH_HANDLE_SEL_ALIGN
@ TH_V3D_CLIPPING_BORDER
@ TH_VERTEX_UNREFERENCED
@ TH_BONE_LOCKED_WEIGHT
@ TH_TRANSPARENT_CHECKER_PRIMARY
@ TH_NURB_SEL_ULINE
@ TH_FACE_RETOPOLOGY
@ TH_GP_VERTEX_SIZE
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
Definition colorband.cc:399
@ SI_OVERLAY_SHOW_OVERLAYS
@ V3D_SHADING_BACKFACE_CULLING
@ CTX_MODE_PARTICLE
@ CTX_MODE_EDIT_TEXT
@ CTX_MODE_EDIT_SURFACE
@ CTX_MODE_EDIT_ARMATURE
@ CTX_MODE_EDIT_CURVES
@ CTX_MODE_EDIT_LATTICE
@ CTX_MODE_EDIT_POINTCLOUD
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_EDIT_METABALL
@ CTX_MODE_EDIT_GREASE_PENCIL
@ CTX_MODE_EDIT_CURVE
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1717
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
unsigned char uchar
Definition BKE_text.h:58
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_GENERAL
T & DRW_object_get_data_for_drawing(const Object &object)
Main * DEG_get_bmain(const Depsgraph *graph)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:61
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_PARTICLE_EDIT
BMesh const char void * data
@ USER_GPU_FLAG_FRESNEL_EDIT
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
int BLI_thread_is_main()
Definition threads.cc:184
void DRW_submission_end()
void DRW_text_cache_draw(DRWTextStore *dt, const ARegion *region, const View3D *v3d)
const DRWContext * DRW_context_get()
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_OBJECT_COLOR
void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth)
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:3082
void _DNA_internal_memzero(void *dst, size_t size)
Definition dna_utils.cc:271
MINLINE float max_ff(float a, float b)
void ED_space_image_get_uv_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
Material * BKE_object_material_get_eval(Object *ob, short act)
void DRW_submission_start()
DRWTextStore * DRW_text_cache_create()
bool DRW_object_is_in_edit_mode(const Object *ob)
void GPU_framebuffer_clear_color_depth(gpu::FrameBuffer *fb, const double4 clear_col, float clear_depth)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
float DEG_get_ctime(const Depsgraph *graph)
VecBase< double, 4 > double4
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const NodeType * type
Definition graph/node.h:179
float grid_axis_brightness
ThemeSpace space_view3d
eColorBand_ColorMode color_mode
eColorBand_Interp ipotype
eColorBand_HueInterp ipotype_hue
bool is_depth() const
DefaultTextureList * viewport_texture_list_get() const
RegionView3D * rv3d
struct blender::DRWContext::@231153257105305272346150064304121064225151163351 options
ViewLayer * view_layer
Depsgraph * depsgraph
bool is_image_render() const
eObjectMode object_mode
float2 viewport_size_get() const
bToolRef * active_tool
bool is_material_select() const
DefaultFramebufferList * viewport_framebuffer_list_get() const
bool is_viewport_image_render() const
enum blender::DRWContext::Mode mode
SpaceLink * space_data
struct RenderData r
eSpaceImageOverlay_Flag flag
SpaceImageOverlay overlay
struct ColorBand coba_weight
eView3DOverlay_Flag flag
eView3DShading_Flag flag
eView3D_GridFlag gridflag
View3DOverlay overlay
eView3D_Flag2 flag2
View3DShading shading
float polygon_offset_factor(const float4x4 &winmat)
Definition draw_view.hh:223
void begin_sync(int clipping_plane_count)
void acquire(const DRWContext *draw_ctx, const State &state)
void update_theme_settings(const DRWContext *ctx, const State &state)
draw::UniformArrayBuffer< float4, 6 > clip_planes_buf
void init(bool clipping_enabled)
draw::UniformBuffer< UniformData > globals_buf
void update_clip_planes(const State &state)
View::OffsetData offset_data_get() const