[Bf-blender-cvs] [f436e0acab6] blender2.8: Cleanup: GPU_BATCH_DISCARD_ARRAY_SAFE (deduplicate existing code)

Dalai Felinto noreply at git.blender.org
Fri Aug 31 00:14:26 CEST 2018


Commit: f436e0acab6cb510a74fe9e04b7dfb1c2ac142b5
Author: Dalai Felinto
Date:   Thu Aug 30 17:47:36 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBf436e0acab6cb510a74fe9e04b7dfb1c2ac142b5

Cleanup: GPU_BATCH_DISCARD_ARRAY_SAFE (deduplicate existing code)

===================================================================

M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/gpu/GPU_batch.h

===================================================================

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



More information about the Bf-blender-cvs mailing list