Blender V4.3
overlay_next_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
9#pragma once
10
12
13namespace blender::draw::overlay {
14class Origins {
15 private:
17
18 PassSimple ps_ = {"Origins"};
19
20 bool enabled_ = false;
21
22 public:
23 void begin_sync(const State &state)
24 {
25 const bool is_paint_mode = (state.object_mode &
28 enabled_ = state.v3d && !is_paint_mode &&
29 (state.overlay.flag & V3D_OVERLAY_HIDE_OBJECT_ORIGINS) == 0;
30 point_buf_.clear();
31 }
32
33 void object_sync(const ObjectRef &ob_ref, Resources &res, State &state)
34 {
35 if (!enabled_) {
36 return;
37 }
38 const Object *ob = ob_ref.object;
39 const bool is_library = ID_REAL_USERS(&ob->id) > 1 || ID_IS_LINKED(ob);
41 const float4 location = float4(ob->object_to_world().location());
42
43 if (ob == BKE_view_layer_active_object_get(state.view_layer)) {
44 point_buf_.append(VertexData{location, res.theme_settings.color_active});
45 }
46 else if (ob->base_flag & BASE_SELECTED) {
47 point_buf_.append(VertexData{location,
48 is_library ? res.theme_settings.color_library_select :
50 }
51 else if (state.v3d_flag & V3D_DRAW_CENTERS) {
52 point_buf_.append(VertexData{location,
53 is_library ? res.theme_settings.color_library :
55 }
56 }
57
58 void end_sync(Resources &res, const State &state)
59 {
60 if (!enabled_) {
61 return;
62 }
63 ps_.init();
65 ps_.shader_set(res.shaders.extra_point.get());
66 ps_.bind_ubo("globalsBlock", &res.globals_buf);
67 point_buf_.push_update();
68 ps_.bind_ssbo("data_buf", &point_buf_);
69 ps_.draw_procedural(GPU_PRIM_POINTS, 1, point_buf_.size());
70 }
71
72 void draw(Framebuffer &framebuffer, Manager &manager, View &view)
73 {
74 if (!enabled_) {
75 return;
76 }
77
78 GPU_framebuffer_bind(framebuffer);
79 manager.submit(ps_, view);
80 }
81};
82} // 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:654
#define ID_REAL_USERS(id)
Definition DNA_ID.h:637
#define OB_MODE_ALL_PAINT
#define OB_MODE_ALL_PAINT_GPENCIL
@ OB_MODE_SCULPT_CURVES
#define BASE_SELECTED(v3d, base)
@ V3D_OVERLAY_HIDE_OBJECT_ORIGINS
@ V3D_DRAW_CENTERS
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
@ GPU_PRIM_POINTS
void submit(PassSimple &pass, View &view)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
Definition draw_pass.hh:833
void state_set(DRWState state, int clip_plane_count=0)
Definition draw_pass.hh:954
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void bind_ssbo(const char *name, GPUStorageBuf *buffer)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
void object_sync(const ObjectRef &ob_ref, Resources &res, State &state)
void begin_sync(const State &state)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void end_sync(Resources &res, const State &state)
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
static ulong state[N]
VecBase< float, 4 > float4
short base_flag