Blender V5.3
draw_pointcloud.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "GPU_batch.hh"
12#include "GPU_material.hh"
13#include "GPU_shader.hh"
14#include "GPU_texture.hh"
15#include "GPU_vertex_buffer.hh"
16
17#include "DRW_render.hh"
18
19#include "draw_cache_impl.hh"
20#include "draw_common.hh"
21#include "draw_common_c.hh"
24/* For drw_curves_get_attribute_sampler_name. */
26
27namespace blender::draw {
28
30 gpu::VertBuf *dummy_vbo = create_dummy_vbo();
31
36
37 private:
38 gpu::VertBuf *create_dummy_vbo()
39 {
40 GPUVertFormat format = {0};
42 &format, "dummy", gpu::VertAttrType::SFLOAT_32_32_32_32);
43
46
47 const float vert[4] = {0.0f, 0.0f, 0.0f, 0.0f};
49 GPU_vertbuf_attr_fill(vbo, dummy_id, vert);
50 return vbo;
51 }
52};
53
55{
56 if (drw_data == nullptr) {
57 drw_data = drw_get().data;
58 }
59 if (drw_data->pointcloud_module == nullptr) {
60 drw_data->pointcloud_module = MEM_new<PointCloudModule>("PointCloudModule");
61 }
62}
63
65{
66 MEM_delete(pointcloud_module);
67}
68
69template<typename PassT>
71 const ObjectRef &ob_ref,
72 const ResourceHandleRange &res_handle,
73 GPUMaterial *gpu_material)
74{
75 const Object *object = ob_ref.object;
77
79 if (pointcloud.type == PointCloudType::GSplat) {
80 /* GSplats are a subtype of point-clouds, so we forward to their implementation. */
81 return gsplat_sub_pass_setup(sub_ps, ob_ref, res_handle, gpu_material);
82 }
83
85
86 /* An empty point-cloud should never result in a draw-call. However, the buffer binding commands
87 * will still be executed. In this case, in order to avoid assertion, we bind dummy VBOs. */
88 const bool is_empty = pointcloud.totpoint == 0;
89
90 /* Ensure we have no unbound resources, required for Vulkan.
91 * Certain GL drivers also refuse to draw anything otherwise. */
92 sub_ps.bind_texture("u", module.dummy_vbo);
93 sub_ps.bind_texture("au", module.dummy_vbo);
94 sub_ps.bind_texture("a", module.dummy_vbo);
95 sub_ps.bind_texture("c", module.dummy_vbo);
96 sub_ps.bind_texture("ac", module.dummy_vbo);
97
98 gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
99 sub_ps.bind_texture("ptcloud_pos_rad_tx", is_empty ? module.dummy_vbo : pos_rad_buf);
100
101 if (gpu_material != nullptr) {
102 ListBaseT<GPUMaterialAttribute> gpu_attrs = GPU_material_attributes(gpu_material);
103 for (GPUMaterialAttribute &gpu_attr : gpu_attrs) {
104 char sampler_name[32];
106 drw_curves_get_attribute_sampler_name(gpu_attr.name, sampler_name);
107
108 gpu::VertBuf **attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud,
109 gpu_attr.name);
110 sub_ps.bind_texture(sampler_name,
111 (attribute_buf && !is_empty) ? attribute_buf : &module.dummy_vbo);
112 }
113 }
114
115 gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
116 return geom;
117}
118
120 const ObjectRef &ob_ref,
121 const ResourceHandleRange &res_handle,
122 GPUMaterial *gpu_material)
123{
124 return pointcloud_sub_pass_setup_implementation(sub_ps, ob_ref, res_handle, gpu_material);
125}
126
128 const ObjectRef &ob_ref,
129 const ResourceHandleRange &res_handle,
130 GPUMaterial *gpu_material)
131{
132 return pointcloud_sub_pass_setup_implementation(sub_ps, ob_ref, res_handle, gpu_material);
133}
134
135} // namespace blender::draw
#define GPU_VERTBUF_DISCARD_SAFE(verts)
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:509
gpu::Batch * pointcloud_surface_get(PointCloud *pointcloud)
void DRW_pointcloud_module_free(draw::PointCloudModule *module)
void drw_curves_get_attribute_sampler_name(const StringRef layer_name, char r_sampler_name[32])
gpu::VertBuf ** DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, StringRef name)
void DRW_pointcloud_init(DRWData *drw_data=nullptr)
gpu::Batch * pointcloud_sub_pass_setup_implementation(PassT &sub_ps, const ObjectRef &ob_ref, const ResourceHandleRange &res_handle, GPUMaterial *gpu_material)
gpu::Batch * pointcloud_sub_pass_setup(PassMain::Sub &sub_ps, const ObjectRef &ob_ref, const ResourceHandleRange &res_handle, GPUMaterial *gpu_material=nullptr)
gpu::VertBuf * pointcloud_position_and_radius_get(PointCloud *pointcloud)
gpu::Batch * gsplat_sub_pass_setup(PassMain::Sub &sub_ps, const ObjectRef &ob_ref, const ResourceHandleRange &res_handle, GPUMaterial *gpu_material=nullptr)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned int uint
Definition BKE_text.h:55
DRWContext & drw_get()
T & DRW_object_get_data_for_drawing(const Object &object)
ListBaseT< GPUMaterialAttribute > GPU_material_attributes(const GPUMaterial *material)
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
draw::PointCloudModule * pointcloud_module