Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_curve.cc
| Show All 13 Lines | |||||
| #include "BLI_math_vec_types.hh" | #include "BLI_math_vec_types.hh" | ||||
| #include "BLI_math_vector.h" | #include "BLI_math_vector.h" | ||||
| #include "BLI_span.hh" | #include "BLI_span.hh" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_curves.hh" | |||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_geometry_set.hh" | #include "BKE_geometry_set.hh" | ||||
| #include "BKE_spline.hh" | |||||
| #include "BKE_vfont.h" | #include "BKE_vfont.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_capabilities.h" | #include "GPU_capabilities.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | static void curve_render_overlay_verts_edges_len_get(ListBase *lb, | ||||
| if (r_vert_len) { | if (r_vert_len) { | ||||
| *r_vert_len = vert_len; | *r_vert_len = vert_len; | ||||
| } | } | ||||
| if (r_edge_len) { | if (r_edge_len) { | ||||
| *r_edge_len = edge_len; | *r_edge_len = edge_len; | ||||
| } | } | ||||
| } | } | ||||
| static void curve_eval_render_wire_verts_edges_len_get(const CurveEval &curve_eval, | static void curve_eval_render_wire_verts_edges_len_get(const blender::bke::CurvesGeometry &curves, | ||||
| int *r_curve_len, | int *r_curve_len, | ||||
| int *r_vert_len, | int *r_vert_len, | ||||
| int *r_edge_len) | int *r_edge_len) | ||||
| { | { | ||||
| Span<SplinePtr> splines = curve_eval.splines(); | *r_curve_len = curves.curves_num(); | ||||
| *r_curve_len = splines.size(); | *r_vert_len = curves.evaluated_points_num(); | ||||
| *r_vert_len = 0; | |||||
| *r_edge_len = 0; | *r_edge_len = 0; | ||||
| for (const SplinePtr &spline : splines) { | const blender::VArray<bool> cyclic = curves.cyclic(); | ||||
| *r_vert_len += spline->evaluated_points_size(); | for (const int i : curves.curves_range()) { | ||||
| *r_edge_len += spline->evaluated_edges_size(); | const IndexRange points = curves.evaluated_points_for_curve(i); | ||||
| *r_edge_len += blender::bke::curves::curve_segment_size(points.size(), cyclic[i]); | |||||
| } | } | ||||
| } | } | ||||
| static int curve_render_normal_len_get(const ListBase *lb, const CurveCache *ob_curve_cache) | static int curve_render_normal_len_get(const ListBase *lb, const CurveCache *ob_curve_cache) | ||||
| { | { | ||||
| int normal_len = 0; | int normal_len = 0; | ||||
| const BevList *bl; | const BevList *bl; | ||||
| const Nurb *nu; | const Nurb *nu; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | struct CurveRenderData { | ||||
| struct { | struct { | ||||
| EditFont *edit_font; | EditFont *edit_font; | ||||
| } text; | } text; | ||||
| /* borrow from 'Object' */ | /* borrow from 'Object' */ | ||||
| CurveCache *ob_curve_cache; | CurveCache *ob_curve_cache; | ||||
| /* Owned by the evaluated object's geometry set (#geometry_set_eval). */ | /* Owned by the evaluated object's geometry set (#geometry_set_eval). */ | ||||
| const CurveEval *curve_eval; | const Curves *curve_eval; | ||||
| /* borrow from 'Curve' */ | /* borrow from 'Curve' */ | ||||
| ListBase *nurbs; | ListBase *nurbs; | ||||
| /* edit, index in nurb list */ | /* edit, index in nurb list */ | ||||
| int actnu; | int actnu; | ||||
| /* edit, index in active nurb (BPoint or BezTriple) */ | /* edit, index in active nurb (BPoint or BezTriple) */ | ||||
| int actvert; | int actvert; | ||||
| Show All 27 Lines | static CurveRenderData *curve_render_data_create(Curve *cu, | ||||
| rdata->actvert = cu->actvert; | rdata->actvert = cu->actvert; | ||||
| rdata->ob_curve_cache = ob_curve_cache; | rdata->ob_curve_cache = ob_curve_cache; | ||||
| rdata->curve_eval = cu->curve_eval; | rdata->curve_eval = cu->curve_eval; | ||||
| if (types & CU_DATATYPE_WIRE) { | if (types & CU_DATATYPE_WIRE) { | ||||
| if (rdata->curve_eval != nullptr) { | if (rdata->curve_eval != nullptr) { | ||||
| curve_eval_render_wire_verts_edges_len_get(*rdata->curve_eval, | curve_eval_render_wire_verts_edges_len_get( | ||||
| blender::bke::CurvesGeometry::wrap(rdata->curve_eval->geometry), | |||||
| &rdata->wire.curve_len, | &rdata->wire.curve_len, | ||||
| &rdata->wire.vert_len, | &rdata->wire.vert_len, | ||||
| &rdata->wire.edge_len); | &rdata->wire.edge_len); | ||||
| } | } | ||||
| } | } | ||||
| if (cu->editnurb) { | if (cu->editnurb) { | ||||
| EditNurb *editnurb = cu->editnurb; | EditNurb *editnurb = cu->editnurb; | ||||
| nurbs = &editnurb->nurbs; | nurbs = &editnurb->nurbs; | ||||
| if (types & CU_DATATYPE_OVERLAY) { | if (types & CU_DATATYPE_OVERLAY) { | ||||
| ▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | static void curve_create_curves_pos(CurveRenderData *rdata, GPUVertBuf *vbo_curves_pos) | ||||
| if (format.attr_len == 0) { | if (format.attr_len == 0) { | ||||
| attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| } | } | ||||
| const int vert_len = curve_render_data_wire_verts_len_get(rdata); | const int vert_len = curve_render_data_wire_verts_len_get(rdata); | ||||
| GPU_vertbuf_init_with_format(vbo_curves_pos, &format); | GPU_vertbuf_init_with_format(vbo_curves_pos, &format); | ||||
| GPU_vertbuf_data_alloc(vbo_curves_pos, vert_len); | GPU_vertbuf_data_alloc(vbo_curves_pos, vert_len); | ||||
| const CurveEval &curve_eval = *rdata->curve_eval; | const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | ||||
| Span<SplinePtr> splines = curve_eval.splines(); | rdata->curve_eval->geometry); | ||||
| Array<int> offsets = curve_eval.evaluated_point_offsets(); | const Span<float3> positions = curves.evaluated_positions(); | ||||
| BLI_assert(offsets.last() == vert_len); | GPU_vertbuf_attr_fill(vbo_curves_pos, attr_id.pos, positions.data()); | ||||
| for (const int i_spline : splines.index_range()) { | |||||
| Span<float3> positions = splines[i_spline]->evaluated_positions(); | |||||
| for (const int i_point : positions.index_range()) { | |||||
| GPU_vertbuf_attr_set( | |||||
| vbo_curves_pos, attr_id.pos, offsets[i_spline] + i_point, positions[i_point]); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| static void curve_create_curves_lines(CurveRenderData *rdata, GPUIndexBuf *ibo_curve_lines) | static void curve_create_curves_lines(CurveRenderData *rdata, GPUIndexBuf *ibo_curve_lines) | ||||
| { | { | ||||
| if (rdata->curve_eval == nullptr) { | if (rdata->curve_eval == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| const int vert_len = curve_render_data_wire_verts_len_get(rdata); | const int vert_len = curve_render_data_wire_verts_len_get(rdata); | ||||
| const int edge_len = curve_render_data_wire_edges_len_get(rdata); | const int edge_len = curve_render_data_wire_edges_len_get(rdata); | ||||
| const int curve_len = curve_render_data_wire_curve_len_get(rdata); | const int curve_len = curve_render_data_wire_curve_len_get(rdata); | ||||
| /* Count the last vertex or each strip and the primitive restart. */ | /* Count the last vertex or each strip and the primitive restart. */ | ||||
| const int index_len = edge_len + curve_len * 2; | const int index_len = edge_len + curve_len * 2; | ||||
| GPUIndexBufBuilder elb; | GPUIndexBufBuilder elb; | ||||
| GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len); | GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINE_STRIP, index_len, vert_len); | ||||
| const CurveEval &curve_eval = *rdata->curve_eval; | const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | ||||
| Span<SplinePtr> splines = curve_eval.splines(); | rdata->curve_eval->geometry); | ||||
| Array<int> offsets = curve_eval.evaluated_point_offsets(); | const blender::VArray<bool> cyclic = curves.cyclic(); | ||||
| BLI_assert(offsets.last() == vert_len); | for (const int i : curves.curves_range()) { | ||||
| const IndexRange points = curves.evaluated_points_for_curve(i); | |||||
| for (const int i_spline : splines.index_range()) { | if (cyclic[i] && points.size() > 1) { | ||||
| const int eval_size = splines[i_spline]->evaluated_points_size(); | GPU_indexbuf_add_generic_vert(&elb, points.last()); | ||||
| if (splines[i_spline]->is_cyclic() && splines[i_spline]->evaluated_edges_size() > 1) { | |||||
| GPU_indexbuf_add_generic_vert(&elb, offsets[i_spline] + eval_size - 1); | |||||
| } | } | ||||
| for (const int i_point : IndexRange(eval_size)) { | for (const int i_point : points) { | ||||
| GPU_indexbuf_add_generic_vert(&elb, offsets[i_spline] + i_point); | GPU_indexbuf_add_generic_vert(&elb, i_point); | ||||
| } | } | ||||
| GPU_indexbuf_add_primitive_restart(&elb); | GPU_indexbuf_add_primitive_restart(&elb); | ||||
| } | } | ||||
| GPU_indexbuf_build_in_place(&elb, ibo_curve_lines); | GPU_indexbuf_build_in_place(&elb, ibo_curve_lines); | ||||
| } | } | ||||
| static void curve_create_edit_curves_nor(CurveRenderData *rdata, | static void curve_create_edit_curves_nor(CurveRenderData *rdata, | ||||
| ▲ Show 20 Lines • Show All 367 Lines • Show Last 20 Lines | |||||