Blender V4.3
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
9#pragma once
10
12#include "BLI_utildefines.h"
13
14#include "GPU_shader.hh"
15
16#include "draw_attributes.hh"
17
18namespace blender::gpu {
19class Batch;
20class IndexBuf;
21} // namespace blender::gpu
22struct TaskGraph;
23
24namespace blender::draw {
25
26struct MeshRenderData;
27struct DRWSubdivCache;
28
29/* Vertex Group Selection and display options */
33
34 short flags;
36
37 /* Set of all selected bones for Multi-paint. */
38 bool *defgroup_sel; /* #defgroup_len */
40
41 /* Set of all locked and unlocked deform bones for Lock Relative mode. */
42 bool *defgroup_locked; /* #defgroup_len */
43 bool *defgroup_unlocked; /* #defgroup_len */
44};
45
46/* DRW_MeshWeightState.flags */
47enum {
51};
52
53int mesh_render_mat_len_get(const Object &object, const Mesh &mesh);
54
56 /* Every VBO below contains at least enough data for every loop in the mesh
57 * (except fdots and skin roots). For some VBOs, it extends to (in this exact order) :
58 * loops + loose_edges * 2 + loose_verts */
59 struct {
60 gpu::VertBuf *pos; /* extend */
61 gpu::VertBuf *nor; /* extend */
62 gpu::VertBuf *edge_fac; /* extend */
63 gpu::VertBuf *weights; /* extend */
68 /* Only for edit mode. */
69 gpu::VertBuf *edit_data; /* extend */
77 // gpu::VertBuf *fdots_edit_data; /* inside fdots_nor for now. */
80 /* Selection */
81 gpu::VertBuf *vert_idx; /* extend */
82 gpu::VertBuf *edge_idx; /* extend */
88 } vbo;
89 /* Index Buffers:
90 * Only need to be updated when topology changes. */
91 struct {
92 /* Indices to vloops. Ordered per material. */
94 /* Loose edges last. */
96 /* Potentially a sub buffer of `lines` only containing the loose edges. */
100 /* 3D overlays. */
101 /* no loose edges. */
110};
111
113 /* Surfaces / Render */
114 gpu::Batch *surface;
115 gpu::Batch *surface_weights;
116 /* Edit mode */
117 gpu::Batch *edit_triangles;
118 gpu::Batch *edit_vertices;
119 gpu::Batch *edit_edges;
120 gpu::Batch *edit_vnor;
121 gpu::Batch *edit_lnor;
122 gpu::Batch *edit_fdots;
124 gpu::Batch *edit_skin_roots;
125 /* Edit UVs */
128 gpu::Batch *edituv_faces;
129 gpu::Batch *edituv_edges;
130 gpu::Batch *edituv_verts;
131 gpu::Batch *edituv_fdots;
132 /* Edit selection */
137 /* Common display / Other */
138 gpu::Batch *all_verts;
139 gpu::Batch *all_edges;
140 gpu::Batch *loose_edges;
141 gpu::Batch *edge_detection;
142 /* Individual edges with face normals. */
143 gpu::Batch *wire_edges;
144 /* Loops around faces. no edges between selected faces */
145 gpu::Batch *wire_loops;
146 /* Same as wire_loops but only has uvs. */
147 gpu::Batch *wire_loops_uvs;
148 gpu::Batch *sculpt_overlays;
150};
151
152#define MBC_BATCH_LEN (sizeof(MeshBatchList) / sizeof(void *))
153#define MBC_VBO_LEN (sizeof(MeshBufferList::vbo) / sizeof(void *))
154#define MBC_IBO_LEN (sizeof(MeshBufferList::ibo) / sizeof(void *))
155
156#define MBC_BATCH_INDEX(batch) (offsetof(MeshBatchList, batch) / sizeof(void *))
157
159 MBC_SURFACE = (1u << MBC_BATCH_INDEX(surface)),
160 MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(surface_weights)),
161 MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(edit_triangles)),
162 MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(edit_vertices)),
163 MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(edit_edges)),
164 MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(edit_vnor)),
165 MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(edit_lnor)),
166 MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_fdots)),
167 MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(edit_mesh_analysis)),
168 MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(edit_skin_roots)),
169 MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_area)),
170 MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(edituv_faces_stretch_angle)),
171 MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(edituv_faces)),
172 MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(edituv_edges)),
173 MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(edituv_verts)),
174 MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(edituv_fdots)),
175 MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(edit_selection_verts)),
176 MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(edit_selection_edges)),
177 MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(edit_selection_faces)),
178 MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(edit_selection_fdots)),
179 MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(all_verts)),
180 MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(all_edges)),
181 MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(loose_edges)),
182 MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(edge_detection)),
183 MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(wire_edges)),
184 MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(wire_loops)),
185 MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(wire_loops_uvs)),
186 MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(sculpt_overlays)),
187 MBC_VIEWER_ATTRIBUTE_OVERLAY = (1u << MBC_BATCH_INDEX(surface_viewer_attribute)),
189};
191
192BLI_STATIC_ASSERT(MBC_BATCH_LEN < 32, "Number of batches exceeded the limit of bit fields");
193
200
202 /* The total number of visible triangles (a sum of the values in #mat_tri_counts). */
210 std::optional<Array<int>> face_tri_offsets;
211};
212
225
226#define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \
227 for (MeshBufferCache *mbc = &batch_cache.final; \
228 mbc == &batch_cache.final || mbc == &batch_cache.cage || mbc == &batch_cache.uv_cage; \
229 mbc = (mbc == &batch_cache.final) ? \
230 &batch_cache.cage : \
231 ((mbc == &batch_cache.cage) ? &batch_cache.uv_cage : nullptr))
232
235
237
238 /* Index buffer per material. These are sub-ranges of `ibo.tris`. */
241
243
246
247 /* Settings to determine if cache is invalid. */
253 /* Instantly invalidates cache, skipping mesh check */
257
259
261
263
265
266 /* Valid only if edge_detection is up to date. */
268
269 /* Total areas for drawing UV Stretching. Contains the summed area in mesh
270 * space (`tot_area`) and the summed area in uv space (`tot_uvarea`).
271 *
272 * Only valid after `DRW_mesh_batch_cache_create_requested` has been called. */
274
276
278};
279
280#define MBC_EDITUV \
281 (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \
282 MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS)
283
285 MeshBatchCache &cache,
286 MeshBufferCache &mbc,
287 Object &object,
288 Mesh &mesh,
289 bool is_editmode,
290 bool is_paint_mode,
291 bool edit_mode_active,
292 const float4x4 &object_to_world,
293 bool do_final,
294 bool do_uvedit,
295 const Scene &scene,
296 const ToolSettings *ts,
297 bool use_hide);
298
299void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
300 MeshBufferCache &mbc,
301 DRWSubdivCache &subdiv_cache,
302 MeshRenderData &mr);
303
304} // namespace blender::draw
#define ENUM_OPERATORS(_type, _max)
eV3DShadingColorType
#define GPU_MAX_ATTR
Definition GPU_shader.hh:29
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")
int mesh_render_mat_len_get(const Object &object, const Mesh &mesh)
void mesh_buffer_cache_create_requested(TaskGraph &task_graph, MeshBatchCache &cache, MeshBufferCache &mbc, Object &object, Mesh &mesh, bool is_editmode, bool is_paint_mode, bool edit_mode_active, const float4x4 &object_to_world, bool do_final, bool do_uvedit, const Scene &scene, const ToolSettings *ts, bool use_hide)
void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache, MeshBufferCache &mbc, DRWSubdivCache &subdiv_cache, MeshRenderData &mr)
MatBase< float, 4, 4 > float4x4
Array< gpu::IndexBuf * > tris_per_mat
Array< gpu::Batch * > surface_per_mat
struct blender::draw::MeshBufferList::@247 vbo
struct blender::draw::MeshBufferList::@248 ibo
gpu::VertBuf * attr[GPU_MAX_ATTR]
std::optional< Array< int > > face_tri_offsets