Blender V5.3
overlay_origin.hh
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#pragma once
10
11#include "BKE_layer.hh"
12
13#include "overlay_base.hh"
14
15namespace blender::draw::overlay {
16
22 private:
24 select::SelectBuf select_buf_;
25
26 PassSimple ps_ = {"Origins"};
27
28 public:
29 Origins(SelectionType selection_type) : select_buf_(selection_type) {}
30
31 void begin_sync(Resources & /*res*/, const State &state) final
32 {
33 const bool is_paint_mode = (state.object_mode & (OB_MODE_ALL_PAINT)) != 0;
34 enabled_ = state.is_space_v3d() && !is_paint_mode && state.show_object_origins();
35 point_buf_.clear();
36 }
37
38 void object_sync(Manager & /*manager*/,
39 const ObjectRef &ob_ref,
40 Resources &res,
41 const State &state) final
42 {
43 if (!enabled_) {
44 return;
45 }
46
47 /* Don't show object extras in set's. */
48 if (is_from_dupli_or_set(ob_ref)) {
49 return;
50 }
51
52 const Object *ob = ob_ref.object;
53 const bool is_library = ID_REAL_USERS(&ob->id) > 1 || ID_IS_LINKED(ob);
55 *DEG_get_bmain(state.depsgraph), state.scene, const_cast<ViewLayer *>(state.view_layer));
56 const float4 location = float4(ob->object_to_world().location(), 0.0f);
57
58 if (ob == BKE_view_layer_active_object_get(state.view_layer)) {
59 select_buf_.select_append(res.select_id(ob_ref));
60 point_buf_.append(VertexData{location, res.theme.colors.active_object});
61 }
62 else if (ob->base_flag & BASE_SELECTED) {
63 select_buf_.select_append(res.select_id(ob_ref));
64 point_buf_.append(VertexData{location,
65 is_library ? res.theme.colors.library_select :
66 res.theme.colors.object_select});
67 }
68 else if (state.v3d_flag & V3D_DRAW_CENTERS) {
69 select_buf_.select_append(res.select_id(ob_ref));
70 point_buf_.append(
71 VertexData{location, is_library ? res.theme.colors.library : res.theme.colors.deselect});
72 }
73 }
74
75 void end_sync(Resources &res, const State &state) final
76 {
77 if (!enabled_) {
78 return;
79 }
80 ps_.init();
81 ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
82 res.select_bind(ps_);
83 ps_.shader_set(res.shaders->extra_point.get());
84 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
85 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
86 select_buf_.select_bind(ps_);
87 point_buf_.push_update();
88 ps_.bind_ssbo("data_buf", &point_buf_);
89 ps_.draw_procedural(GPU_PRIM_POINTS, 1, point_buf_.size());
90 }
91
92 void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
93 {
94 if (!enabled_) {
95 return;
96 }
97
98 GPU_framebuffer_bind(framebuffer);
99 manager.submit(ps_, view);
100 }
101};
102} // namespace blender::draw::overlay
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define OB_MODE_ALL_PAINT
void begin_sync(Resources &, const State &state) final
Origins(SelectionType selection_type)
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
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
const int state
select::SelectionType SelectionType
detail::Pass< command::DrawCommandBuf > PassSimple
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Main * DEG_get_bmain(const Depsgraph *graph)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:57