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/
This commit is contained in:
Nicholas Bishop
2012-01-20 19:27:04 +00:00
parent acfeb47aa3
commit 073ea28d58

View File

@@ -95,6 +95,7 @@ static void arena_release(CCGAllocatorHDL a) {
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 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags fl
} 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 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags fl
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 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
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 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
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 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
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 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
}
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 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
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);