Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_curve.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2017 Blender Foundation. All rights reserved. */ | * Copyright 2017 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw | * \ingroup draw | ||||
| * | * | ||||
| * \brief Curve API for render engines | * \brief Curve API for render engines | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_array.hh" | #include "BLI_array.hh" | ||||
| #include "BLI_color.hh" | |||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #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" | ||||
| Show All 12 Lines | |||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "draw_cache_inline.h" | #include "draw_cache_inline.h" | ||||
| #include "draw_cache_impl.h" /* own include */ | #include "draw_cache_impl.h" /* own include */ | ||||
| using blender::Array; | using blender::Array; | ||||
| using blender::ColorGeometry4f; | |||||
| using blender::float3; | using blender::float3; | ||||
| using blender::IndexRange; | using blender::IndexRange; | ||||
| using blender::Span; | using blender::Span; | ||||
| /* See: edit_curve_point_vert.glsl for duplicate includes. */ | /* See: edit_curve_point_vert.glsl for duplicate includes. */ | ||||
| #define SELECT 1 | #define SELECT 1 | ||||
| #define ACTIVE_NURB (1 << 2) | #define ACTIVE_NURB (1 << 2) | ||||
| #define BEZIER_HANDLE (1 << 3) | #define BEZIER_HANDLE (1 << 3) | ||||
| ▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Curve GPUBatch Cache */ | /* Curve GPUBatch Cache */ | ||||
| struct CurveBatchCache { | struct CurveBatchCache { | ||||
| struct { | struct { | ||||
| GPUVertBuf *curves_pos; | GPUVertBuf *curves_pos; | ||||
| GPUVertBuf *attr_viewer; | |||||
| } ordered; | } ordered; | ||||
| struct { | struct { | ||||
| GPUVertBuf *curves_nor; | GPUVertBuf *curves_nor; | ||||
| /* Edit points (beztriples and bpoints) */ | /* Edit points (beztriples and bpoints) */ | ||||
| GPUVertBuf *pos; | GPUVertBuf *pos; | ||||
| GPUVertBuf *data; | GPUVertBuf *data; | ||||
| } edit; | } edit; | ||||
| struct { | struct { | ||||
| GPUIndexBuf *curves_lines; | GPUIndexBuf *curves_lines; | ||||
| /* Edit mode */ | /* Edit mode */ | ||||
| GPUIndexBuf *edit_verts; | GPUIndexBuf *edit_verts; | ||||
| GPUIndexBuf *edit_lines; | GPUIndexBuf *edit_lines; | ||||
| } ibo; | } ibo; | ||||
| struct { | struct { | ||||
| GPUBatch *curves; | GPUBatch *curves; | ||||
| GPUBatch *curves_viewer_attribute; | |||||
| /* control handles and vertices */ | /* control handles and vertices */ | ||||
| GPUBatch *edit_edges; | GPUBatch *edit_edges; | ||||
| GPUBatch *edit_verts; | GPUBatch *edit_verts; | ||||
| GPUBatch *edit_normals; | GPUBatch *edit_normals; | ||||
| } batch; | } batch; | ||||
| /* settings to determine if cache is invalid */ | /* settings to determine if cache is invalid */ | ||||
| bool is_dirty; | bool is_dirty; | ||||
| ▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | static void curve_create_curves_pos(CurveRenderData *rdata, GPUVertBuf *vbo_curves_pos) | ||||
| GPU_vertbuf_data_alloc(vbo_curves_pos, vert_len); | GPU_vertbuf_data_alloc(vbo_curves_pos, vert_len); | ||||
| const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | ||||
| rdata->curve_eval->geometry); | rdata->curve_eval->geometry); | ||||
| const Span<float3> positions = curves.evaluated_positions(); | const Span<float3> positions = curves.evaluated_positions(); | ||||
| GPU_vertbuf_attr_fill(vbo_curves_pos, attr_id.pos, positions.data()); | GPU_vertbuf_attr_fill(vbo_curves_pos, attr_id.pos, positions.data()); | ||||
| } | } | ||||
| static void curve_create_attribute(CurveRenderData *rdata, GPUVertBuf *vbo_attr) | |||||
| { | |||||
| if (rdata->curve_eval == nullptr) { | |||||
| return; | |||||
| } | |||||
| static GPUVertFormat format = {0}; | |||||
| if (format.attr_len == 0) { | |||||
| GPU_vertformat_attr_add(&format, "attribute_value", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| } | |||||
| const int vert_len = curve_render_data_wire_verts_len_get(rdata); | |||||
| GPU_vertbuf_init_with_format(vbo_attr, &format); | |||||
| GPU_vertbuf_data_alloc(vbo_attr, vert_len); | |||||
| const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( | |||||
| rdata->curve_eval->geometry); | |||||
| curves.ensure_can_interpolate_to_evaluated(); | |||||
| const blender::VArraySpan<ColorGeometry4f> colors = curves.attributes().lookup<ColorGeometry4f>( | |||||
| ".viewer", ATTR_DOMAIN_POINT); | |||||
| ColorGeometry4f *vbo_data = static_cast<ColorGeometry4f *>(GPU_vertbuf_get_data(vbo_attr)); | |||||
| curves.interpolate_to_evaluated(colors, | |||||
| blender::MutableSpan<ColorGeometry4f>{vbo_data, vert_len}); | |||||
| } | |||||
| 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); | ||||
| ▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| GPUBatch *DRW_curve_batch_cache_get_wire_edge(Curve *cu) | GPUBatch *DRW_curve_batch_cache_get_wire_edge(Curve *cu) | ||||
| { | { | ||||
| CurveBatchCache *cache = curve_batch_cache_get(cu); | CurveBatchCache *cache = curve_batch_cache_get(cu); | ||||
| return DRW_batch_request(&cache->batch.curves); | return DRW_batch_request(&cache->batch.curves); | ||||
| } | } | ||||
| GPUBatch *DRW_curve_batch_cache_get_wire_edge_viewer_attribute(Curve *cu) | |||||
| { | |||||
| CurveBatchCache *cache = curve_batch_cache_get(cu); | |||||
| return DRW_batch_request(&cache->batch.curves_viewer_attribute); | |||||
| } | |||||
| GPUBatch *DRW_curve_batch_cache_get_normal_edge(Curve *cu) | GPUBatch *DRW_curve_batch_cache_get_normal_edge(Curve *cu) | ||||
| { | { | ||||
| CurveBatchCache *cache = curve_batch_cache_get(cu); | CurveBatchCache *cache = curve_batch_cache_get(cu); | ||||
| return DRW_batch_request(&cache->batch.edit_normals); | return DRW_batch_request(&cache->batch.edit_normals); | ||||
| } | } | ||||
| GPUBatch *DRW_curve_batch_cache_get_edit_edges(Curve *cu) | GPUBatch *DRW_curve_batch_cache_get_edit_edges(Curve *cu) | ||||
| { | { | ||||
| Show All 25 Lines | void DRW_curve_batch_cache_create_requested(Object *ob, const struct Scene *scene) | ||||
| Curve *cu = (Curve *)ob->data; | Curve *cu = (Curve *)ob->data; | ||||
| CurveBatchCache *cache = curve_batch_cache_get(cu); | CurveBatchCache *cache = curve_batch_cache_get(cu); | ||||
| /* Init batches and request VBOs & IBOs */ | /* Init batches and request VBOs & IBOs */ | ||||
| if (DRW_batch_requested(cache->batch.curves, GPU_PRIM_LINE_STRIP)) { | if (DRW_batch_requested(cache->batch.curves, GPU_PRIM_LINE_STRIP)) { | ||||
| DRW_ibo_request(cache->batch.curves, &cache->ibo.curves_lines); | DRW_ibo_request(cache->batch.curves, &cache->ibo.curves_lines); | ||||
| DRW_vbo_request(cache->batch.curves, &cache->ordered.curves_pos); | DRW_vbo_request(cache->batch.curves, &cache->ordered.curves_pos); | ||||
| } | } | ||||
| if (DRW_batch_requested(cache->batch.curves_viewer_attribute, GPU_PRIM_LINE_STRIP)) { | |||||
| DRW_ibo_request(cache->batch.curves_viewer_attribute, &cache->ibo.curves_lines); | |||||
| DRW_vbo_request(cache->batch.curves_viewer_attribute, &cache->ordered.curves_pos); | |||||
| DRW_vbo_request(cache->batch.curves_viewer_attribute, &cache->ordered.attr_viewer); | |||||
| } | |||||
| /* Edit mode */ | /* Edit mode */ | ||||
| if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) { | if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) { | ||||
| DRW_ibo_request(cache->batch.edit_edges, &cache->ibo.edit_lines); | DRW_ibo_request(cache->batch.edit_edges, &cache->ibo.edit_lines); | ||||
| DRW_vbo_request(cache->batch.edit_edges, &cache->edit.pos); | DRW_vbo_request(cache->batch.edit_edges, &cache->edit.pos); | ||||
| DRW_vbo_request(cache->batch.edit_edges, &cache->edit.data); | DRW_vbo_request(cache->batch.edit_edges, &cache->edit.data); | ||||
| } | } | ||||
| if (DRW_batch_requested(cache->batch.edit_verts, GPU_PRIM_POINTS)) { | if (DRW_batch_requested(cache->batch.edit_verts, GPU_PRIM_POINTS)) { | ||||
| DRW_ibo_request(cache->batch.edit_verts, &cache->ibo.edit_verts); | DRW_ibo_request(cache->batch.edit_verts, &cache->ibo.edit_verts); | ||||
| DRW_vbo_request(cache->batch.edit_verts, &cache->edit.pos); | DRW_vbo_request(cache->batch.edit_verts, &cache->edit.pos); | ||||
| DRW_vbo_request(cache->batch.edit_verts, &cache->edit.data); | DRW_vbo_request(cache->batch.edit_verts, &cache->edit.data); | ||||
| } | } | ||||
| if (DRW_batch_requested(cache->batch.edit_normals, GPU_PRIM_LINES)) { | if (DRW_batch_requested(cache->batch.edit_normals, GPU_PRIM_LINES)) { | ||||
| DRW_vbo_request(cache->batch.edit_normals, &cache->edit.curves_nor); | DRW_vbo_request(cache->batch.edit_normals, &cache->edit.curves_nor); | ||||
| } | } | ||||
| #ifdef DRW_DEBUG_MESH_CACHE_REQUEST | #ifdef DRW_DEBUG_MESH_CACHE_REQUEST | ||||
| printf("-- %s %s --\n", __func__, ob->id.name + 2); | printf("-- %s %s --\n", __func__, ob->id.name + 2); | ||||
| #endif | #endif | ||||
| /* Generate MeshRenderData flags */ | /* Generate MeshRenderData flags */ | ||||
| int mr_flag = 0; | int mr_flag = 0; | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->ordered.curves_pos, CU_DATATYPE_WIRE); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->ordered.curves_pos, CU_DATATYPE_WIRE); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST( | |||||
| mr_flag, cache->ordered.attr_viewer, CU_DATATYPE_WIRE | CU_DATATYPE_OVERLAY); | |||||
| DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.curves_lines, CU_DATATYPE_WIRE); | DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.curves_lines, CU_DATATYPE_WIRE); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.pos, CU_DATATYPE_OVERLAY); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.pos, CU_DATATYPE_OVERLAY); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.data, CU_DATATYPE_OVERLAY); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.data, CU_DATATYPE_OVERLAY); | ||||
| DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.curves_nor, CU_DATATYPE_NORMAL); | DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_flag, cache->edit.curves_nor, CU_DATATYPE_NORMAL); | ||||
| DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_verts, CU_DATATYPE_OVERLAY); | DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_verts, CU_DATATYPE_OVERLAY); | ||||
| DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_lines, CU_DATATYPE_OVERLAY); | DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_flag, cache->ibo.edit_lines, CU_DATATYPE_OVERLAY); | ||||
| #ifdef DRW_DEBUG_MESH_CACHE_REQUEST | #ifdef DRW_DEBUG_MESH_CACHE_REQUEST | ||||
| printf(" mr_flag %d\n\n", mr_flag); | printf(" mr_flag %d\n\n", mr_flag); | ||||
| #endif | #endif | ||||
| CurveRenderData *rdata = curve_render_data_create(cu, ob->runtime.curve_cache, mr_flag); | CurveRenderData *rdata = curve_render_data_create(cu, ob->runtime.curve_cache, mr_flag); | ||||
| /* Generate VBOs */ | /* Generate VBOs */ | ||||
| if (DRW_vbo_requested(cache->ordered.curves_pos)) { | if (DRW_vbo_requested(cache->ordered.curves_pos)) { | ||||
| curve_create_curves_pos(rdata, cache->ordered.curves_pos); | curve_create_curves_pos(rdata, cache->ordered.curves_pos); | ||||
| } | } | ||||
| if (DRW_vbo_requested(cache->ordered.attr_viewer)) { | |||||
| curve_create_attribute(rdata, cache->ordered.attr_viewer); | |||||
| } | |||||
| if (DRW_ibo_requested(cache->ibo.curves_lines)) { | if (DRW_ibo_requested(cache->ibo.curves_lines)) { | ||||
| curve_create_curves_lines(rdata, cache->ibo.curves_lines); | curve_create_curves_lines(rdata, cache->ibo.curves_lines); | ||||
| } | } | ||||
| if (DRW_vbo_requested(cache->edit.pos) || DRW_vbo_requested(cache->edit.data) || | if (DRW_vbo_requested(cache->edit.pos) || DRW_vbo_requested(cache->edit.data) || | ||||
| DRW_ibo_requested(cache->ibo.edit_verts) || DRW_ibo_requested(cache->ibo.edit_lines)) { | DRW_ibo_requested(cache->ibo.edit_verts) || DRW_ibo_requested(cache->ibo.edit_lines)) { | ||||
| curve_create_edit_data_and_handles( | curve_create_edit_data_and_handles( | ||||
| rdata, cache->edit.pos, cache->edit.data, cache->ibo.edit_verts, cache->ibo.edit_lines); | rdata, cache->edit.pos, cache->edit.data, cache->ibo.edit_verts, cache->ibo.edit_lines); | ||||
| } | } | ||||
| Show All 15 Lines | |||||