Blender V5.0
overlay_mode_transfer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_map.hh"
12
13#include "BKE_paint.hh"
14
15#include "draw_cache.hh"
16#include "draw_sculpt.hh"
17
18#include "overlay_base.hh"
19
20namespace blender::draw::overlay {
21
27 private:
28 PassSimple ps_ = {"ModeTransfer"};
29
30 Map<std::string, float, 1> object_factors_;
31
32 float4 flash_color_;
33
34 public:
35 void begin_sync(Resources &res, const State &state) final;
36
37 void object_sync(Manager &manager,
38 const ObjectRef &ob_ref,
39 Resources & /*res*/,
40 const State &state) final
41 {
42 if (!enabled_) {
43 return;
44 }
45
46 const std::optional<float> alpha_opt = object_factors_.lookup_try_as(ob_ref.object->id.name);
47 if (!alpha_opt) {
48 return;
49 }
50
51 const bool renderable = DRW_object_is_renderable(ob_ref.object);
52 const bool draw_surface = (ob_ref.object->dt >= OB_WIRE) &&
53 (renderable || (ob_ref.object->dt == OB_WIRE));
54 if (!draw_surface) {
55 return;
56 }
57
58 constexpr float flash_alpha = 0.25f;
59 const float alpha = *alpha_opt * flash_alpha;
60
61 ps_.push_constant("ucolor", float4(flash_color_.xyz() * alpha, alpha));
62
63 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob_ref.object, state.rv3d) &&
64 !state.is_image_render;
65 if (use_sculpt_pbvh) {
66 ResourceHandleRange handle = manager.unique_handle_for_sculpt(ob_ref);
67
69 ps_.draw(batch.batch, handle);
70 }
71 }
72 else {
73 gpu::Batch *geom = DRW_cache_object_surface_get((Object *)ob_ref.object);
74 if (geom) {
75 ps_.draw(geom, manager.unique_handle(ob_ref));
76 }
77 }
78 }
79
80 void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
81 {
82 if (!enabled_) {
83 return;
84 }
85
86 GPU_framebuffer_bind(framebuffer);
87 manager.submit(ps_, view);
88
89 /* Request redraws until the object fades out (enabled_ will be reset to false). */
91 }
92};
93
94} // namespace blender::draw::overlay
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:3068
@ OB_WIRE
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &, const State &state) final
void begin_sync(Resources &res, const State &state) final
void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
bool DRW_object_is_renderable(const Object *ob)
void DRW_viewport_request_redraw()
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
static ulong state[N]
detail::Pass< command::DrawCommandBuf > PassSimple
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
VecBase< float, 4 > float4