Blender V5.3
draw_curves_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <array>
12#include <string>
13
14#include "GPU_shader.hh"
15#include "GPU_vertex_buffer.hh"
16
17#include "BLI_vector_set.hh"
18
19#include "draw_pass.hh"
20
21namespace blender {
22
23struct Curves;
24struct Object;
25struct ParticleSystem;
26struct PTCacheEdit;
27struct ModifierData;
28struct ParticleCacheKey;
29namespace bke {
30class CurvesGeometry;
31} // namespace bke
32
33namespace gpu {
34class Batch;
35class VertBuf;
36} // namespace gpu
37struct GPUMaterial;
38
39namespace draw {
40
41struct CurvesModule;
42
43#define MAX_FACE_PER_SEGMENT 5
44#define MAX_HAIR_SUBDIV 4 /* see hair_subdiv rna */
45
54
55/* Legacy Hair Particle. */
56
63
65 public:
66 Object *object = nullptr;
67 ParticleSystem *psys = nullptr;
68 ModifierData *md = nullptr;
69 PTCacheEdit *edit = nullptr;
70
71 private:
72 Vector<int> &points_by_curve_storage_;
73 Vector<int> &evaluated_points_by_curve_storage_;
74 int additional_subdivision_;
75
76 public:
77 ParticleDrawSource(Vector<int> &points_by_curve_storage,
78 Vector<int> &evaluated_points_by_curve_storage,
79 int additional_subdivision)
80 : points_by_curve_storage_(points_by_curve_storage),
81 evaluated_points_by_curve_storage_(evaluated_points_by_curve_storage),
82 additional_subdivision_(additional_subdivision)
83 {
84 }
85
87 {
88 if (points_by_curve_storage_.is_empty()) {
90 }
91 return points_by_curve_storage_.size() - 1;
92 }
93
95 {
96 if (points_by_curve_storage_.is_empty()) {
98 }
99 return points_by_curve_storage_.last();
100 }
101
103 {
104 if (additional_subdivision_ == 0) {
105 return points_num();
106 }
108 return evaluated_points_by_curve_storage_.last();
109 }
110
112 {
113 return 1 << additional_subdivision_;
114 }
115
119};
120
121#define CURVES_EVAL_SHADER_NUM 5
122
123/* Curves procedural display: Evaluation is done on the GPU. */
125 /* --- Required attributes. --- */
126
129
131 /* TODO(fclem): Move it to generic point domain attributes. */
134 /* TODO(fclem): Move it to generic curve domain attributes. */
136
137 /* --- Indirection buffers. --- */
138
139 /* Map primitive to point ID and curve ID. Contains restart indices for line and triangle strip
140 * primitive. */
142 /* Map primitive to point ID and curve ID. Compacted for cylinder primitive. */
144
145 /* --- Buffers common to all curve types. --- */
146
157
158 /* --- Buffers only needed if geometry has Bezier curves. Dummy sized otherwise. --- */
159
166
167 /* --- Buffers only needed if geometry has Nurbs curves. Dummy sized otherwise. --- */
168
177
178 /* --- Generic Attributes. --- */
179
193 /* Attributes stored per curve. Nullptr if attribute is not from this domain. */
195 /* Output of the evaluation stage. This is only used by attributes on point domain. */
197 /* If attribute is point domain, use evaluated_attributes_buf. Otherwise curve_attributes_buf. */
198 std::array<bool, GPU_MAX_ATTR> attributes_point_domain;
199
200 /* --- Procedural Drawcalls. --- */
201 std::array<gpu::Batch *, MAX_FACE_PER_SEGMENT> batch;
202
203 void ensure_attribute(struct CurvesModule &module,
205 StringRef name,
206 int index);
207 void ensure_attributes(struct CurvesModule &module,
209 const GPUMaterial *gpu_material);
210
214
216
219 int face_per_segment);
220
221 /* Sets r_over_limit to true if reaching hardware limit for the number of segments. */
222 gpu::Batch *batch_get(int evaluated_point_count,
223 int curve_count,
224 int face_per_segment,
225 bool use_cyclic,
226 bool &r_over_limit);
227
228 void discard_attributes();
229 void clear();
230
231 /* --- Legacy Hair Particle system. --- */
232
233 int resolution = 0;
234
235 void ensure_attribute(CurvesModule &module,
237 const Mesh &mesh,
238 const StringRef name,
239 const int index);
240 void ensure_attributes(CurvesModule &module,
242 const GPUMaterial *gpu_material);
243
245
247
250 int face_per_segment);
251
252 private:
253 /* In the case where there is cyclic curves, add one padding point per curve to ensure easy
254 * indexing in the drawing shader. */
255 int evaluated_point_count_with_cyclic(const bke::CurvesGeometry &curves);
256};
257
259
260void drw_curves_get_attribute_sampler_name(StringRef layer_name, char r_sampler_name[32]);
261
263 CurvesModule &module,
264 CurvesEvalCache &cache,
265 const int face_per_segment,
266 GPUMaterial *gpu_material,
267 gpu::VertBufPtr &indirection_buf,
268 std::optional<StringRef> active_uv_name);
269
271 CurvesModule &module,
272 CurvesEvalCache &cache,
273 const int face_per_segment,
274 GPUMaterial *gpu_material,
275 gpu::VertBufPtr &indirection_buf,
276 std::optional<StringRef> active_uv_name);
277
278} // namespace draw
279} // namespace blender
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:509
void curves_bind_resources(PassMain::Sub &sub_ps, CurvesModule &module, CurvesEvalCache &cache, const int face_per_segment, GPUMaterial *gpu_material, gpu::VertBufPtr &indirection_buf, const std::optional< StringRef > active_uv_name)
CurvesEvalCache & curves_get_eval_cache(Curves &curves_id)
void drw_curves_get_attribute_sampler_name(const StringRef layer_name, char r_sampler_name[32])
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
BMesh Iterators.
gpu::VertBufPtr evaluated_attributes_buf[GPU_MAX_ATTR]
void ensure_bezier(const bke::CurvesGeometry &curves)
std::array< gpu::Batch *, MAX_FACE_PER_SEGMENT > batch
std::array< bool, GPU_MAX_ATTR > attributes_point_domain
void ensure_common(const bke::CurvesGeometry &curves)
gpu::Batch * batch_get(int evaluated_point_count, int curve_count, int face_per_segment, bool use_cyclic, bool &r_over_limit)
gpu::VertBufPtr & indirection_buf_get(CurvesModule &module, const bke::CurvesGeometry &curves, int face_per_segment)
void ensure_attributes(struct CurvesModule &module, const bke::CurvesGeometry &curves, const GPUMaterial *gpu_material)
void ensure_positions(CurvesModule &module, const bke::CurvesGeometry &curves)
gpu::VertBufPtr curve_attributes_buf[GPU_MAX_ATTR]
VectorSet< std::string > attr_used_over_time
VectorSet< std::string > attr_used
void ensure_attribute(struct CurvesModule &module, const bke::CurvesGeometry &curves, StringRef name, int index)
void ensure_nurbs(const bke::CurvesGeometry &curves)
ParticleDrawSource(Vector< int > &points_by_curve_storage, Vector< int > &evaluated_points_by_curve_storage, int additional_subdivision)
void foreach_strand(FunctionRef< void(Span< ParticleCacheKey >)> callback)
Span< ParticleCacheKey * > parent
Span< ParticleCacheKey * > children