Skip to content

Commit 800bb52

Browse files
author
Thayer J Andrews
committed
CCEffectStack - Add some comments to the stitching code - No functional change
1 parent 23ca2f8 commit 800bb52

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cocos2d/CCEffectStack.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,31 +219,39 @@ -(CCEffect *)stitchEffects:(NSArray*)effects startIndex:(int)startIndex
219219
int effectIndex = startIndex;
220220
for(CCEffect* effect in effects)
221221
{
222+
// Construct the prefix to use for name mangling.
222223
NSString *effectPrefix = [NSString stringWithFormat:@"%@_%d_", effect.debugName, effectIndex];
223224

225+
// Mangle the names of the current effect's varyings and record the results.
224226
NSDictionary *varyingReplacements = [CCEffectStack varyingsByApplyingPrefix:effectPrefix toVaryings:effect.varyingVars];
225227
[allVaryings addObjectsFromArray:varyingReplacements.allValues];
226-
228+
229+
// Mangle the names of the current effect's fragment uniforms and record the results.
227230
NSArray *fragmentUniforms = [CCEffectStack uniformsByRemovingUniformsFrom:effect.fragmentUniforms withNamesListedInSet:[CCEffect defaultEffectFragmentUniformNames]];
228231
NSDictionary *fragUniformReplacements = [CCEffectStack uniformsByApplyingPrefix:effectPrefix toUniforms:fragmentUniforms];
229232
[allFragUniforms addObjectsFromArray:fragUniformReplacements.allValues];
230-
233+
234+
// Mangle the names of the current effect's fragment functions.
231235
for(CCEffectFunction *function in effect.fragmentFunctions)
232236
{
233237
CCEffectFunction *prefixedFunction = [CCEffectStack effectFunctionByApplyingPrefix:effectPrefix uniformReplacements:fragUniformReplacements varyingReplacements:varyingReplacements toEffectFunction:function];
234238
[allFragFunctions addObject:prefixedFunction];
235239
}
236-
240+
241+
// Mangle the names of the current effect's vertex uniforms and record the results.
237242
NSArray *vertexUniforms = [CCEffectStack uniformsByRemovingUniformsFrom:effect.vertexUniforms withNamesListedInSet:[CCEffect defaultEffectVertexUniformNames]];
238243
NSDictionary *vtxUniformReplacements = [CCEffectStack uniformsByApplyingPrefix:effectPrefix toUniforms:vertexUniforms];
239244
[allVertexUniforms addObjectsFromArray:vtxUniformReplacements.allValues];
240245

246+
// Mangle the names of the current effect's vertex functions.
241247
for(CCEffectFunction* function in effect.vertexFunctions)
242248
{
243249
CCEffectFunction *prefixedFunction = [CCEffectStack effectFunctionByApplyingPrefix:effectPrefix uniformReplacements:vtxUniformReplacements varyingReplacements:varyingReplacements toEffectFunction:function];
244250
[allVertexFunctions addObject:prefixedFunction];
245251
}
246252

253+
// Update the original effect's translation table so it reflects the new mangled
254+
// uniform names.
247255
effect.uniformTranslationTable = [[NSMutableDictionary alloc] init];
248256
for (NSString *key in vtxUniformReplacements)
249257
{
@@ -260,6 +268,7 @@ -(CCEffect *)stitchEffects:(NSArray*)effects startIndex:(int)startIndex
260268
effectIndex++;
261269
}
262270

271+
// Build a new effect that is the accumulation of all the mangled fragment and vertex functions.
263272
BOOL firstInStack = (startIndex == 0) ? YES : NO;
264273
CCEffect* stitchedEffect = [[CCEffect alloc] initWithFragmentFunction:allFragFunctions vertexFunctions:allVertexFunctions fragmentUniforms:allFragUniforms vertexUniforms:allVertexUniforms varyings:allVaryings firstInStack:firstInStack];
265274
stitchedEffect.debugName = @"CCEffectStack_Stitched";

0 commit comments

Comments
 (0)