Blender  V3.3
extract_mesh_vbo_fdots_pos.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 "BLI_bitmap.h"
9 
10 #include "extract_mesh.hh"
11 
12 #include "draw_subdivision.h"
13 
14 namespace blender::draw {
15 
16 /* ---------------------------------------------------------------------- */
21 {
22  static GPUVertFormat format = {0};
23  if (format.attr_len == 0) {
25  }
26  return &format;
27 }
28 
30 {
31  static GPUVertFormat format = {0};
32  if (format.attr_len == 0) {
34  }
35  return &format;
36 }
37 
38 static void extract_fdots_pos_init(const MeshRenderData *mr,
39  MeshBatchCache *UNUSED(cache),
40  void *buf,
41  void *tls_data)
42 {
43  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
47  void *vbo_data = GPU_vertbuf_get_data(vbo);
48  *(float(**)[3])tls_data = static_cast<float(*)[3]>(vbo_data);
49 }
50 
52  const BMFace *f,
53  const int f_index,
54  void *data)
55 {
56  float(*center)[3] = *static_cast<float(**)[3]>(data);
57 
58  float *co = center[f_index];
59  zero_v3(co);
60 
61  BMLoop *l_iter, *l_first;
62  l_iter = l_first = BM_FACE_FIRST_LOOP(f);
63  do {
64  add_v3_v3(co, bm_vert_co_get(mr, l_iter->v));
65  } while ((l_iter = l_iter->next) != l_first);
66  mul_v3_fl(co, 1.0f / (float)f->len);
67 }
68 
70  const MPoly *mp,
71  const int mp_index,
72  void *data)
73 {
74  float(*center)[3] = *static_cast<float(**)[3]>(data);
75  float *co = center[mp_index];
76  zero_v3(co);
77 
78  const MVert *mvert = mr->mvert;
79  const MLoop *mloop = mr->mloop;
80  const BLI_bitmap *facedot_tags = mr->me->runtime.subsurf_face_dot_tags;
81 
82  const int ml_index_end = mp->loopstart + mp->totloop;
83  for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) {
84  const MLoop *ml = &mloop[ml_index];
85  if (mr->use_subsurf_fdots) {
86  if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
87  copy_v3_v3(center[mp_index], mvert[ml->v].co);
88  break;
89  }
90  }
91  else {
92  const MVert *mv = &mvert[ml->v];
93  add_v3_v3(center[mp_index], mv->co);
94  }
95  }
96 
97  if (!mr->use_subsurf_fdots) {
98  mul_v3_fl(co, 1.0f / (float)mp->totloop);
99  }
100 }
101 
102 static void extract_fdots_init_subdiv(const DRWSubdivCache *subdiv_cache,
103  const MeshRenderData *UNUSED(mr),
104  MeshBatchCache *cache,
105  void *buffer,
106  void *UNUSED(data))
107 {
108  /* We "extract" positions, normals, and indices at once. */
109  GPUVertBuf *fdots_pos_vbo = static_cast<GPUVertBuf *>(buffer);
110  GPUVertBuf *fdots_nor_vbo = cache->final.buff.vbo.fdots_nor;
111  GPUIndexBuf *fdots_pos_ibo = cache->final.buff.ibo.fdots;
112 
113  /* The normals may not be requested. */
114  if (fdots_nor_vbo) {
116  fdots_nor_vbo, get_fdots_nor_format_subdiv(), subdiv_cache->num_coarse_poly);
117  }
119  fdots_pos_vbo, get_fdots_pos_format(), subdiv_cache->num_coarse_poly);
120  GPU_indexbuf_init_build_on_device(fdots_pos_ibo, subdiv_cache->num_coarse_poly);
121  draw_subdiv_build_fdots_buffers(subdiv_cache, fdots_pos_vbo, fdots_nor_vbo, fdots_pos_ibo);
122 }
123 
125 {
126  MeshExtract extractor = {nullptr};
127  extractor.init = extract_fdots_pos_init;
131  extractor.data_type = MR_DATA_NONE;
132  extractor.data_size = sizeof(float(*)[3]);
133  extractor.use_threading = true;
134  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_pos);
135  return extractor;
136 }
137 
140 } // namespace blender::draw
141 
typedef float(TangentPoint)[2]
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:64
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
NSNotificationCenter * center
struct GPUIndexBuf GPUIndexBuf
void GPU_indexbuf_init_build_on_device(GPUIndexBuf *elem, uint index_len)
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_init_build_on_device(GPUVertBuf *verts, GPUVertFormat *format, 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_FACE_FIRST_LOOP(p)
Definition: bmesh_class.h:622
@ MR_DATA_NONE
void draw_subdiv_build_fdots_buffers(const DRWSubdivCache *cache, GPUVertBuf *fdots_pos, GPUVertBuf *fdots_nor, GPUIndexBuf *fdots_indices)
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_fdots_pos
ccl_global float * buffer
format
Definition: logImageCore.h:38
static void extract_fdots_init_subdiv(const DRWSubdivCache *subdiv_cache, const MeshRenderData *UNUSED(mr), MeshBatchCache *cache, void *buffer, void *UNUSED(data))
static GPUVertFormat * get_fdots_nor_format_subdiv()
constexpr MeshExtract create_extractor_fdots_pos()
static GPUVertFormat * get_fdots_pos_format()
static void extract_fdots_pos_iter_poly_bm(const MeshRenderData *mr, const BMFace *f, const int f_index, void *data)
static void extract_fdots_pos_iter_poly_mesh(const MeshRenderData *mr, const MPoly *mp, const int mp_index, void *data)
static void extract_fdots_pos_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *tls_data)
int len
Definition: bmesh_class.h:267
struct BMVert * v
Definition: bmesh_class.h:153
struct BMLoop * next
Definition: bmesh_class.h:233
unsigned int v
float co[3]
MeshBufferCache final
MeshBufferList buff
GPUIndexBuf * fdots
GPUVertBuf * fdots_nor
struct MeshBufferList::@272 vbo
struct MeshBufferList::@273 ibo
GPUVertBuf * fdots_pos
size_t mesh_buffer_offset
eMRDataType data_type
ExtractInitSubdivFn * init_subdiv
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
bool use_subsurf_fdots
Definition: extract_mesh.hh:47
const MVert * mvert
Definition: extract_mesh.hh:74
uint32_t * subsurf_face_dot_tags
Mesh_Runtime runtime