Blender  V3.3
extract_mesh.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 
10 #include "MEM_guardedalloc.h"
11 
12 #include "DNA_object_types.h"
13 
14 #include "ED_uvedit.h"
15 
16 #include "extract_mesh.hh"
17 
18 #include "draw_cache_impl.h"
19 
20 void *mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist)
21 {
22  /* NOTE: POINTER_OFFSET on windows platforms casts internally to `void *`, but on GCC/CLANG to
23  * `MeshBufferList *`. What shows a different usage versus intent. */
24  void **buffer_ptr = (void **)POINTER_OFFSET(mbuflist, extractor->mesh_buffer_offset);
25  void *buffer = *buffer_ptr;
27  return buffer;
28 }
29 
30 eMRIterType mesh_extract_iter_type(const MeshExtract *ext)
31 {
32  eMRIterType type = (eMRIterType)0;
33  SET_FLAG_FROM_TEST(type, (ext->iter_looptri_bm || ext->iter_looptri_mesh), MR_ITER_LOOPTRI);
34  SET_FLAG_FROM_TEST(type, (ext->iter_poly_bm || ext->iter_poly_mesh), MR_ITER_POLY);
35  SET_FLAG_FROM_TEST(type, (ext->iter_ledge_bm || ext->iter_ledge_mesh), MR_ITER_LEDGE);
36  SET_FLAG_FROM_TEST(type, (ext->iter_lvert_bm || ext->iter_lvert_mesh), MR_ITER_LVERT);
37  return type;
38 }
39 
40 /* ---------------------------------------------------------------------- */
47 {
48  if (extractor == &extract_pos_nor) {
49  return &extract_pos_nor_hq;
50  }
51  if (extractor == &extract_lnor) {
52  return &extract_lnor_hq;
53  }
54  if (extractor == &extract_tan) {
55  return &extract_tan_hq;
56  }
57  if (extractor == &extract_fdots_nor) {
58  return &extract_fdots_nor_hq;
59  }
60  return extractor;
61 }
62 
64 {
65  if (extractor == &extract_tris) {
67  }
68  return extractor;
69 }
70 
72  const bool do_hq_normals,
73  const bool do_single_mat)
74 {
75  if (do_hq_normals) {
76  extractor = mesh_extract_override_hq_normals(extractor);
77  }
78 
79  if (do_single_mat) {
80  extractor = mesh_extract_override_single_material(extractor);
81  }
82 
83  return extractor;
84 }
85 
88 /* ---------------------------------------------------------------------- */
93  const BMFace *efa,
94  const int cd_ofs,
95  EditLoopData *eattr)
96 {
97  if (efa == mr->efa_act) {
98  eattr->v_flag |= VFLAG_FACE_ACTIVE;
99  }
100  if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
101  eattr->v_flag |= VFLAG_FACE_SELECTED;
102  }
103 
104  if (efa == mr->efa_act_uv) {
105  eattr->v_flag |= VFLAG_FACE_UV_ACTIVE;
106  }
107  if ((cd_ofs != -1) && uvedit_face_select_test_ex(mr->toolsettings, (BMFace *)efa, cd_ofs)) {
108  eattr->v_flag |= VFLAG_FACE_UV_SELECT;
109  }
110 
111 #ifdef WITH_FREESTYLE
112  if (mr->freestyle_face_ofs != -1) {
113  const FreestyleFace *ffa = (const FreestyleFace *)BM_ELEM_CD_GET_VOID_P(
114  efa, mr->freestyle_face_ofs);
115  if (ffa->flag & FREESTYLE_FACE_MARK) {
116  eattr->v_flag |= VFLAG_FACE_FREESTYLE;
117  }
118  }
119 #endif
120 }
121 
123  BMLoop *l,
124  const int cd_ofs,
125  EditLoopData *eattr)
126 {
127  if (cd_ofs == -1) {
128  return;
129  }
130  MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_ofs);
131  if (luv != nullptr && (luv->flag & MLOOPUV_PINNED)) {
132  eattr->v_flag |= VFLAG_VERT_UV_PINNED;
133  }
134  if (uvedit_uv_select_test_ex(mr->toolsettings, l, cd_ofs)) {
135  eattr->v_flag |= VFLAG_VERT_UV_SELECT;
136  }
137 }
138 
140  BMLoop *l,
141  const int cd_ofs,
142  EditLoopData *eattr)
143 {
144  if (cd_ofs == -1) {
145  return;
146  }
147  if (uvedit_edge_select_test_ex(mr->toolsettings, l, cd_ofs)) {
148  eattr->v_flag |= VFLAG_EDGE_UV_SELECT;
149  eattr->v_flag |= VFLAG_VERT_UV_SELECT;
150  }
151 }
152 
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define SET_FLAG_FROM_TEST(value, test, flag)
#define POINTER_OFFSET(v, ofs)
@ MLOOPUV_PINNED
@ FREESTYLE_FACE_MARK
Object is a sort of wrapper for general info.
bool uvedit_edge_select_test_ex(const struct ToolSettings *ts, struct BMLoop *l, int cd_loop_uv_offset)
bool uvedit_uv_select_test_ex(const struct ToolSettings *ts, struct BMLoop *l, int cd_loop_uv_offset)
bool uvedit_face_select_test_ex(const struct ToolSettings *ts, struct BMFace *efa, int cd_loop_uv_offset)
_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 type
Read Guarded memory(de)allocation.
@ BM_ELEM_SELECT
Definition: bmesh_class.h:471
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:12
ATTR_WARN_UNUSED_RESULT const BMLoop * l
@ VFLAG_FACE_UV_ACTIVE
@ VFLAG_FACE_ACTIVE
@ VFLAG_VERT_UV_PINNED
@ VFLAG_FACE_UV_SELECT
@ VFLAG_FACE_SELECTED
@ VFLAG_VERT_UV_SELECT
@ VFLAG_FACE_FREESTYLE
@ VFLAG_EDGE_UV_SELECT
const MeshExtract * mesh_extract_override_get(const MeshExtract *extractor, const bool do_hq_normals, const bool do_single_mat)
Definition: extract_mesh.cc:71
void mesh_render_data_loop_flag(const MeshRenderData *mr, BMLoop *l, const int cd_ofs, EditLoopData *eattr)
eMRIterType mesh_extract_iter_type(const MeshExtract *ext)
Definition: extract_mesh.cc:30
void * mesh_extract_buffer_get(const MeshExtract *extractor, MeshBufferList *mbuflist)
Definition: extract_mesh.cc:20
static const MeshExtract * mesh_extract_override_hq_normals(const MeshExtract *extractor)
Definition: extract_mesh.cc:46
void mesh_render_data_loop_edge_flag(const MeshRenderData *mr, BMLoop *l, const int cd_ofs, EditLoopData *eattr)
void mesh_render_data_face_flag(const MeshRenderData *mr, const BMFace *efa, const int cd_ofs, EditLoopData *eattr)
Definition: extract_mesh.cc:92
static const MeshExtract * mesh_extract_override_single_material(const MeshExtract *extractor)
Definition: extract_mesh.cc:63
Extraction of Mesh data into VBO to feed to GPU.
const MeshExtract extract_tris_single_mat
const MeshExtract extract_fdots_nor
const MeshExtract extract_lnor
const MeshExtract extract_fdots_nor_hq
const MeshExtract extract_tris
const MeshExtract extract_pos_nor_hq
const MeshExtract extract_lnor_hq
const MeshExtract extract_pos_nor
const MeshExtract extract_tan_hq
const MeshExtract extract_tan
ccl_global float * buffer
size_t mesh_buffer_offset
ExtractLVertBMeshFn * iter_lvert_bm
ExtractLVertMeshFn * iter_lvert_mesh
ExtractLEdgeBMeshFn * iter_ledge_bm
ExtractTriBMeshFn * iter_looptri_bm
ExtractPolyBMeshFn * iter_poly_bm
ExtractLEdgeMeshFn * iter_ledge_mesh
ExtractPolyMeshFn * iter_poly_mesh
ExtractTriMeshFn * iter_looptri_mesh
BMFace * efa_act_uv
Definition: extract_mesh.hh:81
const ToolSettings * toolsettings
Definition: extract_mesh.hh:53
BMFace * efa_act
Definition: extract_mesh.hh:80