Skip to content

Commit 147876e

Browse files
author
Travis Gesslein
committed
wip
1 parent a2cb40d commit 147876e

File tree

5 files changed

+29
-59
lines changed

5 files changed

+29
-59
lines changed

cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ cc.CustomRenderCmd = function (target, func) {
3535
}
3636
};
3737

38+
cc.CustomRenderCmd.prototype.configureBatch = function()
39+
{
40+
return 1;
41+
}
42+
3843
cc.Node._dirtyFlags =
3944
{
4045
transformDirty: 1 << 0,

cocos2d/core/base-nodes/CCNodeWebGLRenderCmd.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
proto.geometryType = cc.geometryTypes.NONE;
4343

4444
proto._updateColor = function(){};
45-
proto._batching = false;
4645
proto._batchedCount = 1;
4746

4847
proto.visit = function (parentCmd) {

cocos2d/core/renderer/RendererWebGL.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,38 +195,22 @@ cc.rendererWebGL = {
195195

196196
this.updateBuffers();
197197

198-
199-
200198
//prepare batching
201-
for (i = 0, len = locCmds.length; i< len; ++i)
199+
for (i = 0, len = locCmds.length; i< len; )
202200
{
203201
var cmd = locCmds[i];
204202

205-
if(!cmd._batched && cmd.configureBatch) //may be set to true by processed cmds during this loop
206-
{
207-
cmd.configureBatch(locCmds, i);
208-
}
203+
var batchedCount = cmd.configureBatch(locCmds, i);
204+
i += batchedCount;
209205
}
210206

211-
for (i = 0, len = locCmds.length; i< len; ++i) {
207+
for (i = 0, len = locCmds.length; i< len;) {
212208
var cmd = locCmds[i];
213-
if(cmd._batching)
214-
{
215-
cmd.batchedRendering();
216-
}
217-
else if(!cmd._batched)
218-
{
219-
cmd.rendering();
220-
}
221-
}
222209

223-
//prepare batching
224-
for (i = 0, len = locCmds.length; i< len; ++i)
225-
{
226-
locCmds[i]._batching = false;
227-
locCmds[i]._batched = false;
210+
cmd.rendering();
211+
i += cmd._batchedCount;
228212
}
229-
213+
230214
cc._stateCacheStats.lastFrameVertexFormatSwitches = cc._stateCacheStats.vertexFormatSwitches;
231215
cc._stateCacheStats.vertexFormatSwitches = 0;
232216
},

cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -265,28 +265,26 @@
265265

266266
proto.rendering = function () {
267267
var node = this._node, locTexture = node._texture;
268-
268+
var count = this._batchedCount;
269269
var program = this._shaderProgram;
270-
if (locTexture) {
271-
program.use();
272270

273-
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
274-
275-
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
276-
//cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
271+
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
277272

278-
cc.glBindVertexFormat(cc.renderer.vertexFormats[1]);
279-
280-
gl.drawArrays(gl.TRIANGLE_STRIP, this._firstQuad * 4, 4);
281-
} else {
282-
program.use();
273+
var elemBuffer = cc.renderer.buffers[cc.geometryTypes.QUAD].indexBuffer;
274+
cc.glBindElementBuffer(elemBuffer);
275+
cc.glBindVertexFormat(cc.renderer.vertexFormats[1]);
276+
277+
program.use();
278+
if (locTexture)
279+
{
280+
cc.glBindTexture2DN(0, locTexture);
281+
gl.drawElements(gl.TRIANGLES, count * 6, gl.UNSIGNED_SHORT, this._firstQuad * 6 * 2);
282+
}
283+
else
284+
{
283285
program._setUniformForMVPMatrixWithMat4(this._stackMatrix);
284-
285-
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
286286
cc.glBindTexture2D(null);
287287

288-
cc.glBindVertexFormat(cc.renderer.vertexFormats[1]);
289-
290288
gl.drawArrays(gl.TRIANGLE_STRIP, this._firstQuad * 4, 4);
291289
}
292290

@@ -330,19 +328,10 @@
330328
if (texture !== otherNode.getTexture()) {
331329
break;
332330
}
333-
334-
cmd._batched = true;
335331
}
336332

337333
var count = i - myIndex;
338-
339-
if (count > 1) {
340-
this._batching = true;
341-
this._batchedCount = count;
342-
}
343-
else {
344-
return 1;
345-
}
334+
this._batchedCount = count;
346335

347336
return count;
348337
}

cocos2d/labels/BatchedLabelWebGLRenderCmd.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
proto.rendering = function ()
5656
{
57-
//return;
57+
return;
5858
var node = this._node;
5959
if(node._stringDirty)
6060
{
@@ -288,19 +288,12 @@
288288
//also, when batching we have to 0 out the vertex data buffer to make sure those quads aren't drawn (they are uploaded to gpu anyways)
289289
}
290290

291-
cmd._batched = true;
292291
drawnQuads += cmd._numQuads;
293292
}
294293

295294
var count = i - myIndex;
296295

297-
if (count > 1) {
298-
this._batching = true;
299-
this._batchedCount = count;
300-
}
301-
else {
302-
return 1;
303-
}
296+
this._batchedCount = count;
304297

305298
if(node._stringDirty)
306299
{

0 commit comments

Comments
 (0)