Blender V5.0
overlay_lattice.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 "draw_cache.hh"
12#include "draw_cache_impl.hh"
13#include "draw_common_c.hh"
14#include "overlay_base.hh"
15
16namespace blender::draw::overlay {
17
22 private:
23 PassMain ps_ = {"Lattice"};
24
25 PassMain::Sub *lattice_ps_;
26 PassMain::Sub *edit_lattice_wire_ps_;
27 PassMain::Sub *edit_lattice_point_ps_;
28
29 public:
30 void begin_sync(Resources &res, const State &state) final
31 {
32 enabled_ = state.is_space_v3d();
33 if (!enabled_) {
34 return;
35 }
36
37 auto create_sub_pass = [&](const char *name, gpu::Shader *shader, bool add_weight_tex) {
38 PassMain::Sub &sub_pass = ps_.sub(name);
39 sub_pass.shader_set(shader);
40 if (add_weight_tex) {
41 sub_pass.bind_texture("weight_tx", &res.weight_ramp_tx);
42 }
43 return &sub_pass;
44 };
45
46 ps_.init();
48 state.clipping_plane_count);
49 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
50 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
51 res.select_bind(ps_);
52 edit_lattice_wire_ps_ = create_sub_pass(
53 "edit_lattice_wire", res.shaders->lattice_wire.get(), true);
54 edit_lattice_point_ps_ = create_sub_pass(
55 "edit_lattice_points", res.shaders->lattice_points.get(), false);
56 lattice_ps_ = create_sub_pass("lattice", res.shaders->extra_wire_object.get(), false);
57 }
58
60 const ObjectRef &ob_ref,
61 Resources &res,
62 const State & /*state*/) final
63 {
64 if (!enabled_) {
65 return;
66 }
67
68 ResourceHandleRange res_handle = manager.unique_handle(ob_ref);
69 {
70 gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, true);
71 edit_lattice_wire_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
72 }
73 {
74 gpu::Batch *geom = DRW_cache_lattice_vert_overlay_get(ob_ref.object);
75 edit_lattice_point_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
76 }
77 }
78
79 void object_sync(Manager &manager,
80 const ObjectRef &ob_ref,
81 Resources &res,
82 const State &state) final
83 {
84 if (!enabled_) {
85 return;
86 }
87
88 if (!state.show_extras() || (ob_ref.object->dt == OB_BOUNDBOX)) {
89 return;
90 }
91
92 gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, false);
93 if (geom) {
94 const float4 &color = res.object_wire_color(ob_ref, state);
95 float4x4 draw_mat(ob_ref.object->object_to_world().ptr());
96 for (int i : IndexRange(3)) {
97 draw_mat[i][3] = color[i];
98 }
99 draw_mat[3][3] = 0.0f /* No stipples. */;
100 ResourceHandleRange res_handle = manager.resource_handle(
101 ob_ref, &draw_mat, nullptr, nullptr);
102 lattice_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
103 }
104 }
105
106 void pre_draw(Manager &manager, View &view) final
107 {
108 if (!enabled_) {
109 return;
110 }
111
112 manager.generate_commands(ps_, view);
113 }
114
115 void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
116 {
117 if (!enabled_) {
118 return;
119 }
120
121 GPU_framebuffer_bind(framebuffer);
122 manager.submit_only(ps_, view);
123 }
124};
125} // namespace blender::draw::overlay
@ OB_BOUNDBOX
static AppView * view
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:499
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &) final
void begin_sync(Resources &res, const State &state) final
void pre_draw(Manager &manager, View &view) final
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state) 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]
detail::Pass< command::DrawMultiBuf > PassMain
gpu::Batch * DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
gpu::Batch * DRW_cache_lattice_vert_overlay_get(Object *ob)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
const char * name
i
Definition text_draw.cc:230