[Bf-blender-cvs] [99cfad6a01] blender2.8: Convert MBC_ API to Mesh (instead of derived mesh) and move it to mesh_render

Dalai Felinto noreply at git.blender.org
Wed Jan 25 10:03:50 CET 2017


Commit: 99cfad6a015715a090fa2e1d808196dd1a02b390
Author: Dalai Felinto
Date:   Wed Jan 25 09:16:29 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB99cfad6a015715a090fa2e1d808196dd1a02b390

Convert MBC_ API to Mesh (instead of derived mesh) and move it to mesh_render

This includes a few fixes in the MBC_ api.

The idea here is for this to be the only interface the render engines
will deal with for the meshes.

If we need to expose special options for sculpting engine we refactor
this accordingly. But for now we are shaping this in a per-case base.

Note:
* We still need to hook up to the depsgraph to force clear/update of
batch_cache when mesh changes

(I'm waiting for Sergey Sharybin's depsgraph update for this though)

* Also ideally we could/should use BMesh directly instead of
DerivedMesh, but this will do for now.

Note 2:
In the end I renamed the `BKE_mesh_render` functions to `static
mesh_render`. We can re-expose them as BKE_* later once we need it.

Reviewers: merwin

Subscribers: fclem

Differential Revision: https://developer.blender.org/D2476

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

M	source/blender/blenkernel/BKE_DerivedMesh.h
A	source/blender/blenkernel/BKE_mesh_render.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/mesh.c
A	source/blender/blenkernel/intern/mesh_render.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/gpu/gawain/batch.h
M	source/blender/makesdna/DNA_mesh_types.h

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 059f7309cf..784c76bffd 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -145,10 +145,6 @@ 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),
@@ -176,6 +172,8 @@ typedef enum DMDirtyFlag {
 
 	/* check this with modifier dependsOnNormals callback to see if normals need recalculation */
 	DM_DIRTY_NORMALS = 1 << 2,
+
+	DM_MESH_BATCH_CACHE = 1 << 3,
 }  DMDirtyFlag;
 
 typedef struct DerivedMesh DerivedMesh;
@@ -187,7 +185,6 @@ 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/BKE_mesh_render.h b/source/blender/blenkernel/BKE_mesh_render.h
new file mode 100644
index 0000000000..8a2b3f9d9e
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mesh_render.h
@@ -0,0 +1,42 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __BKE_MESH_RENDER_H__
+#define __BKE_MESH_RENDER_H__
+
+/** \file BKE_mesh_render.h
+ *  \ingroup bke
+ */
+
+struct Batch;
+struct Mesh;
+
+void BKE_mesh_batch_cache_free(struct Mesh *me);
+struct Batch *BKE_mesh_batch_cache_get_all_edges(struct Mesh *me);
+struct Batch *BKE_mesh_batch_cache_get_all_triangles(struct Mesh *me);
+struct Batch *BKE_mesh_batch_cache_get_all_verts(struct Mesh *me);
+struct Batch *BKE_mesh_batch_cache_get_fancy_edges(struct Mesh *me);
+struct Batch *BKE_mesh_batch_cache_get_overlay_edges(struct Mesh *me);
+
+#endif /* __BKE_MESH_RENDER_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 2ccbed58b0..f3bab55b47 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -133,6 +133,7 @@ set(SRC
 	intern/mesh_evaluate.c
 	intern/mesh_mapping.c
 	intern/mesh_remap.c
+	intern/mesh_render.c
 	intern/mesh_validate.c
 	intern/modifier.c
 	intern/modifiers_bmesh.c
@@ -257,6 +258,7 @@ set(SRC
 	BKE_mesh.h
 	BKE_mesh_mapping.h
 	BKE_mesh_remap.h
+	BKE_mesh_render.h
 	BKE_modifier.h
 	BKE_movieclip.h
 	BKE_multires.h
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index fb0087aefa..e0bbe345fc 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -260,12 +260,6 @@ 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)
@@ -324,8 +318,6 @@ void DM_init(
 
 	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;
@@ -385,10 +377,7 @@ 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);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index af02e02b01..134173580a 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -48,6 +48,7 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
 #include "BKE_mesh.h"
+#include "BKE_mesh_render.h"
 #include "BKE_displist.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
@@ -435,6 +436,8 @@ void BKE_mesh_free(Mesh *me)
 {
 	BKE_animdata_free(&me->id, false);
 
+	BKE_mesh_batch_cache_free(me);
+
 	CustomData_free(&me->vdata, me->totvert);
 	CustomData_free(&me->edata, me->totedge);
 	CustomData_free(&me->fdata, me->totface);
@@ -522,6 +525,7 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 	BKE_mesh_update_customdata_pointers(men, do_tessface);
 
 	men->edit_btmesh = NULL;
+	men->batch_cache = NULL;
 
 	men->mselect = MEM_dupallocN(men->mselect);
 	men->bb = MEM_dupallocN(men->bb);
diff --git a/source/blender/blenkernel/intern/mesh_render.c b/source/blender/blenkernel/intern/mesh_render.c
new file mode 100644
index 0000000000..f90783a3db
--- /dev/null
+++ b/source/blender/blenkernel/intern/mesh_render.c
@@ -0,0 +1,619 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/mesh_render.c
+ *  \ingroup bke
+ *
+ * \brief Mesh API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_editmesh.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_render.h"
+
+#include "GPU_batch.h"
+
+/* ---------------------------------------------------------------------- */
+/* Mesh Interface */
+
+#define MESH_RENDER_FUNCTION(func_name)     \
+	if (me->edit_btmesh) {                  \
+	    return mesh_bmesh_##func_name(me);  \
+	}                                       \
+	else {                                  \
+	    return mesh_struct_##func_name(me); \
+	}
+
+
+/* Mesh Implementation */
+
+static int mesh_struct_get_num_edges(Mesh *me)
+{
+	return me->totedge;
+}
+
+static int mesh_struct_get_num_verts(Mesh *me)
+{
+	return me->totvert;
+}
+
+static int mesh_struct_get_num_faces(Mesh *me)
+{
+	BKE_mesh_tessface_ensure(me);
+	return me->totface;
+}
+
+static int mesh_struct_get_num_polys(Mesh *me)
+{
+	return me->totpoly;
+}
+
+static MEdge *mesh_struct_get_array_edge(Mesh *me)
+{
+	return CustomData_get_layer(&me->edata, CD_MEDGE);
+}
+
+static MFace *mesh_struct_get_array_face(Mesh *me)
+{
+	BKE_mesh_tessface_ensure(me);
+	return CustomData_get_layer(&me->fdata, CD_MFACE);
+}
+
+static MLoop *mesh_struct_get_array_loop(Mesh *me)
+{
+	return me->mloop;
+}
+
+static MPoly *mesh_struct_get_array_poly(Mesh *me)
+{
+	return me->mpoly;
+}
+
+static MVert *mesh_struct_get_array_vert(Mesh *me)
+{
+	return CustomData_get_layer(&me->vdata, CD_MVERT);
+}
+
+/* BMesh Implementation */
+
+/* NOTE: we may want to get rid of Derived Mesh and
+ * access BMesh directly */
+
+static int mesh_bmesh_get_num_verts(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getNumVerts(dm);
+}
+
+static int mesh_bmesh_get_num_edges(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getNumEdges(dm);
+}
+
+static int mesh_bmesh_get_num_faces(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getNumTessFaces(dm);
+}
+
+static int mesh_bmesh_get_num_polys(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getNumPolys(dm);
+}
+
+static MEdge *mesh_bmesh_get_array_edge(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getEdgeArray(dm);
+}
+
+static MFace *mesh_bmesh_get_array_face(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getTessFaceArray(dm);
+}
+
+static MLoop *mesh_bmesh_get_array_loop(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMesh *dm = bm->derivedFinal;
+	return dm->getLoopArray(dm);
+}
+
+static MPoly *mesh_bmesh_get_array_poly(Mesh *me)
+{
+	BMEditMesh *bm = me->edit_btmesh;
+	DerivedMes

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list