Blender V5.0
overlay_axes.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
10
11#pragma once
12
13#include "overlay_base.hh"
14
15namespace blender::draw::overlay {
16
22class Axes : Overlay {
23 using EmptyInstanceBuf = ShapeInstanceBuf<ExtraInstanceData>;
24
25 private:
26 const SelectionType selection_type_;
27
28 PassSimple ps_ = {"Axes"};
29
30 EmptyInstanceBuf axes_buf = {selection_type_, "object_axes"};
31 EmptyInstanceBuf xform_origins_buf = {selection_type_, "xform_origins"};
32
33 public:
34 Axes(const SelectionType selection_type) : selection_type_{selection_type} {};
35
36 void begin_sync(Resources & /*res*/, const State &state) final
37 {
38 enabled_ = state.is_space_v3d();
39
40 ps_.init();
41 axes_buf.clear();
42 xform_origins_buf.clear();
43 }
44
45 void object_sync(Manager & /*manager*/,
46 const ObjectRef &ob_ref,
47 Resources &res,
48 const State &state) final
49 {
50 if (!enabled_) {
51 return;
52 }
53
54 Object *ob = ob_ref.object;
55 if (is_from_dupli_or_set(ob)) {
56 return;
57 }
58
59 const bool use_display_axis = (ob->dtx & OB_AXIS) != 0;
60 const bool use_xform_origins_axis = state.ctx_mode == CTX_MODE_OBJECT &&
61 (state.scene->toolsettings->transform_flag &
64 if (!use_display_axis && !use_xform_origins_axis) {
65 return;
66 }
67
68 ExtraInstanceData data(ob->object_to_world(), res.object_wire_color(ob_ref, state), 1.0f);
69 if (use_xform_origins_axis) {
70 data.color_ = float4(0.15f, 0.15f, 0.15f, 0.7f);
71 xform_origins_buf.append(data, select::SelectMap::select_invalid_id());
72 }
73 else {
74 axes_buf.append(data, res.select_id(ob_ref));
75 }
76 }
77
78 void end_sync(Resources &res, const State &state) final
79 {
80 if (!enabled_) {
81 return;
82 }
84 ps_.state_set(state_common | DRW_STATE_DEPTH_LESS_EQUAL, state.clipping_plane_count);
85 ps_.shader_set(res.shaders->extra_shape.get());
86 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
87 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
88 res.select_bind(ps_);
89
90 axes_buf.end_sync(ps_, res.shapes.arrows.get());
91
92 PassSimple::Sub &xform_origins_ps = ps_.sub("XForm Origins");
93 xform_origins_ps.state_set(state_common | DRW_STATE_DEPTH_ALWAYS, state.clipping_plane_count);
94
95 xform_origins_buf.end_sync(xform_origins_ps, res.shapes.arrows.get());
96 }
97
98 void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
99 {
100 if (!enabled_) {
101 return;
102 }
103
104 GPU_framebuffer_bind(framebuffer);
105 manager.submit(ps_, view);
106 }
107};
108
109} // namespace blender::draw::overlay
@ CTX_MODE_OBJECT
@ OB_AXIS
#define BASE_SELECTED(v3d, base)
@ SCE_XFORM_DATA_ORIGIN
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
BMesh const char void * data
void state_set(DRWState state, int clip_plane_count=0)
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:499
Axes(const SelectionType selection_type)
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void end_sync(Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void begin_sync(Resources &, const State &state) final
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
DRWState
Definition draw_state.hh:25
@ 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
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:36
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