Skip to content

Commit 9ac32af

Browse files
author
SeanLin
committed
Merge pull request cocos2d#964 from dingpinglv/Iss2269_FixBugForLabelTTF
fixed cocos2d#2269 Switch shader of cc.Sprite when call setTexture(null)
2 parents 390fb05 + 455055f commit 9ac32af

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cocos2d/sprite_nodes/CCSprite.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,6 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
21142114
this._quad.tl.colors = new cc.Color4B(255, 255, 255, 255);
21152115
this._quad.tr.colors = new cc.Color4B(255, 255, 255, 255);
21162116
this._quadDirty = true;
2117-
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_TEXTURECOLOR));
21182117

21192118
// updated in "useSelfRender"
21202119
// Atlas: TexCoords
@@ -2517,6 +2516,11 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
25172516
// If batchnode, then texture id should be the same
25182517
cc.Assert(!this._batchNode, "cc.Sprite: Batched sprites should use the same texture as the batchnode");
25192518

2519+
if(texture)
2520+
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_TEXTURECOLOR));
2521+
else
2522+
this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_COLOR));
2523+
25202524
if (!this._batchNode && this._texture != texture) {
25212525
this._texture = texture;
25222526
this._updateBlendFunc();
@@ -2647,9 +2651,8 @@ cc.SpriteWebGL = cc.Node.extend(/** @lends cc.SpriteWebGL# */{
26472651
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
26482652
}
26492653
} else {
2650-
var shaderProgram = cc.ShaderCache.getInstance().programForKey(cc.SHADER_POSITION_COLOR);
2651-
shaderProgram.use();
2652-
shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
2654+
this._shaderProgram.use();
2655+
this._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
26532656

26542657
cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst);
26552658
cc.glBindTexture2D(null);

0 commit comments

Comments
 (0)