Blender  V3.3
extract_mesh_vbo_fdots_nor.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. All rights reserved. */
3 
8 #include "extract_mesh.hh"
9 
10 namespace blender::draw {
11 
12 /* ---------------------------------------------------------------------- */
16 #define NOR_AND_FLAG_DEFAULT 0
17 #define NOR_AND_FLAG_SELECT 1
18 #define NOR_AND_FLAG_ACTIVE -1
19 #define NOR_AND_FLAG_HIDDEN -2
20 
21 static void extract_fdots_nor_init(const MeshRenderData *mr,
22  MeshBatchCache *UNUSED(cache),
23  void *buf,
24  void *UNUSED(tls_data))
25 {
26  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
27  static GPUVertFormat format = {0};
28  if (format.attr_len == 0) {
30  }
31 
34 }
35 
37  MeshBatchCache *UNUSED(cache),
38  void *buf,
39  void *UNUSED(data))
40 {
41  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
42  static float invalid_normal[3] = {0.0f, 0.0f, 0.0f};
44  BMFace *efa;
45 
46  /* Quicker than doing it for each loop. */
47  if (mr->extract_type == MR_EXTRACT_BMESH) {
48  for (int f = 0; f < mr->poly_len; f++) {
49  efa = BM_face_at_index(mr->bm, f);
50  const bool is_face_hidden = BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
51  if (is_face_hidden || (mr->extract_type == MR_EXTRACT_MAPPED && mr->p_origindex &&
52  mr->p_origindex[f] == ORIGINDEX_NONE)) {
53  nor[f] = GPU_normal_convert_i10_v3(invalid_normal);
54  nor[f].w = NOR_AND_FLAG_HIDDEN;
55  }
56  else {
58  /* Select / Active Flag. */
59  nor[f].w = (BM_elem_flag_test(efa, BM_ELEM_SELECT) ?
62  }
63  }
64  }
65  else {
66  for (int f = 0; f < mr->poly_len; f++) {
67  efa = bm_original_face_get(mr, f);
68  const bool is_face_hidden = efa && BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
69  if (is_face_hidden || (mr->extract_type == MR_EXTRACT_MAPPED && mr->p_origindex &&
70  mr->p_origindex[f] == ORIGINDEX_NONE)) {
71  nor[f] = GPU_normal_convert_i10_v3(invalid_normal);
72  nor[f].w = NOR_AND_FLAG_HIDDEN;
73  }
74  else {
76  /* Select / Active Flag. */
77  nor[f].w = (BM_elem_flag_test(efa, BM_ELEM_SELECT) ?
80  }
81  }
82  }
83 }
84 
86 {
87  MeshExtract extractor = {nullptr};
88  extractor.init = extract_fdots_nor_init;
89  extractor.finish = extract_fdots_nor_finish;
90  extractor.data_type = MR_DATA_LOOP_NOR;
91  extractor.data_size = 0;
92  extractor.use_threading = false;
93  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_nor);
94  return extractor;
95 }
96 
99 /* ---------------------------------------------------------------------- */
104  MeshBatchCache *UNUSED(cache),
105  void *buf,
106  void *UNUSED(tls_data))
107 {
108  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
109  static GPUVertFormat format = {0};
110  if (format.attr_len == 0) {
112  }
113 
116 }
117 
119  MeshBatchCache *UNUSED(cache),
120  void *buf,
121  void *UNUSED(data))
122 {
123  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
124  static float invalid_normal[3] = {0.0f, 0.0f, 0.0f};
125  short *nor = (short *)GPU_vertbuf_get_data(vbo);
126  BMFace *efa;
127 
128  /* Quicker than doing it for each loop. */
129  if (mr->extract_type == MR_EXTRACT_BMESH) {
130  for (int f = 0; f < mr->poly_len; f++) {
131  efa = BM_face_at_index(mr->bm, f);
132  const bool is_face_hidden = BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
133  if (is_face_hidden || (mr->extract_type == MR_EXTRACT_MAPPED && mr->p_origindex &&
134  mr->p_origindex[f] == ORIGINDEX_NONE)) {
135  normal_float_to_short_v3(&nor[f * 4], invalid_normal);
136  nor[f * 4 + 3] = NOR_AND_FLAG_HIDDEN;
137  }
138  else {
139  normal_float_to_short_v3(&nor[f * 4], bm_face_no_get(mr, efa));
140  /* Select / Active Flag. */
141  nor[f * 4 + 3] = (BM_elem_flag_test(efa, BM_ELEM_SELECT) ?
142  ((efa == mr->efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT) :
144  }
145  }
146  }
147  else {
148  for (int f = 0; f < mr->poly_len; f++) {
149  efa = bm_original_face_get(mr, f);
150  const bool is_face_hidden = efa && BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
151  if (is_face_hidden || (mr->extract_type == MR_EXTRACT_MAPPED && mr->p_origindex &&
152  mr->p_origindex[f] == ORIGINDEX_NONE)) {
153  normal_float_to_short_v3(&nor[f * 4], invalid_normal);
154  nor[f * 4 + 3] = NOR_AND_FLAG_HIDDEN;
155  }
156  else {
157  normal_float_to_short_v3(&nor[f * 4], bm_face_no_get(mr, efa));
158  /* Select / Active Flag. */
159  nor[f * 4 + 3] = (BM_elem_flag_test(efa, BM_ELEM_SELECT) ?
160  ((efa == mr->efa_act) ? NOR_AND_FLAG_ACTIVE : NOR_AND_FLAG_SELECT) :
162  }
163  }
164  }
165 }
166 
168 {
169  MeshExtract extractor = {nullptr};
170  extractor.init = extract_fdots_nor_hq_init;
172  extractor.data_type = MR_DATA_LOOP_NOR;
173  extractor.data_size = 0;
174  extractor.use_threading = false;
175  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_nor);
176  return extractor;
177 }
178 
181 } // namespace blender::draw
182 
#define ORIGINDEX_NONE
MINLINE void normal_float_to_short_v3(short r[3], const float n[3])
#define UNUSED(x)
struct GPUVertBuf GPUVertBuf
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len)
#define GPU_vertbuf_init_with_format(verts, format)
void * GPU_vertbuf_get_data(const GPUVertBuf *verts)
@ GPU_FETCH_INT_TO_FLOAT_UNIT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
BLI_INLINE GPUPackedNormal GPU_normal_convert_i10_v3(const float data[3])
@ GPU_COMP_I10
@ GPU_COMP_I16
@ BM_ELEM_HIDDEN
Definition: bmesh_class.h:472
@ BM_ELEM_SELECT
Definition: bmesh_class.h:471
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:12
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:115
@ MR_DATA_LOOP_NOR
Extraction of Mesh data into VBO to feed to GPU.
BLI_INLINE const float * bm_face_no_get(const MeshRenderData *mr, const BMFace *efa)
BLI_INLINE BMFace * bm_original_face_get(const MeshRenderData *mr, int idx)
@ MR_EXTRACT_BMESH
Definition: extract_mesh.hh:31
@ MR_EXTRACT_MAPPED
Definition: extract_mesh.hh:32
const MeshExtract extract_fdots_nor
#define NOR_AND_FLAG_ACTIVE
#define NOR_AND_FLAG_DEFAULT
const MeshExtract extract_fdots_nor_hq
#define NOR_AND_FLAG_SELECT
#define NOR_AND_FLAG_HIDDEN
uint nor
format
Definition: logImageCore.h:38
constexpr MeshExtract create_extractor_fdots_nor()
static void extract_fdots_nor_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(tls_data))
constexpr MeshExtract create_extractor_fdots_nor_hq()
static void extract_fdots_nor_finish(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(data))
static void extract_fdots_nor_hq_finish(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(data))
static void extract_fdots_nor_hq_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(tls_data))
GPUVertBuf * fdots_nor
size_t mesh_buffer_offset
eMRDataType data_type
ExtractFinishFn * finish
size_t data_size
bool use_threading
ExtractInitFn * init
eMRExtractType extract_type
Definition: extract_mesh.hh:37
const int * p_origindex
Definition: extract_mesh.hh:66
BMFace * efa_act
Definition: extract_mesh.hh:80