Blender V5.3
extract_mesh_vbo_fdots_nor.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "extract_mesh.hh"
10
12
13namespace blender::draw {
14
15#define NOR_AND_FLAG_DEFAULT 0
16#define NOR_AND_FLAG_SELECT 1
17#define NOR_AND_FLAG_ACTIVE -1
18#define NOR_AND_FLAG_HIDDEN -2
19
20template<typename GPUType>
22{
24 const GPUType invalid_normal = gpu::convert_normal<GPUType>(float3(0));
25 threading::parallel_for(IndexRange(mr.faces_num), 4096, [&](const IndexRange range) {
26 for (const int i : range) {
27 const BMFace *face = bm_original_face_get(mr, i);
28 if (!face || BM_elem_flag_test(face, BM_ELEM_HIDDEN)) {
29 normals[i] = invalid_normal;
30 normals[i].w = NOR_AND_FLAG_HIDDEN;
31 }
32 else if (BM_elem_flag_test(face, BM_ELEM_SELECT)) {
33 normals[i].w = (face == mr.efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT;
34 }
35 }
36 });
37}
38
39template<typename GPUType>
41{
42 const GPUType invalid_normal = gpu::convert_normal<GPUType>(float3(0));
43 threading::parallel_for(IndexRange(mr.faces_num), 4096, [&](const IndexRange range) {
44 for (const int i : range) {
45 BMFace *face = BM_face_at_index(mr.bm, i);
46 if (BM_elem_flag_test(face, BM_ELEM_HIDDEN)) {
47 normals[i] = invalid_normal;
48 normals[i].w = NOR_AND_FLAG_HIDDEN;
49 }
50 else {
51 normals[i] = gpu::convert_normal<GPUType>(bm_face_no_get(mr, face));
52 normals[i].w = (BM_elem_flag_test(face, BM_ELEM_SELECT) ?
53 ((face == mr.efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT) :
54 NOR_AND_FLAG_DEFAULT);
55 }
56 }
57 });
58}
59
61{
62 if (use_hq) {
63 static const GPUVertFormat format = GPU_vertformat_from_attribute(
64 "norAndFlag", gpu::VertAttrType::SNORM_16_16_16_16);
65 gpu::VertBufPtr vbo = gpu::VertBufPtr(GPU_vertbuf_create_with_format(format));
67 MutableSpan vbo_data = vbo->data<short4>();
68
71 }
72 else {
73 extract_face_dot_normals_bm(mr, vbo_data);
74 }
75 return vbo;
76 }
77 static const GPUVertFormat format = GPU_vertformat_from_attribute(
78 "norAndFlag", gpu::VertAttrType::SNORM_10_10_10_2);
79 gpu::VertBufPtr vbo = gpu::VertBufPtr(GPU_vertbuf_create_with_format(format));
81 MutableSpan vbo_data = vbo->data<int1010102_norm>();
82
85 }
86 else {
87 extract_face_dot_normals_bm(mr, vbo_data);
88 }
89 return vbo;
90}
91
92} // namespace blender::draw
constexpr IndexRange()=default
constexpr T * data() const
Definition BLI_span.hh:545
Extraction of Mesh data into VBO to feed to GPU.
static void extract_face_dot_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > normals)
gpu::VertBufPtr extract_face_dot_normals(const MeshRenderData &mr, bool use_hq)
void extract_face_dot_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
GPUType convert_normal(const float3 &src)
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
NormalizedIntVecBase< int32_t, 4, 10, 10, 10, 2 > int1010102_norm
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
VecBase< int16_t, 4 > short4
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
VecBase< float, 3 > float3