Blender  V3.3
extract_mesh_vbo_skin_roots.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 struct SkinRootData {
17  float size;
18  float local_pos[3];
19 };
20 
22  MeshBatchCache *UNUSED(cache),
23  void *buf,
24  void *UNUSED(tls_data))
25 {
26  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
27  /* Exclusively for edit mode. */
28  BLI_assert(mr->bm);
29 
30  static GPUVertFormat format = {0};
31  if (format.attr_len == 0) {
34  }
35 
38 
40 
41  int root_len = 0;
42  int cd_ofs = CustomData_get_offset(&mr->bm->vdata, CD_MVERT_SKIN);
43 
44  BMIter iter;
45  BMVert *eve;
46  BM_ITER_MESH (eve, &iter, mr->bm, BM_VERTS_OF_MESH) {
47  const MVertSkin *vs = (const MVertSkin *)BM_ELEM_CD_GET_VOID_P(eve, cd_ofs);
48  if (vs->flag & MVERT_SKIN_ROOT) {
49  vbo_data->size = (vs->radius[0] + vs->radius[1]) * 0.5f;
50  copy_v3_v3(vbo_data->local_pos, bm_vert_co_get(mr, eve));
51  vbo_data++;
52  root_len++;
53  }
54  }
55 
56  /* It's really unlikely that all verts will be roots. Resize to avoid losing VRAM. */
57  GPU_vertbuf_data_len_set(vbo, root_len);
58 }
59 
61 {
62  MeshExtract extractor = {nullptr};
63  extractor.init = extract_skin_roots_init;
64  extractor.data_type = MR_DATA_NONE;
65  extractor.data_size = 0;
66  extractor.use_threading = false;
67  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.skin_roots);
68  return extractor;
69 }
70 
73 } // namespace blender::draw
74 
int CustomData_get_offset(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)
@ CD_MVERT_SKIN
@ MVERT_SKIN_ROOT
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)
void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len)
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_VERTS_OF_MESH
@ MR_DATA_NONE
Extraction of Mesh data into VBO to feed to GPU.
BLI_INLINE const float * bm_vert_co_get(const MeshRenderData *mr, const BMVert *eve)
const MeshExtract extract_skin_roots
format
Definition: logImageCore.h:38
constexpr MeshExtract create_extractor_skin_roots()
static void extract_skin_roots_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *UNUSED(tls_data))
int totvert
Definition: bmesh_class.h:297
CustomData vdata
Definition: bmesh_class.h:337
GPUVertBuf * skin_roots
size_t mesh_buffer_offset
eMRDataType data_type
size_t data_size
bool use_threading
ExtractInitFn * init