Cleanup: GPU_BATCH_DISCARD_ARRAY_SAFE (deduplicate existing code)

This commit is contained in:
Dalai Felinto 2018-08-30 17:47:36 -03:00
parent 7527f2317a
commit f436e0acab
2 changed files with 13 additions and 13 deletions

View File

@ -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) {

View File

@ -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__ */