From e15320568a29e163b32e261dc1aaee22404e0dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Fri, 8 Apr 2022 18:23:40 +0200 Subject: Curves edit mode: show dots for points This adds support to show dots for the curves points when in edit mode, using a specific overlay. This also adds `DRW_curves_batch_cache_create_requested` which for now only creates the point buffer for the newly added `edit_points` batch. In the future, this will also handle other edit mode overlays, and probably also replace the current curves batch cache creation. Maniphest Tasks: T95770 Differential Revision: https://developer.blender.org/D14262 --- source/blender/draw/intern/DRW_render.h | 2 ++ source/blender/draw/intern/draw_cache.c | 3 +++ source/blender/draw/intern/draw_cache_impl.h | 10 ++++++++ .../blender/draw/intern/draw_cache_impl_curves.cc | 30 ++++++++++++++++++++-- source/blender/draw/intern/draw_manager.c | 2 +- 5 files changed, 44 insertions(+), 3 deletions(-) (limited to 'source/blender/draw/intern') diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index d3b1d2e74a2..1bf67a4f315 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -367,6 +367,8 @@ typedef enum { DRW_STATE_PROGRAM_POINT_SIZE = (1u << 31), } DRWState; +ENUM_OPERATORS(DRWState, DRW_STATE_PROGRAM_POINT_SIZE); + #define DRW_STATE_DEFAULT \ (DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL) #define DRW_STATE_BLEND_ENABLED \ diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 5fa0b4fc26a..e606d67df25 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -3348,6 +3348,9 @@ void drw_batch_cache_generate_requested(Object *ob) case OB_SURF: DRW_curve_batch_cache_create_requested(ob, scene); break; + case OB_CURVES: + DRW_curves_batch_cache_create_requested(ob); + break; /* TODO: all cases. */ default: break; diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index e728d8614de..f877c94208f 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -351,6 +351,16 @@ struct GPUBatch *DRW_particles_batch_cache_get_edit_tip_points(struct Object *ob /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Curves + * \{ */ + +struct GPUBatch *DRW_curves_batch_cache_get_edit_points(struct Curves *curves); + +void DRW_curves_batch_cache_create_requested(const struct Object *ob); + +/** \} */ + #ifdef __cplusplus } #endif diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index 0b8913402e6..b084a5e5945 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -21,6 +21,7 @@ #include "DNA_curves_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" #include "BKE_curves.hh" @@ -28,7 +29,8 @@ #include "GPU_material.h" #include "GPU_texture.h" -#include "draw_cache_impl.h" /* own include */ +#include "draw_cache_impl.h" /* own include */ +#include "draw_cache_inline.h" #include "draw_hair_private.h" /* own include */ using blender::float3; @@ -41,6 +43,8 @@ using blender::Span; struct CurvesBatchCache { ParticleHairCache hair; + GPUBatch *edit_points; + /* To determine if cache is invalid. */ bool is_dirty; }; @@ -74,6 +78,7 @@ static void curves_batch_cache_clear(Curves &curves) } particle_batch_cache_clear_hair(&cache->hair); + GPU_BATCH_DISCARD_SAFE(cache->edit_points); } void DRW_curves_batch_cache_validate(Curves *curves) @@ -167,10 +172,11 @@ static void curves_batch_cache_ensure_procedural_pos(Curves &curves, ParticleHairCache &cache, GPUMaterial *gpu_material) { - if (cache.proc_point_buf == nullptr) { + if (cache.proc_point_buf == nullptr || DRW_vbo_requested(cache.proc_point_buf)) { /* Initialize vertex format. */ GPUVertFormat format = {0}; uint pos_id = GPU_vertformat_attr_add(&format, "posTime", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + GPU_vertformat_alias_add(&format, "pos"); cache.proc_point_buf = GPU_vertbuf_create_with_format(&format); GPU_vertbuf_data_alloc(cache.proc_point_buf, cache.point_len); @@ -366,3 +372,23 @@ int DRW_curves_material_count_get(Curves *curves) { return max_ii(1, curves->totcol); } + +GPUBatch *DRW_curves_batch_cache_get_edit_points(Curves *curves) +{ + CurvesBatchCache &cache = curves_batch_cache_get(*curves); + return DRW_batch_request(&cache.edit_points); +} + +void DRW_curves_batch_cache_create_requested(const Object *ob) +{ + Curves *curves = static_cast(ob->data); + 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); + } + + if (DRW_vbo_requested(cache.hair.proc_point_buf)) { + curves_batch_cache_ensure_procedural_pos(*curves, cache.hair, nullptr); + } +} diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 75c27937f25..ec3a5b3a7b1 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -197,7 +197,7 @@ bool DRW_object_is_renderable(const Object *ob) bool DRW_object_is_in_edit_mode(const Object *ob) { if (BKE_object_is_in_editmode(ob)) { - if (ob->type == OB_MESH) { + if (ELEM(ob->type, OB_MESH, OB_CURVES)) { if ((ob->mode & OB_MODE_EDIT) == 0) { return false; } -- cgit v1.2.3