Skip to content

Commit cb118aa

Browse files
committed
Merge pull request cocos2d#3280 from pandamicro/develop
Fix last issues about new rendering process
2 parents 7b25ebc + 7dea348 commit cb118aa

File tree

8 files changed

+80
-22
lines changed

8 files changed

+80
-22
lines changed

cocos2d/core/renderer/RendererCanvas.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ cc.rendererCanvas = {
7575
for (i = 0, len = locCmds.length; i < len; i++) {
7676
locCmds[i].rendering(ctx, scaleX, scaleY);
7777
}
78-
locCmds.length = 0;
79-
var locIDs = this._cacheInstanceIds;
80-
delete this._cacheToCanvasCmds[instanceID];
81-
cc.arrayRemoveObject(locIDs, instanceID);
78+
this._removeCache(instanceID);
8279

80+
var locIDs = this._cacheInstanceIds;
8381
if (locIDs.length === 0)
8482
this._isCacheToCanvasOn = false;
8583
else
@@ -99,6 +97,15 @@ cc.rendererCanvas = {
9997
this._isCacheToCanvasOn = false;
10098
},
10199

100+
_removeCache: function (instanceID) {
101+
instanceID = instanceID || this._currentID;
102+
this._cacheToCanvasCmds[instanceID].length = 0;
103+
delete this._cacheToCanvasCmds[instanceID];
104+
105+
var locIDs = this._cacheInstanceIds;
106+
cc.arrayRemoveObject(locIDs, instanceID);
107+
},
108+
102109
resetFlag: function () {
103110
this.childrenOrderDirty = false;
104111
this._transformNodePool.length = 0;

cocos2d/core/renderer/RendererWebGL.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,23 @@ return {
196196
this._isCacheToBufferOn = false;
197197
},
198198

199+
_removeCache: function (instanceID) {
200+
instanceID = instanceID || this._currentID;
201+
this._cacheToBufferCmds[instanceID].length = 0;
202+
delete this._cacheToBufferCmds[instanceID];
203+
204+
var locIDs = this._cacheInstanceIds;
205+
cc.arrayRemoveObject(locIDs, instanceID);
206+
},
207+
199208
/**
200209
* drawing all renderer command to cache canvas' context
201210
* @param {Number} [renderTextureId]
202211
*/
203212
_renderingToBuffer: function (renderTextureId) {
204213
renderTextureId = renderTextureId || this._currentID;
205214
var locCmds = this._cacheToBufferCmds[renderTextureId], i, len;
206-
var ctx = cc._renderContext, locIDs = this._cacheInstanceIds;
215+
var ctx = cc._renderContext;
207216
// Update all global buffers (only invoke bufferSubData when buffer is dirty)
208217
for (i = 0, len = _gbuffers.length; i < len; ++i) {
209218
_gbuffers[i].update();
@@ -213,10 +222,9 @@ return {
213222
for (i = 0, len = locCmds.length; i < len; i++) {
214223
locCmds[i].rendering(ctx);
215224
}
216-
locCmds.length = 0;
217-
delete this._cacheToBufferCmds[renderTextureId];
218-
cc.arrayRemoveObject(locIDs, renderTextureId);
225+
this._removeCache(renderTextureId);
219226

227+
var locIDs = this._cacheInstanceIds;
220228
if (locIDs.length === 0)
221229
this._isCacheToBufferOn = false;
222230
else
@@ -676,6 +684,9 @@ return {
676684
this._refreshVirtualBuffers();
677685
}
678686

687+
// Reset buffer for rendering
688+
context.bindBuffer(gl.ARRAY_BUFFER, null);
689+
679690
for (i = 0, len = locCmds.length; i < len; ++i) {
680691
cmd = locCmds[i];
681692
next = locCmds[i+1];

cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@
523523
};
524524

525525
proto.needDraw = function () {
526-
var node = this._node, locTexture = node._texture;
527-
return (this._buffer && locTexture && locTexture._textureLoaded && node._rect.width && node._rect.height && this._displayedOpacity);
526+
return (this._buffer && this._node._texture);
528527
};
529528

530529
proto.rendering = function (ctx) {

cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
proto.rendering = function (ctx) {
4848
var node = this._node;
4949
var context = ctx || cc._renderContext;
50-
if (!this._vertexDataCount || !node._sprite)
50+
if (this._vertexDataCount === 0 || !node._sprite)
5151
return;
5252

5353
this._shaderProgram.use();
@@ -177,7 +177,11 @@
177177
proto.releaseData = function(){
178178
if (this._vertexData) {
179179
//release all previous information
180-
cc._renderContext.deleteBuffer(this._vertexWebGLBuffer);
180+
var webglBuffer = this._vertexWebGLBuffer;
181+
setTimeout(function () {
182+
cc._renderContext.deleteBuffer(webglBuffer);
183+
}, 0.1);
184+
this._vertexWebGLBuffer = null;
181185
this._vertexData = null;
182186
this._float32View = null;
183187
this._vertexArrayBuffer = null;

cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
this._fullViewport = fullViewport;
4949
};
5050

51+
proto.needDraw = function () {
52+
return this._needDraw && this._node.autoDraw;
53+
};
54+
5155
proto.rendering = function (ctx) {
5256
var gl = ctx || cc._renderContext;
5357
var node = this._node;

extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ ccui.ScrollView = ccui.Layout.extend(/** @lends ccui.ScrollView# */{
131131
this.scheduleUpdate();
132132
},
133133

134+
onExit: function () {
135+
cc.renderer._removeCache(this.__instanceId);
136+
ccui.Layout.prototype.onExit.call(this);
137+
},
138+
134139
/**
135140
* When a widget is in a layout, you could call this method to get the next focused widget within a specified _direction. <br/>
136141
* If the widget is not in a layout, it will return itself

extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,37 @@
163163
currentStack.top = this._stackMatrix;
164164

165165
node.sortAllChildren();
166-
cc.renderer.pushRenderCommand(this);
166+
167+
var renderer = cc.renderer,
168+
children = node._children, child,
169+
i, len = children.length;
170+
171+
for (i = 0; i < len; i++) {
172+
child = children[i];
173+
if (child._localZOrder < 0) {
174+
if (isNaN(child._customZ)) {
175+
child._vertexZ = renderer.assignedZ;
176+
renderer.assignedZ += renderer.assignedZStep;
177+
}
178+
}
179+
else {
180+
break;
181+
}
182+
}
183+
184+
if (isNaN(node._customZ)) {
185+
node._vertexZ = renderer.assignedZ;
186+
renderer.assignedZ += renderer.assignedZStep;
187+
}
188+
renderer.pushRenderCommand(this);
189+
190+
for (; i < len; i++) {
191+
child = children[i];
192+
if (isNaN(child._customZ)) {
193+
child._vertexZ = renderer.assignedZ;
194+
renderer.assignedZ += renderer.assignedZStep;
195+
}
196+
}
167197

168198
this._dirtyFlag = 0;
169199
currentStack.top = currentStack.stack.pop();

extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
var node = this._node;
4646
var locQuad = this._quad;
4747
var vertices = this._vertices;
48-
// If it is not visible, or one of its ancestors is not visible, then do nothing:
49-
if (!node._visible)
50-
locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y: 0, z: 0};
51-
else if (this._buffer) {
48+
49+
if (this._buffer) {
5250
//
5351
// calculate the Quad based on the Affine Matrix
5452
//
@@ -86,11 +84,11 @@
8684
if (node.textureAtlas) {
8785
node.textureAtlas.updateQuad(locQuad, node.textureAtlas.getTotalQuads());
8886
}
89-
90-
this._quadDirty = true;
91-
this._savedDirtyFlag = true;
92-
this._bufferDirty = true;
93-
this._buffer.setDirty();
87+
88+
// Need manually buffer data because it's invoked during rendering
89+
cc._renderContext.bindBuffer(gl.ARRAY_BUFFER, this._buffer.vertexBuffer);
90+
cc._renderContext.bufferSubData(gl.ARRAY_BUFFER, this._bufferOffset, this._float32View);
91+
cc._renderContext.bindBuffer(gl.ARRAY_BUFFER, null);
9492
}
9593
};
9694
})();

0 commit comments

Comments
 (0)