Blender  V3.3
draw_subdivision.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. */
3 
4 #pragma once
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #include "BLI_sys_types.h"
11 
12 struct BMesh;
13 struct GPUIndexBuf;
14 struct GPUUniformBuf;
15 struct GPUVertBuf;
16 struct GPUVertFormat;
17 struct Mesh;
18 struct MeshBatchCache;
19 struct MeshBufferCache;
20 struct MeshRenderData;
21 struct Object;
22 struct Scene;
23 struct Subdiv;
24 struct ToolSettings;
25 
26 /* -------------------------------------------------------------------- */
33 typedef struct DRWPatchMap {
38  int max_depth;
41 
44 /* -------------------------------------------------------------------- */
50 typedef struct DRWSubdivLooseEdge {
51  /* The corresponding coarse edge, this is always valid. */
53  /* Pointers into #DRWSubdivLooseGeom.verts. */
57 
60 /* -------------------------------------------------------------------- */
67 typedef struct DRWSubdivLooseVertex {
68  /* The corresponding coarse vertex, or -1 if this vertex is the result
69  * of subdivision. */
70  unsigned int coarse_vertex_index;
71  /* Position and normal of the vertex. */
72  float co[3];
73  float nor[3];
75 
78 /* -------------------------------------------------------------------- */
84 typedef struct DRWSubdivLooseGeom {
87  int edge_len;
88  int vert_len;
89  int loop_len;
91 
94 /* -------------------------------------------------------------------- */
100 typedef struct DRWSubdivCache {
101  struct Mesh *mesh;
102  struct BMesh *bm;
103  struct Subdiv *subdiv;
106 
107  /* Coordinates used to evaluate patches for positions and normals. */
109  /* Coordinates used to evaluate patches for attributes. */
111  /* Coordinates used to evaluate patches for the face centers (or face dots) in edit-mode. */
113 
114  /* Resolution used to generate the patch coordinates. */
116 
117  /* Number of subdivided loops, also the number of patch coordinates since we have one coordinate
118  * but quad corner/vertex. */
124 
125  /* We only do the subdivision traversal for full faces, however we may have geometries that only
126  * have loose edges (e.g. a custom bone shape). This flag is used to detect those cases, as the
127  * counters above will all be set to zero if we do not have subdivision loops. */
129 
130  /* Number of polygons in the coarse mesh, notably used to compute a coarse polygon index given a
131  * subdivision loop index. */
133 
134  /* Maps subdivision loop to subdivided vertex index. */
136  /* Maps subdivision loop to subdivided edge index. */
138  /* Maps subdivision loop to original coarse poly index. */
140 
141  /* Indices of faces adjacent to the vertices, ordered by vertex index, with no particular
142  * winding. */
144  /* The difference between value (i + 1) and (i) gives the number of faces adjacent to vertex (i).
145  */
147 
148  /* Maps subdivision loop to original coarse vertex index, only really useful for edit mode. */
150  /* Maps subdivision loop to original coarse edge index, only really useful for edit mode. */
152 
153  /* Owned by #Subdiv. Indexed by coarse polygon index, difference between value (i + 1) and (i)
154  * gives the number of ptex faces for coarse polygon (i). */
156  /* Vertex buffer for face_ptex_offset. */
158 
161 
162  /* Contains the start loop index and the smooth flag for each coarse polygon. */
164 
165  /* Computed for `ibo.points`, one value per subdivided vertex,
166  * mapping coarse vertices -> subdivided loop. */
168 
169  /* Material offsets. */
170  int *mat_start;
171  int *mat_end;
173 
175 
177 
178  /* UBO to store settings for the various compute shaders. */
180 
181  /* Extra flags, passed to the UBO. */
183  bool use_hide;
185 
186 /* Only frees the data of the cache, caller is responsible to free the cache itself if necessary.
187  */
189 
192 void DRW_create_subdivision(struct Object *ob,
193  struct Mesh *mesh,
194  struct MeshBatchCache *batch_cache,
195  struct MeshBufferCache *mbc,
196  const bool is_editmode,
197  const bool is_paint_mode,
198  const bool is_mode_active,
199  const float obmat[4][4],
200  const bool do_final,
201  const bool do_uvedit,
202  const bool do_cage,
203  const ToolSettings *ts,
204  const bool use_hide);
205 
206 void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, struct MeshBufferCache *cache);
207 
208 void DRW_subdiv_cache_free(struct Subdiv *subdiv);
209 
211  struct MeshRenderData *mr,
212  const struct ToolSettings *toolsettings);
213 
215  int32_t *vert_origindex,
216  uint num_loops,
217  uint loose_len);
218 
219 struct GPUVertBuf *draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops);
220 
221 /* Compute shader functions. */
222 
224  struct GPUVertBuf *mask_vbo,
225  struct GPUVertBuf *face_set_vbo,
226  struct GPUVertBuf *sculpt_data);
227 
229  struct GPUVertBuf *pos_nor,
230  struct GPUVertBuf *face_adjacency_offsets,
231  struct GPUVertBuf *face_adjacency_lists,
232  struct GPUVertBuf *vertex_loop_map,
233  struct GPUVertBuf *vertex_normals);
234 
236  struct GPUVertBuf *vertex_normals,
237  struct GPUVertBuf *subdiv_loop_subdiv_vert_index,
238  struct GPUVertBuf *pos_nor);
239 
241  GPUVertBuf *src_custom_normals,
242  GPUVertBuf *pos_nor);
243 
245  struct GPUVertBuf *pos_nor,
246  struct GPUVertBuf *orco);
247 
249  struct GPUVertBuf *src_data,
250  struct GPUVertBuf *dst_data,
251  int dimensions,
252  int dst_offset,
253  bool compress_to_u16);
254 
255 void draw_subdiv_extract_uvs(const DRWSubdivCache *cache,
256  struct GPUVertBuf *uvs,
257  int face_varying_channel,
258  int dst_offset);
259 
261  struct GPUVertBuf *pos_nor,
262  struct GPUVertBuf *edge_idx,
263  struct GPUVertBuf *edge_fac);
264 
266  struct GPUIndexBuf *subdiv_tris,
267  int material_count);
268 
270  struct GPUIndexBuf *lines_indices);
271 
273  struct GPUIndexBuf *lines_indices,
274  GPUVertBuf *lines_flags,
275  uint num_loose_edges);
276 
278  struct GPUVertBuf *fdots_pos,
279  struct GPUVertBuf *fdots_nor,
280  struct GPUIndexBuf *fdots_indices);
281 
283  struct GPUVertBuf *pos_nor,
284  struct GPUVertBuf *lnor);
285 
287  struct GPUVertBuf *coarse_data,
288  struct GPUVertBuf *subdiv_data);
289 
291  struct GPUVertBuf *pos_nor,
292  struct GPUVertBuf *uvs,
293  int uvs_offset,
294  struct GPUVertBuf *stretch_angles);
295 
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #ifdef __cplusplus
305 # include "BLI_span.hh"
306 
307 /* Helper to access the loose edges. */
309 
310 /* Helper to access only the loose vertices, i.e. not the ones attached to loose edges. To access
311  * loose vertices of loose edges #draw_subdiv_cache_get_loose_edges should be used. */
313 
314 #endif
unsigned int uint
Definition: BLI_sys_types.h:67
struct GPUIndexBuf GPUIndexBuf
struct GPUUniformBuf GPUUniformBuf
struct GPUVertBuf GPUVertBuf
blender::Span< DRWSubdivLooseVertex > draw_subdiv_cache_get_loose_verts(const DRWSubdivCache *cache)
blender::Span< DRWSubdivLooseEdge > draw_subdiv_cache_get_loose_edges(const DRWSubdivCache *cache)
void draw_subdiv_init_mesh_render_data(DRWSubdivCache *cache, struct MeshRenderData *mr, const struct ToolSettings *toolsettings)
void draw_subdiv_init_origindex_buffer(struct GPUVertBuf *buffer, int32_t *vert_origindex, uint num_loops, uint loose_len)
void draw_subdiv_accumulate_normals(const DRWSubdivCache *cache, struct GPUVertBuf *pos_nor, struct GPUVertBuf *face_adjacency_offsets, struct GPUVertBuf *face_adjacency_lists, struct GPUVertBuf *vertex_loop_map, struct GPUVertBuf *vertex_normals)
struct GPUVertFormat * draw_subdiv_get_pos_nor_format(void)
void draw_subdiv_build_fdots_buffers(const DRWSubdivCache *cache, struct GPUVertBuf *fdots_pos, struct GPUVertBuf *fdots_nor, struct GPUIndexBuf *fdots_indices)
struct DRWSubdivLooseVertex DRWSubdivLooseVertex
void draw_subdiv_build_edituv_stretch_area_buffer(const DRWSubdivCache *cache, struct GPUVertBuf *coarse_data, struct GPUVertBuf *subdiv_data)
void draw_subdiv_build_edge_fac_buffer(const DRWSubdivCache *cache, struct GPUVertBuf *pos_nor, struct GPUVertBuf *edge_idx, struct GPUVertBuf *edge_fac)
void draw_subdiv_finalize_normals(const DRWSubdivCache *cache, struct GPUVertBuf *vertex_normals, struct GPUVertBuf *subdiv_loop_subdiv_vert_index, struct GPUVertBuf *pos_nor)
void DRW_create_subdivision(struct Object *ob, struct Mesh *mesh, struct MeshBatchCache *batch_cache, struct MeshBufferCache *mbc, 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 do_cage, const ToolSettings *ts, const bool use_hide)
void draw_subdiv_build_sculpt_data_buffer(const DRWSubdivCache *cache, struct GPUVertBuf *mask_vbo, struct GPUVertBuf *face_set_vbo, struct GPUVertBuf *sculpt_data)
struct DRWPatchMap DRWPatchMap
struct DRWSubdivLooseEdge DRWSubdivLooseEdge
void DRW_subdiv_cache_free(struct Subdiv *subdiv)
void draw_subdiv_extract_uvs(const DRWSubdivCache *cache, struct GPUVertBuf *uvs, int face_varying_channel, int dst_offset)
void draw_subdiv_build_edituv_stretch_angle_buffer(const DRWSubdivCache *cache, struct GPUVertBuf *pos_nor, struct GPUVertBuf *uvs, int uvs_offset, struct GPUVertBuf *stretch_angles)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache *cache, struct GPUVertBuf *pos_nor, struct GPUVertBuf *lnor)
void draw_subdiv_finalize_custom_normals(const DRWSubdivCache *cache, GPUVertBuf *src_custom_normals, GPUVertBuf *pos_nor)
void draw_subdiv_build_tris_buffer(const DRWSubdivCache *cache, struct GPUIndexBuf *subdiv_tris, int material_count)
struct DRWSubdivCache DRWSubdivCache
void draw_subdiv_build_lines_loose_buffer(const DRWSubdivCache *cache, struct GPUIndexBuf *lines_indices, GPUVertBuf *lines_flags, uint num_loose_edges)
struct GPUVertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
void draw_subdiv_cache_free(DRWSubdivCache *cache)
void draw_subdiv_extract_pos_nor(const DRWSubdivCache *cache, struct GPUVertBuf *pos_nor, struct GPUVertBuf *orco)
struct DRWSubdivLooseGeom DRWSubdivLooseGeom
void draw_subdiv_build_lines_buffer(const DRWSubdivCache *cache, struct GPUIndexBuf *lines_indices)
void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, struct MeshBufferCache *cache)
void draw_subdiv_interp_custom_data(const DRWSubdivCache *cache, struct GPUVertBuf *src_data, struct GPUVertBuf *dst_data, int dimensions, int dst_offset, bool compress_to_u16)
ccl_global float * buffer
signed int int32_t
Definition: stdint.h:77
struct GPUVertBuf * patch_map_handles
struct GPUVertBuf * patch_map_quadtree
int patches_are_triangular
struct GPUVertBuf * face_ptex_offset_buffer
struct BMesh * bm
struct GPUVertBuf * edges_orig_index
struct GPUVertBuf * subdiv_vertex_face_adjacency_offsets
struct GPUUniformBuf * ubo
struct GPUVertBuf * patch_coords
int * subdiv_loop_subdiv_vert_index
struct Subdiv * subdiv
struct GPUVertBuf * fdots_patch_coords
struct GPUVertBuf * verts_orig_index
struct GPUVertBuf * polygon_mat_offset
struct GPUVertBuf * corner_patch_coords
struct Mesh * mesh
DRWPatchMap gpu_patch_map
int * subdiv_loop_poly_index
struct GPUVertBuf * extra_coarse_face_data
int * subdiv_loop_subdiv_edge_index
DRWSubdivLooseGeom loose_geom
struct GPUVertBuf * subdiv_vertex_face_adjacency
struct GPUVertBuf * subdiv_polygon_offset_buffer
DRWSubdivLooseVertex * verts
DRWSubdivLooseEdge * edges
unsigned int coarse_vertex_index