Blender V4.3
overlay_next_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
9#pragma once
10
11#include "draw_cache_impl.hh"
12#include "draw_common_c.hh"
14
15#include "ED_lattice.hh"
16
17namespace blender::draw::overlay {
18
19class Lattices {
20 private:
21 PassMain ps_ = {"Lattice"};
22
23 PassMain::Sub *lattice_ps_;
24 PassMain::Sub *edit_lattice_wire_ps_;
25 PassMain::Sub *edit_lattice_point_ps_;
26
27 public:
28 void begin_sync(Resources &res, const State &state)
29 {
32
33 auto create_sub_pass = [&](const char *name, GPUShader *shader, bool add_weight_tex) {
34 PassMain::Sub &sub_pass = ps_.sub(name);
35 sub_pass.state_set(pass_state, state.clipping_plane_count);
36 sub_pass.shader_set(shader);
37 sub_pass.bind_ubo("globalsBlock", &res.globals_buf);
38 if (add_weight_tex) {
39 sub_pass.bind_texture("weightTex", &res.weight_ramp_tx);
40 }
41 return &sub_pass;
42 };
43
44 ps_.init();
45 edit_lattice_wire_ps_ = create_sub_pass(
46 "edit_lattice_wire", res.shaders.lattice_wire.get(), true);
47 edit_lattice_point_ps_ = create_sub_pass(
48 "edit_lattice_points", res.shaders.lattice_points.get(), false);
49 lattice_ps_ = create_sub_pass("lattice", res.shaders.extra_wire_object.get(), false);
50 res.select_bind(ps_);
51 }
52
53 void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res)
54 {
55 ResourceHandle res_handle = manager.unique_handle(ob_ref);
56 {
57 gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, true);
58 edit_lattice_wire_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
59 }
60 {
61 gpu::Batch *geom = DRW_cache_lattice_vert_overlay_get(ob_ref.object);
62 edit_lattice_point_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
63 }
64 }
65
66 void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
67 {
68 gpu::Batch *geom = DRW_cache_lattice_wire_get(ob_ref.object, false);
69 if (geom) {
70 const float4 &color = res.object_wire_color(ob_ref, state);
71 float4x4 draw_mat(ob_ref.object->object_to_world().ptr());
72 for (int i : IndexRange(3)) {
73 draw_mat[i][3] = color[i];
74 }
75 draw_mat[3][3] = 0.0f /* No stipples. */;
76 ResourceHandle res_handle = manager.resource_handle(ob_ref, &draw_mat, nullptr, nullptr);
77 lattice_ps_->draw(geom, res_handle, res.select_id(ob_ref).get());
78 }
79 }
80
81 void draw(Framebuffer &framebuffer, Manager &manager, View &view)
82 {
83 GPU_framebuffer_bind(framebuffer);
84 manager.submit(ps_, view);
85 }
86};
87} // namespace blender::draw::overlay
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
struct GPUShader GPUShader
ResourceHandle unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
ResourceHandle resource_handle(const ObjectRef &ref, float inflate_bounds=0.0f)
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
Definition draw_pass.hh:760
PassBase< DrawCommandBufType > & sub(const char *name)
Definition draw_pass.hh:616
void state_set(DRWState state, int clip_plane_count=0)
Definition draw_pass.hh:954
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void begin_sync(Resources &res, const State &state)
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res)
void object_sync(Manager &manager, const ObjectRef &ob_ref, Resources &res, const State &state)
blender::gpu::Batch * DRW_cache_lattice_vert_overlay_get(Object *ob)
blender::gpu::Batch * DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
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
static ulong state[N]
const float4 & object_wire_color(const ObjectRef &ob_ref, ThemeColorID theme_id) const
void select_bind(PassSimple &pass)
const ID select_id(const ObjectRef &ob_ref, uint sub_object_id=0)