[Bf-blender-cvs] [d5bc786] opensubdiv-modifier: OpenSubdiv: Do proper coarse positions update for limit evaluation

Sergey Sharybin noreply at git.blender.org
Sat Jul 11 20:02:20 CEST 2015


Commit: d5bc786f38468979ed30cf80b74ba67f663fdcfa
Author: Sergey Sharybin
Date:   Fri Jul 10 14:56:40 2015 +0200
Branches: opensubdiv-modifier
https://developer.blender.org/rBd5bc786f38468979ed30cf80b74ba67f663fdcfa

OpenSubdiv: Do proper coarse positions update for limit evaluation

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

M	intern/opensubdiv/opensubdiv_capi.h
M	intern/opensubdiv/opensubdiv_converter.h
M	intern/opensubdiv/opensubdiv_evaluator_capi.cc
M	source/blender/blenkernel/intern/CCGSubSurf.c

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

diff --git a/intern/opensubdiv/opensubdiv_capi.h b/intern/opensubdiv/opensubdiv_capi.h
index c3c5608..eb273c1 100644
--- a/intern/opensubdiv/opensubdiv_capi.h
+++ b/intern/opensubdiv/opensubdiv_capi.h
@@ -97,6 +97,11 @@ OpenSubdiv_EvaluatorDescr *openSubdiv_createEvaluatorDescr(DerivedMesh *dm,
 
 void openSubdiv_deleteEvaluatorDescr(OpenSubdiv_EvaluatorDescr *evaluator_descr);
 
+void openSubdiv_setEvaluatorCoarsePositions(OpenSubdiv_EvaluatorDescr *evaluator_descr,
+                                            float *positions,
+                                            int start_vertex,
+                                            int num_vertex);
+
 void openSubdiv_evaluateLimit(OpenSubdiv_EvaluatorDescr *evaluator_descr,
                               int osd_face_index,
                               float face_u, float face_v,
diff --git a/intern/opensubdiv/opensubdiv_converter.h b/intern/opensubdiv/opensubdiv_converter.h
index 487459c..618216e 100644
--- a/intern/opensubdiv/opensubdiv_converter.h
+++ b/intern/opensubdiv/opensubdiv_converter.h
@@ -46,6 +46,7 @@ public:
 	int get_num_edges() const;
 	int get_num_verts() const;
 
+	/* TODO(sergey): Currently unused, but might be handy in the future. */
 	void get_coarse_verts(float *coords) const;
 
 	/* Face relationships. */
diff --git a/intern/opensubdiv/opensubdiv_evaluator_capi.cc b/intern/opensubdiv/opensubdiv_evaluator_capi.cc
index a4be717..280af4a 100644
--- a/intern/opensubdiv/opensubdiv_evaluator_capi.cc
+++ b/intern/opensubdiv/opensubdiv_evaluator_capi.cc
@@ -584,12 +584,6 @@ OpenSubdiv_EvaluatorDescr *openSubdiv_createEvaluatorDescr(DerivedMesh *dm,
 	                                               num_total_verts,
 	                                               patch_table);
 
-	float *g_positions = new float[3 * num_coarse_verts];
-	conv.get_coarse_verts(g_positions);
-	eval_output->UpdateData(&g_positions[0], 0, num_coarse_verts);
-	delete [] g_positions;
-	eval_output->Refine();
-
 	OpenSubdiv::Far::PatchMap *patch_map = new PatchMap(*patch_table);
 
 	OpenSubdiv_EvaluatorDescr *evaluator_descr;
@@ -615,6 +609,19 @@ void openSubdiv_deleteEvaluatorDescr(OpenSubdiv_EvaluatorDescr *evaluator_descr)
 	OBJECT_GUARDED_DELETE(evaluator_descr, OpenSubdiv_EvaluatorDescr);
 }
 
+void openSubdiv_setEvaluatorCoarsePositions(OpenSubdiv_EvaluatorDescr *evaluator_descr,
+                                            float *positions,
+                                            int start_vert,
+                                            int num_verts)
+{
+	/* TODO(sergey): Add sanity check on indices. */
+	evaluator_descr->eval_output->UpdateData(positions, start_vert, num_verts);
+	/* TODO(sergey): Consider moving this to a separate call,
+	 * so we can updatwe coordinates in chunks.
+	 */
+	evaluator_descr->eval_output->Refine();
+}
+
 void openSubdiv_evaluateLimit(OpenSubdiv_EvaluatorDescr *evaluator_descr,
                               int osd_face_index,
                               float face_u, float face_v,
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 78bf4f8..0b84198 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -2661,6 +2661,15 @@ static bool check_topology_changed(CCGSubSurf *ss)
 	return false;
 }
 
+static bool opensubdiv_createEvaluator(CCGSubSurf *ss)
+{
+	ss->osd_compute = U.opensubdiv_compute_type;
+	ss->osd_evaluator =
+	    openSubdiv_createEvaluatorDescr(ss->dm,
+	                                    ss->subdivLevels);
+	return ss->osd_evaluator != NULL;
+}
+
 static bool opensubdiv_ensureEvaluator(CCGSubSurf *ss)
 {
 	if (ss->osd_evaluator != NULL) {
@@ -2686,9 +2695,7 @@ static bool opensubdiv_ensureEvaluator(CCGSubSurf *ss)
 	if (ss->osd_evaluator == NULL) {
 		int num_basis_verts = ss->vMap->numEntries;
 		OSD_LOG("Allocating new evaluator, %d verts\n", num_basis_verts);
-		ss->osd_evaluator =
-		        openSubdiv_createEvaluatorDescr(ss->dm,
-		                                        ss->subdivLevels);
+		opensubdiv_createEvaluator(ss);
 	} else {
 		OSD_LOG("Re-using old evaluator\n");
 	}
@@ -2702,6 +2709,11 @@ static void opensubdiv_updateCoarsePositions(CCGSubSurf *ss)
 	int num_basis_verts = ss->vMap->numEntries;
 	int i;
 
+	/* TODO(sergey): Avoid allocation on every update. We could either update
+	 * coordinates in chunks of 1K vertices (which will only use stack memory)
+	 * or do some callback magic for OSD evaluator can invoke it and fill in
+	 * buffer directly.
+	 */
 	if (ss->meshIFC.numLayers == 3) {
 		/* If all the components are to be initialized, no need to memset the
 		 * new memory block.
@@ -2729,10 +2741,10 @@ static void opensubdiv_updateCoarsePositions(CCGSubSurf *ss)
 		}
 	}
 
-	/* TODO(sergey): Need proper port. */
-	//openSubdiv_setEvaluatorCoarsePositions(ss->osd_evaluator,
-	//                                       (float *) positions,
-	//                                       num_basis_verts);
+	openSubdiv_setEvaluatorCoarsePositions(ss->osd_evaluator,
+	                                       (float*)positions,
+	                                       0,
+	                                       num_basis_verts);
 
 	MEM_freeN(positions);
 }




More information about the Bf-blender-cvs mailing list