diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-08-30 23:47:36 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-08-30 23:49:05 +0300 |
commit | f436e0acab6cb510a74fe9e04b7dfb1c2ac142b5 (patch) | |
tree | edae4e385c9018ab7f4586e1edededcd1841d719 /source | |
parent | 7527f2317a01b911638c0db5df2661241c31c7b0 (diff) |
Cleanup: GPU_BATCH_DISCARD_ARRAY_SAFE (deduplicate existing code)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_curve.c | 16 | ||||
-rw-r--r-- | source/blender/gpu/GPU_batch.h | 10 |
2 files changed, 13 insertions, 13 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index f468288fefe..3fd8a970db9 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -458,12 +458,8 @@ static void curve_batch_cache_clear(Curve *cu) GPU_VERTBUF_DISCARD_SAFE(cache->surface.verts); GPU_INDEXBUF_DISCARD_SAFE(cache->surface.triangles_in_order); - if (cache->surface.shaded_triangles) { - for (int i = 0; i < cache->surface.mat_len; ++i) { - GPU_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]); - } - } - MEM_SAFE_FREE(cache->surface.shaded_triangles); + + GPU_BATCH_DISCARD_ARRAY_SAFE(cache->surface.shaded_triangles, cache->surface.mat_len); GPU_BATCH_DISCARD_SAFE(cache->surface.batch); /* don't own vbo & elems */ @@ -1037,13 +1033,7 @@ GPUBatch **DRW_curve_batch_cache_get_surface_shaded( CurveBatchCache *cache = curve_batch_cache_get(cu); if (cache->surface.mat_len != gpumat_array_len) { - /* TODO: deduplicate code */ - if (cache->surface.shaded_triangles) { - for (int i = 0; i < cache->surface.mat_len; ++i) { - GPU_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]); - } - } - MEM_SAFE_FREE(cache->surface.shaded_triangles); + GPU_BATCH_DISCARD_ARRAY_SAFE(cache->surface.shaded_triangles, cache->surface.mat_len); } if (cache->surface.shaded_triangles == NULL) { diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index bb67a90d619..cf69af11aa6 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -196,4 +196,14 @@ void gpu_batch_exit(void); } \ } while (0) +#define GPU_BATCH_DISCARD_ARRAY_SAFE(_batch_array, _len) do { \ + if (_batch_array != NULL) { \ + BLI_assert(_len > 0); \ + for (int _i = 0; _i < _len; _i++) { \ + GPU_BATCH_DISCARD_SAFE(_batch_array[_i]); \ + } \ + MEM_freeN(_batch_array); \ + } \ +} while (0) + #endif /* __GPU_BATCH_H__ */ |