Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/gpencil/gpencil_cache_utils.c
| Show First 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | static GpencilBatchCache *gpencil_batch_cache_init(Object *ob, int cfra) | ||||
| } | } | ||||
| cache->is_editmode = GPENCIL_ANY_EDIT_MODE(gpd); | cache->is_editmode = GPENCIL_ANY_EDIT_MODE(gpd); | ||||
| cache->is_dirty = true; | cache->is_dirty = true; | ||||
| cache->cache_frame = cfra; | cache->cache_frame = cfra; | ||||
| /* create array of derived frames equal to number of layers */ | |||||
| cache->tot_layers = BLI_listbase_count(&gpd->layers); | |||||
| CLAMP_MIN(cache->tot_layers, 1); | |||||
| cache->derived_array = MEM_callocN(sizeof(struct bGPDframe) * cache->tot_layers, "Derived GPF"); | |||||
| return cache; | return cache; | ||||
| } | } | ||||
| /* clear cache */ | /* clear cache */ | ||||
| static void gpencil_batch_cache_clear(GpencilBatchCache *cache) | static void gpencil_batch_cache_clear(GpencilBatchCache *cache) | ||||
| { | { | ||||
| if (!cache) { | if (!cache) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPU_BATCH_DISCARD_SAFE(cache->b_stroke.batch); | GPU_BATCH_DISCARD_SAFE(cache->b_stroke.batch); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->b_point.batch); | GPU_BATCH_DISCARD_SAFE(cache->b_point.batch); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->b_fill.batch); | GPU_BATCH_DISCARD_SAFE(cache->b_fill.batch); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->b_edit.batch); | GPU_BATCH_DISCARD_SAFE(cache->b_edit.batch); | ||||
| GPU_BATCH_DISCARD_SAFE(cache->b_edlin.batch); | GPU_BATCH_DISCARD_SAFE(cache->b_edlin.batch); | ||||
| MEM_SAFE_FREE(cache->b_stroke.batch); | MEM_SAFE_FREE(cache->b_stroke.batch); | ||||
| MEM_SAFE_FREE(cache->b_point.batch); | MEM_SAFE_FREE(cache->b_point.batch); | ||||
| MEM_SAFE_FREE(cache->b_fill.batch); | MEM_SAFE_FREE(cache->b_fill.batch); | ||||
| MEM_SAFE_FREE(cache->b_edit.batch); | MEM_SAFE_FREE(cache->b_edit.batch); | ||||
| MEM_SAFE_FREE(cache->b_edlin.batch); | MEM_SAFE_FREE(cache->b_edlin.batch); | ||||
| /* internal format data */ | |||||
| MEM_SAFE_FREE(cache->b_stroke.format); | |||||
| MEM_SAFE_FREE(cache->b_point.format); | |||||
| MEM_SAFE_FREE(cache->b_fill.format); | |||||
| MEM_SAFE_FREE(cache->b_edit.format); | |||||
| MEM_SAFE_FREE(cache->b_edlin.format); | |||||
| MEM_SAFE_FREE(cache->grp_cache); | MEM_SAFE_FREE(cache->grp_cache); | ||||
| cache->grp_size = 0; | cache->grp_size = 0; | ||||
| cache->grp_used = 0; | cache->grp_used = 0; | ||||
| /* clear all frames derived data */ | |||||
| for (int i = 0; i < cache->tot_layers; i++) { | |||||
| bGPDframe *derived_gpf = &cache->derived_array[i]; | |||||
| BKE_gpencil_free_frame_runtime_data(derived_gpf); | |||||
| derived_gpf = NULL; | |||||
| } | |||||
| cache->tot_layers = 0; | |||||
| MEM_SAFE_FREE(cache->derived_array); | |||||
| } | } | ||||
| /* get cache */ | /* get cache */ | ||||
| GpencilBatchCache *gpencil_batch_cache_get(Object *ob, int cfra) | GpencilBatchCache *gpencil_batch_cache_get(Object *ob, int cfra) | ||||
| { | { | ||||
| bGPdata *gpd = (bGPdata *)ob->data; | bGPdata *gpd = (bGPdata *)ob->data; | ||||
| GpencilBatchCache *cache = gpencil_batch_get_element(ob); | GpencilBatchCache *cache = gpencil_batch_get_element(ob); | ||||
| Show All 26 Lines | void DRW_gpencil_freecache(struct Object *ob) | ||||
| if ((ob) && (ob->type == OB_GPENCIL)) { | if ((ob) && (ob->type == OB_GPENCIL)) { | ||||
| gpencil_batch_cache_clear(ob->runtime.gpencil_cache); | gpencil_batch_cache_clear(ob->runtime.gpencil_cache); | ||||
| MEM_SAFE_FREE(ob->runtime.gpencil_cache); | MEM_SAFE_FREE(ob->runtime.gpencil_cache); | ||||
| bGPdata *gpd = (bGPdata *)ob->data; | bGPdata *gpd = (bGPdata *)ob->data; | ||||
| if (gpd) { | if (gpd) { | ||||
| gpd->flag |= GP_DATA_CACHE_IS_DIRTY; | gpd->flag |= GP_DATA_CACHE_IS_DIRTY; | ||||
| } | } | ||||
| } | } | ||||
| /* clear all frames derived data */ | |||||
| for (int i = 0; i < ob->runtime.gpencil_tot_layers; i++) { | |||||
| bGPDframe *derived_gpf = &ob->runtime.gpencil_derived_frames[i]; | |||||
| BKE_gpencil_free_frame_runtime_data(derived_gpf); | |||||
| derived_gpf = NULL; | |||||
| } | |||||
| ob->runtime.gpencil_tot_layers = 0; | |||||
| MEM_SAFE_FREE(ob->runtime.gpencil_derived_frames); | |||||
| } | } | ||||