Blender V5.3
draw_subdivision.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
14#include "BLI_span.hh"
15#include "BLI_sys_types.hh"
16
18
19namespace blender {
20
21struct BMesh;
22namespace gpu {
23class IndexBuf;
24class UniformBuf;
25class VertBuf;
26} // namespace gpu
27struct GPUVertFormat;
28struct Mesh;
29struct Object;
30namespace bke::subdiv {
31struct Subdiv;
32}
33struct ToolSettings;
34
35namespace draw {
36
37struct MeshBatchCache;
38struct MeshBufferCache;
39struct MeshRenderData;
40
41/* -------------------------------------------------------------------- */
47
56
58
59/* -------------------------------------------------------------------- */
64
66 const Mesh *mesh;
72
73 /* Coordinates used to evaluate patches for positions and normals. */
75 /* Coordinates used to evaluate patches for attributes. */
77 /* Coordinates used to evaluate patches for the face centers (or face dots) in edit-mode. */
79
80 /* Resolution used to generate the patch coordinates. */
82
83 /* Number of subdivided loops, also the number of patch coordinates since we have one coordinate
84 * but quad corner/vertex. */
90
91 /* We only do the subdivision traversal for full faces, however we may have geometries that only
92 * have loose edges (e.g. a custom bone shape). This flag is used to detect those cases, as the
93 * counters above will all be set to zero if we do not have subdivision loops. */
95
96 /* Number of faces in the coarse mesh, notably used to compute a coarse face index given a
97 * subdivision loop index. */
99
100 /* Maps subdivision loop to subdivided vertex index. */
102 /* Maps subdivision loop to subdivided edge index. */
104 /* Maps subdivision loop to original coarse face index. */
106
107 /* Indices of faces adjacent to the vertices, ordered by vertex index, with no particular
108 * winding. */
110 /* The difference between value (i + 1) and (i) gives the number of faces adjacent to vertex (i).
111 */
113
114 /* Maps subdivision loop to original coarse vertex index, only really useful for edit mode. */
116 /* Maps subdivision loop to original coarse edge index, only really useful for edit mode. */
118 /* Indicates if edge should be drawn in optimal display mode. */
120
121 /* Owned by #Subdiv. Indexed by coarse face index, difference between value (i + 1) and (i)
122 * gives the number of ptex faces for coarse face (i). */
124 /* Vertex buffer for face_ptex_offset. */
126
129
130 /* Contains the start loop index and the smooth flag for each coarse face. */
132
133 /* Material offsets. */
137
139
145
146 /* UBO to store settings for the various compute shaders. */
148
149 /* Extra flags, passed to the UBO. */
152};
153
154/* Only frees the data of the cache, caller is responsible to free the cache itself if necessary.
155 */
157
159
161 Mesh &mesh,
162 MeshBatchCache &batch_cache,
163 MeshBufferCache &mbc,
164 Span<IBOType> ibo_requests,
165 Span<VBOType> vbo_requests,
166 bool is_editmode,
167 bool is_paint_mode,
168 bool do_final,
169 bool do_uvedit,
170 bool do_cage,
171 const ToolSettings *ts,
172 bool use_hide);
173
174void DRW_subdivide_loose_geom(DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache);
175
177
179 uint num_loops,
180 uint loose_len);
181
182gpu::VertBuf *draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops);
185
186/* Compute shader functions. */
187
189 gpu::VertBuf *mask_vbo,
190 gpu::VertBuf *face_set_vbo,
191 gpu::VertBuf *sculpt_data);
192
194 gpu::VertBuf *pos,
195 gpu::VertBuf *face_adjacency_offsets,
196 gpu::VertBuf *face_adjacency_lists,
197 gpu::VertBuf *vert_loop_map,
198 gpu::VertBuf *vert_normals);
199
201
203 gpu::VertBuf &src_data,
204 gpu::VertBuf &dst_data,
205 GPUVertCompType comp_type,
206 int dimensions,
207 int dst_offset);
208
210 gpu::VertBuf &src_data,
211 gpu::VertBuf &dst_data);
212
214 gpu::VertBuf *uvs,
215 int face_varying_channel,
216 int dst_offset);
217
219 gpu::VertBuf *pos,
220 gpu::VertBuf *edge_draw_flag,
221 gpu::VertBuf *poly_other_map,
222 gpu::VertBuf *edge_fac);
223
225 gpu::IndexBuf *subdiv_tris,
226 int material_count);
227
228void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices);
229
231 gpu::IndexBuf *lines_indices,
232 gpu::VertBuf *lines_flags,
233 uint edge_loose_offset,
234 uint num_loose_edges);
235
237 gpu::VertBuf *fdots_pos,
238 gpu::VertBuf *fdots_nor,
239 gpu::IndexBuf *fdots_indices);
240
242 gpu::VertBuf *pos,
243 gpu::VertBuf *vert_normals,
244 gpu::VertBuf *subdiv_corner_verts,
245 gpu::VertBuf *lnor);
246
248
250 gpu::VertBuf *coarse_data,
251 gpu::VertBuf *subdiv_data);
252
254 gpu::VertBuf *pos,
255 gpu::VertBuf *uvs,
256 int uvs_offset,
257 gpu::VertBuf *stretch_angles);
258
261{
262 return cache.resolution - 1;
263}
264
267{
268 return subdiv_edges_per_coarse_edge(cache) * 2;
269}
270
272inline int subdiv_loose_edges_num(const MeshRenderData &mr, const DRWSubdivCache &cache)
273{
274 return mr.loose_edges.size() * subdiv_edges_per_coarse_edge(cache);
275}
276
278inline int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
279{
280 return cache.num_subdiv_loops + subdiv_loose_edges_num(mr, cache) * 2 + mr.loose_verts.size();
281}
282
283} // namespace draw
284} // namespace blender
Extraction of Mesh data into VBO to feed to GPU.
void draw_subdiv_build_edge_fac_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *edge_draw_flag, gpu::VertBuf *poly_other_map, gpu::VertBuf *edge_fac)
int subdiv_loose_edges_num(const MeshRenderData &mr, const DRWSubdivCache &cache)
int subdiv_verts_per_coarse_edge(const DRWSubdivCache &cache)
void draw_subdiv_extract_uvs(const DRWSubdivCache &cache, gpu::VertBuf *uvs, const int face_varying_channel, const int dst_offset)
gpu::VertBufPtr draw_subdiv_init_origindex_buffer(int32_t *vert_origindex, uint num_loops, uint loose_len)
int subdiv_edges_per_coarse_edge(const DRWSubdivCache &cache)
void draw_subdiv_build_edituv_stretch_area_buffer(const DRWSubdivCache &cache, gpu::VertBuf *coarse_data, gpu::VertBuf *subdiv_data)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *vert_normals, gpu::VertBuf *subdiv_corner_verts, gpu::VertBuf *lnor)
void draw_subdiv_build_fdots_buffers(const DRWSubdivCache &cache, gpu::VertBuf *fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf *fdots_indices)
void draw_subdiv_interp_corner_normals(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data)
void DRW_subdivide_loose_geom(DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache)
void draw_subdiv_interp_custom_data(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data, GPUVertCompType comp_type, int dimensions, int dst_offset)
void draw_subdiv_cache_free(DRWSubdivCache &cache)
void draw_subdiv_build_paint_overlay_flag_buffer(const DRWSubdivCache &cache, gpu::VertBuf &flags)
void draw_subdiv_build_tris_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *subdiv_tris, const int material_count)
void DRW_subdiv_cache_free(bke::subdiv::Subdiv *subdiv)
void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices)
void draw_subdiv_extract_pos(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *orco)
int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
void draw_subdiv_build_lines_loose_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices, gpu::VertBuf *lines_flags, uint edge_loose_offset, uint num_loose_edges)
void draw_subdiv_build_edituv_stretch_angle_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *uvs, int uvs_offset, gpu::VertBuf *stretch_angles)
void draw_subdiv_build_sculpt_data_buffer(const DRWSubdivCache &cache, gpu::VertBuf *mask_vbo, gpu::VertBuf *face_set_vbo, gpu::VertBuf *sculpt_data)
void DRW_create_subdivision(Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const Span< IBOType > ibo_requests, const Span< VBOType > vbo_requests, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
gpu::VertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
void draw_subdiv_accumulate_normals(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vert_loop_map, gpu::VertBuf *vert_normals)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
BMesh Iterators.
unsigned int uint
Definition BKE_text.h:55
signed int int32_t
Definition BKE_text.h:78
gpu::VertBuf * subdiv_vert_face_adjacency_offsets