Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-04-22 18:43:48 +0300
committerHans Goudey <h.goudey@me.com>2022-04-22 18:44:01 +0300
commit5b87862ddca2cb1b9351a5e250e1743b7245f38b (patch)
tree53d6e591709d50bcf77ac444f2cb10c12c1874e9 /source/blender/draw/intern/draw_cache_impl_curves.cc
parent8f05a547d539feb4a8da35ee15239fa46ff38083 (diff)
Curves: Further split of curves draw code from particles
Extends the changes started in f31c3f8114616bb to completely separate much of the DRW curves code from the particle hair drawing. In the short term this increases duplication, but the idea is to simplify development by making it easier to do larger changes to the new code, and the new system will replace the particle hair at some point. After this, only the shaders themselves are shared. Differential Revision: https://developer.blender.org/D14699
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_curves.cc')
-rw-r--r--source/blender/draw/intern/draw_cache_impl_curves.cc67
1 files changed, 49 insertions, 18 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc
index b084a5e5945..f2e747cb276 100644
--- a/source/blender/draw/intern/draw_cache_impl_curves.cc
+++ b/source/blender/draw/intern/draw_cache_impl_curves.cc
@@ -29,9 +29,11 @@
#include "GPU_material.h"
#include "GPU_texture.h"
+#include "DRW_render.h"
+
#include "draw_cache_impl.h" /* own include */
#include "draw_cache_inline.h"
-#include "draw_hair_private.h" /* own include */
+#include "draw_curves_private.h" /* own include */
using blender::float3;
using blender::IndexRange;
@@ -41,7 +43,7 @@ using blender::Span;
/* Curves GPUBatch Cache */
struct CurvesBatchCache {
- ParticleHairCache hair;
+ CurvesEvalCache curves_cache;
GPUBatch *edit_points;
@@ -70,6 +72,33 @@ static void curves_batch_cache_init(Curves &curves)
cache->is_dirty = false;
}
+static void curves_batch_cache_clear_data(CurvesEvalCache &curves_cache)
+{
+ /* TODO: more granular update tagging. */
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_point_buf);
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_length_buf);
+ DRW_TEXTURE_FREE_SAFE(curves_cache.point_tex);
+ DRW_TEXTURE_FREE_SAFE(curves_cache.length_tex);
+
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_strand_buf);
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_strand_seg_buf);
+ DRW_TEXTURE_FREE_SAFE(curves_cache.strand_tex);
+ DRW_TEXTURE_FREE_SAFE(curves_cache.strand_seg_tex);
+
+ for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.final[i].proc_buf);
+ DRW_TEXTURE_FREE_SAFE(curves_cache.final[i].proc_tex);
+ for (int j = 0; j < MAX_THICKRES; j++) {
+ GPU_BATCH_DISCARD_SAFE(curves_cache.final[i].proc_hairs[j]);
+ }
+ }
+
+ /* "Normal" legacy hairs */
+ GPU_BATCH_DISCARD_SAFE(curves_cache.hairs);
+ GPU_VERTBUF_DISCARD_SAFE(curves_cache.pos);
+ GPU_INDEXBUF_DISCARD_SAFE(curves_cache.indices);
+}
+
static void curves_batch_cache_clear(Curves &curves)
{
CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache);
@@ -77,7 +106,8 @@ static void curves_batch_cache_clear(Curves &curves)
return;
}
- particle_batch_cache_clear_hair(&cache->hair);
+ curves_batch_cache_clear_data(cache->curves_cache);
+
GPU_BATCH_DISCARD_SAFE(cache->edit_points);
}
@@ -116,7 +146,7 @@ void DRW_curves_batch_cache_free(Curves *curves)
MEM_SAFE_FREE(curves->batch_cache);
}
-static void ensure_seg_pt_count(const Curves &curves, ParticleHairCache &curves_cache)
+static void ensure_seg_pt_count(const Curves &curves, CurvesEvalCache &curves_cache)
{
if ((curves_cache.pos != nullptr && curves_cache.indices != nullptr) ||
(curves_cache.proc_point_buf != nullptr)) {
@@ -169,7 +199,7 @@ static void curves_batch_cache_fill_segments_proc_pos(const Curves &curves_id,
}
static void curves_batch_cache_ensure_procedural_pos(Curves &curves,
- ParticleHairCache &cache,
+ CurvesEvalCache &cache,
GPUMaterial *gpu_material)
{
if (cache.proc_point_buf == nullptr || DRW_vbo_requested(cache.proc_point_buf)) {
@@ -229,7 +259,7 @@ static void curves_batch_cache_fill_strands_data(const Curves &curves_id,
}
static void curves_batch_cache_ensure_procedural_strand_data(Curves &curves,
- ParticleHairCache &cache)
+ CurvesEvalCache &cache)
{
GPUVertBufRaw data_step, seg_step;
@@ -259,7 +289,7 @@ static void curves_batch_cache_ensure_procedural_strand_data(Curves &curves,
cache.proc_strand_seg_buf);
}
-static void curves_batch_cache_ensure_procedural_final_points(ParticleHairCache &cache, int subdiv)
+static void curves_batch_cache_ensure_procedural_final_points(CurvesEvalCache &cache, int subdiv)
{
/* Same format as point_tex. */
GPUVertFormat format = {0};
@@ -296,7 +326,7 @@ static void curves_batch_cache_fill_segments_indices(const Curves &curves,
}
static void curves_batch_cache_ensure_procedural_indices(Curves &curves,
- ParticleHairCache &cache,
+ CurvesEvalCache &cache,
const int thickness_res,
const int subdiv)
{
@@ -330,7 +360,7 @@ static void curves_batch_cache_ensure_procedural_indices(Curves &curves,
}
bool curves_ensure_procedural_data(Object *object,
- ParticleHairCache **r_hair_cache,
+ CurvesEvalCache **r_hair_cache,
GPUMaterial *gpu_material,
const int subdiv,
const int thickness_res)
@@ -339,30 +369,31 @@ bool curves_ensure_procedural_data(Object *object,
Curves &curves = *static_cast<Curves *>(object->data);
CurvesBatchCache &cache = curves_batch_cache_get(curves);
- *r_hair_cache = &cache.hair;
+ *r_hair_cache = &cache.curves_cache;
const int steps = 3; /* TODO: don't hard-code? */
(*r_hair_cache)->final[subdiv].strands_res = 1 << (steps + subdiv);
/* Refreshed on combing and simulation. */
if ((*r_hair_cache)->proc_point_buf == nullptr) {
- ensure_seg_pt_count(curves, cache.hair);
- curves_batch_cache_ensure_procedural_pos(curves, cache.hair, gpu_material);
+ ensure_seg_pt_count(curves, cache.curves_cache);
+ curves_batch_cache_ensure_procedural_pos(curves, cache.curves_cache, gpu_material);
need_ft_update = true;
}
/* Refreshed if active layer or custom data changes. */
if ((*r_hair_cache)->strand_tex == nullptr) {
- curves_batch_cache_ensure_procedural_strand_data(curves, cache.hair);
+ curves_batch_cache_ensure_procedural_strand_data(curves, cache.curves_cache);
}
/* Refreshed only on subdiv count change. */
if ((*r_hair_cache)->final[subdiv].proc_buf == nullptr) {
- curves_batch_cache_ensure_procedural_final_points(cache.hair, subdiv);
+ curves_batch_cache_ensure_procedural_final_points(cache.curves_cache, subdiv);
need_ft_update = true;
}
if ((*r_hair_cache)->final[subdiv].proc_hairs[thickness_res - 1] == nullptr) {
- curves_batch_cache_ensure_procedural_indices(curves, cache.hair, thickness_res, subdiv);
+ curves_batch_cache_ensure_procedural_indices(
+ curves, cache.curves_cache, thickness_res, subdiv);
}
return need_ft_update;
@@ -385,10 +416,10 @@ void DRW_curves_batch_cache_create_requested(const Object *ob)
CurvesBatchCache &cache = curves_batch_cache_get(*curves);
if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) {
- DRW_vbo_request(cache.edit_points, &cache.hair.proc_point_buf);
+ DRW_vbo_request(cache.edit_points, &cache.curves_cache.proc_point_buf);
}
- if (DRW_vbo_requested(cache.hair.proc_point_buf)) {
- curves_batch_cache_ensure_procedural_pos(*curves, cache.hair, nullptr);
+ if (DRW_vbo_requested(cache.curves_cache.proc_point_buf)) {
+ curves_batch_cache_ensure_procedural_pos(*curves, cache.curves_cache, nullptr);
}
}