Blender V4.3
overlay_next_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
9#pragma once
10
12
13namespace blender::draw::overlay {
14
16 private:
17 PassSimple ps_ = {"ModeTransfer"};
18
19 float4 flash_color_;
20
21 double current_time_ = 0.0;
22
23 bool enabled_ = false;
24
25 /* True if any object used was synced using this overlay. */
26 bool any_animated_ = false;
27
28 public:
29 void begin_sync(Resources &res, const State &state)
30 {
31 enabled_ = state.v3d && (res.selection_type == SelectionType::DISABLED);
32
33 if (!enabled_) {
34 /* Not used. But release the data. */
35 ps_.init();
36 return;
37 }
38
40 srgb_to_linearrgb_v4(flash_color_, flash_color_);
41
42 current_time_ = BLI_time_now_seconds();
43
44 ps_.init();
46 state.clipping_plane_count);
47 ps_.shader_set(res.shaders.uniform_color.get());
48 ps_.bind_ubo("globalsBlock", &res.globals_buf);
49
50 any_animated_ = false;
51 }
52
53 void object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state)
54 {
55 if (!enabled_) {
56 return;
57 }
58
59 const bool renderable = DRW_object_is_renderable(ob_ref.object);
60 const bool draw_surface = (ob_ref.object->dt >= OB_WIRE) &&
61 (renderable || (ob_ref.object->dt == OB_WIRE));
62 if (!draw_surface) {
63 return;
64 }
65
66 const float time = current_time_ - ob_ref.object->runtime->overlay_mode_transfer_start_time;
67 const float alpha = alpha_from_time_get(time);
68 if (alpha == 0.0f) {
69 return;
70 }
71
72 ps_.push_constant("ucolor", float4(flash_color_.xyz() * alpha, alpha));
73
74 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob_ref.object, state.rv3d) &&
76 if (use_sculpt_pbvh) {
77 ResourceHandle handle = manager.resource_handle_for_sculpt(ob_ref);
78
80 ps_.draw(batch.batch, handle);
81 }
82 }
83 else {
84 gpu::Batch *geom = DRW_cache_object_surface_get((Object *)ob_ref.object);
85 if (geom) {
86 ps_.draw(geom, manager.unique_handle(ob_ref));
87 }
88 }
89
90 any_animated_ = true;
91 }
92
93 void draw(Framebuffer &framebuffer, Manager &manager, View &view)
94 {
95 if (!enabled_) {
96 return;
97 }
98
99 GPU_framebuffer_bind(framebuffer);
100 manager.submit(ps_, view);
101
102 if (any_animated_) {
103 /* Request redraws until the object fades out. */
105 }
106 }
107
108 private:
109 static constexpr float flash_length = 0.55f;
110 static constexpr float flash_alpha = 0.25f;
111
112 static float alpha_from_time_get(const float anim_time)
113 {
114 if (anim_time > flash_length) {
115 return 0.0f;
116 }
117 if (anim_time < 0.0f) {
118 return 0.0f;
119 }
120 return (1.0f - (anim_time / flash_length)) * flash_alpha;
121 }
122};
123
124} // namespace blender::draw::overlay
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2862
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
double BLI_time_now_seconds(void)
Definition time.c:65
@ OB_WIRE
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_VERTEX_SELECT
ResourceHandle unique_handle(const ObjectRef &ref)
ResourceHandle resource_handle_for_sculpt(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
Definition draw_pass.hh:760
void state_set(DRWState state, int clip_plane_count=0)
Definition draw_pass.hh:954
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void push_constant(const char *name, const float &data)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
void object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void begin_sync(Resources &res, const State &state)
blender::gpu::Batch * DRW_cache_object_surface_get(Object *ob)
bool DRW_object_is_renderable(const Object *ob)
bool DRW_state_is_image_render()
void DRW_viewport_request_redraw()
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
struct @620::@622 batch
static ulong state[N]
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)
VecBase< float, 4 > float4
ObjectRuntimeHandle * runtime
VecBase< T, 3 > xyz() const