Skip to content

Commit 619e661

Browse files
committed
Enable color tinting for CCDrawNode.
1 parent 49586f9 commit 619e661

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cocos2d/CCDrawNode.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
// Faster for draw nodes that draw many vertexes, but can't be batched.
4040
static NSString *CCDrawNodeHWTransformVertexShaderSource =
4141
@"uniform highp mat4 u_MVP;\n"
42+
@"uniform highp vec4 u_TintColor;\n"
4243
@"void main(){\n"
4344
@" gl_Position = u_MVP*cc_Position;\n"
44-
@" cc_FragColor = clamp(cc_Color, 0.0, 1.0);\n"
45+
@" cc_FragColor = clamp(u_TintColor*cc_Color, 0.0, 1.0);\n"
4546
@" cc_FragTexCoord1 = cc_TexCoord1;\n"
4647
@"}\n";
4748

@@ -161,6 +162,7 @@ -(void)enableBatchMode
161162
_useBatchMode = YES;
162163

163164
if(_shader == CCDRAWNODE_HWTRANSFORM_SHADER){
165+
CCLOGINFO(@"Changing the blend mode or shader of a CCBatchNode disables GPU accelerated transform and tinting.");
164166
_shader = CCDRAWNODE_BATCH_SHADER;
165167
}
166168

@@ -188,6 +190,9 @@ -(void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
188190
// If batch mode is disabled (default), update the MVP matrix in the uniforms.
189191
if(!_useBatchMode){
190192
self.shaderUniforms[@"u_MVP"] = [NSValue valueWithGLKMatrix4:*transform];
193+
194+
GLKVector4 color = Premultiply(GLKVector4Make(_displayColor.r, _displayColor.g, _displayColor.b, _displayColor.a));
195+
self.shaderUniforms[@"u_TintColor"] = [NSValue valueWithGLKVector4:color];
191196
}
192197

193198
CCRenderBuffer buffer = [renderer enqueueTriangles:_indexCount/3 andVertexes:_vertexCount withState:self.renderState globalSortOrder:0];

0 commit comments

Comments
 (0)