Skip to content

Commit 5264fbe

Browse files
committed
Fixes for CCRenderState copying and caching.
1 parent 270f12f commit 5264fbe

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

cocos2d/CCRenderer.m

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ +(CCBlendMode *)multiplyMode
231231

232232

233233
//MARK: Render States.
234-
@interface CCRenderState() {
235-
@public
236-
CCBlendMode *_blendMode;
237-
CCShader *_shader;
238-
NSDictionary *_shaderUniforms;
239-
}
240-
241-
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms;
242-
243-
@end
244-
245-
246234
@interface CCRenderStateCache : CCCache
247235
@end
248236

@@ -256,7 +244,7 @@ -(id)createSharedDataForKey:(CCRenderState *)renderState
256244

257245
-(id)createPublicObjectForSharedData:(CCRenderState *)renderState
258246
{
259-
return [[CCRenderState alloc] initWithBlendMode:renderState->_blendMode shader:renderState->_shader shaderUniforms:renderState->_shaderUniforms];
247+
return [renderState copy];
260248
}
261249

262250
// Nothing special
@@ -275,6 +263,11 @@ -(void)flush
275263

276264
@implementation CCRenderState {
277265
CCTexture *_mainTexture;
266+
267+
@public
268+
CCBlendMode *_blendMode;
269+
CCShader *_shader;
270+
NSDictionary *_shaderUniforms;
278271
}
279272

280273
CCRenderStateCache *CCRENDERSTATE_CACHE = nil;
@@ -312,10 +305,11 @@ +(instancetype)renderStateWithBlendMode:(CCBlendMode *)blendMode shader:(CCShade
312305

313306
-(id)copyWithZone:(NSZone *)zone
314307
{
315-
if([_shaderUniforms isKindOfClass:[NSMutableDictionary class]]){
316-
return [[CCRenderState allocWithZone:zone] initWithBlendMode:_blendMode shader:_shader shaderUniforms:[_shaderUniforms copy]];
317-
} else {
308+
NSDictionary *shaderUniforms = [_shaderUniforms copy];
309+
if(shaderUniforms == _shaderUniforms){
318310
return self;
311+
} else {
312+
return [[CCRenderState allocWithZone:zone] initWithBlendMode:_blendMode shader:_shader shaderUniforms:shaderUniforms];
319313
}
320314
}
321315

0 commit comments

Comments
 (0)