Skip to content

Commit f1406f2

Browse files
author
Thayer J Andrews
committed
CCEffectRenderer - Don't use the node's default shader for render target copy operations
When direct rendering is disabled or when stacking and not stitching, don't use the affected node's default shader (probably color*texture) to do compositing operations. Instead we just want texture to be unmultiplied by node color. Create a texture only shader to do these texture-only compositing passes.
1 parent ae2ca0f commit f1406f2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cocos2d/CCEffectRenderer.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,24 @@ @interface CCEffectRenderer ()
123123
@property (nonatomic, assign) GLKVector4 oldViewport;
124124
@property (nonatomic, assign) GLint oldFBO;
125125

126+
+(CCShader *)sharedCopyShader;
127+
126128
@end
127129

128130

129131
@implementation CCEffectRenderer
130132

133+
+ (CCShader *)sharedCopyShader
134+
{
135+
static dispatch_once_t once;
136+
static CCShader *copyShader = nil;
137+
dispatch_once(&once, ^{
138+
copyShader = [[CCShader alloc] initWithFragmentShaderSource:@"void main(){gl_FragColor = texture2D(cc_MainTexture, cc_FragTexCoord1);}"];
139+
copyShader.debugName = @"CCEffectRendererTextureCopyShader";
140+
});
141+
return copyShader;
142+
}
143+
131144
-(id)init
132145
{
133146
if((self = [super init]))
@@ -214,6 +227,7 @@ -(void)drawSprite:(CCSprite *)sprite withEffect:(CCEffect *)effect uniforms:(NSM
214227
[renderer pushGroup];
215228

216229
CCTexture *backup = sprite.texture;
230+
sprite.shader = [CCEffectRenderer sharedCopyShader];
217231
sprite.texture = previousPassRT.texture;
218232
[sprite enqueueTriangles:renderer transform:transform];
219233
sprite.texture = backup;

0 commit comments

Comments
 (0)