Blender V4.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
9#include "BLI_string_utils.hh"
10#include "BLI_utildefines.h"
11
13
14#include "GPU_batch.hh"
15#include "GPU_capabilities.hh"
16#include "GPU_compute.hh"
17#include "GPU_material.hh"
18#include "GPU_shader.hh"
19#include "GPU_texture.hh"
20#include "GPU_vertex_buffer.hh"
21
22#include "DRW_gpu_wrapper.hh"
23#include "DRW_render.hh"
24
25#include "draw_attributes.hh"
26#include "draw_cache_impl.hh"
27#include "draw_common.hh"
28#include "draw_common_c.hh"
29#include "draw_manager_c.hh"
31/* For drw_curves_get_attribute_sampler_name. */
33
34namespace blender::draw {
35
36static gpu::VertBuf *g_dummy_vbo = nullptr;
37
39{
40 if (g_dummy_vbo == nullptr) {
41 /* initialize vertex format */
44
47
48 const float vert[4] = {0.0f, 0.0f, 0.0f, 0.0f};
50 GPU_vertbuf_attr_fill(g_dummy_vbo, dummy_id, vert);
51 }
52}
53
55 DRWShadingGroup *shgrp_parent,
56 GPUMaterial *gpu_material)
57{
58 PointCloud &pointcloud = *static_cast<PointCloud *>(object->data);
59
60 DRWShadingGroup *shgrp = DRW_shgroup_create_sub(shgrp_parent);
61
62 /* Fix issue with certain driver not drawing anything if there is no texture bound to
63 * "ac", "au", "u" or "c". */
68
69 gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
70 DRW_shgroup_buffer_texture(shgrp, "ptcloud_pos_rad_tx", pos_rad_buf);
71
72 if (gpu_material != nullptr) {
73
74 // const DRW_Attributes &attrs = cache->attr_used;
75 // for (int i = 0; i < attrs.num_requests; i++) {
76 // const DRW_AttributeRequest &request = attrs.requests[i];
77
78 // char sampler_name[32];
79 // /* \note reusing curve attribute function. */
80 // drw_curves_get_attribute_sampler_name(request.attribute_name, sampler_name);
81
82 // GPUTexture *attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud);
83 // if (!cache->attributes_buf[i]) {
84 // continue;
85 // }
86 // DRW_shgroup_buffer_texture_ref(shgrp, sampler_name, attribute_buf);
87 // }
88
89 /* Only single material supported for now. */
90 gpu::Batch **geom = pointcloud_surface_shaded_get(&pointcloud, &gpu_material, 1);
91 DRW_shgroup_call(shgrp, geom[0], object);
92 }
93 else {
94 gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
95 DRW_shgroup_call(shgrp, geom, object);
96 }
97 return shgrp;
98}
99
104
105template<typename PassT>
107 Object *object,
108 GPUMaterial *gpu_material)
109{
110 BLI_assert(object->type == OB_POINTCLOUD);
111 PointCloud &pointcloud = *static_cast<PointCloud *>(object->data);
112
113 /* Fix issue with certain driver not drawing anything if there is no texture bound to
114 * "ac", "au", "u" or "c". */
115 sub_ps.bind_texture("u", g_dummy_vbo);
116 sub_ps.bind_texture("au", g_dummy_vbo);
117 sub_ps.bind_texture("c", g_dummy_vbo);
118 sub_ps.bind_texture("ac", g_dummy_vbo);
119
120 gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
121 sub_ps.bind_texture("ptcloud_pos_rad_tx", pos_rad_buf);
122
123 if (gpu_material != nullptr) {
124 ListBase gpu_attrs = GPU_material_attributes(gpu_material);
125 LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
126 char sampler_name[32];
128 drw_curves_get_attribute_sampler_name(gpu_attr->name, sampler_name);
129
130 gpu::VertBuf **attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud,
131 gpu_attr->name);
132 sub_ps.bind_texture(sampler_name, (attribute_buf) ? attribute_buf : &g_dummy_vbo);
133 }
134 }
135
136 gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
137 return geom;
138}
139
141 Object *object,
142 GPUMaterial *gpu_material)
143{
144 return point_cloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
145}
146
148 Object *object,
149 GPUMaterial *gpu_material)
150{
151 return point_cloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
152}
153
154} // namespace blender::draw
#define BLI_assert(a)
Definition BLI_assert.h:50
#define LISTBASE_FOREACH(type, var, list)
unsigned int uint
@ OB_POINTCLOUD
#define DRW_shgroup_call(shgroup, geom, ob)
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 *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:462
Utilities for rendering attributes.
void DRW_shgroup_buffer_texture(DRWShadingGroup *shgroup, const char *name, blender::gpu::VertBuf *vertex_buffer)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
format
gpu::Batch * point_cloud_sub_pass_setup(PassMain::Sub &sub_ps, Object *object, GPUMaterial *gpu_material=nullptr)
gpu::Batch * pointcloud_surface_get(PointCloud *pointcloud)
void drw_curves_get_attribute_sampler_name(const char *layer_name, char r_sampler_name[32])
gpu::Batch ** pointcloud_surface_shaded_get(PointCloud *pointcloud, GPUMaterial **gpu_materials, int mat_len)
static gpu::VertBuf * g_dummy_vbo
void DRW_pointcloud_init()
gpu::Batch * point_cloud_sub_pass_setup_implementation(PassT &sub_ps, Object *object, GPUMaterial *gpu_material)
DRWShadingGroup * DRW_shgroup_pointcloud_create_sub(Object *object, DRWShadingGroup *shgrp_parent, GPUMaterial *gpu_material)
gpu::VertBuf ** DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name)
gpu::VertBuf * pointcloud_position_and_radius_get(PointCloud *pointcloud)
ustring name
Definition graph/node.h:177