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
137
139 /* Though using maps here may add some overhead compared to just indexed arrays, it's a bit more
140 * convenient currently, because the "buffer exists" test is very clear, it's just whether the
141 * map contains it (e.g. compared to "buffer is allocated but not filled with data"). The
142 * sparseness *may* be useful for reducing memory usage when only few buffers are used. */
143
146};
147
149 /* Surfaces / Render */
150 gpu::Batch *surface;
151 gpu::Batch *surface_weights;
152 /* Edit mode */
153 gpu::Batch *edit_triangles;
154 gpu::Batch *edit_vertices;
155 gpu::Batch *edit_edges;
156 gpu::Batch *edit_vnor;
157 gpu::Batch *edit_lnor;
158 gpu::Batch *edit_fdots;
160 gpu::Batch *edit_skin_roots;
161 /* Edit UVs */
164 gpu::Batch *edituv_faces;
165 gpu::Batch *edituv_edges;
166 gpu::Batch *edituv_verts;
167 gpu::Batch *edituv_fdots;
168 /* Edit selection */
173 /* Common display / Other */
174 gpu::Batch *uv_faces;
175 gpu::Batch *all_verts;
176 gpu::Batch *all_edges;
177 gpu::Batch *loose_edges;
178 gpu::Batch *edge_detection;
179 /* Individual edges with face normals. */
180 gpu::Batch *wire_edges;
181 /* Loops around faces. no edges between selected faces */
182 gpu::Batch *wire_loops;
183 /* Same as wire_loops but only has uvs. */
185 gpu::Batch *wire_loops_uvs;
187 gpu::Batch *sculpt_overlays;
189};
190
191#define MBC_BATCH_LEN (sizeof(MeshBatchList) / sizeof(void *))
192
193#define MBC_BATCH_INDEX(batch) (offsetof(MeshBatchList, batch) / sizeof(void *))
194
196 MBC_SURFACE = (1u << MBC_BATCH_INDEX(surface)),
197 MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(surface_weights)),
198 MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(edit_triangles)),
199 MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(edit_vertices)),
200 MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(edit_edges)),
201 MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(edit_vnor)),
202 MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(edit_lnor)),
203 MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_fdots)),
204 MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(edit_mesh_analysis)),
205 MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(edit_skin_roots)),
206 MBC_UV_FACES = (1u << MBC_BATCH_INDEX(uv_faces)),
207 MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_area)),
208 MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_angle)),
209 MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(edituv_faces)),
210 MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(edituv_edges)),
211 MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(edituv_verts)),
212 MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(edituv_fdots)),
213 MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(edit_selection_verts)),
214 MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(edit_selection_edges)),
215 MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(edit_selection_faces)),
216 MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_selection_fdots)),
217 MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(all_verts)),
218 MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(all_edges)),
219 MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(loose_edges)),
220 MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(edge_detection)),
221 MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(wire_edges)),
222 MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(wire_loops)),
223 MBC_WIRE_LOOPS_ALL_UVS = (1u << MBC_BATCH_INDEX(wire_loops_all_uvs)),
224 MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(wire_loops_uvs)),
225 MBC_WIRE_LOOPS_EDITUVS = (1u << MBC_BATCH_INDEX(wire_loops_edituvs)),
226 MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(sculpt_overlays)),
227 MBC_VIEWER_ATTRIBUTE_OVERLAY = (1u << MBC_BATCH_INDEX(surface_viewer_attribute)),
229};
231
232BLI_STATIC_ASSERT(MBC_BATCH_LEN < 64, "Number of batches exceeded the limit of bit fields");
233
240
242 /* The total number of visible triangles (a sum of the values in #mat_tri_counts). */
250 std::optional<Array<int>> face_tri_offsets;
251};
252
265
266#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
267 for (MeshBufferCache *mbc = &batch_cache.final; \
268 mbc == &batch_cache.final || mbc == &batch_cache.cage || mbc == &batch_cache.uv_cage; \
269 mbc = (mbc == &batch_cache.final) ? \
270 &batch_cache.cage : \
271 ((mbc == &batch_cache.cage) ? &batch_cache.uv_cage : nullptr))
272
275
277
278 /* Index buffer per material. These are sub-ranges of `ibo.tris`. */
281
283
286
287 /* Settings to determine if cache is invalid. */
293 /* Instantly invalidates cache, skipping mesh check */
297
299
301
303
305
306 /* Valid only if edge_detection is up to date. */
308
310
311 /* Total areas for drawing UV Stretching. Contains the summed area in mesh
312 * space (`tot_area`) and the summed area in uv space (`tot_uvarea`).
313 *
314 * Only valid after `DRW_mesh_batch_cache_create_requested` has been called. */
316};
317
318#define MBC_EDITUV \
319 (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \
320 MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_UV_FACES | \
321 MBC_WIRE_LOOPS_ALL_UVS | MBC_WIRE_LOOPS_UVS | MBC_WIRE_LOOPS_EDITUVS)
322
324 const Scene &scene,
325 MeshBatchCache &cache,
326 MeshBufferCache &mbc,
327 Span<IBOType> ibo_requests,
328 Span<VBOType> vbo_requests,
329 Object &object,
330 Mesh &mesh,
331 bool is_editmode,
332 bool is_paint_mode,
333 bool do_final,
334 bool do_uvedit,
335 bool use_hide);
336
337void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
338 MeshBufferCache &mbc,
339 Span<IBOType> ibo_requests,
340 Span<VBOType> vbo_requests,
341 DRWSubdivCache &subdiv_cache,
342 MeshRenderData &mr);
343
344} // namespace blender::draw
#define ENUM_OPERATORS(_type, _max)
unsigned long long int uint64_t
Utilities for rendering attributes.
#define MBC_BATCH_LEN
#define MBC_BATCH_INDEX(batch)
void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, DRWSubdivCache &subdiv_cache, MeshRenderData &mr)
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 64, "Number of batches exceeded the limit of bit fields")
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