[Bf-blender-cvs] [001dad2] opensubdiv-modifier: OpenSubdiv: Use batched face drawing in GLSL mode

Sergey Sharybin noreply at git.blender.org
Fri Jul 25 18:17:00 CEST 2014


Commit: 001dad257de9a59e53fa6a387a74f2bd11742450
Author: Sergey Sharybin
Date:   Fri Jul 25 22:16:17 2014 +0600
Branches: opensubdiv-modifier
https://developer.blender.org/rB001dad257de9a59e53fa6a387a74f2bd11742450

OpenSubdiv: Use batched face drawing in GLSL mode

Gives quite reaosnable speedup here on my gt620.

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

M	source/blender/blenkernel/intern/subsurf_ccg.c

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

diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 28fd1a7..c494aad 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2047,10 +2047,12 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
 	if (ccgdm->useGpuBackend) {
 		int i, matnr = -1, shademodel = -1;
 		CCGFaceIterator *fi;
+		int start_partition = 0, num_partitions = 0;
 		if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, false) == false)) {
 			return;
 		}
-		do_draw = 0;
+
+		do_draw = false;
 		for (fi = ccgSubSurf_getFaceIterator(ss), i = 0;
 		     !ccgFaceIterator_isStopped(fi);
 		     ccgFaceIterator_next(fi), ++i)
@@ -2071,26 +2073,53 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
 				new_matnr = 1;
 			}
 
-			if (new_shademodel != shademodel) {
-				glShadeModel(new_shademodel);
-				shademodel = new_shademodel;
-			}
+			if (new_shademodel != shademodel || new_matnr != matnr) {
+				if (num_partitions) {
+					ccgSubSurf_drawGLMesh(ss, true,
+					                      start_partition, num_partitions);
+				}
+
+				start_partition = i;
+				num_partitions = 0;
+
+				/* Update material settings for the next partitions batch. */
+				if (new_shademodel != shademodel) {
+					glShadeModel(new_shademodel);
+				}
+
+				if (new_matnr != matnr) {
+					do_draw = setMaterial(new_matnr, &gattribs);
+				}
 
-			if (new_matnr != matnr) {
-				do_draw = setMaterial(matnr = new_matnr, &gattribs);
+				/* Cache settings. */
+				shademodel = new_shademodel;
 				matnr = new_matnr;
 			}
 
+			/* TODO(sergey): This isn't actually tested.. */
 			if (!do_draw || (setDrawOptions && (origIndex != ORIGINDEX_NONE) &&
 			                (setDrawOptions(userData, origIndex) == DM_DRAW_OPTION_SKIP)))
 			{
+				if (num_partitions) {
+					ccgSubSurf_drawGLMesh(ss, true,
+					                      start_partition, num_partitions);
+				}
+
+				start_partition = i;
+				num_partitions = 0;
+
 				continue;
 			}
 
-			ccgSubSurf_drawGLMesh(ss, true, i, 1);
+			num_partitions++;
 		}
 		ccgFaceIterator_free(fi);
 
+		/* Draw residual tail of the partitions. */
+		if (num_partitions) {
+			ccgSubSurf_drawGLMesh(ss, true, start_partition, num_partitions);
+		}
+
 		/* We're done with drawing if drawing happens using OpenSubdiv. */
 		return;
 	}




More information about the Bf-blender-cvs mailing list