Blender V4.5
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
45
46 const float vert[4] = {0.0f, 0.0f, 0.0f, 0.0f};
48 GPU_vertbuf_attr_fill(vbo, dummy_id, vert);
49 return vbo;
50 }
51};
52
54{
55 if (drw_data == nullptr) {
56 drw_data = drw_get().data;
57 }
58 if (drw_data->pointcloud_module == nullptr) {
59 drw_data->pointcloud_module = MEM_new<PointCloudModule>("PointCloudModule");
60 }
61}
62
64{
65 MEM_delete(pointcloud_module);
66}
67
68template<typename PassT>
70 Object *object,
71 GPUMaterial *gpu_material)
72{
73 BLI_assert(object->type == OB_POINTCLOUD);
75 /* An empty point cloud should never result in a draw-call. However, the buffer binding commands
76 * will still be executed. In this case, in order to avoid assertion, we bind dummy VBOs. */
77 bool is_empty = pointcloud.totpoint == 0;
78
80 /* Ensure we have no unbound resources.
81 * Required for Vulkan.
82 * Fixes issues with certain GL drivers not drawing anything. */
83 sub_ps.bind_texture("u", module.dummy_vbo);
84 sub_ps.bind_texture("au", module.dummy_vbo);
85 sub_ps.bind_texture("a", module.dummy_vbo);
86 sub_ps.bind_texture("c", module.dummy_vbo);
87 sub_ps.bind_texture("ac", module.dummy_vbo);
88
89 gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
90 sub_ps.bind_texture("ptcloud_pos_rad_tx", is_empty ? module.dummy_vbo : pos_rad_buf);
91
92 if (gpu_material != nullptr) {
93 ListBase gpu_attrs = GPU_material_attributes(gpu_material);
94 LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
95 char sampler_name[32];
97 drw_curves_get_attribute_sampler_name(gpu_attr->name, sampler_name);
98
99 gpu::VertBuf **attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud,
100 gpu_attr->name);
101 sub_ps.bind_texture(sampler_name,
102 (attribute_buf && !is_empty) ? attribute_buf : &module.dummy_vbo);
103 }
104 }
105
106 gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
107 return geom;
108}
109
111 Object *object,
112 GPUMaterial *gpu_material)
113{
114 return pointcloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
115}
116
118 Object *object,
119 GPUMaterial *gpu_material)
120{
121 return pointcloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
122}
123
124} // namespace blender::draw
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
unsigned int uint
@ OB_POINTCLOUD
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
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:490
Mesh & DRW_object_get_data_for_drawing(const Object &object)
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