Blender V5.0
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 &
36 enabled_ = state.is_space_v3d() && !is_paint_mode && state.show_object_origins();
37 point_buf_.clear();
38 }
39
40 void object_sync(Manager & /*manager*/,
41 const ObjectRef &ob_ref,
42 Resources &res,
43 const State &state) final
44 {
45 if (!enabled_) {
46 return;
47 }
48
49 /* Don't show object extras in set's. */
50 if (is_from_dupli_or_set(ob_ref)) {
51 return;
52 }
53
54 const Object *ob = ob_ref.object;
55 const bool is_library = ID_REAL_USERS(&ob->id) > 1 || ID_IS_LINKED(ob);
57 const float4 location = float4(ob->object_to_world().location(), 0.0f);
58
59 if (ob == BKE_view_layer_active_object_get(state.view_layer)) {
60 select_buf_.select_append(res.select_id(ob_ref));
61 point_buf_.append(VertexData{location, res.theme.colors.active_object});
62 }
63 else if (ob->base_flag & BASE_SELECTED) {
64 select_buf_.select_append(res.select_id(ob_ref));
65 point_buf_.append(VertexData{location,
66 is_library ? res.theme.colors.library_select :
67 res.theme.colors.object_select});
68 }
69 else if (state.v3d_flag & V3D_DRAW_CENTERS) {
70 select_buf_.select_append(res.select_id(ob_ref));
71 point_buf_.append(
72 VertexData{location, is_library ? res.theme.colors.library : res.theme.colors.deselect});
73 }
74 }
75
76 void end_sync(Resources &res, const State &state) final
77 {
78 if (!enabled_) {
79 return;
80 }
81 ps_.init();
82 ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA, state.clipping_plane_count);
83 res.select_bind(ps_);
84 ps_.shader_set(res.shaders->extra_point.get());
85 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
86 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
87 select_buf_.select_bind(ps_);
88 point_buf_.push_update();
89 ps_.bind_ssbo("data_buf", &point_buf_);
90 ps_.draw_procedural(GPU_PRIM_POINTS, 1, point_buf_.size());
91 }
92
93 void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view) final
94 {
95 if (!enabled_) {
96 return;
97 }
98
99 GPU_framebuffer_bind(framebuffer);
100 manager.submit(ps_, view);
101 }
102};
103} // namespace blender::draw::overlay
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:694
#define ID_REAL_USERS(id)
Definition DNA_ID.h:676
#define OB_MODE_ALL_PAINT
#define OB_MODE_ALL_PAINT_GPENCIL
@ OB_MODE_SCULPT_CURVES
#define BASE_SELECTED(v3d, base)
@ V3D_DRAW_CENTERS
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
@ GPU_PRIM_POINTS
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
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
static ulong state[N]
select::SelectionType SelectionType
static bool is_from_dupli_or_set(const Object *ob)
detail::Pass< command::DrawCommandBuf > PassSimple
VecBase< float, 4 > float4
short base_flag