Revision: 43572
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43572
Author:   nicholasbishop
Date:     2012-01-20 19:27:04 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Skip subsurf normal allocation/calculation when not needed.

CCGSubsurf has already a function to disable calculation of normals,
but seems it wasn't used. This patch changes subsurf UV and
subsurf_calculate_limit_positions() to not calculate normals, and also
not allocate space for them.

Should be no functional changes, just a small speedup/less memory use
during subdivision for these cases.

Code review link:
http://codereview.appspot.com/5558058/

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c

Modified: trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c        
2012-01-20 19:05:13 UTC (rev 43571)
+++ trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c        
2012-01-20 19:27:04 UTC (rev 43572)
@@ -95,6 +95,7 @@
 typedef enum {
        CCG_USE_AGING = 1,
        CCG_USE_ARENA = 2,
+       CCG_CALC_NORMALS = 4,
 } CCGFlags;
 
 static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags 
flags) {
@@ -125,7 +126,7 @@
        } else {
                ifc.vertUserSize = ifc.edgeUserSize = ifc.faceUserSize = 8;
        }
-       ifc.vertDataSize = sizeof(DMGridData);
+       ifc.vertDataSize = sizeof(float) * (flags & CCG_CALC_NORMALS ? 6 : 3);
 
        if (useArena) {
                CCGAllocatorIFC allocatorIFC;
@@ -145,7 +146,10 @@
                ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8);
        }
 
-       ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no));
+       if (flags & CCG_CALC_NORMALS)
+               ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, 
no));
+       else
+               ccgSubSurf_setCalcVertexNormals(ccgSS, 0, 0);
 
        return ccgSS;
 }
@@ -359,14 +363,14 @@
                int numVerts = ccgSubSurf_getFaceNumVerts(f);
 
                for (S=0; S<numVerts; S++) {
-                       DMGridData *faceGridData= 
ccgSubSurf_getFaceGridDataArray(uvss, f, S);
+                       float (*faceGridData)[3]= 
ccgSubSurf_getFaceGridDataArray(uvss, f, S);
 
                        for(y = 0; y < gridFaces; y++) {
                                for(x = 0; x < gridFaces; x++) {
-                                       copy_v2_v2(tf->uv[0], faceGridData[(y + 
0)*gridSize + x + 0].co);
-                                       copy_v2_v2(tf->uv[1], faceGridData[(y + 
1)*gridSize + x + 0].co);
-                                       copy_v2_v2(tf->uv[2], faceGridData[(y + 
1)*gridSize + x + 1].co);
-                                       copy_v2_v2(tf->uv[3], faceGridData[(y + 
0)*gridSize + x + 1].co);
+                                       copy_v2_v2(tf->uv[0], faceGridData[(y + 
0)*gridSize + x + 0]);
+                                       copy_v2_v2(tf->uv[1], faceGridData[(y + 
1)*gridSize + x + 0]);
+                                       copy_v2_v2(tf->uv[2], faceGridData[(y + 
1)*gridSize + x + 1]);
+                                       copy_v2_v2(tf->uv[3], faceGridData[(y + 
0)*gridSize + x + 1]);
 
                                        tf++;
                                }
@@ -2787,7 +2791,7 @@
        if(forEditMode) {
                int levels= (smd->modifier.scene)? 
get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
 
-               smd->emCache = _getSubSurf(smd->emCache, levels, useAging);
+               smd->emCache = _getSubSurf(smd->emCache, levels, 
useAging|CCG_CALC_NORMALS);
                ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple);
 
                result = getCCGDerivedMesh(smd->emCache,
@@ -2801,7 +2805,7 @@
                if(levels == 0)
                        return dm;
                
-               ss = _getSubSurf(NULL, levels, CCG_USE_ARENA);
+               ss = _getSubSurf(NULL, levels, CCG_USE_ARENA|CCG_CALC_NORMALS);
 
                ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
 
@@ -2831,7 +2835,7 @@
                }
 
                if(useIncremental && isFinalCalc) {
-                       smd->mCache = ss = _getSubSurf(smd->mCache, levels, 
useAging);
+                       smd->mCache = ss = _getSubSurf(smd->mCache, levels, 
useAging|CCG_CALC_NORMALS);
 
                        ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
 
@@ -2844,7 +2848,7 @@
                                smd->mCache = NULL;
                        }
 
-                       ss = _getSubSurf(NULL, levels, CCG_USE_ARENA);
+                       ss = _getSubSurf(NULL, levels, 
CCG_USE_ARENA|CCG_CALC_NORMALS);
                        ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
 
                        result = getCCGDerivedMesh(ss, drawInteriorEdges, 
useSubsurfUv, dm);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to