Blender  V3.3
extract_mesh_vbo_orco.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 /* ---------------------------------------------------------------------- */
17  float (*vbo_data)[4];
18  const float (*orco)[3];
19 };
20 
21 static void extract_orco_init(const MeshRenderData *mr,
22  MeshBatchCache *UNUSED(cache),
23  void *buf,
24  void *tls_data)
25 {
26  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
27  static GPUVertFormat format = {0};
28  if (format.attr_len == 0) {
29  /* FIXME(fclem): We use the last component as a way to differentiate from generic vertex
30  * attributes. This is a substantial waste of video-ram and should be done another way.
31  * Unfortunately, at the time of writing, I did not found any other "non disruptive"
32  * alternative. */
34  }
35 
38 
39  CustomData *cd_vdata = &mr->me->vdata;
40 
41  MeshExtract_Orco_Data *data = static_cast<MeshExtract_Orco_Data *>(tls_data);
42  data->vbo_data = (float(*)[4])GPU_vertbuf_get_data(vbo);
43  data->orco = static_cast<const float(*)[3]>(CustomData_get_layer(cd_vdata, CD_ORCO));
44  /* Make sure `orco` layer was requested only if needed! */
45  BLI_assert(data->orco);
46 }
47 
49  const BMFace *f,
50  const int UNUSED(f_index),
51  void *data)
52 {
54  BMLoop *l_iter, *l_first;
55  l_iter = l_first = BM_FACE_FIRST_LOOP(f);
56  do {
57  const int l_index = BM_elem_index_get(l_iter);
58  float *loop_orco = orco_data->vbo_data[l_index];
59  copy_v3_v3(loop_orco, orco_data->orco[BM_elem_index_get(l_iter->v)]);
60  loop_orco[3] = 0.0; /* Tag as not a generic attribute. */
61  } while ((l_iter = l_iter->next) != l_first);
62 }
63 
65  const MPoly *mp,
66  const int UNUSED(mp_index),
67  void *data)
68 {
69  const MLoop *mloop = mr->mloop;
70  const int ml_index_end = mp->loopstart + mp->totloop;
71  for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) {
72  const MLoop *ml = &mloop[ml_index];
74  float *loop_orco = orco_data->vbo_data[ml_index];
75  copy_v3_v3(loop_orco, orco_data->orco[ml->v]);
76  loop_orco[3] = 0.0; /* Tag as not a generic attribute. */
77  }
78 }
79 
81 {
82  MeshExtract extractor = {nullptr};
83  extractor.init = extract_orco_init;
86  extractor.data_type = MR_DATA_NONE;
87  extractor.data_size = sizeof(MeshExtract_Orco_Data);
88  extractor.use_threading = true;
89  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.orco);
90  return extractor;
91 }
92 
95 } // namespace blender::draw
96 
typedef float(TangentPoint)[2]
void * CustomData_get_layer(const struct CustomData *data, int type)
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE void copy_v3_v3(float r[3], const float a[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_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
#define BM_FACE_FIRST_LOOP(p)
Definition: bmesh_class.h:622
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:110
@ MR_DATA_NONE
Extraction of Mesh data into VBO to feed to GPU.
const MeshExtract extract_orco
format
Definition: logImageCore.h:38
static void extract_orco_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *tls_data)
constexpr MeshExtract create_extractor_orco()
static void extract_orco_iter_poly_mesh(const MeshRenderData *mr, const MPoly *mp, const int UNUSED(mp_index), void *data)
static void extract_orco_iter_poly_bm(const MeshRenderData *UNUSED(mr), const BMFace *f, const int UNUSED(f_index), void *data)
struct BMVert * v
Definition: bmesh_class.h:153
struct BMLoop * next
Definition: bmesh_class.h:233
unsigned int v
size_t mesh_buffer_offset
eMRDataType data_type
size_t data_size
ExtractPolyBMeshFn * iter_poly_bm
ExtractPolyMeshFn * iter_poly_mesh
bool use_threading
ExtractInitFn * init
const MLoop * mloop
Definition: extract_mesh.hh:76
CustomData vdata