Blender V5.0
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
21struct Curves;
22struct Object;
23struct ParticleSystem;
24struct PTCacheEdit;
25struct ModifierData;
26struct ParticleCacheKey;
27namespace blender::bke {
28class CurvesGeometry;
29} // namespace blender::bke
30
31namespace blender::gpu {
32class Batch;
33class VertBuf;
34} // namespace blender::gpu
35struct GPUMaterial;
36
37namespace blender::draw {
38
39struct CurvesModule;
40
41#define MAX_FACE_PER_SEGMENT 5
42#define MAX_HAIR_SUBDIV 4 /* see hair_subdiv rna */
43
52
53/* Legacy Hair Particle. */
54
61
63 public:
64 Object *object = nullptr;
65 ParticleSystem *psys = nullptr;
66 ModifierData *md = nullptr;
67 PTCacheEdit *edit = nullptr;
68
69 private:
70 Vector<int> &points_by_curve_storage_;
71 Vector<int> &evaluated_points_by_curve_storage_;
72 int additional_subdivision_;
73
74 public:
75 ParticleDrawSource(Vector<int> &points_by_curve_storage,
76 Vector<int> &evaluated_points_by_curve_storage,
77 int additional_subdivision)
78 : points_by_curve_storage_(points_by_curve_storage),
79 evaluated_points_by_curve_storage_(evaluated_points_by_curve_storage),
80 additional_subdivision_(additional_subdivision)
81 {
82 }
83
85 {
86 if (points_by_curve_storage_.is_empty()) {
88 }
89 return points_by_curve_storage_.size() - 1;
90 }
91
93 {
94 if (points_by_curve_storage_.is_empty()) {
96 }
97 return points_by_curve_storage_.last();
98 }
99
101 {
102 if (additional_subdivision_ == 0) {
103 return points_num();
104 }
106 return evaluated_points_by_curve_storage_.last();
107 }
108
110 {
111 return 1 << additional_subdivision_;
112 }
113
117};
118
119#define CURVES_EVAL_SHADER_NUM 5
120
121/* Curves procedural display: Evaluation is done on the GPU. */
123 /* --- Required attributes. --- */
124
127
129 /* TODO(fclem): Move it to generic point domain attributes. */
132 /* TODO(fclem): Move it to generic curve domain attributes. */
134
135 /* --- Indirection buffers. --- */
136
137 /* Map primitive to point ID and curve ID. Contains restart indices for line and triangle strip
138 * primitive. */
140 /* Map primitive to point ID and curve ID. Compacted for cylinder primitive. */
142
143 /* --- Buffers common to all curve types. --- */
144
155
156 /* --- Buffers only needed if geometry has Bezier curves. Dummy sized otherwise. --- */
157
164
165 /* --- Buffers only needed if geometry has Nurbs curves. Dummy sized otherwise. --- */
166
175
176 /* --- Generic Attributes. --- */
177
191 /* Attributes stored per curve. Nullptr if attribute is not from this domain. */
193 /* Output of the evaluation stage. This is only used by attributes on point domain. */
195 /* If attribute is point domain, use evaluated_attributes_buf. Otherwise curve_attributes_buf. */
196 std::array<bool, GPU_MAX_ATTR> attributes_point_domain;
197
198 /* --- Procedural Drawcalls. --- */
199 std::array<gpu::Batch *, MAX_FACE_PER_SEGMENT> batch;
200
202 const bke::CurvesGeometry &curves,
204 int index);
206 const bke::CurvesGeometry &curves,
207 const GPUMaterial *gpu_material);
208
209 void ensure_common(const bke::CurvesGeometry &curves);
210 void ensure_bezier(const bke::CurvesGeometry &curves);
211 void ensure_nurbs(const bke::CurvesGeometry &curves);
212
214
216 const bke::CurvesGeometry &curves,
217 int face_per_segment);
218
219 /* Sets r_over_limit to true if reaching hardware limit for the number of segments. */
220 gpu::Batch *batch_get(int evaluated_point_count,
221 int curve_count,
222 int face_per_segment,
223 bool use_cyclic,
224 bool &r_over_limit);
225
226 void discard_attributes();
227 void clear();
228
229 /* --- Legacy Hair Particle system. --- */
230
231 int resolution = 0;
232
235 const Mesh &mesh,
236 const StringRef name,
237 const int index);
240 const GPUMaterial *gpu_material);
241
243
245
248 int face_per_segment);
249
250 private:
251 /* In the case where there is cyclic curves, add one padding point per curve to ensure easy
252 * indexing in the drawing shader. */
253 int evaluated_point_count_with_cyclic(const bke::CurvesGeometry &curves);
254};
255
257
258void drw_curves_get_attribute_sampler_name(StringRef layer_name, char r_sampler_name[32]);
259
262 CurvesEvalCache &cache,
263 const int face_per_segment,
264 GPUMaterial *gpu_material,
265 gpu::VertBufPtr &indirection_buf,
266 std::optional<StringRef> active_uv_name);
267
270 CurvesEvalCache &cache,
271 const int face_per_segment,
272 GPUMaterial *gpu_material,
273 gpu::VertBufPtr &indirection_buf,
274 std::optional<StringRef> active_uv_name);
275
276} // namespace blender::draw
static constexpr int GPU_MAX_ATTR
Definition GPU_shader.hh:33
detail::PassBase< command::DrawMultiBuf > Sub
Definition draw_pass.hh:499
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
static struct PyModuleDef module
Definition python.cpp:796
const char * name
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