Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_curves.cc
| Show All 37 Lines | |||||
| #include "draw_curves_private.h" /* own include */ | #include "draw_curves_private.h" /* own include */ | ||||
| #include "draw_shader.h" | #include "draw_shader.h" | ||||
| using blender::ColorGeometry4f; | using blender::ColorGeometry4f; | ||||
| using blender::float3; | using blender::float3; | ||||
| using blender::IndexRange; | using blender::IndexRange; | ||||
| using blender::MutableSpan; | using blender::MutableSpan; | ||||
| using blender::Span; | using blender::Span; | ||||
| using blender::VArray; | |||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Curves GPUBatch Cache */ | /* Curves GPUBatch Cache */ | ||||
| struct CurvesBatchCache { | struct CurvesBatchCache { | ||||
| CurvesEvalCache curves_cache; | CurvesEvalCache curves_cache; | ||||
| GPUBatch *edit_points; | GPUBatch *edit_points; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | static void curves_discard_attributes(CurvesEvalCache &curves_cache) | ||||
| } | } | ||||
| } | } | ||||
| static void curves_batch_cache_clear_data(CurvesEvalCache &curves_cache) | static void curves_batch_cache_clear_data(CurvesEvalCache &curves_cache) | ||||
| { | { | ||||
| /* TODO: more granular update tagging. */ | /* TODO: more granular update tagging. */ | ||||
| GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_point_buf); | GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_point_buf); | ||||
| GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_length_buf); | GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_length_buf); | ||||
| GPU_VERTBUF_DISCARD_SAFE(curves_cache.data); | |||||
| DRW_TEXTURE_FREE_SAFE(curves_cache.point_tex); | DRW_TEXTURE_FREE_SAFE(curves_cache.point_tex); | ||||
| DRW_TEXTURE_FREE_SAFE(curves_cache.length_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_buf); | ||||
| GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_strand_seg_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_tex); | ||||
| DRW_TEXTURE_FREE_SAFE(curves_cache.strand_seg_tex); | DRW_TEXTURE_FREE_SAFE(curves_cache.strand_seg_tex); | ||||
| ▲ Show 20 Lines • Show All 572 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void DRW_curves_batch_cache_create_requested(Object *ob) | void DRW_curves_batch_cache_create_requested(Object *ob) | ||||
| { | { | ||||
| Curves *curves = static_cast<Curves *>(ob->data); | Curves *curves = static_cast<Curves *>(ob->data); | ||||
| CurvesBatchCache &cache = curves_batch_cache_get(*curves); | CurvesBatchCache &cache = curves_batch_cache_get(*curves); | ||||
| if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) { | if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) { | ||||
| /* Editmode, requires "data" VBO for selection drawing. */ | |||||
| DRW_vbo_request(cache.edit_points, &cache.curves_cache.proc_point_buf); | DRW_vbo_request(cache.edit_points, &cache.curves_cache.proc_point_buf); | ||||
| DRW_vbo_request(cache.edit_points, &cache.curves_cache.data); | |||||
| } | } | ||||
| if (DRW_vbo_requested(cache.curves_cache.proc_point_buf)) { | if (DRW_vbo_requested(cache.curves_cache.proc_point_buf)) { | ||||
| curves_batch_cache_ensure_procedural_pos(*curves, cache.curves_cache, nullptr); | curves_batch_cache_ensure_procedural_pos(*curves, cache.curves_cache, nullptr); | ||||
| } | } | ||||
| if (DRW_vbo_requested(cache.curves_cache.data)) { | |||||
| blender::bke::CurvesGeometry &curves_geo = blender::bke::CurvesGeometry::wrap(curves->geometry); | |||||
| const VArray<float> points_selection = curves_geo.selection_point_float(); | |||||
| static GPUVertFormat format_data = {0}; | |||||
| uint data = GPU_vertformat_attr_add(&format_data, "data", GPU_COMP_U8, 1, GPU_FETCH_INT); | |||||
| GPU_vertbuf_init_with_format(cache.curves_cache.data, &format_data); | |||||
| GPU_vertbuf_data_alloc(cache.curves_cache.data, curves_geo.points_num()); | |||||
| for (const int point_i : points_selection.index_range()) { | |||||
| uint8_t vflag = 0; | |||||
| const float point_selection = points_selection[point_i]; | |||||
| SET_FLAG_FROM_TEST(vflag, (point_selection > 0.0f), VFLAG_VERT_SELECTED); | |||||
| GPU_vertbuf_attr_set(cache.curves_cache.data, data, point_i, &vflag); | |||||
| } | |||||
| } | |||||
| } | } | ||||