Blender V4.5
draw_cache_extract.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_map.hh"
14#include "BLI_utildefines.h"
15
16#include "DNA_view3d_enums.h"
17
18#include "GPU_index_buffer.hh"
19#include "GPU_shader.hh"
20#include "GPU_vertex_buffer.hh"
21
22#include "draw_attributes.hh"
23
24namespace blender::gpu {
25class Batch;
26class IndexBuf;
27} // namespace blender::gpu
28struct Mesh;
29struct Object;
30struct Scene;
31struct TaskGraph;
32struct ToolSettings;
33
34namespace blender::draw {
35
36struct MeshRenderData;
37struct DRWSubdivCache;
38
39/* Vertex Group Selection and display options */
43
44 short flags;
46
47 /* Set of all selected bones for Multi-paint. */
48 bool *defgroup_sel; /* #defgroup_len */
50
51 /* Set of all locked and unlocked deform bones for Lock Relative mode. */
52 bool *defgroup_locked; /* #defgroup_len */
53 bool *defgroup_unlocked; /* #defgroup_len */
54};
55
56/* DRW_MeshWeightState.flags */
57enum {
61};
62
113
135
137 /* Though using maps here may add some overhead compared to just indexed arrays, it's a bit more
138 * convenient currently, because the "buffer exists" test is very clear, it's just whether the
139 * map contains it (e.g. compared to "buffer is allocated but not filled with data"). The
140 * sparseness *may* be useful for reducing memory usage when only few buffers are used. */
141
144};
145
147 /* Surfaces / Render */
148 gpu::Batch *surface;
149 gpu::Batch *surface_weights;
150 /* Edit mode */
151 gpu::Batch *edit_triangles;
152 gpu::Batch *edit_vertices;
153 gpu::Batch *edit_edges;
154 gpu::Batch *edit_vnor;
155 gpu::Batch *edit_lnor;
156 gpu::Batch *edit_fdots;
158 gpu::Batch *edit_skin_roots;
159 /* Edit UVs */
162 gpu::Batch *edituv_faces;
163 gpu::Batch *edituv_edges;
164 gpu::Batch *edituv_verts;
165 gpu::Batch *edituv_fdots;
166 /* Edit selection */
171 /* Common display / Other */
172 gpu::Batch *uv_faces;
173 gpu::Batch *all_verts;
174 gpu::Batch *all_edges;
175 gpu::Batch *loose_edges;
176 gpu::Batch *edge_detection;
177 /* Individual edges with face normals. */
178 gpu::Batch *wire_edges;
179 /* Loops around faces. no edges between selected faces */
180 gpu::Batch *wire_loops;
181 /* Same as wire_loops but only has uvs. */
182 gpu::Batch *wire_loops_uvs;
184 gpu::Batch *sculpt_overlays;
186};
187
188#define MBC_BATCH_LEN (sizeof(MeshBatchList) / sizeof(void *))
189
190#define MBC_BATCH_INDEX(batch) (offsetof(MeshBatchList, batch) / sizeof(void *))
191
193 MBC_SURFACE = (1u << MBC_BATCH_INDEX(surface)),
194 MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(surface_weights)),
195 MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(edit_triangles)),
196 MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(edit_vertices)),
197 MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(edit_edges)),
198 MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(edit_vnor)),
199 MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(edit_lnor)),
200 MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_fdots)),
201 MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(edit_mesh_analysis)),
202 MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(edit_skin_roots)),
203 MBC_UV_FACES = (1u << MBC_BATCH_INDEX(uv_faces)),
204 MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_area)),
205 MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_angle)),
206 MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(edituv_faces)),
207 MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(edituv_edges)),
208 MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(edituv_verts)),
209 MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(edituv_fdots)),
210 MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(edit_selection_verts)),
211 MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(edit_selection_edges)),
212 MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(edit_selection_faces)),
213 MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_selection_fdots)),
214 MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(all_verts)),
215 MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(all_edges)),
216 MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(loose_edges)),
217 MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(edge_detection)),
218 MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(wire_edges)),
219 MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(wire_loops)),
220 MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(wire_loops_uvs)),
221 MBC_WIRE_LOOPS_EDITUVS = (1u << MBC_BATCH_INDEX(wire_loops_edituvs)),
222 MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(sculpt_overlays)),
223 MBC_VIEWER_ATTRIBUTE_OVERLAY = (1u << MBC_BATCH_INDEX(surface_viewer_attribute)),
225};
227
228BLI_STATIC_ASSERT(MBC_BATCH_LEN < 32, "Number of batches exceeded the limit of bit fields");
229
236
238 /* The total number of visible triangles (a sum of the values in #mat_tri_counts). */
246 std::optional<Array<int>> face_tri_offsets;
247};
248
261
262#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
263 for (MeshBufferCache *mbc = &batch_cache.final; \
264 mbc == &batch_cache.final || mbc == &batch_cache.cage || mbc == &batch_cache.uv_cage; \
265 mbc = (mbc == &batch_cache.final) ? \
266 &batch_cache.cage : \
267 ((mbc == &batch_cache.cage) ? &batch_cache.uv_cage : nullptr))
268
271
273
274 /* Index buffer per material. These are sub-ranges of `ibo.tris`. */
277
279
282
283 /* Settings to determine if cache is invalid. */
289 /* Instantly invalidates cache, skipping mesh check */
293
295
297
299
301
302 /* Valid only if edge_detection is up to date. */
304
306
307 /* Total areas for drawing UV Stretching. Contains the summed area in mesh
308 * space (`tot_area`) and the summed area in uv space (`tot_uvarea`).
309 *
310 * Only valid after `DRW_mesh_batch_cache_create_requested` has been called. */
312};
313
314#define MBC_EDITUV \
315 (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \
316 MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_UV_FACES | \
317 MBC_WIRE_LOOPS_UVS | MBC_WIRE_LOOPS_EDITUVS)
318
320 const Scene &scene,
321 MeshBatchCache &cache,
322 MeshBufferCache &mbc,
323 Span<IBOType> ibo_requests,
324 Span<VBOType> vbo_requests,
325 Object &object,
326 Mesh &mesh,
327 bool is_editmode,
328 bool is_paint_mode,
329 bool do_final,
330 bool do_uvedit,
331 bool use_hide);
332
333void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
334 MeshBufferCache &mbc,
335 Span<IBOType> ibo_requests,
336 Span<VBOType> vbo_requests,
337 DRWSubdivCache &subdiv_cache,
338 MeshRenderData &mr);
339
340} // namespace blender::draw
#define ENUM_OPERATORS(_type, _max)
Utilities for rendering attributes.
#define MBC_BATCH_LEN
#define MBC_BATCH_INDEX(batch)
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 32, "Number of batches exceeded the limit of bit fields")
void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, DRWSubdivCache &subdiv_cache, MeshRenderData &mr)
void mesh_buffer_cache_create_requested(TaskGraph &task_graph, const Scene &scene, MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, Object &object, Mesh &mesh, bool is_editmode, bool is_paint_mode, bool do_final, bool do_uvedit, bool use_hide)
VectorSet< std::string > attr_used_over_time
Array< gpu::IndexBufPtr > tris_per_mat
VectorSet< std::string > attr_used
Array< gpu::Batch * > surface_per_mat
VectorSet< std::string > attr_needed
Map< IBOType, std::unique_ptr< gpu::IndexBuf, gpu::IndexBufDeleter > > ibos
Map< VBOType, std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > > vbos
std::optional< Array< int > > face_tri_offsets