@@ -1736,13 +1736,32 @@ -(BOOL) doesOpacityModifyRGB{
1736
1736
1737
1737
#pragma mark - RenderState Methods
1738
1738
1739
+ // The default dictionary is either nil or only contains the main texture.
1740
+ static inline BOOL
1741
+ CheckDefaultUniforms (NSDictionary *uniforms, CCTexture *texture)
1742
+ {
1743
+ if (uniforms == nil ){
1744
+ return YES ;
1745
+ } else {
1746
+ // Check that the uniforms has only one key for the main texture.
1747
+ return (uniforms.count == 1 && uniforms[CCShaderUniformMainTexture] == texture);
1748
+ }
1749
+ }
1750
+
1739
1751
-(CCRenderState *)renderState
1740
1752
{
1741
1753
if (_renderState == nil ){
1742
- if (_shaderUniforms.count > 1 ){
1743
- _renderState = [[CCRenderState alloc ] initWithBlendMode: _blendMode shader: _shader shaderUniforms: _shaderUniforms];
1754
+ CCTexture *texture = (_texture ?: [CCTexture none ]);
1755
+
1756
+ if (CheckDefaultUniforms (_shaderUniforms, texture)){
1757
+ // Create a cached render state so we can use the fast path.
1758
+ _renderState = [CCRenderState renderStateWithBlendMode: _blendMode shader: _shader mainTexture: texture];
1759
+
1760
+ // If the uniform dictionary was set, it was the default. Throw it away.
1761
+ _shaderUniforms = nil ;
1744
1762
} else {
1745
- _renderState = [CCRenderState renderStateWithBlendMode: _blendMode shader: _shader mainTexture: (_texture ?: [CCTexture none ])];
1763
+ // Since the node has unique uniforms, it cannot be batched or use the fast path.
1764
+ _renderState = [[CCRenderState alloc ] initWithBlendMode: _blendMode shader: _shader shaderUniforms: _shaderUniforms];
1746
1765
}
1747
1766
}
1748
1767
@@ -1768,10 +1787,7 @@ -(CCBlendMode *)blendMode
1768
1787
-(NSMutableDictionary *)shaderUniforms
1769
1788
{
1770
1789
if (_shaderUniforms == nil ){
1771
- _shaderUniforms = [NSMutableDictionary dictionaryWithObjectsAndKeys:
1772
- (_texture ?: [CCTexture none ]), CCShaderUniformMainTexture,
1773
- nil
1774
- ];
1790
+ _shaderUniforms = [NSMutableDictionary dictionaryWithObject: (_texture ?: [CCTexture none ]) forKey: CCShaderUniformMainTexture];
1775
1791
1776
1792
_renderState = nil ;
1777
1793
}
0 commit comments