Blender V5.0
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 {
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 Object *object,
72 GPUMaterial *gpu_material)
73{
74 BLI_assert(object->type == OB_POINTCLOUD);
76 /* An empty point cloud should never result in a draw-call. However, the buffer binding commands
77 * will still be executed. In this case, in order to avoid assertion, we bind dummy VBOs. */
78 bool is_empty = pointcloud.totpoint == 0;
79
81 /* Ensure we have no unbound resources.
82 * Required for Vulkan.
83 * Fixes issues with certain GL drivers not drawing anything. */
84 sub_ps.bind_texture("u", module.dummy_vbo);
85 sub_ps.bind_texture("au", module.dummy_vbo);
86 sub_ps.bind_texture("a", module.dummy_vbo);
87 sub_ps.bind_texture("c", module.dummy_vbo);
88 sub_ps.bind_texture("ac", module.dummy_vbo);
89
90 gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
91 sub_ps.bind_texture("ptcloud_pos_rad_tx", is_empty ? module.dummy_vbo : pos_rad_buf);
92
93 if (gpu_material != nullptr) {
94 ListBase gpu_attrs = GPU_material_attributes(gpu_material);
95 LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
96 char sampler_name[32];
98 drw_curves_get_attribute_sampler_name(gpu_attr->name, sampler_name);
99
100 gpu::VertBuf **attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud,
101 gpu_attr->name);
102 sub_ps.bind_texture(sampler_name,
103 (attribute_buf && !is_empty) ? attribute_buf : &module.dummy_vbo);
104 }
105 }
106
107 gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
108 return geom;
109}
110
112 Object *object,
113 GPUMaterial *gpu_material)
114{
115 return pointcloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
116}
117
119 Object *object,
120 GPUMaterial *gpu_material)
121{
122 return pointcloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
123}
124
125} // namespace blender::draw
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
unsigned int uint
@ OB_POINTCLOUD
T & DRW_object_get_data_for_drawing(const Object &object)
ListBase GPU_material_attributes(const GPUMaterial *material)
void GPU_vertbuf_attr_fill(blender::gpu::VertBuf *, uint a_idx, const void *data)
blender::gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_USAGE_STATIC
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:499
DRWContext & drw_get()
format
gpu::Batch * pointcloud_surface_get(PointCloud *pointcloud)
void DRW_pointcloud_module_free(draw::PointCloudModule *module)
gpu::Batch * pointcloud_sub_pass_setup_implementation(PassT &sub_ps, Object *object, GPUMaterial *gpu_material)
gpu::Batch * pointcloud_sub_pass_setup(PassMain::Sub &sub_ps, Object *object, GPUMaterial *gpu_material=nullptr)
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::VertBuf * pointcloud_position_and_radius_get(PointCloud *pointcloud)
static struct PyModuleDef module
Definition python.cpp:796
DRWData * data
blender::draw::PointCloudModule * pointcloud_module
ustring name
Definition graph/node.h:177