Blender V4.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
5#pragma once
6
7#include "BLI_array.hh"
10#include "BLI_span.hh"
11#include "BLI_sys_types.h"
12
14
15struct BMesh;
16struct GPUUniformBuf;
17namespace blender::gpu {
18class IndexBuf;
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/* -------------------------------------------------------------------- */
50
53/* -------------------------------------------------------------------- */
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. */
141 GPUUniformBuf *ubo;
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
155 Mesh &mesh,
156 MeshBatchCache &batch_cache,
157 MeshBufferCache &mbc,
158 bool is_editmode,
159 bool is_paint_mode,
160 bool edit_mode_active,
161 const float4x4 &object_to_world,
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 int32_t *vert_origindex,
174 uint num_loops,
175 uint loose_len);
176
177gpu::VertBuf *draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops);
178
179/* Compute shader functions. */
180
182 gpu::VertBuf *mask_vbo,
183 gpu::VertBuf *face_set_vbo,
184 gpu::VertBuf *sculpt_data);
185
187 gpu::VertBuf *pos_nor,
188 gpu::VertBuf *face_adjacency_offsets,
189 gpu::VertBuf *face_adjacency_lists,
190 gpu::VertBuf *vertex_loop_map,
191 gpu::VertBuf *vert_normals);
192
194 gpu::VertBuf *vert_normals,
195 gpu::VertBuf *subdiv_loop_subdiv_vert_index,
196 gpu::VertBuf *pos_nor);
197
199 gpu::VertBuf *src_custom_normals,
200 gpu::VertBuf *pos_nor);
201
203 gpu::VertBuf *flags_buffer,
204 gpu::VertBuf *pos_nor,
205 gpu::VertBuf *orco);
206
208 gpu::VertBuf &src_data,
209 gpu::VertBuf &dst_data,
210 int comp_type, /*GPUVertCompType*/
211 int dimensions,
212 int dst_offset);
213
215 gpu::VertBuf *uvs,
216 int face_varying_channel,
217 int dst_offset);
218
220 gpu::VertBuf *pos_nor,
221 gpu::VertBuf *edge_draw_flag,
222 gpu::VertBuf *poly_other_map,
223 gpu::VertBuf *edge_fac);
224
226 gpu::IndexBuf *subdiv_tris,
227 int material_count);
228
229void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices);
230
232 gpu::IndexBuf *lines_indices,
233 gpu::VertBuf *lines_flags,
234 uint edge_loose_offset,
235 uint num_loose_edges);
236
238 gpu::VertBuf *fdots_pos,
239 gpu::VertBuf *fdots_nor,
240 gpu::IndexBuf *fdots_indices);
241
243 gpu::VertBuf *pos_nor,
244 gpu::VertBuf *lnor);
245
247 gpu::VertBuf *coarse_data,
248 gpu::VertBuf *subdiv_data);
249
251 gpu::VertBuf *pos_nor,
252 gpu::VertBuf *uvs,
253 int uvs_offset,
254 gpu::VertBuf *stretch_angles);
255
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 blender::draw
unsigned int uint
constexpr int64_t size() const
Definition BLI_span.hh:253
Extraction of Mesh data into VBO to feed to GPU.
int subdiv_loose_edges_num(const MeshRenderData &mr, const DRWSubdivCache &cache)
int subdiv_verts_per_coarse_edge(const DRWSubdivCache &cache)
void draw_subdiv_build_edge_fac_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *edge_draw_flag, gpu::VertBuf *poly_other_map, gpu::VertBuf *edge_fac)
void draw_subdiv_extract_uvs(const DRWSubdivCache &cache, gpu::VertBuf *uvs, const int face_varying_channel, const int dst_offset)
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_fdots_buffers(const DRWSubdivCache &cache, gpu::VertBuf *fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf *fdots_indices)
void DRW_subdivide_loose_geom(DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache)
void DRW_create_subdivision(Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const bool is_editmode, const bool is_paint_mode, const bool edit_mode_active, const float4x4 &object_to_world, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
void draw_subdiv_cache_free(DRWSubdivCache &cache)
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_accumulate_normals(const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vertex_loop_map, gpu::VertBuf *vert_normals)
void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *lnor)
void draw_subdiv_extract_pos_nor(const DRWSubdivCache &cache, gpu::VertBuf *flags_buffer, gpu::VertBuf *pos_nor, 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_sculpt_data_buffer(const DRWSubdivCache &cache, gpu::VertBuf *mask_vbo, gpu::VertBuf *face_set_vbo, gpu::VertBuf *sculpt_data)
void draw_subdiv_interp_custom_data(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data, int comp_type, int dimensions, int dst_offset)
void draw_subdiv_finalize_normals(const DRWSubdivCache &cache, gpu::VertBuf *vert_normals, gpu::VertBuf *subdiv_loop_subdiv_vert_index, gpu::VertBuf *pos_nor)
gpu::VertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
const GPUVertFormat & draw_subdiv_get_pos_nor_format()
void draw_subdiv_init_origindex_buffer(gpu::VertBuf &buffer, int32_t *vert_origindex, uint num_loops, uint loose_len)
void draw_subdiv_finalize_custom_normals(const DRWSubdivCache &cache, gpu::VertBuf *src_custom_normals, gpu::VertBuf *pos_nor)
void draw_subdiv_build_edituv_stretch_angle_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *uvs, int uvs_offset, gpu::VertBuf *stretch_angles)
signed int int32_t
Definition stdint.h:77
gpu::VertBuf * subdiv_vertex_face_adjacency_offsets