Skip to content

Gotta batch them all #3248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f4d6f3
fix scale9sprite opacity update
Talisca Nov 30, 2015
ed45554
update artifacts by stretching texel
Talisca Nov 30, 2015
ae20de2
fix scrollview webgl renderer: resolved flickering and black screen
Talisca Nov 30, 2015
c3b7abc
fix scale9sprite opacity update
Talisca Nov 30, 2015
fa1648c
update artifacts by stretching texel
Talisca Nov 30, 2015
14d6b41
fix scrollview webgl renderer: resolved flickering and black screen
Talisca Nov 30, 2015
e159b2f
Merge branch 'develop' of https://github.com/Talisca/cocos2d-html5 in…
Talisca Feb 22, 2016
6113a3c
fix scale9sprites opacity
Talisca Feb 22, 2016
eeacead
annihilated some useless canvas render cmds
Mar 2, 2016
5098e22
nuked more canvas
Mar 2, 2016
a60e060
applying punishment to canvas
Mar 2, 2016
319b04a
bombarded the GAF stuff from orbit
Mar 3, 2016
8c0375a
removed more
Mar 3, 2016
8816b8d
removed more stuff
Mar 3, 2016
230da82
forcing children reordering in order to make z order work for spriteb…
Mar 3, 2016
3f7919a
added parsing support for tile animations from tiled
Mar 9, 2016
99cd391
modified the default projection matrix to have a smaller depth range …
Mar 11, 2016
80843a9
added support for spritesheet textures to ccparticlesystem. in the pl…
Mar 12, 2016
d3bc8e6
made sure the stats labels of ccprofiler stay on top
Mar 12, 2016
1a79a12
dummy commit
Mar 17, 2016
a297571
experimenting with z buffer for z ordering integration
Mar 19, 2016
b3b9d03
some work on auto sprite batching
Mar 20, 2016
caee732
auto batching now works with naive (slow) implementation
Mar 20, 2016
2012855
removed debug stuff
Mar 21, 2016
3ce36b7
removed error
Mar 22, 2016
3954663
Merge commit 'HEAD@{1}' into gotta-batch-them-all
Mar 22, 2016
10925ae
changed sprite batch code to use re-used webgl buffers from a pool
Mar 22, 2016
f393d52
now putting the data into one buffer and uploading it at once
Mar 22, 2016
358bb9e
experimenting a bit with more optimization of the configure batch loo…
Mar 22, 2016
7c2ba0b
could merge the inner for loops, another 20%
Mar 22, 2016
b7f4d8a
shaved another % off of configureBatch... using uint32arrays instead …
Mar 22, 2016
e9203d0
skipping the texture loaded check
Mar 22, 2016
f07210f
removed some unused node stuff
Mar 26, 2016
2d3afec
adding minz and maxz to nodes when assigning the global z value
TravisGesslein Mar 29, 2016
b73c59d
experimenting with solutions for the z bugs
Mar 30, 2016
c456512
now not updating z order of invisible nodes
Mar 31, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,45 @@
THE SOFTWARE.
****************************************************************************/



/**
* The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace
* @namespace
* @name cc
*/
var cc = cc || {};

cc.create3DContext = function (canvas, opt_attribs) {
var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
var context = null;
for (var ii = 0; ii < names.length; ++ii) {
try {
context = canvas.getContext(names[ii], opt_attribs);
} catch (e) {
}
if (context) {
break;
}
}
return context;
};

/*
(function () {
var canvas = document.getElementById("gameCanvas");
if (canvas) {
var ctx = cc.create3DContext(canvas);

if(!ctx)
{
throw new Error("LOL!");
}
}
}
)();
*/

cc._tmp = cc._tmp || {};
cc._LogInfos = {};

Expand Down Expand Up @@ -1184,20 +1217,7 @@ cc.formatStr = function(){
var _tmpCanvas1 = document.createElement("canvas"),
_tmpCanvas2 = document.createElement("canvas");

cc.create3DContext = function (canvas, opt_attribs) {
var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
var context = null;
for (var ii = 0; ii < names.length; ++ii) {
try {
context = canvas.getContext(names[ii], opt_attribs);
} catch (e) {
}
if (context) {
break;
}
}
return context;
};


var _initSys = function () {
/**
Expand Down Expand Up @@ -2210,6 +2230,11 @@ cc.game = /** @lends cc.game# */{
config = self.config,
CONFIG_KEY = self.CONFIG_KEY;

if(window["gli"]) //if webinspector is installed, we have to hook iterator
{
gli.setupContext();
}

this._loadConfig();

// Already prepared
Expand Down Expand Up @@ -2497,6 +2522,9 @@ cc.game = /** @lends cc.game# */{
cc.shaderCache._init();
cc._drawingUtil = new cc.DrawingPrimitiveWebGL(this._renderContext);
cc.textureCache._initializingRenderer();
cc.glExt = {};
cc.glExt.instanced_arrays = gl.getExtension("ANGLE_instanced_arrays");
cc.glExt.element_uint = gl.getExtension("OES_element_index_uint");
} else {
cc.renderer = cc.rendererCanvas;
this._renderContext = cc._renderContext = new cc.CanvasContextWrapper(localCanvas.getContext("2d"));
Expand Down
3 changes: 0 additions & 3 deletions cocos2d/clipping-nodes/CCClippingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
},

_createRenderCmd: function(){
if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
return new cc.ClippingNode.CanvasRenderCmd(this);
else
return new cc.ClippingNode.WebGLRenderCmd(this);
}
});
Expand Down
215 changes: 0 additions & 215 deletions cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
Original file line number Diff line number Diff line change
@@ -1,215 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

//-------------------------- ClippingNode's canvas render cmd --------------------------------
(function(){
cc.ClippingNode.CanvasRenderCmd = function(renderable){
cc.Node.CanvasRenderCmd.call(this, renderable);
this._needDraw = false;

this._godhelpme = false;
this._clipElemType = false;

this._rendererSaveCmd = new cc.CustomRenderCmd(this, this._saveCmdCallback);
this._rendererClipCmd = new cc.CustomRenderCmd(this, this._clipCmdCallback);
this._rendererRestoreCmd = new cc.CustomRenderCmd(this, this._restoreCmdCallback);
};
var proto = cc.ClippingNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
proto.constructor = cc.ClippingNode.CanvasRenderCmd;

proto.initStencilBits = function(){};

proto.setStencil = function(stencil){
if(stencil == null)
return;

this._node._stencil = stencil;

// For shape stencil, rewrite the draw of stencil ,only init the clip path and draw nothing.
//else
if (stencil instanceof cc.DrawNode) {
if(stencil._buffer){
for(var i=0; i<stencil._buffer.length; i++){
stencil._buffer[i].isFill = false;
stencil._buffer[i].isStroke = false;
}
}

stencil._renderCmd.rendering = function (ctx, scaleX, scaleY) {
scaleX = scaleX || cc.view.getScaleX();
scaleY = scaleY ||cc.view.getScaleY();
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();

var t = this._transform;
context.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY);
for (var i = 0; i < stencil._buffer.length; i++) {
var vertices = stencil._buffer[i].verts;
//TODO: need support circle etc
//cc.assert(cc.vertexListIsClockwise(vertices),
// "Only clockwise polygons should be used as stencil");

var firstPoint = vertices[0];
context.moveTo(firstPoint.x * scaleX, -firstPoint.y * scaleY);
for (var j = vertices.length - 1; j > 0; j--)
context.lineTo(vertices[j].x * scaleX, -vertices[j].y * scaleY);
}
};
}else{
stencil._parent = this._node;
}
};

proto._saveCmdCallback = function(ctx, scaleX, scaleY) {
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();

if (this._clipElemType) {
var locCache = cc.ClippingNode.CanvasRenderCmd._getSharedCache();
var canvas = context.canvas;
locCache.width = canvas.width;
locCache.height = canvas.height; //note: on some browser, it can't clear the canvas, e.g. baidu
var locCacheCtx = locCache.getContext("2d");
locCacheCtx.drawImage(canvas, 0, 0); //save the result to shareCache canvas
} else {
wrapper.save();
context.beginPath(); //save for clip
//Because drawNode's content size is zero
wrapper.setTransform(this._worldTransform, scaleX, scaleY);

if (this._node.inverted) {
context.rect(0, 0, context.canvas.width, -context.canvas.height);
context.clip();
}
}
};

proto._setStencilCompositionOperation = function(stencil){
if(!stencil)
return;
var node = this._node;
if(stencil._renderCmd && stencil._renderCmd._blendFuncStr) //it is a hack way.
stencil._renderCmd._blendFuncStr = (node.inverted ? "destination-out" : "destination-in");

if(!stencil._children)
return;
var children = stencil._children;
for(var i = 0, len = children.length; i < len; i++){
this._setStencilCompositionOperation(children[i]);
}
};

proto._clipCmdCallback = function(ctx) {
var node = this._node;
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();

if (this._clipElemType) {
//hack
this._setStencilCompositionOperation(node._stencil);
} else {
context.clip();
}
};

proto._restoreCmdCallback = function (ctx) {
var locCache = cc.ClippingNode.CanvasRenderCmd._getSharedCache();
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
if (this._clipElemType) {
// Redraw the cached canvas, so that the clipped area shows the background etc.
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.globalCompositeOperation = "destination-over";
context.drawImage(locCache, 0, 0);
context.restore();
this._dirtyFlag = 0;
} else {
wrapper.restore(); //use for restore clip operation
}
};

proto.transform = function(parentCmd, recursive){
cc.Node.CanvasRenderCmd.prototype.transform.call(this, parentCmd, recursive);
var node = this._node;
if(node._stencil && node._stencil._renderCmd)
node._stencil._renderCmd.transform(this, recursive);
};

proto._cangodhelpme = function (godhelpme) {
if (godhelpme === true || godhelpme === false)
cc.ClippingNode.CanvasRenderCmd.prototype._godhelpme = godhelpme;
return cc.ClippingNode.CanvasRenderCmd.prototype._godhelpme;
};

proto.visit = function(parentCmd){
var node = this._node;
// quick return if not visible
if (!node._visible)
return;

parentCmd = parentCmd || this.getParentRenderCmd();
if( parentCmd)
this._curLevel = parentCmd._curLevel + 1;
var transformRenderCmd = this;

// Composition mode, costy but support texture stencil
this._clipElemType = !(!this._cangodhelpme() && node._stencil instanceof cc.DrawNode);
if (!node._stencil || !node._stencil.visible) {
if (this.inverted)
cc.Node.CanvasRenderCmd.prototype.visit.call(this, parentCmd); // draw everything
return;
}

this._syncStatus(parentCmd);
cc.renderer.pushRenderCommand(this._rendererSaveCmd);
if(this._clipElemType){
// Draw everything first using node visit function
cc.Node.CanvasRenderCmd.prototype.visit.call(this, parentCmd);
}else{
node._stencil.visit(this);
}
cc.renderer.pushRenderCommand(this._rendererClipCmd);

if(this._clipElemType){
node._stencil.visit(transformRenderCmd);
}else{
var i, children = node._children;
// Clip mode doesn't support recursive stencil, so once we used a clip stencil,
// so if it has ClippingNode as a child, the child must uses composition stencil.
this._cangodhelpme(true);
var len = children.length;
if (len > 0) {
node.sortAllChildren();
for (i = 0; i < len; i++)
children[i]._renderCmd.visit(this);
}
this._cangodhelpme(false);
}

cc.renderer.pushRenderCommand(this._rendererRestoreCmd);
this._dirtyFlag = 0;
};

cc.ClippingNode.CanvasRenderCmd._sharedCache = null;
cc.ClippingNode.CanvasRenderCmd._getSharedCache = function () {
return (cc.ClippingNode.CanvasRenderCmd._sharedCache) || (cc.ClippingNode.CanvasRenderCmd._sharedCache = document.createElement("canvas"));
};
})();
7 changes: 2 additions & 5 deletions cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,11 @@
var gl = ctx || cc._renderContext, node = this._node;
cc.ClippingNode.WebGLRenderCmd._layer++;

// mask of the current layer (ie: for layer 3: 00000100)

var mask_layer = 0x1 << cc.ClippingNode.WebGLRenderCmd._layer;
// mask of all layers less than the current (ie: for layer 3: 00000011)
var mask_layer_l = mask_layer - 1;
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
//var mask_layer_le = mask_layer | mask_layer_l;
this._mask_layer_le = mask_layer | mask_layer_l;
// manually save the stencil state

this._currentStencilEnabled = gl.isEnabled(gl.STENCIL_TEST);
this._currentStencilWriteMask = gl.getParameter(gl.STENCIL_WRITEMASK);
this._currentStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
Expand Down
Loading