[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30093] branches/soc-2010-nicolasbishop/ source/blender: Some preparation for accelerating other paint modes than sculpt

Nicholas Bishop nicholasbishop at gmail.com
Wed Jul 7 21:11:55 CEST 2010


Revision: 30093
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30093
Author:   nicholasbishop
Date:     2010-07-07 21:11:55 +0200 (Wed, 07 Jul 2010)

Log Message:
-----------
Some preparation for accelerating other paint modes than sculpt

* Replaced Object.sculpt with Object.paint. This new PaintSession type for now just contains the PBVH so it can be built more or less the same for different paint modes. It also contains the old SculptSession data.
* Removed a couple of unused fields from SculptSession.
* Changed a lot of sculpt functions to pass around the Object rather than SculptSession; made sense anyway because we added an Object field to SculptSession to work around that problem.
* There should be no visible changes from this commit.

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/object.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt_intern.h
    branches/soc-2010-nicolasbishop/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_object_types.h
    branches/soc-2010-nicolasbishop/source/blender/modifiers/intern/MOD_multires.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-07 19:11:55 UTC (rev 30093)
@@ -60,32 +60,18 @@
 
 void paint_refresh_mask_display(struct Object *ob);
 
-/* Session data (mode-specific) */
-
 typedef struct SculptSession {
-	struct ProjVert *projverts;
-
 	/* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
 	struct MultiresModifierData *multires; /* Special handling for multires meshes */
 	struct MVert *mvert;
 	struct MFace *mface;
 	int totvert, totface;
 	float *face_normals;
-	struct Object *ob;
 	struct KeyBlock *kb;
 	
 	/* Mesh connectivity */
 	struct ListBase *fmap;
 
-	/* PBVH acceleration structure */
-	struct PBVH *pbvh;
-
-	/* Used temporarily per-stroke */
-	float *vertexcosnos;
-
-	/* Partial redraw */
-	int partial_redraw;
-
 	/* Area hiding */
 	ListBase hidden_areas;
 	
@@ -98,11 +84,21 @@
 	struct SculptStroke *stroke;
 	struct StrokeCache *cache;
 
-	struct GPUDrawObject *drawobject;
-
 	int modifiers_active;
 } SculptSession;
 
-void free_sculptsession(struct Object *ob);
+typedef struct PaintSession {
+	/* mode-specific data (just sculpt for now */
+	SculptSession *sculpt;
 
+	/* PBVH acceleration structure */
+	struct PBVH *pbvh;
+
+	/* Partial redraw */
+	int partial_redraw;
+} PaintSession;
+
+void create_paintsession(struct Object *ob);
+void free_paintsession(struct Object *ob);
+
 #endif

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/DerivedMesh.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -2182,13 +2182,13 @@
 		ob->derivedDeform->release(ob->derivedDeform);
 		ob->derivedDeform= NULL;
 	}
-	/* we free pbvh on changes, except during sculpt since it can't deal with
+	/* we free pbvh on changes, except during paint since it can't deal with
 	   changing PVBH node organization, we hope topology does not change in
 	   the meantime .. weak */
-	if(ob->sculpt && ob->sculpt->pbvh) {
-		if(!ob->sculpt->cache) {
-			BLI_pbvh_free(ob->sculpt->pbvh);
-			ob->sculpt->pbvh= NULL;
+	if(ob->paint && ob->paint->pbvh) {
+		if(!ob->paint->sculpt->cache) {
+			BLI_pbvh_free(ob->paint->pbvh);
+			ob->paint->pbvh= NULL;
 		}
 	}
 }

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -191,13 +191,14 @@
 	CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
 	Mesh *me= (ob)? ob->data: NULL;
 
-	if(ob->sculpt->modifiers_active) return 0;
+	if(ob->paint->sculpt && ob->paint->sculpt->modifiers_active) return 0;
 
-	return (cddm->mvert == me->mvert) || ob->sculpt->kb;
+	return (cddm->mvert == me->mvert) || ob->paint->sculpt->kb;
 }
 
 static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
 {
+	SculptSession *ss;
 	CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
 	Mesh *me= (ob)? ob->data: NULL;
 
@@ -206,10 +207,12 @@
 		return NULL;
 	}
 
-	if(!ob->sculpt)
+	if(!ob->paint)
 		return NULL;
-	if(ob->sculpt->pbvh) {
-		cddm->pbvh= ob->sculpt->pbvh;
+	ss = ob->paint->sculpt;
+
+	if(ob->paint->pbvh) {
+		cddm->pbvh= ob->paint->pbvh;
 		cddm->pbvh_draw = can_pbvh_draw(ob, dm);
 	}
 
@@ -221,7 +224,7 @@
 		cddm->pbvh_draw = can_pbvh_draw(ob, dm);
 		BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert,
 				    &me->vdata, me->totface, me->totvert,
-				    &ob->sculpt->hidden_areas);
+				    ss ? &ss->hidden_areas : NULL);
 	}
 
 	return cddm->pbvh;

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -136,9 +136,9 @@
 			ob->derivedFinal->release(ob->derivedFinal);
 			ob->derivedFinal = NULL;
 		}
-		if(ob->sculpt && ob->sculpt->pbvh) {
-			BLI_pbvh_free(ob->sculpt->pbvh);
-			ob->sculpt->pbvh= NULL;
+		if(ob->paint && ob->paint->pbvh) {
+			BLI_pbvh_free(ob->paint->pbvh);
+			ob->paint->pbvh= NULL;
 		}
 	}
 }

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/object.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/object.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -228,32 +228,6 @@
 	freedisplist(&ob->disp);
 }
 
-void free_sculptsession(Object *ob)
-{
-	if(ob && ob->sculpt) {
-		SculptSession *ss = ob->sculpt;
-		DerivedMesh *dm= ob->derivedFinal;
-
-		if(ss->pbvh)
-			BLI_pbvh_free(ss->pbvh);
-
-		BLI_freelistN(&ss->hidden_areas);
-
-		if(dm && dm->getPBVH)
-			dm->getPBVH(NULL, dm); /* signal to clear */
-
-		if(ss->texcache)
-			MEM_freeN(ss->texcache);
-
-		if(ss->layer_co)
-			MEM_freeN(ss->layer_co);
-
-		MEM_freeN(ss);
-
-		ob->sculpt = NULL;
-	}
-}
-
 /* do not free object itself */
 void free_object(Object *ob)
 {
@@ -309,7 +283,7 @@
 	if(ob->bsoft) bsbFree(ob->bsoft);
 	if(ob->gpulamp.first) GPU_lamp_free(ob);
 
-	free_sculptsession(ob);
+	free_paintsession(ob);
 
 	if(ob->pc_ids.first) BLI_freelistN(&ob->pc_ids);
 }
@@ -1319,7 +1293,7 @@
 	copy_constraints(&obn->constraints, &ob->constraints, TRUE);
 
 	obn->mode = 0;
-	obn->sculpt = NULL;
+	obn->paint = NULL;
 
 	/* increase user numbers */
 	id_us_plus((ID *)obn->data);

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -32,10 +32,12 @@
 #include "DNA_scene_types.h"
 
 #include "BKE_brush.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_library.h"
 #include "BKE_paint.h"
 #include "BKE_utildefines.h"
 
+#include "BLI_listbase.h"
 #include "BLI_pbvh.h"
 
 #include <stdlib.h>
@@ -199,9 +201,55 @@
 /* Update the mask without doing a full object recalc */
 void paint_refresh_mask_display(Object *ob)
 {
-	if(ob && ob->sculpt && ob->sculpt->pbvh) {
-		BLI_pbvh_search_callback(ob->sculpt->pbvh, NULL, NULL,
+	if(ob && ob->paint && ob->paint->pbvh) {
+		BLI_pbvh_search_callback(ob->paint->pbvh, NULL, NULL,
 					 BLI_pbvh_node_set_flags,
 					 SET_INT_IN_POINTER(PBVH_UpdateColorBuffers));
 	}
 }
+
+void create_paintsession(Object *ob)
+{
+	if(ob->paint)
+		free_paintsession(ob);
+
+	ob->paint = MEM_callocN(sizeof(PaintSession), "PaintSession");
+}
+
+static void free_sculptsession(PaintSession *ps)
+{
+	if(ps && ps->sculpt) {
+		SculptSession *ss = ps->sculpt;
+
+		BLI_freelistN(&ss->hidden_areas);
+
+		if(ss->texcache)
+			MEM_freeN(ss->texcache);
+
+		if(ss->layer_co)
+			MEM_freeN(ss->layer_co);
+
+		MEM_freeN(ss);
+
+		ps->sculpt = NULL;
+	}
+}
+
+void free_paintsession(Object *ob)
+{
+	if(ob && ob->paint) {
+		PaintSession *ps = ob->paint;
+		DerivedMesh *dm= ob->derivedFinal;
+
+		free_sculptsession(ps);
+
+		if(ps->pbvh)
+			BLI_pbvh_free(ps->pbvh);
+
+		if(dm && dm->getPBVH)
+			dm->getPBVH(NULL, dm); /* signal to clear PBVH */
+
+		MEM_freeN(ps);
+		ob->paint = NULL;
+	}
+}

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-07 18:47:49 UTC (rev 30092)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-07 19:11:55 UTC (rev 30093)
@@ -2292,6 +2292,7 @@
 
 static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
 {
+	SculptSession *ss;
 	CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm;
 	int gridSize, numGrids, grid_pbvh;
 	GridKey *gridkey;
@@ -2301,24 +2302,25 @@
 		return NULL;
 	}
 
-	if(!ob->sculpt)
+	if(!ob->paint)
 		return NULL;
+	ss = ob->paint->sculpt;
 
 	grid_pbvh = ccgDM_use_grid_pbvh(ccgdm);
 
-	if(ob->sculpt->pbvh) {
+	if(ob->paint->pbvh) {
 		if(grid_pbvh) {
 			/* pbvh's grids, gridadj and gridfaces points to data inside ccgdm
 			   but this can be freed on ccgdm release, this updates the pointers
 			   when the ccgdm gets remade, the assumption is that the topology
 			   does not change. */
 			ccgdm_create_grids(dm);
-			BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData,
+			BLI_pbvh_grids_update(ob->paint->pbvh, ccgdm->gridData,
 					      ccgdm->gridAdjacency, (void**)ccgdm->gridFaces,
 					      ccgDM_getGridKey(&ccgdm->dm));
 		}
 
-		ccgdm->pbvh = ob->sculpt->pbvh;
+		ccgdm->pbvh = ob->paint->pbvh;
 		ccgdm->pbvh_draw = grid_pbvh;
 	}
 
@@ -2335,19 +2337,20 @@
 		numGrids = ccgDM_getNumGrids(dm);
 		gridkey = ccgDM_getGridKey(dm);
 
-		ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
+		ob->paint->pbvh= ccgdm->pbvh = BLI_pbvh_new();
 		BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency,
 				     numGrids, gridSize, gridkey, (void**)ccgdm->gridFaces,
-				     &get_mesh(ob)->vdata, &ob->sculpt->hidden_areas);
+				     &get_mesh(ob)->vdata,
+				     ss ? &ss->hidden_areas : NULL);
 		ccgdm->pbvh_draw = 1;
 	}
 	else if(ob->type == OB_MESH) {
 		Mesh *me= ob->data;
 
-		ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
+		ob->paint->pbvh= ccgdm->pbvh = BLI_pbvh_new();
 		BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert,
 				    &me->vdata, me->totface, me->totvert,
-				    &ob->sculpt->hidden_areas);
+				    ss ? &ss->hidden_areas : NULL);
 		ccgdm->pbvh_draw = 0;
 	}
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list