Blender V4.5
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_time.h"
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 float4 flash_color_;
31
32 double current_time_ = 0.0;
33
34 /* True if any object used was synced using this overlay. */
35 bool any_animated_ = false;
36
37 public:
38 void begin_sync(Resources &res, const State &state) final
39 {
40 enabled_ = state.is_space_v3d() && !res.is_selection();
41
42 if (!enabled_) {
43 /* Not used. But release the data. */
44 ps_.init();
45 return;
46 }
47
49 srgb_to_linearrgb_v4(flash_color_, flash_color_);
50
51 current_time_ = BLI_time_now_seconds();
52
53 ps_.init();
55 state.clipping_plane_count);
56 ps_.shader_set(res.shaders->uniform_color.get());
57 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
58 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
59
60 any_animated_ = false;
61 }
62
63 void object_sync(Manager &manager,
64 const ObjectRef &ob_ref,
65 Resources & /*res*/,
66 const State &state) final
67 {
68 if (!enabled_) {
69 return;
70 }
71
72 const bool renderable = DRW_object_is_renderable(ob_ref.object);
73 const bool draw_surface = (ob_ref.object->dt >= OB_WIRE) &&
74 (renderable || (ob_ref.object->dt == OB_WIRE));
75 if (!draw_surface) {
76 return;
77 }
78
79 const float time = current_time_ - ob_ref.object->runtime->overlay_mode_transfer_start_time;
80 const float alpha = alpha_from_time_get(time);
81 if (alpha == 0.0f) {
82 return;
83 }
84
85 ps_.push_constant("ucolor", float4(flash_color_.xyz() * alpha, alpha));
86
87 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob_ref.object, state.rv3d) &&
88 !state.is_image_render;
89 if (use_sculpt_pbvh) {
90 ResourceHandle handle = manager.resource_handle_for_sculpt(ob_ref);
91
93 ps_.draw(batch.batch, handle);
94 }
95 }
96 else {
97 gpu::Batch *geom = DRW_cache_object_surface_get((Object *)ob_ref.object);
98 if (geom) {
99 ps_.draw(geom, manager.unique_handle(ob_ref));
100 }
101 }
102
103 any_animated_ = true;
104 }
105
106 void draw(Framebuffer &framebuffer, Manager &manager, View &view) final
107 {
108 if (!enabled_) {
109 return;
110 }
111
112 GPU_framebuffer_bind(framebuffer);
113 manager.submit(ps_, view);
114
115 if (any_animated_) {
116 /* Request redraws until the object fades out. */
118 }
119 }
120
121 private:
122 static constexpr float flash_length = 0.55f;
123 static constexpr float flash_alpha = 0.25f;
124
125 static float alpha_from_time_get(const float anim_time)
126 {
127 if (anim_time > flash_length) {
128 return 0.0f;
129 }
130 if (anim_time < 0.0f) {
131 return 0.0f;
132 }
133 return (1.0f - (anim_time / flash_length)) * flash_alpha;
134 }
135};
136
137} // namespace blender::draw::overlay
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2928
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
Platform independent time functions.
double BLI_time_now_seconds(void)
Definition time.cc:65
@ OB_WIRE
static AppView * view
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_VERTEX_SELECT
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()
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
@ 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 @064345207361167251075330302113175271221317160336::@113254110077376341056327177062323111323010325277 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