Skip to content

Commit b78819f

Browse files
committed
Merge pull request #3273 from pandamicro/develop
Fix issues caused by performance improvement
2 parents eea7a86 + 4c4982e commit b78819f

23 files changed

+336
-283
lines changed

CCBoot.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ cc.loader = (function () {
885885
isCrossOrigin: true
886886
};
887887
if (callback !== undefined)
888-
opt.isCrossOrigin = option.isCrossOrigin === null ? opt.isCrossOrigin : option.isCrossOrigin;
888+
opt.isCrossOrigin = option.isCrossOrigin === undefined ? opt.isCrossOrigin : option.isCrossOrigin;
889889
else if (option !== undefined)
890890
callback = option;
891891

@@ -917,9 +917,9 @@ cc.loader = (function () {
917917
if (queue) {
918918
callbacks = queue.callbacks;
919919
for (var i = 0; i < callbacks.length; ++i) {
920-
var callback = callbacks[i];
921-
if (callback) {
922-
callback(null, img);
920+
var cb = callbacks[i];
921+
if (cb) {
922+
cb(null, img);
923923
}
924924
}
925925
queue.img = null;
@@ -940,9 +940,9 @@ cc.loader = (function () {
940940
if (queue) {
941941
callbacks = queue.callbacks;
942942
for (var i = 0; i < callbacks.length; ++i) {
943-
var callback = callbacks[i];
944-
if (callback) {
945-
callback("load image failed");
943+
var cb = callbacks[i];
944+
if (cb) {
945+
cb("load image failed");
946946
}
947947
}
948948
queue.img = null;
@@ -1180,6 +1180,11 @@ cc.loader = (function () {
11801180
*/
11811181
release: function (url) {
11821182
var cache = this.cache;
1183+
var queue = _queue[url];
1184+
if (queue) {
1185+
queue.img = null;
1186+
delete _queue[url];
1187+
}
11831188
delete cache[url];
11841189
delete cache[_aliases[url]];
11851190
delete _aliases[url];
@@ -1415,7 +1420,7 @@ var _initSys = function () {
14151420
* @constant
14161421
* @type {Number}
14171422
*/
1418-
sys.LANGUAGE_UNKNOWN = "unknown";
1423+
sys.LANGUAGE_UNKNOWN = "unkonwn";
14191424

14201425
/**
14211426
* @memberof cc.sys
@@ -2649,10 +2654,13 @@ cc.game = /** @lends cc.game# */{
26492654
if (this._renderContext) {
26502655
cc.renderer = cc.rendererWebGL;
26512656
win.gl = this._renderContext; // global variable declared in CCMacro.js
2652-
cc.renderer.initQuadIndexBuffer();
2657+
cc.renderer.init();
26532658
cc.shaderCache._init();
26542659
cc._drawingUtil = new cc.DrawingPrimitiveWebGL(this._renderContext);
26552660
cc.textureCache._initializingRenderer();
2661+
cc.glExt = {};
2662+
cc.glExt.instanced_arrays = gl.getExtension("ANGLE_instanced_arrays");
2663+
cc.glExt.element_uint = gl.getExtension("OES_element_index_uint");
26562664
} else {
26572665
cc.renderer = cc.rendererCanvas;
26582666
this._renderContext = cc._renderContext = new cc.CanvasContextWrapper(localCanvas.getContext("2d"));

cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
proto.transform = function(parentCmd, recursive){
5858
var node = this._node;
5959
cc.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
60-
if(node._stencil)
60+
if(node._stencil) {
6161
node._stencil._renderCmd.transform(this, recursive);
62+
}
6263
};
6364

6465
proto.visit = function(parentCmd){
@@ -72,7 +73,7 @@
7273

7374
// if stencil buffer disabled
7475
if (cc.stencilBits < 1) {
75-
// draw everything, as if there where no stencil
76+
// draw everything, as if there were no stencil
7677
cc.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd);
7778
return;
7879
}
@@ -102,7 +103,7 @@
102103
this._syncStatus(parentCmd);
103104
currentStack.top = this._stackMatrix;
104105

105-
//this._stencil._stackMatrix = this._stackMatrix;
106+
// node._stencil._stackMatrix = node._stackMatrix;
106107
node._stencil._renderCmd.visit(this);
107108

108109
cc.renderer.pushRenderCommand(this._afterDrawStencilCmd);
@@ -166,6 +167,7 @@
166167
// set our alphaThreshold
167168
cc.glUseProgram(program.getProgram());
168169
program.setUniformLocationWith1f(cc.UNIFORM_ALPHA_TEST_VALUE_S, node.alphaThreshold);
170+
program.setUniformLocationWithMatrix4fv(cc.UNIFORM_MVMATRIX_S, cc.renderer.mat4Identity.mat);
169171
cc.setProgram(node._stencil, program);
170172
}
171173
};

cocos2d/core/CCDirector.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
228228
this._beforeVisitScene();
229229

230230
// draw the scene
231-
var skipRendering = false;
232231
if (this._runningScene) {
233232
if (renderer.childrenOrderDirty === true) {
234233
cc.renderer.clearRenderCommands();
@@ -240,14 +239,9 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
240239
else if (renderer.transformDirty() === true) {
241240
renderer.transform();
242241
}
243-
else {
244-
skipRendering = true;
245-
}
246242
}
247243

248-
if (!skipRendering) {
249-
renderer.clear();
250-
}
244+
renderer.clear();
251245

252246
// draw the notifications node
253247
if (this._notificationNode)
@@ -259,9 +253,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
259253
if (this._afterVisitScene)
260254
this._afterVisitScene();
261255

262-
if (!skipRendering) {
263-
renderer.rendering(cc._renderContext);
264-
}
256+
renderer.rendering(cc._renderContext);
265257
this._totalFrames++;
266258

267259
cc.eventManager.dispatchEvent(this._eventAfterDraw);

cocos2d/core/CCDirectorWebGL.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
8282
size.width - ox,
8383
-oy,
8484
size.height - oy,
85-
-1, 1);
85+
-1024, 1024);
8686
cc.kmGLMultMatrix(orthoMatrix);
8787
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
8888
cc.kmGLLoadIdentity();

cocos2d/core/base-nodes/CCNode.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
132132
_localZOrder: 0, ///< Local order (relative to its siblings) used to sort the node
133133
_globalZOrder: 0, ///< Global order used to sort the node
134134
_vertexZ: 0.0,
135+
_customZ: NaN,
135136

136137
_rotationX: 0,
137138
_rotationY: 0.0,
@@ -487,7 +488,7 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
487488
* @param {Number} Var
488489
*/
489490
setVertexZ: function (Var) {
490-
this._vertexZ = Var;
491+
this._customZ = this._vertexZ = Var;
491492
},
492493

493494
/**

cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cc.CustomRenderCmd = function (target, func) {
3636
};
3737

3838
cc.Node._dirtyFlags = {transformDirty: 1 << 0, visibleDirty: 1 << 1, colorDirty: 1 << 2, opacityDirty: 1 << 3, cacheDirty: 1 << 4,
39-
orderDirty: 1 << 5, textDirty: 1 << 6, gradientDirty:1 << 7, all: (1 << 8) - 1};
39+
orderDirty: 1 << 5, textDirty: 1 << 6, gradientDirty:1 << 7, textureDirty: 1 << 8, all: (1 << 9) - 1};
4040

4141
//-------------------------Base -------------------------
4242
cc.Node.RenderCmd = function(renderable){
@@ -368,7 +368,7 @@ cc.Node.RenderCmd.prototype = {
368368
if(colorDirty || opacityDirty)
369369
this._updateColor();
370370

371-
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL || locFlag & flags.transformDirty)
371+
if (locFlag & flags.transformDirty)
372372
//update the transform
373373
this.transform(parentCmd, true);
374374

@@ -395,18 +395,21 @@ cc.Node.RenderCmd.prototype = {
395395
}
396396
}
397397

398-
var z = renderer.assignedZ;
399-
node._vertexZ = z;
400-
renderer.assignedZ += renderer.assignedZStep;
398+
if (isNaN(node._customZ)) {
399+
node._vertexZ = renderer.assignedZ;
400+
renderer.assignedZ += renderer.assignedZStep;
401+
}
401402

402403
renderer.pushRenderCommand(this);
403404
for (; i < len; i++) {
404405
child = children[i];
405406
child._renderCmd.visit(this);
406407
}
407408
} else {
408-
node._vertexZ = renderer.assignedZ;
409-
renderer.assignedZ += renderer.assignedZStep;
409+
if (isNaN(node._customZ)) {
410+
node._vertexZ = renderer.assignedZ;
411+
renderer.assignedZ += renderer.assignedZStep;
412+
}
410413

411414
renderer.pushRenderCommand(this);
412415
}

cocos2d/core/base-nodes/CCNodeWebGLRenderCmd.js

+24
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@
8989
// Update Z depth
9090
t4x4Mat[14] = node._vertexZ;
9191

92+
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix
93+
if (node._camera !== null && !(node.grid !== null && node.grid.isActive())) {
94+
var apx = this._anchorPointInPoints.x, apy = this._anchorPointInPoints.y;
95+
var translate = (apx !== 0.0 || apy !== 0.0);
96+
if (translate){
97+
if(!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
98+
apx = 0 | apx;
99+
apy = 0 | apy;
100+
}
101+
//cc.kmGLTranslatef(apx, apy, 0);
102+
var translation = cc.math.Matrix4.createByTranslation(apx, apy, 0, t4x4); //t4x4 as a temp matrix
103+
stackMatrix.multiply(translation);
104+
105+
node._camera._locateForRenderer(stackMatrix);
106+
107+
//cc.kmGLTranslatef(-apx, -apy, 0); optimize at here : kmGLTranslatef
108+
translation = cc.math.Matrix4.createByTranslation(-apx, -apy, 0, translation);
109+
stackMatrix.multiply(translation);
110+
t4x4.identity(); //reset t4x4;
111+
} else {
112+
node._camera._locateForRenderer(stackMatrix);
113+
}
114+
}
115+
92116
if (!recursive || !node._children) {
93117
return;
94118
}

cocos2d/core/platform/CCMacro.js

+5
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ cc.UNIFORM_MAX = 8;
621621
* @type {String}
622622
*/
623623
cc.SHADER_POSITION_TEXTURECOLOR = "ShaderPositionTextureColor";
624+
/**
625+
* @constant
626+
* @type {String}
627+
*/
628+
cc.SHADER_SPRITE_POSITION_TEXTURECOLOR = "ShaderSpritePositionTextureColor";
624629
/**
625630
* @constant
626631
* @type {String}

cocos2d/core/renderer/GlobalVertexBuffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var GlobalVertexBuffer = function (gl) {
4040

4141
// Init buffer data
4242
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
43-
gl.bufferData(gl.ARRAY_BUFFER, this.byteLength, gl.DYNAMIC_DRAW);
43+
gl.bufferData(gl.ARRAY_BUFFER, this.dataArray, gl.DYNAMIC_DRAW);
4444

4545
this._dirty = false;
4646
this._spaces = {

cocos2d/core/renderer/RendererWebGL.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ function createVirtualBuffer (buffer, vertexOffset, totalBufferSize, count, data
126126
}
127127

128128
return {
129+
mat4Identity: null,
130+
129131
childrenOrderDirty: true,
130132
assignedZ: 0,
131133
assignedZStep: 1/10000,
@@ -139,7 +141,9 @@ return {
139141
_currentID: 0,
140142
_clearColor: cc.color(), //background color,default BLACK
141143

142-
initQuadIndexBuffer: function () {
144+
init: function () {
145+
this.mat4Identity = new cc.math.Matrix4();
146+
this.mat4Identity.identity();
143147
getQuadIndexBuffer(1000);
144148
},
145149

@@ -193,6 +197,12 @@ return {
193197
renderTextureId = renderTextureId || this._currentID;
194198
var locCmds = this._cacheToBufferCmds[renderTextureId], i, len;
195199
var ctx = cc._renderContext, locIDs = this._cacheInstanceIds;
200+
// Update all global buffers (only invoke bufferSubData when buffer is dirty)
201+
for (i = 0, len = _gbuffers.length; i < len; ++i) {
202+
_gbuffers[i].update();
203+
}
204+
// Reset buffer cache to avoid issue
205+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
196206
for (i = 0, len = locCmds.length; i < len; i++) {
197207
locCmds[i].rendering(ctx);
198208
}

cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
this._needDraw = true;
3333

3434
this._vertices = [
35-
{x: 0, y: 0, z: 0},
36-
{x: 0, y: 0, z: 0},
37-
{x: 0, y: 0, z: 0},
38-
{x: 0, y: 0, z: 0}
35+
{x: 0, y: 0, z: 0}, // tl
36+
{x: 0, y: 0, z: 0}, // bl
37+
{x: 0, y: 0, z: 0}, // tr
38+
{x: 0, y: 0, z: 0} // br
3939
];
4040
var length = this.vertexBytesPerUnit;
4141
var bufInfo = cc.renderer.requestBuffer(length);
@@ -321,7 +321,6 @@
321321
for (i = 0; i < 4; ++i) {
322322
x = vertices[i].x;
323323
y = vertices[i].y;
324-
z = vertices[i].z;
325324
buffer[offset] = x * mat[0] + y * mat[4] + mat[12];
326325
buffer[offset+1] = x * mat[1] + y * mat[5] + mat[13];
327326
buffer[offset+2] = mat[14];
@@ -555,7 +554,7 @@
555554
}
556555
} else {
557556
program.use();
558-
program._setUniformForMVPMatrixWithMat4(this._stackMatrix);
557+
program._updateProjectionUniform();
559558

560559
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
561560

cocos2d/particle/CCParticleSystemWebGLRenderCmd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
proto.postStep = function(){
367367
var gl = cc._renderContext;
368368
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
369-
gl.bufferData(gl.ARRAY_BUFFER, this._quadsArrayBuffer, gl.DYNAMIC_DRAW);
369+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this._quadsArrayBuffer);
370370
};
371371

372372
proto._setBlendAdditive = function(){

0 commit comments

Comments
 (0)