2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2017 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw
|
|
|
|
|
*/
|
|
|
|
|
|
2023-10-18 17:15:30 +02:00
|
|
|
#include "BLI_string_utils.hh"
|
2022-10-25 10:43:47 +02:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_pointcloud_types.h"
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_batch.hh"
|
|
|
|
|
#include "GPU_capabilities.hh"
|
|
|
|
|
#include "GPU_compute.hh"
|
2024-02-01 10:40:24 -05:00
|
|
|
#include "GPU_material.hh"
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_shader.hh"
|
|
|
|
|
#include "GPU_texture.hh"
|
|
|
|
|
#include "GPU_vertex_buffer.hh"
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
#include "DRW_gpu_wrapper.hh"
|
2024-01-05 11:16:57 -05:00
|
|
|
#include "DRW_render.hh"
|
2022-10-25 10:43:47 +02:00
|
|
|
|
2023-02-13 20:56:24 +01:00
|
|
|
#include "draw_attributes.hh"
|
2023-08-03 20:04:50 -04:00
|
|
|
#include "draw_cache_impl.hh"
|
2024-01-05 12:20:30 -05:00
|
|
|
#include "draw_common.hh"
|
2024-03-22 23:51:35 -04:00
|
|
|
#include "draw_common_c.hh"
|
|
|
|
|
#include "draw_manager_c.hh"
|
2022-10-25 10:43:47 +02:00
|
|
|
#include "draw_pointcloud_private.hh"
|
2024-01-05 12:20:30 -05:00
|
|
|
/* For drw_curves_get_attribute_sampler_name. */
|
|
|
|
|
#include "draw_curves_private.hh"
|
|
|
|
|
|
|
|
|
|
namespace blender::draw {
|
2022-10-25 10:43:47 +02:00
|
|
|
|
2024-03-24 16:38:30 +01:00
|
|
|
static gpu::VertBuf *g_dummy_vbo = nullptr;
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
void DRW_pointcloud_init()
|
|
|
|
|
{
|
|
|
|
|
if (g_dummy_vbo == nullptr) {
|
|
|
|
|
/* initialize vertex format */
|
|
|
|
|
GPUVertFormat format = {0};
|
|
|
|
|
uint dummy_id = GPU_vertformat_attr_add(&format, "dummy", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
|
|
|
|
|
|
|
|
|
g_dummy_vbo = GPU_vertbuf_create_with_format_ex(
|
|
|
|
|
&format, GPU_USAGE_STATIC | GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY);
|
|
|
|
|
|
|
|
|
|
const float vert[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
GPU_vertbuf_data_alloc(g_dummy_vbo, 1);
|
|
|
|
|
GPU_vertbuf_attr_fill(g_dummy_vbo, dummy_id, vert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DRWShadingGroup *DRW_shgroup_pointcloud_create_sub(Object *object,
|
|
|
|
|
DRWShadingGroup *shgrp_parent,
|
|
|
|
|
GPUMaterial *gpu_material)
|
|
|
|
|
{
|
|
|
|
|
PointCloud &pointcloud = *static_cast<PointCloud *>(object->data);
|
|
|
|
|
|
|
|
|
|
DRWShadingGroup *shgrp = DRW_shgroup_create_sub(shgrp_parent);
|
|
|
|
|
|
|
|
|
|
/* Fix issue with certain driver not drawing anything if there is no texture bound to
|
|
|
|
|
* "ac", "au", "u" or "c". */
|
|
|
|
|
DRW_shgroup_buffer_texture(shgrp, "u", g_dummy_vbo);
|
|
|
|
|
DRW_shgroup_buffer_texture(shgrp, "au", g_dummy_vbo);
|
|
|
|
|
DRW_shgroup_buffer_texture(shgrp, "c", g_dummy_vbo);
|
|
|
|
|
DRW_shgroup_buffer_texture(shgrp, "ac", g_dummy_vbo);
|
|
|
|
|
|
2024-03-24 16:38:30 +01:00
|
|
|
gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
|
2022-10-25 10:43:47 +02:00
|
|
|
DRW_shgroup_buffer_texture(shgrp, "ptcloud_pos_rad_tx", pos_rad_buf);
|
|
|
|
|
|
|
|
|
|
if (gpu_material != nullptr) {
|
|
|
|
|
|
|
|
|
|
// const DRW_Attributes &attrs = cache->attr_used;
|
|
|
|
|
// for (int i = 0; i < attrs.num_requests; i++) {
|
|
|
|
|
// const DRW_AttributeRequest &request = attrs.requests[i];
|
|
|
|
|
|
|
|
|
|
// char sampler_name[32];
|
|
|
|
|
// /* \note reusing curve attribute function. */
|
|
|
|
|
// drw_curves_get_attribute_sampler_name(request.attribute_name, sampler_name);
|
|
|
|
|
|
|
|
|
|
// GPUTexture *attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud);
|
2022-10-25 16:16:58 +02:00
|
|
|
// if (!cache->attributes_buf[i]) {
|
2022-10-25 10:43:47 +02:00
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// DRW_shgroup_buffer_texture_ref(shgrp, sampler_name, attribute_buf);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/* Only single material supported for now. */
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch **geom = pointcloud_surface_shaded_get(&pointcloud, &gpu_material, 1);
|
2022-10-25 10:43:47 +02:00
|
|
|
DRW_shgroup_call(shgrp, geom[0], object);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
|
2022-10-25 10:43:47 +02:00
|
|
|
DRW_shgroup_call(shgrp, geom, object);
|
|
|
|
|
}
|
|
|
|
|
return shgrp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DRW_pointcloud_free()
|
|
|
|
|
{
|
|
|
|
|
GPU_VERTBUF_DISCARD_SAFE(g_dummy_vbo);
|
|
|
|
|
}
|
2023-07-03 11:16:44 +02:00
|
|
|
|
|
|
|
|
template<typename PassT>
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch *point_cloud_sub_pass_setup_implementation(PassT &sub_ps,
|
|
|
|
|
Object *object,
|
|
|
|
|
GPUMaterial *gpu_material)
|
2023-07-03 11:16:44 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(object->type == OB_POINTCLOUD);
|
|
|
|
|
PointCloud &pointcloud = *static_cast<PointCloud *>(object->data);
|
|
|
|
|
|
|
|
|
|
/* Fix issue with certain driver not drawing anything if there is no texture bound to
|
|
|
|
|
* "ac", "au", "u" or "c". */
|
|
|
|
|
sub_ps.bind_texture("u", g_dummy_vbo);
|
|
|
|
|
sub_ps.bind_texture("au", g_dummy_vbo);
|
|
|
|
|
sub_ps.bind_texture("c", g_dummy_vbo);
|
|
|
|
|
sub_ps.bind_texture("ac", g_dummy_vbo);
|
|
|
|
|
|
2024-03-24 16:38:30 +01:00
|
|
|
gpu::VertBuf *pos_rad_buf = pointcloud_position_and_radius_get(&pointcloud);
|
2023-07-03 11:16:44 +02:00
|
|
|
sub_ps.bind_texture("ptcloud_pos_rad_tx", pos_rad_buf);
|
|
|
|
|
|
|
|
|
|
if (gpu_material != nullptr) {
|
2023-07-14 17:23:29 +02:00
|
|
|
ListBase gpu_attrs = GPU_material_attributes(gpu_material);
|
|
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
|
2024-02-02 19:34:58 +01:00
|
|
|
char sampler_name[32];
|
|
|
|
|
/** NOTE: Reusing curve attribute function. */
|
|
|
|
|
drw_curves_get_attribute_sampler_name(gpu_attr->name, sampler_name);
|
|
|
|
|
|
2024-03-24 16:38:30 +01:00
|
|
|
gpu::VertBuf **attribute_buf = DRW_pointcloud_evaluated_attribute(&pointcloud,
|
|
|
|
|
gpu_attr->name);
|
2024-02-02 19:34:58 +01:00
|
|
|
sub_ps.bind_texture(sampler_name, (attribute_buf) ? attribute_buf : &g_dummy_vbo);
|
2023-07-14 17:23:29 +02:00
|
|
|
}
|
2023-07-03 11:16:44 +02:00
|
|
|
}
|
2023-07-14 17:23:29 +02:00
|
|
|
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch *geom = pointcloud_surface_get(&pointcloud);
|
2023-07-14 17:23:29 +02:00
|
|
|
return geom;
|
2023-07-03 11:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch *point_cloud_sub_pass_setup(PassMain::Sub &sub_ps,
|
|
|
|
|
Object *object,
|
|
|
|
|
GPUMaterial *gpu_material)
|
2023-07-03 11:16:44 +02:00
|
|
|
{
|
|
|
|
|
return point_cloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 03:06:25 +01:00
|
|
|
gpu::Batch *point_cloud_sub_pass_setup(PassSimple::Sub &sub_ps,
|
|
|
|
|
Object *object,
|
|
|
|
|
GPUMaterial *gpu_material)
|
2023-07-03 11:16:44 +02:00
|
|
|
{
|
|
|
|
|
return point_cloud_sub_pass_setup_implementation(sub_ps, object, gpu_material);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::draw
|