Blender  V3.3
extract_mesh_vbo_fdots_uv.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 namespace blender::draw {
13 
14 /* ---------------------------------------------------------------------- */
19  float (*vbo_data)[2];
20  const MLoopUV *uv_data;
21  int cd_ofs;
22 };
23 
24 static void extract_fdots_uv_init(const MeshRenderData *mr,
25  MeshBatchCache *UNUSED(cache),
26  void *buf,
27  void *tls_data)
28 {
29  GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
30  static GPUVertFormat format = {0};
31  if (format.attr_len == 0) {
35  }
36 
39 
40  if (!mr->use_subsurf_fdots) {
41  /* Clear so we can accumulate on it. */
42  memset(GPU_vertbuf_get_data(vbo), 0x0, mr->poly_len * GPU_vertbuf_get_format(vbo)->stride);
43  }
44 
45  MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(tls_data);
46  data->vbo_data = (float(*)[2])GPU_vertbuf_get_data(vbo);
47 
48  if (mr->extract_type == MR_EXTRACT_BMESH) {
49  data->cd_ofs = CustomData_get_offset(&mr->bm->ldata, CD_MLOOPUV);
50  }
51  else {
52  data->uv_data = (const MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
53  }
54 }
55 
57  const BMFace *f,
58  const int UNUSED(f_index),
59  void *_data)
60 {
61  MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data);
62  BMLoop *l_iter, *l_first;
63  l_iter = l_first = BM_FACE_FIRST_LOOP(f);
64  do {
65  float w = 1.0f / (float)f->len;
66  const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, data->cd_ofs);
67  madd_v2_v2fl(data->vbo_data[BM_elem_index_get(f)], luv->uv, w);
68  } while ((l_iter = l_iter->next) != l_first);
69 }
70 
72  const MPoly *mp,
73  const int mp_index,
74  void *_data)
75 {
76  MeshExtract_FdotUV_Data *data = static_cast<MeshExtract_FdotUV_Data *>(_data);
77  const BLI_bitmap *facedot_tags = mr->me->runtime.subsurf_face_dot_tags;
78 
79  const MLoop *mloop = mr->mloop;
80  const int ml_index_end = mp->loopstart + mp->totloop;
81  for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) {
82  const MLoop *ml = &mloop[ml_index];
83  if (mr->use_subsurf_fdots) {
84  if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
85  copy_v2_v2(data->vbo_data[mp_index], data->uv_data[ml_index].uv);
86  }
87  }
88  else {
89  float w = 1.0f / (float)mp->totloop;
90  madd_v2_v2fl(data->vbo_data[mp_index], data->uv_data[ml_index].uv, w);
91  }
92  }
93 }
94 
96 {
97  MeshExtract extractor = {nullptr};
98  extractor.init = extract_fdots_uv_init;
101  extractor.data_type = MR_DATA_NONE;
102  extractor.data_size = sizeof(MeshExtract_FdotUV_Data);
103  extractor.use_threading = true;
104  extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.fdots_uv);
105  return extractor;
106 }
107 
110 } // namespace blender::draw
111 
typedef float(TangentPoint)[2]
void * CustomData_get_layer(const struct CustomData *data, int type)
int CustomData_get_offset(const struct CustomData *data, int type)
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:64
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
#define UNUSED(x)
@ CD_MLOOPUV
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
const GPUVertFormat * GPU_vertbuf_get_format(const GPUVertBuf *verts)
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)
void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias)
@ GPU_COMP_F32
#define BM_FACE_FIRST_LOOP(p)
Definition: bmesh_class.h:622
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:110
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
@ MR_DATA_NONE
Extraction of Mesh data into VBO to feed to GPU.
@ MR_EXTRACT_BMESH
Definition: extract_mesh.hh:31
const MeshExtract extract_fdots_uv
format
Definition: logImageCore.h:38
constexpr MeshExtract create_extractor_fdots_uv()
static void extract_fdots_uv_init(const MeshRenderData *mr, MeshBatchCache *UNUSED(cache), void *buf, void *tls_data)
static void extract_fdots_uv_iter_poly_bm(const MeshRenderData *UNUSED(mr), const BMFace *f, const int UNUSED(f_index), void *_data)
static void extract_fdots_uv_iter_poly_mesh(const MeshRenderData *mr, const MPoly *mp, const int mp_index, void *_data)
int len
Definition: bmesh_class.h:267
struct BMLoop * next
Definition: bmesh_class.h:233
CustomData ldata
Definition: bmesh_class.h:337
unsigned int v
GPUVertBuf * fdots_uv
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
eMRExtractType extract_type
Definition: extract_mesh.hh:37
const MLoop * mloop
Definition: extract_mesh.hh:76
bool use_subsurf_fdots
Definition: extract_mesh.hh:47
uint32_t * subsurf_face_dot_tags
Mesh_Runtime runtime
CustomData ldata