Blender V5.0
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
5#pragma once
6
7#include "BLI_array.hh"
10#include "BLI_span.hh"
11#include "BLI_sys_types.h"
12
14
15struct BMesh;
16namespace blender::gpu {
17class IndexBuf;
18class UniformBuf;
19class VertBuf;
20} // namespace blender::gpu
21struct GPUVertFormat;
22struct Mesh;
23struct Object;
24namespace blender::bke::subdiv {
25struct Subdiv;
26}
27struct ToolSettings;
28
29namespace blender::draw {
30
31struct MeshBatchCache;
32struct MeshBufferCache;
33struct MeshRenderData;
34
35/* -------------------------------------------------------------------- */
41
50
52
53/* -------------------------------------------------------------------- */
58
60 const Mesh *mesh;
66
67 /* Coordinates used to evaluate patches for positions and normals. */
69 /* Coordinates used to evaluate patches for attributes. */
71 /* Coordinates used to evaluate patches for the face centers (or face dots) in edit-mode. */
73
74 /* Resolution used to generate the patch coordinates. */
76
77 /* Number of subdivided loops, also the number of patch coordinates since we have one coordinate
78 * but quad corner/vertex. */
84
85 /* We only do the subdivision traversal for full faces, however we may have geometries that only
86 * have loose edges (e.g. a custom bone shape). This flag is used to detect those cases, as the
87 * counters above will all be set to zero if we do not have subdivision loops. */
89
90 /* Number of faces in the coarse mesh, notably used to compute a coarse face index given a
91 * subdivision loop index. */
93
94 /* Maps subdivision loop to subdivided vertex index. */
96 /* Maps subdivision loop to subdivided edge index. */
98 /* Maps subdivision loop to original coarse face index. */
100
101 /* Indices of faces adjacent to the vertices, ordered by vertex index, with no particular
102 * winding. */
104 /* The difference between value (i + 1) and (i) gives the number of faces adjacent to vertex (i).
105 */
107
108 /* Maps subdivision loop to original coarse vertex index, only really useful for edit mode. */
110 /* Maps subdivision loop to original coarse edge index, only really useful for edit mode. */
112 /* Indicates if edge should be drawn in optimal display mode. */
114
115 /* Owned by #Subdiv. Indexed by coarse face index, difference between value (i + 1) and (i)
116 * gives the number of ptex faces for coarse face (i). */
118 /* Vertex buffer for face_ptex_offset. */
120
123
124 /* Contains the start loop index and the smooth flag for each coarse face. */
126
127 /* Material offsets. */
131
133
139
140 /* UBO to store settings for the various compute shaders. */
142
143 /* Extra flags, passed to the UBO. */
146};
147
148/* Only frees the data of the cache, caller is responsible to free the cache itself if necessary.
149 */
151
153
155 Mesh &mesh,
156 MeshBatchCache &batch_cache,
157 MeshBufferCache &mbc,
158 Span<IBOType> ibo_requests,
159 Span<VBOType> vbo_requests,
160 bool is_editmode,
161 bool is_paint_mode,
162 bool do_final,
163 bool do_uvedit,
164 bool do_cage,
165 const ToolSettings *ts,
166 bool use_hide);
167
168void DRW_subdivide_loose_geom(DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache);
169
171
173 uint num_loops,
174 uint loose_len);
175
176gpu::VertBuf *draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops);
179
180/* Compute shader functions. */
181
183 gpu::VertBuf *mask_vbo,
184 gpu::VertBuf *face_set_vbo,
185 gpu::VertBuf *sculpt_data);
186
189 gpu::VertBuf *face_adjacency_offsets,
190 gpu::VertBuf *face_adjacency_lists,
191 gpu::VertBuf *vertex_loop_map,
192 gpu::VertBuf *vert_normals);
193
195
197 gpu::VertBuf &src_data,
198 gpu::VertBuf &dst_data,
199 GPUVertCompType comp_type,
200 int dimensions,
201 int dst_offset);
202
204 gpu::VertBuf &src_data,
205 gpu::VertBuf &dst_data);
206
208 gpu::VertBuf *uvs,
209 int face_varying_channel,
210 int dst_offset);
211
214 gpu::VertBuf *edge_draw_flag,
215 gpu::VertBuf *poly_other_map,
216 gpu::VertBuf *edge_fac);
217
219 gpu::IndexBuf *subdiv_tris,
220 int material_count);
221
222void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices);
223
225 gpu::IndexBuf *lines_indices,
226 gpu::VertBuf *lines_flags,
227 uint edge_loose_offset,
228 uint num_loose_edges);
229
231 gpu::VertBuf *fdots_pos,
232 gpu::VertBuf *fdots_nor,
233 gpu::IndexBuf *fdots_indices);
234
237 gpu::VertBuf *vert_normals,
238 gpu::VertBuf *subdiv_corner_verts,
239 gpu::VertBuf *lnor);
240
242
244 gpu::VertBuf *coarse_data,
245 gpu::VertBuf *subdiv_data);
246
249 gpu::VertBuf *uvs,
250 int uvs_offset,
251 gpu::VertBuf *stretch_angles);
252
255{
256 return cache.resolution - 1;
257}
258
261{
262 return subdiv_edges_per_coarse_edge(cache) * 2;
263}
264
266inline int subdiv_loose_edges_num(const MeshRenderData &mr, const DRWSubdivCache &cache)
267{
268 return mr.loose_edges.size() * subdiv_edges_per_coarse_edge(cache);
269}
270
272inline int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
273{
274 return cache.num_subdiv_loops + subdiv_loose_edges_num(mr, cache) * 2 + mr.loose_verts.size();
275}
276
277} // namespace blender::draw
unsigned int uint
GPUVertCompType
constexpr int64_t size() const
Definition BLI_span.hh:252
Extraction of Mesh data into VBO to feed to GPU.
uint pos
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 *vertex_loop_map, gpu::VertBuf *vert_normals)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
gpu::VertBuf * subdiv_vertex_face_adjacency_offsets