diff options
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_metaball.c')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_metaball.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c index 811f01aa83a..46c247d67ea 100644 --- a/source/blender/draw/intern/draw_cache_impl_metaball.c +++ b/source/blender/draw/intern/draw_cache_impl_metaball.c @@ -47,6 +47,7 @@ static void metaball_batch_cache_clear(MetaBall *mb); typedef struct MetaBallBatchCache { GPUBatch *batch; GPUBatch **shaded_triangles; + int mat_len; /* Shared */ @@ -57,8 +58,15 @@ typedef struct MetaBallBatchCache { GPUBatch *batch; } face_wire; + /* Edge detection */ + GPUBatch *edge_detection; + GPUIndexBuf *edges_adj_lines; + /* settings to determine if cache is invalid */ bool is_dirty; + + /* Valid only if edge_detection is up to date. */ + bool is_manifold; } MetaBallBatchCache; /* GPUBatch cache management. */ @@ -87,6 +95,9 @@ static void metaball_batch_cache_init(MetaBall *mb) cache->is_dirty = false; cache->pos_nor_in_order = NULL; cache->face_wire.batch = NULL; + cache->edge_detection = NULL; + cache->edges_adj_lines = NULL; + cache->is_manifold = false; } static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb) @@ -122,10 +133,13 @@ static void metaball_batch_cache_clear(MetaBall *mb) GPU_BATCH_DISCARD_SAFE(cache->face_wire.batch); GPU_BATCH_DISCARD_SAFE(cache->batch); + GPU_BATCH_DISCARD_SAFE(cache->edge_detection); GPU_VERTBUF_DISCARD_SAFE(cache->pos_nor_in_order); + GPU_INDEXBUF_DISCARD_SAFE(cache->edges_adj_lines); /* Note: shaded_triangles[0] is already freed by cache->batch */ MEM_SAFE_FREE(cache->shaded_triangles); cache->mat_len = 0; + cache->is_manifold = false; } void DRW_mball_batch_cache_free(MetaBall *mb) @@ -144,6 +158,16 @@ static GPUVertBuf *mball_batch_cache_get_pos_and_normals(Object *ob, MetaBallBat return cache->pos_nor_in_order; } +static GPUIndexBuf *mball_batch_cache_get_edges_adj_lines(Object *ob, MetaBallBatchCache *cache) +{ + if (cache->edges_adj_lines == NULL) { + ListBase *lb = &ob->runtime.curve_cache->disp; + cache->edges_adj_lines = MEM_callocN(sizeof(GPUVertBuf), __func__); + DRW_displist_indexbuf_create_edges_adjacency_lines(lb, cache->edges_adj_lines, &cache->is_manifold); + } + return cache->edges_adj_lines; +} + /* -------------------------------------------------------------------- */ /** \name Public Object/MetaBall API * \{ */ @@ -219,3 +243,26 @@ GPUBatch *DRW_metaball_batch_cache_get_wireframes_face(Object *ob) return cache->face_wire.batch; } + +struct GPUBatch *DRW_metaball_batch_cache_get_edge_detection(struct Object *ob, bool *r_is_manifold) +{ + if (!BKE_mball_is_basis(ob)) { + return NULL; + } + + MetaBall *mb = ob->data; + MetaBallBatchCache *cache = metaball_batch_cache_get(mb); + + if (cache->edge_detection == NULL) { + cache->edge_detection = GPU_batch_create( + GPU_PRIM_LINES_ADJ, + mball_batch_cache_get_pos_and_normals(ob, cache), + mball_batch_cache_get_edges_adj_lines(ob, cache)); + } + + if (r_is_manifold) { + *r_is_manifold = cache->is_manifold; + } + + return cache->edge_detection; +}
\ No newline at end of file |