Blender  V2.93
draw_cache_extract.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2019, Blender Foundation.
17  */
18 
23 #pragma once
24 
25 struct TaskGraph;
26 
27 /* Vertex Group Selection and display options */
28 typedef struct DRW_MeshWeightState {
31 
32  short flags;
33  char alert_mode;
34 
35  /* Set of all selected bones for Multipaint. */
36  bool *defgroup_sel; /* [defgroup_len] */
38 
39  /* Set of all locked and unlocked deform bones for Lock Relative mode. */
40  bool *defgroup_locked; /* [defgroup_len] */
41  bool *defgroup_unlocked; /* [defgroup_len] */
43 
44 /* DRW_MeshWeightState.flags */
45 enum {
49 };
50 
51 typedef struct DRW_MeshCDMask {
52  uint32_t uv : 8;
63 /* Keep `DRW_MeshCDMask` struct within an `uint64_t`.
64  * bit-wise and atomic operations are used to compare and update the struct.
65  * See `mesh_cd_layers_type_*` functions. */
66 BLI_STATIC_ASSERT(sizeof(DRW_MeshCDMask) <= sizeof(uint64_t), "DRW_MeshCDMask exceeds 64 bits")
67 
68 typedef enum eMRIterType {
69  MR_ITER_LOOPTRI = 1 << 0,
70  MR_ITER_POLY = 1 << 1,
71  MR_ITER_LEDGE = 1 << 2,
72  MR_ITER_LVERT = 1 << 3,
74 
75 typedef enum eMRDataType {
76  MR_DATA_POLY_NOR = 1 << 1,
77  MR_DATA_LOOP_NOR = 1 << 2,
78  MR_DATA_LOOPTRI = 1 << 3,
82 
83 typedef enum eMRExtractType {
88 
90 {
91  return MAX2(1, me->totcol);
92 }
93 
94 typedef struct MeshBufferCache {
95  /* Every VBO below contains at least enough
96  * data for every loops in the mesh (except fdots and skin roots).
97  * For some VBOs, it extends to (in this exact order) :
98  * loops + loose_edges*2 + loose_verts */
99  struct {
100  GPUVertBuf *pos_nor; /* extend */
101  GPUVertBuf *lnor; /* extend */
102  GPUVertBuf *edge_fac; /* extend */
103  GPUVertBuf *weights; /* extend */
109  /* Only for edit mode. */
110  GPUVertBuf *edit_data; /* extend */
118  // GPUVertBuf *fdots_edit_data; /* inside fdots_nor for now. */
121  /* Selection */
122  GPUVertBuf *vert_idx; /* extend */
123  GPUVertBuf *edge_idx; /* extend */
126  } vbo;
127  /* Index Buffers:
128  * Only need to be updated when topology changes. */
129  struct {
130  /* Indices to vloops. */
131  GPUIndexBuf *tris; /* Ordered per material. */
132  GPUIndexBuf *lines; /* Loose edges last. */
133  GPUIndexBuf *lines_loose; /* sub buffer of `lines` only containing the loose edges. */
136  /* 3D overlays. */
137  GPUIndexBuf *lines_paint_mask; /* no loose edges. */
139  /* Uv overlays. (visibility can differ from 3D view) */
144  } ibo;
145  /* Index buffer per material. These are subranges of `ibo.tris` */
148 
149 typedef enum DRWBatchFlag {
150  MBC_SURFACE = (1 << 0),
152  MBC_EDIT_TRIANGLES = (1 << 2),
153  MBC_EDIT_VERTICES = (1 << 3),
154  MBC_EDIT_EDGES = (1 << 4),
155  MBC_EDIT_VNOR = (1 << 5),
156  MBC_EDIT_LNOR = (1 << 6),
157  MBC_EDIT_FACEDOTS = (1 << 7),
161  MBC_EDITUV_FACES = (1 << 11),
162  MBC_EDITUV_EDGES = (1 << 12),
163  MBC_EDITUV_VERTS = (1 << 13),
164  MBC_EDITUV_FACEDOTS = (1 << 14),
169  MBC_ALL_VERTS = (1 << 19),
170  MBC_ALL_EDGES = (1 << 20),
171  MBC_LOOSE_EDGES = (1 << 21),
172  MBC_EDGE_DETECTION = (1 << 22),
173  MBC_WIRE_EDGES = (1 << 23),
174  MBC_WIRE_LOOPS = (1 << 24),
175  MBC_WIRE_LOOPS_UVS = (1 << 25),
176  MBC_SKIN_ROOTS = (1 << 26),
177  MBC_SCULPT_OVERLAYS = (1 << 27),
179 
180 #define MBC_EDITUV \
181  (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \
182  MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS)
183 
184 #define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
185  for (MeshBufferCache *mbc = &batch_cache->final; \
186  mbc == &batch_cache->final || mbc == &batch_cache->cage || mbc == &batch_cache->uv_cage; \
187  mbc = (mbc == &batch_cache->final) ? \
188  &batch_cache->cage : \
189  ((mbc == &batch_cache->cage) ? &batch_cache->uv_cage : NULL))
190 
191 typedef struct MeshBatchCache {
193 
194  struct {
195  /* Surfaces / Render */
198  /* Edit mode */
207  /* Edit UVs */
214  /* Edit selection */
219  /* Common display / Other */
224  GPUBatch *wire_edges; /* Individual edges with face normals. */
225  GPUBatch *wire_loops; /* Loops around faces. no edges between selected faces */
226  GPUBatch *wire_loops_uvs; /* Same as wire_loops but only has uvs. */
228  } batch;
229 
231 
234 
235  /* settings to determine if cache is invalid */
236  int edge_len;
237  int tri_len;
238  int poly_len;
239  int vert_len;
240  int mat_len;
241  bool is_dirty; /* Instantly invalidates cache, skipping mesh check */
244 
246 
248 
250 
251  /* Valid only if edge_detection is up to date. */
253 
254  /* Total areas for drawing UV Stretching. Contains the summed area in mesh
255  * space (`tot_area`) and the summed area in uv space (`tot_uvarea`).
256  *
257  * Only valid after `DRW_mesh_batch_cache_create_requested` has been called. */
259 
262 
263 void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
264  MeshBatchCache *cache,
265  MeshBufferCache mbc,
266  Mesh *me,
267  const bool is_editmode,
268  const bool is_paint_mode,
269  const bool is_mode_active,
270  const float obmat[4][4],
271  const bool do_final,
272  const bool do_uvedit,
273  const bool use_subsurf_fdots,
274  const DRW_MeshCDMask *cd_layer_used,
275  const Scene *scene,
276  const ToolSettings *ts,
277  const bool use_hide);
#define BLI_INLINE
#define MAX2(a, b)
GPUBatch
Definition: GPU_batch.h:93
struct GPUIndexBuf GPUIndexBuf
struct GPUVertBuf GPUVertBuf
Scene scene
struct MeshBufferCache MeshBufferCache
@ DRW_MESH_WEIGHT_STATE_MULTIPAINT
@ DRW_MESH_WEIGHT_STATE_AUTO_NORMALIZE
@ DRW_MESH_WEIGHT_STATE_LOCK_RELATIVE
struct DRW_MeshCDMask DRW_MeshCDMask
BLI_INLINE int mesh_render_mat_len_get(Mesh *me)
BLI_STATIC_ASSERT(sizeof(DRW_MeshCDMask)<=sizeof(uint64_t), "DRW_MeshCDMask exceeds 64 bits") typedef enum eMRIterType
struct DRW_MeshWeightState DRW_MeshWeightState
eMRExtractType
@ MR_EXTRACT_BMESH
@ MR_EXTRACT_MESH
@ MR_EXTRACT_MAPPED
eMRIterType
DRWBatchFlag
@ MBC_EDIT_VNOR
@ MBC_EDITUV_FACES_STRETCH_AREA
@ MBC_EDIT_EDGES
@ MBC_LOOSE_EDGES
@ MBC_EDITUV_EDGES
@ MBC_EDITUV_FACEDOTS
@ MBC_SCULPT_OVERLAYS
@ MBC_EDIT_SELECTION_EDGES
@ MBC_EDGE_DETECTION
@ MBC_WIRE_LOOPS_UVS
@ MBC_EDIT_LNOR
@ MBC_ALL_EDGES
@ MBC_EDITUV_FACES
@ MBC_EDITUV_FACES_STRETCH_ANGLE
@ MBC_EDIT_VERTICES
@ MBC_EDIT_MESH_ANALYSIS
@ MBC_EDIT_SELECTION_FACEDOTS
@ MBC_EDIT_FACEDOTS
@ MBC_SURFACE_WEIGHTS
@ MBC_WIRE_LOOPS
@ MBC_EDITUV_VERTS
@ MBC_SKIN_ROOTS
@ MBC_SURFACE
@ MBC_ALL_VERTS
@ MBC_EDIT_SELECTION_VERTS
@ MBC_EDIT_TRIANGLES
@ MBC_WIRE_EDGES
@ MBC_EDIT_SELECTION_FACES
struct MeshBatchCache MeshBatchCache
eMRDataType
@ MR_DATA_LOOP_NOR
@ MR_DATA_TAN_LOOP_NOR
@ MR_DATA_POLY_NOR
@ MR_DATA_LOOPTRI
void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, MeshBatchCache *cache, MeshBufferCache mbc, Mesh *me, const bool is_editmode, const bool is_paint_mode, const bool is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, const bool use_subsurf_fdots, const DRW_MeshCDMask *cd_layer_used, const Scene *scene, const ToolSettings *ts, const bool use_hide)
unsigned int uint32_t
Definition: stdint.h:83
unsigned __int64 uint64_t
Definition: stdint.h:93
uint32_t sculpt_overlays
DRW_MeshCDMask cd_used
GPUBatch * edit_selection_faces
GPUBatch * edituv_edges
DRW_MeshCDMask cd_needed
DRW_MeshCDMask cd_used_over_time
GPUBatch * edit_selection_edges
GPUBatch ** surface_per_mat
GPUBatch * sculpt_overlays
MeshBufferCache uv_cage
GPUBatch * edituv_verts
MeshBufferCache cage
DRWBatchFlag batch_requested
GPUBatch * edit_skin_roots
GPUBatch * edituv_faces_stretch_angle
GPUBatch * wire_loops_uvs
GPUBatch * edit_vertices
GPUBatch * edit_selection_verts
GPUBatch * loose_edges
GPUBatch * edit_mesh_analysis
GPUBatch * edituv_faces_stretch_area
GPUBatch * edge_detection
DRWBatchFlag batch_ready
struct DRW_MeshWeightState weight_state
GPUBatch * edituv_faces
GPUBatch * surface_weights
GPUBatch * edit_triangles
GPUBatch * edituv_fdots
GPUBatch * edit_selection_fdots
struct MeshBatchCache::@262 batch
GPUIndexBuf * edituv_tris
GPUVertBuf * fdots_uv
GPUIndexBuf * edituv_fdots
GPUVertBuf * edituv_data
GPUVertBuf * edge_fac
GPUVertBuf * edge_idx
GPUVertBuf * fdots_pos
GPUIndexBuf * lines_adjacency
GPUIndexBuf * lines_paint_mask
struct MeshBufferCache::@261 ibo
GPUIndexBuf * edituv_lines
GPUVertBuf * poly_idx
GPUVertBuf * edituv_stretch_area
GPUVertBuf * fdot_idx
GPUVertBuf * edituv_stretch_angle
GPUVertBuf * fdots_nor
GPUIndexBuf * tris
GPUIndexBuf ** tris_per_mat
GPUVertBuf * weights
GPUIndexBuf * lines
GPUVertBuf * mesh_analysis
GPUVertBuf * skin_roots
GPUIndexBuf * points
struct MeshBufferCache::@260 vbo
GPUIndexBuf * lines_loose
GPUIndexBuf * fdots
GPUVertBuf * vert_idx
GPUVertBuf * sculpt_data
GPUVertBuf * fdots_edituv_data
GPUVertBuf * edit_data
GPUIndexBuf * edituv_points
GPUVertBuf * pos_nor
short totcol