Blender V5.0
overlay_speaker.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 "DNA_speaker_types.h"
12
13#include "overlay_base.hh"
14
15namespace blender::draw::overlay {
16
21 using SpeakerInstanceBuf = ShapeInstanceBuf<ExtraInstanceData>;
22
23 private:
24 const SelectionType selection_type_;
25
26 PassSimple ps_ = {"Speakers"};
27
28 SpeakerInstanceBuf speaker_buf_ = {selection_type_, "speaker_data_buf"};
29
30 public:
31 Speakers(const SelectionType selection_type) : selection_type_(selection_type) {};
32
33 void begin_sync(Resources & /*res*/, const State &state) final
34 {
35 enabled_ = state.is_space_v3d() && state.show_extras();
36
37 if (!enabled_) {
38 return;
39 }
40
41 speaker_buf_.clear();
42 }
43
44 void object_sync(Manager & /*manager*/,
45 const ObjectRef &ob_ref,
46 Resources &res,
47 const State &state) final
48 {
49 if (!enabled_) {
50 return;
51 }
52
53 const float4 color = res.object_wire_color(ob_ref, state);
54 const select::ID select_id = res.select_id(ob_ref);
55
56 speaker_buf_.append({ob_ref.object->object_to_world(), color, 1.0f}, select_id);
57 }
58
59 void end_sync(Resources &res, const State &state) final
60 {
61 if (!enabled_) {
62 return;
63 }
64
65 ps_.init();
67 state.clipping_plane_count);
68 ps_.shader_set(res.shaders->extra_shape.get());
69 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
70 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
71 res.select_bind(ps_);
72
73 speaker_buf_.end_sync(ps_, res.shapes.speaker.get());
74 }
75
76 void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
77 {
78 if (!enabled_) {
79 return;
80 }
81
82 GPU_framebuffer_bind(framebuffer);
83 manager.submit(ps_, view);
84 }
85};
86
87} // namespace blender::draw::overlay
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void begin_sync(Resources &, const State &state) final
void end_sync(Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
Speakers(const SelectionType selection_type)
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
#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
static ulong state[N]
select::SelectionType SelectionType
detail::Pass< command::DrawCommandBuf > PassSimple
VecBase< float, 4 > float4