Blender V4.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
9#include "extract_mesh.hh"
10
11namespace blender::draw {
12
13#define NOR_AND_FLAG_DEFAULT 0
14#define NOR_AND_FLAG_SELECT 1
15#define NOR_AND_FLAG_ACTIVE -1
16#define NOR_AND_FLAG_HIDDEN -2
17
18template<typename GPUType>
20{
21 convert_normals(mr.face_normals, normals);
22 const GPUType invalid_normal = convert_normal<GPUType>(float3(0));
23 threading::parallel_for(IndexRange(mr.faces_num), 4096, [&](const IndexRange range) {
24 for (const int i : range) {
25 const BMFace *face = bm_original_face_get(mr, i);
26 if (!face || BM_elem_flag_test(face, BM_ELEM_HIDDEN)) {
27 normals[i] = invalid_normal;
28 normals[i].w = NOR_AND_FLAG_HIDDEN;
29 }
30 else if (BM_elem_flag_test(face, BM_ELEM_SELECT)) {
31 normals[i].w = (face == mr.efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT;
32 }
33 }
34 });
35}
36
37template<typename GPUType>
39{
40 const GPUType invalid_normal = convert_normal<GPUType>(float3(0));
41 threading::parallel_for(IndexRange(mr.faces_num), 4096, [&](const IndexRange range) {
42 for (const int i : range) {
43 BMFace *face = BM_face_at_index(mr.bm, i);
44 if (BM_elem_flag_test(face, BM_ELEM_HIDDEN)) {
45 normals[i] = invalid_normal;
46 normals[i].w = NOR_AND_FLAG_HIDDEN;
47 }
48 else {
49 normals[i] = convert_normal<GPUType>(bm_face_no_get(mr, face));
50 normals[i].w = (BM_elem_flag_test(face, BM_ELEM_SELECT) ?
51 ((face == mr.efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT) :
52 NOR_AND_FLAG_DEFAULT);
53 }
54 }
55 });
56}
57
58void extract_face_dot_normals(const MeshRenderData &mr, const bool use_hq, gpu::VertBuf &vbo)
59{
60 if (use_hq) {
61 static GPUVertFormat format = {0};
62 if (format.attr_len == 0) {
64 }
67 MutableSpan vbo_data = vbo.data<short4>();
68
69 if (mr.extract_type == MR_EXTRACT_MESH) {
71 }
72 else {
73 extract_face_dot_normals_bm(mr, vbo_data);
74 }
75 }
76 else {
77 static GPUVertFormat format = {0};
78 if (format.attr_len == 0) {
80 }
83 MutableSpan vbo_data = vbo.data<GPUPackedNormal>();
84
85 if (mr.extract_type == MR_EXTRACT_MESH) {
87 }
88 else {
89 extract_face_dot_normals_bm(mr, vbo_data);
90 }
91 }
92}
93
94} // namespace blender::draw
#define GPU_vertbuf_init_with_format(verts, format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_FETCH_INT_TO_FLOAT_UNIT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_I10
@ GPU_COMP_I16
MutableSpan< T > data()
Extraction of Mesh data into VBO to feed to GPU.
format
GPUType convert_normal(const float3 &src)
static void extract_face_dot_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > normals)
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
void extract_face_dot_normals(const MeshRenderData &mr, const bool use_hq, gpu::VertBuf &vbo)
void extract_face_dot_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
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:95
VecBase< float, 3 > float3