Differential D15954 Diff 56253 source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2021 Blender Foundation. All rights reserved. */ | * Copyright 2021 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw | * \ingroup draw | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include <functional> | #include <functional> | ||||
| #include "BLI_color.hh" | #include "BLI_color.hh" | ||||
| #include "BLI_math_vec_types.hh" | #include "BLI_math_vec_types.hh" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BKE_attribute.h" | #include "BKE_attribute.h" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_mesh.h" | |||||
| #include "draw_attributes.h" | #include "draw_attributes.h" | ||||
| #include "draw_subdivision.h" | #include "draw_subdivision.h" | ||||
| #include "extract_mesh.hh" | #include "extract_mesh.hh" | ||||
| namespace blender::draw { | namespace blender::draw { | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | constexpr MeshExtract create_extractor_attr(ExtractInitFn fn, ExtractInitSubdivFn subdiv_fn) | ||||
| extractor.init_subdiv = subdiv_fn; | extractor.init_subdiv = subdiv_fn; | ||||
| extractor.data_type = MR_DATA_NONE; | extractor.data_type = MR_DATA_NONE; | ||||
| extractor.data_size = 0; | extractor.data_size = 0; | ||||
| extractor.use_threading = false; | extractor.use_threading = false; | ||||
| extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.attr[Index]); | extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.attr[Index]); | ||||
| return extractor; | return extractor; | ||||
| } | } | ||||
| static void extract_mesh_attr_viewer_init(const MeshRenderData *mr, | |||||
| MeshBatchCache *UNUSED(cache), | |||||
| void *buf, | |||||
| void *UNUSED(tls_data)) | |||||
| { | |||||
| GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf); | |||||
| static GPUVertFormat format = {0}; | |||||
| if (format.attr_len == 0) { | |||||
| GPU_vertformat_attr_add(&format, "attribute_value", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| } | |||||
| GPU_vertbuf_init_with_format(vbo, &format); | |||||
| GPU_vertbuf_data_alloc(vbo, mr->loop_len); | |||||
| MutableSpan<ColorGeometry4f> attr{static_cast<ColorGeometry4f *>(GPU_vertbuf_get_data(vbo)), | |||||
| mr->loop_len}; | |||||
| const StringRefNull attr_name = ".viewer"; | |||||
| const bke::AttributeAccessor attributes = mr->me->attributes(); | |||||
| attributes | |||||
| .lookup_or_default<ColorGeometry4f>(attr_name, ATTR_DOMAIN_CORNER, {1.0f, 0.0f, 1.0f, 1.0f}) | |||||
| .materialize(attr); | |||||
| } | |||||
| constexpr MeshExtract create_extractor_attr_viewer() | |||||
| { | |||||
| MeshExtract extractor = {nullptr}; | |||||
| extractor.init = extract_mesh_attr_viewer_init; | |||||
| extractor.data_type = MR_DATA_NONE; | |||||
| extractor.data_size = 0; | |||||
| extractor.use_threading = false; | |||||
| extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.attr_viewer); | |||||
| return extractor; | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| } // namespace blender::draw | } // namespace blender::draw | ||||
| #define CREATE_EXTRACTOR_ATTR(index) \ | #define CREATE_EXTRACTOR_ATTR(index) \ | ||||
| blender::draw::create_extractor_attr<index>(blender::draw::extract_attr_init##index, \ | blender::draw::create_extractor_attr<index>(blender::draw::extract_attr_init##index, \ | ||||
| blender::draw::extract_attr_init_subdiv##index) | blender::draw::extract_attr_init_subdiv##index) | ||||
| Show All 9 Lines | const MeshExtract extract_attr[GPU_MAX_ATTR] = { | ||||
| CREATE_EXTRACTOR_ATTR(8), | CREATE_EXTRACTOR_ATTR(8), | ||||
| CREATE_EXTRACTOR_ATTR(9), | CREATE_EXTRACTOR_ATTR(9), | ||||
| CREATE_EXTRACTOR_ATTR(10), | CREATE_EXTRACTOR_ATTR(10), | ||||
| CREATE_EXTRACTOR_ATTR(11), | CREATE_EXTRACTOR_ATTR(11), | ||||
| CREATE_EXTRACTOR_ATTR(12), | CREATE_EXTRACTOR_ATTR(12), | ||||
| CREATE_EXTRACTOR_ATTR(13), | CREATE_EXTRACTOR_ATTR(13), | ||||
| CREATE_EXTRACTOR_ATTR(14), | CREATE_EXTRACTOR_ATTR(14), | ||||
| }; | }; | ||||
| const MeshExtract extract_attr_viewer = blender::draw::create_extractor_attr_viewer(); | |||||