@@ -219,31 +219,39 @@ -(CCEffect *)stitchEffects:(NSArray*)effects startIndex:(int)startIndex
219
219
int effectIndex = startIndex;
220
220
for (CCEffect* effect in effects)
221
221
{
222
+ // Construct the prefix to use for name mangling.
222
223
NSString *effectPrefix = [NSString stringWithFormat: @" %@ _%d _" , effect.debugName, effectIndex];
223
224
225
+ // Mangle the names of the current effect's varyings and record the results.
224
226
NSDictionary *varyingReplacements = [CCEffectStack varyingsByApplyingPrefix: effectPrefix toVaryings: effect.varyingVars];
225
227
[allVaryings addObjectsFromArray: varyingReplacements.allValues];
226
-
228
+
229
+ // Mangle the names of the current effect's fragment uniforms and record the results.
227
230
NSArray *fragmentUniforms = [CCEffectStack uniformsByRemovingUniformsFrom: effect.fragmentUniforms withNamesListedInSet: [CCEffect defaultEffectFragmentUniformNames ]];
228
231
NSDictionary *fragUniformReplacements = [CCEffectStack uniformsByApplyingPrefix: effectPrefix toUniforms: fragmentUniforms];
229
232
[allFragUniforms addObjectsFromArray: fragUniformReplacements.allValues];
230
-
233
+
234
+ // Mangle the names of the current effect's fragment functions.
231
235
for (CCEffectFunction *function in effect.fragmentFunctions )
232
236
{
233
237
CCEffectFunction *prefixedFunction = [CCEffectStack effectFunctionByApplyingPrefix: effectPrefix uniformReplacements: fragUniformReplacements varyingReplacements: varyingReplacements toEffectFunction: function];
234
238
[allFragFunctions addObject: prefixedFunction];
235
239
}
236
-
240
+
241
+ // Mangle the names of the current effect's vertex uniforms and record the results.
237
242
NSArray *vertexUniforms = [CCEffectStack uniformsByRemovingUniformsFrom: effect.vertexUniforms withNamesListedInSet: [CCEffect defaultEffectVertexUniformNames ]];
238
243
NSDictionary *vtxUniformReplacements = [CCEffectStack uniformsByApplyingPrefix: effectPrefix toUniforms: vertexUniforms];
239
244
[allVertexUniforms addObjectsFromArray: vtxUniformReplacements.allValues];
240
245
246
+ // Mangle the names of the current effect's vertex functions.
241
247
for (CCEffectFunction* function in effect.vertexFunctions )
242
248
{
243
249
CCEffectFunction *prefixedFunction = [CCEffectStack effectFunctionByApplyingPrefix: effectPrefix uniformReplacements: vtxUniformReplacements varyingReplacements: varyingReplacements toEffectFunction: function];
244
250
[allVertexFunctions addObject: prefixedFunction];
245
251
}
246
252
253
+ // Update the original effect's translation table so it reflects the new mangled
254
+ // uniform names.
247
255
effect.uniformTranslationTable = [[NSMutableDictionary alloc ] init ];
248
256
for (NSString *key in vtxUniformReplacements)
249
257
{
@@ -260,6 +268,7 @@ -(CCEffect *)stitchEffects:(NSArray*)effects startIndex:(int)startIndex
260
268
effectIndex++;
261
269
}
262
270
271
+ // Build a new effect that is the accumulation of all the mangled fragment and vertex functions.
263
272
BOOL firstInStack = (startIndex == 0 ) ? YES : NO ;
264
273
CCEffect* stitchedEffect = [[CCEffect alloc ] initWithFragmentFunction: allFragFunctions vertexFunctions: allVertexFunctions fragmentUniforms: allFragUniforms vertexUniforms: allVertexUniforms varyings: allVaryings firstInStack: firstInStack];
265
274
stitchedEffect.debugName = @" CCEffectStack_Stitched" ;
0 commit comments