[Bf-blender-cvs] [2cb45c9] blender2.8: a place to cache draw data in DerivedMesh

Mike Erwin noreply at git.blender.org
Mon Oct 24 05:39:31 CEST 2016


Commit: 2cb45c993886c16b5b8e0e3187e1db5b92032d4f
Author: Mike Erwin
Date:   Sun Oct 23 23:22:16 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB2cb45c993886c16b5b8e0e3187e1db5b92032d4f

a place to cache draw data in DerivedMesh

DerivedMesh owns this cache and cleans up as part of DM cleanup. DM has no idea what is stored in this cache. Loose coupling FTW

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

M	source/blender/blenkernel/BKE_DerivedMesh.h
M	source/blender/blenkernel/intern/DerivedMesh.c

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 789bc8d..059f730 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -145,6 +145,10 @@ typedef DMDrawOption (*DMSetDrawOptions)(void *userData, int index);
 typedef DMDrawOption (*DMSetDrawOptionsMappedTex)(void *userData, int origindex, int mat_nr);
 typedef DMDrawOption (*DMSetDrawOptionsTex)(struct MTexPoly *mtexpoly, const bool has_vcol, int matnr);
 
+/* Cleanup callback type */
+typedef void (*DMCleanupBatchCache)(void *batchCache);
+void DM_set_batch_cleanup_callback(DMCleanupBatchCache);
+
 typedef enum DMDrawFlag {
 	DM_DRAW_USE_COLORS          = (1 << 0),
 	DM_DRAW_ALWAYS_SMOOTH       = (1 << 1),
@@ -183,6 +187,7 @@ struct DerivedMesh {
 	int deformedOnly; /* set by modifier stack if only deformed from original */
 	BVHCache *bvhCache;
 	struct GPUDrawObject *drawObject;
+	void *batchCache;
 	DerivedMeshType type;
 	float auto_bump_scale;
 	DMDirtyFlag dirty;
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index ae18f52..8716ebe 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -258,6 +258,12 @@ static CustomData *dm_getPolyCData(DerivedMesh *dm)
 	return &dm->polyData;
 }
 
+static DMCleanupBatchCache cleanupBatchCache = NULL;
+void DM_set_batch_cleanup_callback(DMCleanupBatchCache func)
+{
+	cleanupBatchCache = func;
+}
+
 /**
  * Utility function to initialize a DerivedMesh's function pointers to
  * the default implementation (for those functions which have a default)
@@ -315,7 +321,9 @@ void DM_init(
 	dm->numPolyData = numPolys;
 
 	DM_init_funcs(dm);
-	
+
+	dm->batchCache = NULL; /* necessary? dm->drawObject is not set to NULL yet it works fine */
+
 	dm->needsFree = 1;
 	dm->auto_bump_scale = -1.0f;
 	dm->dirty = 0;
@@ -375,6 +383,10 @@ int DM_release(DerivedMesh *dm)
 	if (dm->needsFree) {
 		bvhcache_free(&dm->bvhCache);
 		GPU_drawobject_free(dm);
+		if (dm->batchCache && cleanupBatchCache) {
+			cleanupBatchCache(dm->batchCache);
+			dm->batchCache = NULL;
+		}
 		CustomData_free(&dm->vertData, dm->numVertData);
 		CustomData_free(&dm->edgeData, dm->numEdgeData);
 		CustomData_free(&dm->faceData, dm->numTessFaceData);




More information about the Bf-blender-cvs mailing list