Skip to content

Commit a442dd4

Browse files
Merge pull request #1 from pandamicro/programstate
Small improvements to GLProgramState implementation
2 parents ea7994d + d4751be commit a442dd4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

cocos2d/core/base-nodes/CCNodeWebGLRenderCmd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
// to ease the transition from using glPrograms directly, to
5858
// using glProgramStates.
5959
Object.defineProperty(proto, '_shaderProgram', {
60-
set: function () { this.setShaderProgram.apply(this, arguments); },
60+
set: function (value) { this.setShaderProgram(value); },
6161
get: function () { return this.getShaderProgram(); }
6262
});
6363
})();

cocos2d/shaders/CCGLProgramState.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ cc.GLProgramState = function (glprogram) {
153153
this._boundTextureUnits = {};
154154
this._textureUnitIndex = 1; // Start at 1, as CC_Texture0 is bound to 0
155155

156-
157156
var activeUniforms = glprogram._glContext.getProgramParameter(glprogram._programObj,
158157
glprogram._glContext.ACTIVE_UNIFORMS);
159158

@@ -168,7 +167,7 @@ cc.GLProgramState = function (glprogram) {
168167
this._uniforms.push(uniformValue);
169168
this._uniformsByName[uniform.name] = count;
170169
this._uniformsByLocation[uniform.location] = count;
171-
count++;
170+
count++;
172171
}
173172
}
174173
};
@@ -181,7 +180,10 @@ cc.GLProgramState.prototype = {
181180
}
182181

183182
for (var i = 0; i < this._uniforms.length; ++i) {
184-
this._uniforms[i].apply();
183+
var uniform = this._uniforms[i];
184+
if (uniform._currentBoundValue !== uniform._value) {
185+
uniform.apply();
186+
}
185187
}
186188
},
187189

0 commit comments

Comments
 (0)