mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 18:42:40 +08:00
@@ -23,7 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var cc = cc || {};
|
||||
cc._tmp = cc._tmp || {};
|
||||
cc._LogInfos = cc._LogInfos || {};
|
||||
|
||||
@@ -94,11 +93,8 @@ cc._gameDiv = null;
|
||||
|
||||
cc.isEditor = typeof Editor !== 'undefined';
|
||||
|
||||
require('../cocos2d/core/utils');
|
||||
require('../cocos2d/core/platform/CCSys');
|
||||
require('../cocos2d/core/load-pipeline/CCLoader');
|
||||
|
||||
require('../cocos2d/core/CCGame');
|
||||
require('./cocos2d/core/utils');
|
||||
require('./cocos2d/core/platform/CCSys');
|
||||
|
||||
|
||||
//+++++++++++++++++++++++++Engine initialization function begin+++++++++++++++++++++++++++
|
||||
|
||||
@@ -23,198 +23,196 @@
|
||||
****************************************************************************/
|
||||
|
||||
//-------------------------- ClippingNode's canvas render cmd --------------------------------
|
||||
(function(){
|
||||
cc.ClippingNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
cc.ClippingNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
|
||||
this._godhelpme = false;
|
||||
this._clipElemType = 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(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ClippingNode.CanvasRenderCmd;
|
||||
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(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ClippingNode.CanvasRenderCmd;
|
||||
|
||||
proto.initStencilBits = function(){};
|
||||
proto.initStencilBits = function(){};
|
||||
|
||||
proto.setStencil = function(stencil){
|
||||
if(stencil == null)
|
||||
return;
|
||||
proto.setStencil = function(stencil){
|
||||
if(stencil == null)
|
||||
return;
|
||||
|
||||
this._node._stencil = stencil;
|
||||
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) {
|
||||
context.save();
|
||||
context.globalAlpha = this._displayedOpacity/ 255;
|
||||
var locCache = cc.ClippingNode.CanvasRenderCmd._getSharedCache();
|
||||
var canvas = context.canvas;
|
||||
if (locCache.width !== canvas.width)
|
||||
locCache.width = canvas.width;
|
||||
if (locCache.height !== canvas.height)
|
||||
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();
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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");
|
||||
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();
|
||||
|
||||
if(!stencil._children)
|
||||
return;
|
||||
var children = stencil._children;
|
||||
for(var i = 0, len = children.length; i < len; i++){
|
||||
this._setStencilCompositionOperation(children[i]);
|
||||
}
|
||||
};
|
||||
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");
|
||||
|
||||
proto._clipCmdCallback = function(ctx) {
|
||||
var node = this._node;
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
if (this._clipElemType) {
|
||||
//hack
|
||||
this._setStencilCompositionOperation(node._stencil);
|
||||
} else {
|
||||
proto._saveCmdCallback = function(ctx, scaleX, scaleY) {
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
|
||||
if (this._clipElemType) {
|
||||
context.save();
|
||||
context.globalAlpha = this._displayedOpacity/ 255;
|
||||
var locCache = cc.ClippingNode.CanvasRenderCmd._getSharedCache();
|
||||
var canvas = context.canvas;
|
||||
if (locCache.width !== canvas.width)
|
||||
locCache.width = canvas.width;
|
||||
if (locCache.height !== canvas.height)
|
||||
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._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;
|
||||
context.restore();
|
||||
} else {
|
||||
wrapper.restore(); //use for restore clip operation
|
||||
}
|
||||
};
|
||||
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");
|
||||
|
||||
proto.transform = function(parentCmd, recursive){
|
||||
_ccsg.Node.CanvasRenderCmd.prototype.transform.call(this, parentCmd, recursive);
|
||||
var node = this._node;
|
||||
if(node._stencil && node._stencil._renderCmd)
|
||||
node._stencil._renderCmd.transform(this, recursive);
|
||||
};
|
||||
if(!stencil._children)
|
||||
return;
|
||||
var children = stencil._children;
|
||||
for(var i = 0, len = children.length; i < len; i++){
|
||||
this._setStencilCompositionOperation(children[i]);
|
||||
}
|
||||
};
|
||||
|
||||
proto._cangodhelpme = function (godhelpme) {
|
||||
if (godhelpme === true || godhelpme === false)
|
||||
cc.ClippingNode.CanvasRenderCmd.prototype._godhelpme = godhelpme;
|
||||
return cc.ClippingNode.CanvasRenderCmd.prototype._godhelpme;
|
||||
};
|
||||
proto._clipCmdCallback = function(ctx) {
|
||||
var node = this._node;
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
if (this._clipElemType) {
|
||||
//hack
|
||||
this._setStencilCompositionOperation(node._stencil);
|
||||
} else {
|
||||
context.clip();
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
_ccsg.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
|
||||
_ccsg.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);
|
||||
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;
|
||||
};
|
||||
context.restore();
|
||||
} else {
|
||||
wrapper.restore(); //use for restore clip operation
|
||||
}
|
||||
};
|
||||
|
||||
cc.ClippingNode.CanvasRenderCmd._sharedCache = null;
|
||||
cc.ClippingNode.CanvasRenderCmd._getSharedCache = function () {
|
||||
return (cc.ClippingNode.CanvasRenderCmd._sharedCache) || (cc.ClippingNode.CanvasRenderCmd._sharedCache = document.createElement("canvas"));
|
||||
};
|
||||
})();
|
||||
proto.transform = function(parentCmd, recursive){
|
||||
_ccsg.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)
|
||||
_ccsg.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
|
||||
_ccsg.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"));
|
||||
};
|
||||
@@ -23,216 +23,225 @@
|
||||
****************************************************************************/
|
||||
|
||||
// ------------------------------- ClippingNode's WebGL render cmd ------------------------------
|
||||
(function(){
|
||||
cc.ClippingNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
function setProgram (node, program) {
|
||||
node.shaderProgram = program;
|
||||
|
||||
this._beforeVisitCmd = new cc.CustomRenderCmd(this, this._onBeforeVisit);
|
||||
this._afterDrawStencilCmd = new cc.CustomRenderCmd(this, this._onAfterDrawStencil);
|
||||
this._afterVisitCmd = new cc.CustomRenderCmd(this, this._onAfterVisit);
|
||||
var children = node.children;
|
||||
if (!children)
|
||||
return;
|
||||
|
||||
this._currentStencilFunc = null;
|
||||
this._currentStencilRef = null;
|
||||
this._currentStencilValueMask = null;
|
||||
this._currentStencilFail = null;
|
||||
this._currentStencilPassDepthFail = null;
|
||||
this._currentStencilPassDepthPass = null;
|
||||
this._currentStencilWriteMask = null;
|
||||
this._currentStencilEnabled = null;
|
||||
this._currentDepthWriteMask = null;
|
||||
this._mask_layer_le = null;
|
||||
};
|
||||
for (var i = 0; i < children.length; i++)
|
||||
setProgram(children[i], program);
|
||||
};
|
||||
|
||||
var proto = cc.ClippingNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.ClippingNode.WebGLRenderCmd;
|
||||
cc.ClippingNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = null;
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = null;
|
||||
cc.ClippingNode.WebGLRenderCmd._layer = -1;
|
||||
this._beforeVisitCmd = new cc.CustomRenderCmd(this, this._onBeforeVisit);
|
||||
this._afterDrawStencilCmd = new cc.CustomRenderCmd(this, this._onAfterDrawStencil);
|
||||
this._afterVisitCmd = new cc.CustomRenderCmd(this, this._onAfterVisit);
|
||||
|
||||
proto.initStencilBits = function(){
|
||||
// get (only once) the number of bits of the stencil buffer
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = true;
|
||||
if (cc.ClippingNode.WebGLRenderCmd._init_once) {
|
||||
cc.ClippingNode.stencilBits = cc._renderContext.getParameter(cc._renderContext.STENCIL_BITS);
|
||||
if (cc.ClippingNode.stencilBits <= 0)
|
||||
cc.log("Stencil buffer is not enabled.");
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = false;
|
||||
this._currentStencilFunc = null;
|
||||
this._currentStencilRef = null;
|
||||
this._currentStencilValueMask = null;
|
||||
this._currentStencilFail = null;
|
||||
this._currentStencilPassDepthFail = null;
|
||||
this._currentStencilPassDepthPass = null;
|
||||
this._currentStencilWriteMask = null;
|
||||
this._currentStencilEnabled = null;
|
||||
this._currentDepthWriteMask = null;
|
||||
this._mask_layer_le = null;
|
||||
};
|
||||
|
||||
var proto = cc.ClippingNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.ClippingNode.WebGLRenderCmd;
|
||||
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = null;
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = null;
|
||||
cc.ClippingNode.WebGLRenderCmd._layer = -1;
|
||||
|
||||
proto.initStencilBits = function(){
|
||||
// get (only once) the number of bits of the stencil buffer
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = true;
|
||||
if (cc.ClippingNode.WebGLRenderCmd._init_once) {
|
||||
cc.ClippingNode.stencilBits = cc._renderContext.getParameter(cc._renderContext.STENCIL_BITS);
|
||||
if (cc.ClippingNode.stencilBits <= 0)
|
||||
cc.log("Stencil buffer is not enabled.");
|
||||
cc.ClippingNode.WebGLRenderCmd._init_once = false;
|
||||
}
|
||||
};
|
||||
|
||||
proto.transform = function(parentCmd, recursive){
|
||||
var node = this._node;
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
|
||||
if(node._stencil)
|
||||
node._stencil._renderCmd.transform(this, recursive);
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
|
||||
if( node._parent && node._parent._renderCmd)
|
||||
this._curLevel = node._parent._renderCmd._curLevel + 1;
|
||||
|
||||
// if stencil buffer disabled
|
||||
if (cc.ClippingNode.stencilBits < 1) {
|
||||
// draw everything, as if there where no stencil
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node._stencil || !node._stencil.visible) {
|
||||
if (node.inverted)
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd); // draw everything
|
||||
return;
|
||||
}
|
||||
|
||||
if (cc.ClippingNode.WebGLRenderCmd._layer + 1 === cc.ClippingNode.stencilBits) {
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = true;
|
||||
if (cc.ClippingNode.WebGLRenderCmd._visit_once) {
|
||||
cc.log("Nesting more than " + cc.ClippingNode.stencilBits + "stencils is not supported. Everything will be drawn without stencil for this node and its children.");
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = false;
|
||||
}
|
||||
};
|
||||
// draw everything, as if there where no stencil
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd);
|
||||
return;
|
||||
}
|
||||
|
||||
proto.transform = function(parentCmd, recursive){
|
||||
var node = this._node;
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
|
||||
if(node._stencil)
|
||||
node._stencil._renderCmd.transform(this, recursive);
|
||||
};
|
||||
cc.renderer.pushRenderCommand(this._beforeVisitCmd);
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
//optimize performance for javascript
|
||||
var currentStack = cc.current_stack;
|
||||
currentStack.stack.push(currentStack.top);
|
||||
this._syncStatus(parentCmd);
|
||||
currentStack.top = this._stackMatrix;
|
||||
|
||||
if( node._parent && node._parent._renderCmd)
|
||||
this._curLevel = node._parent._renderCmd._curLevel + 1;
|
||||
//this._stencil._stackMatrix = this._stackMatrix;
|
||||
node._stencil._renderCmd.visit(this);
|
||||
|
||||
// if stencil buffer disabled
|
||||
if (cc.ClippingNode.stencilBits < 1) {
|
||||
// draw everything, as if there where no stencil
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd);
|
||||
return;
|
||||
cc.renderer.pushRenderCommand(this._afterDrawStencilCmd);
|
||||
|
||||
// draw (according to the stencil test func) this node and its children
|
||||
var locChildren = node._children;
|
||||
if (locChildren && locChildren.length > 0) {
|
||||
var childLen = locChildren.length;
|
||||
node.sortAllChildren();
|
||||
// draw children zOrder < 0
|
||||
for (var i = 0; i < childLen; i++) {
|
||||
locChildren[i]._renderCmd.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (!node._stencil || !node._stencil.visible) {
|
||||
if (node.inverted)
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd); // draw everything
|
||||
return;
|
||||
}
|
||||
cc.renderer.pushRenderCommand(this._afterVisitCmd);
|
||||
|
||||
if (cc.ClippingNode.WebGLRenderCmd._layer + 1 === cc.ClippingNode.stencilBits) {
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = true;
|
||||
if (cc.ClippingNode.WebGLRenderCmd._visit_once) {
|
||||
cc.log("Nesting more than " + cc.ClippingNode.stencilBits + "stencils is not supported. Everything will be drawn without stencil for this node and its children.");
|
||||
cc.ClippingNode.WebGLRenderCmd._visit_once = false;
|
||||
}
|
||||
// draw everything, as if there where no stencil
|
||||
_ccsg.Node.WebGLRenderCmd.prototype.visit.call(this, parentCmd);
|
||||
return;
|
||||
}
|
||||
this._dirtyFlag = 0;
|
||||
//optimize performance for javascript
|
||||
currentStack.top = currentStack.stack.pop();
|
||||
};
|
||||
|
||||
cc.renderer.pushRenderCommand(this._beforeVisitCmd);
|
||||
proto.setStencil = function(stencil){
|
||||
var node = this._node;
|
||||
if(node._stencil)
|
||||
node._stencil._parent = null;
|
||||
node._stencil = stencil;
|
||||
if(node._stencil)
|
||||
node._stencil._parent = node;
|
||||
};
|
||||
|
||||
//optimize performance for javascript
|
||||
var currentStack = cc.current_stack;
|
||||
currentStack.stack.push(currentStack.top);
|
||||
this._syncStatus(parentCmd);
|
||||
currentStack.top = this._stackMatrix;
|
||||
proto._drawFullScreenQuadClearStencil = function () {
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
var projStack = cc.math.projection_matrix_stack;
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
//cc.math.glPushMatrix();
|
||||
//cc.math.glLoadIdentity();
|
||||
projStack.push();
|
||||
projStack.top.identity();
|
||||
|
||||
//this._stencil._stackMatrix = this._stackMatrix;
|
||||
node._stencil._renderCmd.visit(this);
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
//cc.math.glPushMatrix();
|
||||
//cc.math.glLoadIdentity();
|
||||
var modelViewStack = cc.math.modelview_matrix_stack;
|
||||
modelViewStack.push();
|
||||
modelViewStack.top.identity();
|
||||
|
||||
cc.renderer.pushRenderCommand(this._afterDrawStencilCmd);
|
||||
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
|
||||
|
||||
// draw (according to the stencil test func) this node and its children
|
||||
var locChildren = node._children;
|
||||
if (locChildren && locChildren.length > 0) {
|
||||
var childLen = locChildren.length;
|
||||
node.sortAllChildren();
|
||||
// draw children zOrder < 0
|
||||
for (var i = 0; i < childLen; i++) {
|
||||
locChildren[i]._renderCmd.visit(this);
|
||||
}
|
||||
}
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
//cc.math.glPopMatrix();
|
||||
projStack.pop();
|
||||
|
||||
cc.renderer.pushRenderCommand(this._afterVisitCmd);
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
//cc.math.glPopMatrix();
|
||||
modelViewStack.pop();
|
||||
};
|
||||
|
||||
this._dirtyFlag = 0;
|
||||
//optimize performance for javascript
|
||||
currentStack.top = currentStack.stack.pop();
|
||||
};
|
||||
proto._onBeforeVisit = function(ctx){
|
||||
var gl = ctx || cc._renderContext, node = this._node;
|
||||
cc.ClippingNode.WebGLRenderCmd._layer++;
|
||||
|
||||
proto.setStencil = function(stencil){
|
||||
var node = this._node;
|
||||
if(node._stencil)
|
||||
node._stencil._parent = null;
|
||||
node._stencil = stencil;
|
||||
if(node._stencil)
|
||||
node._stencil._parent = node;
|
||||
};
|
||||
// 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);
|
||||
this._currentStencilRef = gl.getParameter(gl.STENCIL_REF);
|
||||
this._currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK);
|
||||
this._currentStencilFail = gl.getParameter(gl.STENCIL_FAIL);
|
||||
this._currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
|
||||
this._currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
|
||||
|
||||
proto._drawFullScreenQuadClearStencil = function () {
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
var projStack = cc.math.projection_matrix_stack;
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
//cc.math.glPushMatrix();
|
||||
//cc.math.glLoadIdentity();
|
||||
projStack.push();
|
||||
projStack.top.identity();
|
||||
// enable stencil use
|
||||
gl.enable(gl.STENCIL_TEST);
|
||||
gl.stencilMask(mask_layer);
|
||||
this._currentDepthWriteMask = gl.getParameter(gl.DEPTH_WRITEMASK);
|
||||
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
//cc.math.glPushMatrix();
|
||||
//cc.math.glLoadIdentity();
|
||||
var modelViewStack = cc.math.modelview_matrix_stack;
|
||||
modelViewStack.push();
|
||||
modelViewStack.top.identity();
|
||||
gl.depthMask(false);
|
||||
|
||||
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
|
||||
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
|
||||
gl.stencilOp(!node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP);
|
||||
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
//cc.math.glPopMatrix();
|
||||
projStack.pop();
|
||||
this._drawFullScreenQuadClearStencil();
|
||||
|
||||
//cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
//cc.math.glPopMatrix();
|
||||
modelViewStack.pop();
|
||||
};
|
||||
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
|
||||
gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
|
||||
|
||||
proto._onBeforeVisit = function(ctx){
|
||||
var gl = ctx || cc._renderContext, node = this._node;
|
||||
cc.ClippingNode.WebGLRenderCmd._layer++;
|
||||
if (node.alphaThreshold < 1) { //TODO desktop
|
||||
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
||||
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
|
||||
// set our alphaThreshold
|
||||
cc.gl.useProgram(program.getProgram());
|
||||
program.setUniformLocationWith1f(alphaValueLocation, node.alphaThreshold);
|
||||
setProgram(node._stencil, program);
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
this._currentStencilRef = gl.getParameter(gl.STENCIL_REF);
|
||||
this._currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK);
|
||||
this._currentStencilFail = gl.getParameter(gl.STENCIL_FAIL);
|
||||
this._currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
|
||||
this._currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
|
||||
proto._onAfterDrawStencil = function(ctx){
|
||||
var gl = ctx || cc._renderContext;
|
||||
gl.depthMask(this._currentDepthWriteMask);
|
||||
|
||||
// enable stencil use
|
||||
gl.enable(gl.STENCIL_TEST);
|
||||
gl.stencilMask(mask_layer);
|
||||
this._currentDepthWriteMask = gl.getParameter(gl.DEPTH_WRITEMASK);
|
||||
gl.stencilFunc(gl.EQUAL, this._mask_layer_le, this._mask_layer_le);
|
||||
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
};
|
||||
|
||||
gl.depthMask(false);
|
||||
proto._onAfterVisit = function(ctx){
|
||||
var gl = ctx || cc._renderContext;
|
||||
|
||||
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
|
||||
gl.stencilOp(!node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP);
|
||||
gl.stencilFunc(this._currentStencilFunc, this._currentStencilRef, this._currentStencilValueMask);
|
||||
gl.stencilOp(this._currentStencilFail, this._currentStencilPassDepthFail, this._currentStencilPassDepthPass);
|
||||
gl.stencilMask(this._currentStencilWriteMask);
|
||||
if (!this._currentStencilEnabled)
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
this._drawFullScreenQuadClearStencil();
|
||||
|
||||
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
|
||||
gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
|
||||
|
||||
if (node.alphaThreshold < 1) { //TODO desktop
|
||||
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
||||
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
|
||||
// set our alphaThreshold
|
||||
cc.glUseProgram(program.getProgram());
|
||||
program.setUniformLocationWith1f(alphaValueLocation, node.alphaThreshold);
|
||||
cc.setProgram(node._stencil, program);
|
||||
}
|
||||
};
|
||||
|
||||
proto._onAfterDrawStencil = function(ctx){
|
||||
var gl = ctx || cc._renderContext;
|
||||
gl.depthMask(this._currentDepthWriteMask);
|
||||
|
||||
gl.stencilFunc(gl.EQUAL, this._mask_layer_le, this._mask_layer_le);
|
||||
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
||||
};
|
||||
|
||||
proto._onAfterVisit = function(ctx){
|
||||
var gl = ctx || cc._renderContext;
|
||||
|
||||
gl.stencilFunc(this._currentStencilFunc, this._currentStencilRef, this._currentStencilValueMask);
|
||||
gl.stencilOp(this._currentStencilFail, this._currentStencilPassDepthFail, this._currentStencilPassDepthPass);
|
||||
gl.stencilMask(this._currentStencilWriteMask);
|
||||
if (!this._currentStencilEnabled)
|
||||
gl.disable(gl.STENCIL_TEST);
|
||||
|
||||
// we are done using this layer, decrement
|
||||
cc.ClippingNode.WebGLRenderCmd._layer--;
|
||||
};
|
||||
})();
|
||||
// we are done using this layer, decrement
|
||||
cc.ClippingNode.WebGLRenderCmd._layer--;
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ cc.Codec = {name:'Jacob__Codec'};
|
||||
* @param {Array} input Byte array
|
||||
* @returns {String} Unpacked byte string
|
||||
*/
|
||||
cc.unzip = function () {
|
||||
cc.Codec.unzip = function () {
|
||||
return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, arguments);
|
||||
};
|
||||
|
||||
@@ -23,9 +23,9 @@ cc.unzip = function () {
|
||||
* @param {String} input Byte string encoded as base64
|
||||
* @returns {String} Unpacked byte string
|
||||
*/
|
||||
cc.unzipBase64 = function () {
|
||||
cc.Codec.unzipBase64 = function () {
|
||||
var tmpInput = cc.Codec.Base64.decode.apply(cc.Codec.Base64, arguments);
|
||||
return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, [tmpInput]);
|
||||
return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, [tmpInput]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ cc.unzipBase64 = function () {
|
||||
* @param {Number} bytes Bytes per array item
|
||||
* @returns {Array} Unpacked byte array
|
||||
*/
|
||||
cc.unzipBase64AsArray = function (input, bytes) {
|
||||
cc.Codec.unzipBase64AsArray = function (input, bytes) {
|
||||
bytes = bytes || 1;
|
||||
|
||||
var dec = this.unzipBase64(input),
|
||||
@@ -54,7 +54,7 @@ cc.unzipBase64AsArray = function (input, bytes) {
|
||||
* @param {Number} bytes Bytes per array item
|
||||
* @returns {Array} Unpacked byte array
|
||||
*/
|
||||
cc.unzipAsArray = function (input, bytes) {
|
||||
cc.Codec.unzipAsArray = function (input, bytes) {
|
||||
bytes = bytes || 1;
|
||||
|
||||
var dec = this.unzip(input),
|
||||
@@ -67,16 +67,3 @@ cc.unzipAsArray = function (input, bytes) {
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
|
||||
/**
|
||||
* string to array
|
||||
* @param {String} input
|
||||
* @returns {Array} array
|
||||
*/
|
||||
cc.StringToArray = function (input) {
|
||||
var tmp = input.split(","), ar = [], i;
|
||||
for (i = 0; i < tmp.length; i++) {
|
||||
ar.push(parseInt(tmp[i]));
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
|
||||
@@ -80,16 +80,3 @@ cc.Codec.Base64.decodeAsArray = function Jacob__Codec__Base64___decodeAsArray(in
|
||||
|
||||
return ar;
|
||||
};
|
||||
|
||||
cc.uint8ArrayToUint32Array = function(uint8Arr){
|
||||
if(uint8Arr.length % 4 !== 0)
|
||||
return null;
|
||||
|
||||
var arrLen = uint8Arr.length /4;
|
||||
var retArr = window.Uint32Array? new Uint32Array(arrLen) : [];
|
||||
for(var i = 0; i < arrLen; i++){
|
||||
var offset = i * 4;
|
||||
retArr[i] = uint8Arr[offset] + uint8Arr[offset + 1] * (1 << 8) + uint8Arr[offset + 2] * (1 << 16) + uint8Arr[offset + 3] * (1<<24);
|
||||
}
|
||||
return retArr;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
require('./ZipUtils');
|
||||
require('./base64');
|
||||
require('./gzip');
|
||||
require('./zlib.min');
|
||||
Vendored
+2
-2
@@ -43,11 +43,11 @@ V.prototype.J=function(a){var c,b=this.input.length/this.c+1|0,e,f,d,g=this.inpu
|
||||
V.prototype.t=function(){var a=0,c=this.a,b=this.k,e,f=new (H?Uint8Array:Array)(this.q+(this.b-32768)),d,g,h,m;if(0===b.length)return H?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);d=0;for(g=b.length;d<g;++d){e=b[d];h=0;for(m=e.length;h<m;++h)f[a++]=e[h]}d=32768;for(g=this.b;d<g;++d)f[a++]=c[d];this.k=[];return this.buffer=f};
|
||||
V.prototype.H=function(){var a,c=this.b;H?this.B?(a=new Uint8Array(c),a.set(this.a.subarray(0,c))):a=this.a.subarray(0,c):(this.a.length>c&&(this.a.length=c),a=this.a);return this.buffer=a};function nb(a,c){var b,e;this.input=a;this.c=0;if(c||!(c={}))c.index&&(this.c=c.index),c.verify&&(this.M=c.verify);b=a[this.c++];e=a[this.c++];switch(b&15){case Ea:this.method=Ea;break;default:i(Error("unsupported compression method"))}0!==((b<<8)+e)%31&&i(Error("invalid fcheck flag:"+((b<<8)+e)%31));e&32&&i(Error("fdict flag is not supported"));this.A=new V(a,{index:this.c,bufferSize:c.bufferSize,bufferType:c.bufferType,resize:c.resize})}
|
||||
nb.prototype.p=function(){var a=this.input,c,b;c=this.A.p();this.c=this.A.c;this.M&&(b=(a[this.c++]<<24|a[this.c++]<<16|a[this.c++]<<8|a[this.c++])>>>0,b!==ba(c)&&i(Error("invalid adler-32 checksum")));return c};y("Zlib.Inflate",nb);y("Zlib.Inflate.BufferType",Ha);Ha.ADAPTIVE=Ha.C;Ha.BLOCK=Ha.D;y("Zlib.Inflate.prototype.decompress",nb.prototype.p);var ob=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];H&&new Uint16Array(ob);var pb=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258];H&&new Uint16Array(pb);var qb=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0];H&&new Uint8Array(qb);var rb=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577];H&&new Uint16Array(rb);
|
||||
var sb=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];H&&new Uint8Array(sb);var tb=new (H?Uint8Array:Array)(288),Z,ub;Z=0;for(ub=tb.length;Z<ub;++Z)tb[Z]=143>=Z?8:255>=Z?9:279>=Z?7:8;S(tb);var vb=new (H?Uint8Array:Array)(30),wb,xb;wb=0;for(xb=vb.length;wb<xb;++wb)vb[wb]=5;S(vb);var Ea=8;}).call(this);
|
||||
var sb=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];H&&new Uint8Array(sb);var tb=new (H?Uint8Array:Array)(288),Z,ub;Z=0;for(ub=tb.length;Z<ub;++Z)tb[Z]=143>=Z?8:255>=Z?9:279>=Z?7:8;S(tb);var vb=new (H?Uint8Array:Array)(30),wb,xb;wb=0;for(xb=vb.length;wb<xb;++wb)vb[wb]=5;S(vb);var Ea=8;}).call(window);
|
||||
|
||||
//add for cocos2d-html5
|
||||
var _p = window;
|
||||
_p = _p.Zlib = _p["Zlib"];
|
||||
_p = window.Zlib = _p["Zlib"];
|
||||
_p.Deflate = _p["Deflate"];
|
||||
_p.Deflate.compress = _p.Deflate["compress"];
|
||||
_p.Inflate = _p["Inflate"];
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
/*
|
||||
* @class HashElement
|
||||
* @extends cc._Class
|
||||
* @private
|
||||
* @example
|
||||
* var element = new cc.HashElement();
|
||||
*/
|
||||
cc.HashElement = cc._Class.extend(/** @lends cc.HashElement# */{
|
||||
var HashElement = cc._Class.extend(/** @lends cc.HashElement# */{
|
||||
actions:null,
|
||||
target:null, //ccobject
|
||||
actionIndex:0,
|
||||
@@ -106,7 +106,7 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
//if doesnt exists, create a hashelement and push in mpTargets
|
||||
if (!element) {
|
||||
element = new cc.HashElement();
|
||||
element = new HashElement();
|
||||
element.paused = paused;
|
||||
element.target = target;
|
||||
this._hashTargets[target.__instanceId] = element;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
var EventTarget = require('./event/event-target');
|
||||
var Class = require('./platform/_CCClass');
|
||||
var CCObject = require('./platform/CCObject');
|
||||
|
||||
cc.g_NumberOfDraws = 0;
|
||||
|
||||
@@ -820,7 +819,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* Sets the view, where everything is rendered, do not call this function.<br/>
|
||||
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.
|
||||
* @method setOpenGLView
|
||||
* @param {EGLView} openGLView
|
||||
* @param {View} openGLView
|
||||
*/
|
||||
setOpenGLView: null,
|
||||
|
||||
@@ -840,10 +839,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
setViewport: null,
|
||||
|
||||
/**
|
||||
* Get the CCEGLView, where everything is rendered.<br/>
|
||||
* Get the View, where everything is rendered.<br/>
|
||||
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.
|
||||
* @method getOpenGLView
|
||||
* @return {EGLView}
|
||||
* @return {View}
|
||||
*/
|
||||
getOpenGLView: null,
|
||||
|
||||
@@ -1205,14 +1204,14 @@ cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Update for components
|
||||
this.emit(cc.Director.EVENT_COMPONENT_UPDATE, this._deltaTime);
|
||||
// Destroy entities that have been removed recently
|
||||
CCObject._deferredDestroy();
|
||||
// Engine update with scheduler
|
||||
this.engineUpdate(this._deltaTime);
|
||||
// Late update for components
|
||||
this.emit(cc.Director.EVENT_COMPONENT_LATE_UPDATE, this._deltaTime);
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
}
|
||||
|
||||
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
|
||||
|
||||
@@ -133,7 +133,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
}
|
||||
_t._projection = projection;
|
||||
_t.emit(cc.Director.EVENT_PROJECTION_CHANGED, _t);
|
||||
cc.setProjectionMatrixDirty();
|
||||
cc.gl.setProjectionMatrixDirty();
|
||||
cc.renderer.childrenOrderDirty = true;
|
||||
};
|
||||
|
||||
@@ -253,9 +253,9 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
|
||||
_p.setAlphaBlending = function (on) {
|
||||
if (on)
|
||||
cc.glBlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
|
||||
cc.gl.blendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
|
||||
else
|
||||
cc.glBlendFunc(cc.macro.ONE, cc.macro.ZERO);
|
||||
cc.gl.blendFunc(cc.macro.ONE, cc.macro.ZERO);
|
||||
//cc.checkGLErrorDebug();
|
||||
};
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
|
||||
|
||||
@@ -114,7 +114,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
|
||||
|
||||
@@ -149,7 +149,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -204,7 +204,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -235,7 +235,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -283,7 +283,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -321,7 +321,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -360,7 +360,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
@@ -420,7 +420,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
glContext.uniform4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
****************************************************************************/
|
||||
|
||||
var EventTarget = require('./event/event-target');
|
||||
var View;
|
||||
if (!(CC_EDITOR && Editor.isCoreLevel)) {
|
||||
View = require('./platform/CCView');
|
||||
}
|
||||
|
||||
/**
|
||||
* An object to boot the game.
|
||||
@@ -259,7 +263,7 @@ var game = /** @lends cc.game# */{
|
||||
* @property view
|
||||
* @type View
|
||||
*/
|
||||
cc.view = cc.EGLView._getInstance();
|
||||
cc.view = View ? View._getInstance() : null;
|
||||
|
||||
/**
|
||||
* @property director
|
||||
|
||||
+30
-43
@@ -27,16 +27,8 @@
|
||||
* @module cc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Minimum priority level for user scheduling.
|
||||
* @property PRIORITY_NON_SYSTEM
|
||||
* @final
|
||||
* @type Number
|
||||
*/
|
||||
cc.PRIORITY_NON_SYSTEM = cc.PRIORITY_SYSTEM + 1;
|
||||
|
||||
//data structures
|
||||
/**
|
||||
/*
|
||||
* A list double-linked list used for "updates with priority"
|
||||
* @class ListEntry
|
||||
* @param {ListEntry} prev
|
||||
@@ -47,7 +39,7 @@ cc.PRIORITY_NON_SYSTEM = cc.PRIORITY_SYSTEM + 1;
|
||||
* @param {Boolean} paused
|
||||
* @param {Boolean} markedForDeletion selector will no longer be called and entry will be removed at end of the next tick
|
||||
*/
|
||||
cc.ListEntry = function (prev, next, callback, target, priority, paused, markedForDeletion) {
|
||||
var ListEntry = function (prev, next, callback, target, priority, paused, markedForDeletion) {
|
||||
this.prev = prev;
|
||||
this.next = next;
|
||||
this.callback = callback;
|
||||
@@ -56,11 +48,11 @@ cc.ListEntry = function (prev, next, callback, target, priority, paused, markedF
|
||||
this.paused = paused;
|
||||
this.markedForDeletion = markedForDeletion;
|
||||
};
|
||||
cc.ListEntry.prototype.trigger = function (dt) {
|
||||
ListEntry.prototype.trigger = function (dt) {
|
||||
this.callback.call(this.target, dt);
|
||||
};
|
||||
|
||||
/**
|
||||
/*
|
||||
* A update entry list
|
||||
* @class HashUpdateEntry
|
||||
* @param {Array} list Which list does it belong to ?
|
||||
@@ -69,7 +61,7 @@ cc.ListEntry.prototype.trigger = function (dt) {
|
||||
* @param {function} callback
|
||||
* @param {Array} hh
|
||||
*/
|
||||
cc.HashUpdateEntry = function (list, entry, target, callback, hh) {
|
||||
var HashUpdateEntry = function (list, entry, target, callback, hh) {
|
||||
this.list = list;
|
||||
this.entry = entry;
|
||||
this.target = target;
|
||||
@@ -78,7 +70,7 @@ cc.HashUpdateEntry = function (list, entry, target, callback, hh) {
|
||||
};
|
||||
|
||||
//
|
||||
/**
|
||||
/*
|
||||
* Hash Element used for "selectors with interval"
|
||||
* @class HashTimerEntry
|
||||
* @param {Array} timers
|
||||
@@ -89,7 +81,7 @@ cc.HashUpdateEntry = function (list, entry, target, callback, hh) {
|
||||
* @param {Boolean} paused
|
||||
* @param {Array} hh
|
||||
*/
|
||||
cc.HashTimerEntry = cc.hashSelectorEntry = function (timers, target, timerIndex, currentTimer, currentTimerSalvaged, paused, hh) {
|
||||
var HashTimerEntry = function (timers, target, timerIndex, currentTimer, currentTimerSalvaged, paused, hh) {
|
||||
var _t = this;
|
||||
_t.timers = timers;
|
||||
_t.target = target;
|
||||
@@ -100,20 +92,11 @@ cc.HashTimerEntry = cc.hashSelectorEntry = function (timers, target, timerIndex,
|
||||
_t.hh = hh;
|
||||
};
|
||||
|
||||
/**
|
||||
/*
|
||||
* Light weight timer
|
||||
* @class Timer
|
||||
*/
|
||||
|
||||
cc.Timer = cc._Class.extend(/** @lends cc.Timer# */{
|
||||
_scheduler: null,
|
||||
_elapsed:0.0,
|
||||
_runForever:false,
|
||||
_useDelay:false,
|
||||
_timesExecuted:0,
|
||||
_repeat:0, //0 = once, 1 is 2 x executed
|
||||
_delay:0,
|
||||
_interval:0.0,
|
||||
var Timer = cc._Class.extend({
|
||||
|
||||
getInterval : function(){return this._interval;},
|
||||
setInterval : function(interval){this._interval = interval;},
|
||||
@@ -182,9 +165,7 @@ cc.Timer = cc._Class.extend(/** @lends cc.Timer# */{
|
||||
}
|
||||
});
|
||||
|
||||
cc.TimerTargetSelector = cc.Timer.extend({
|
||||
_target: null,
|
||||
_selector: null,
|
||||
var TimerTargetSelector = Timer.extend({
|
||||
|
||||
ctor: function(){
|
||||
this._target = null;
|
||||
@@ -217,15 +198,12 @@ cc.TimerTargetSelector = cc.Timer.extend({
|
||||
|
||||
});
|
||||
|
||||
cc.TimerTargetCallback = cc.Timer.extend({
|
||||
|
||||
_target: null,
|
||||
_callback: null,
|
||||
_key: null,
|
||||
var TimerTargetCallback = Timer.extend({
|
||||
|
||||
ctor: function(){
|
||||
this._target = null;
|
||||
this._callback = null;
|
||||
this._key = null;
|
||||
},
|
||||
|
||||
initWithCallback: function(scheduler, callback, target, key, seconds, repeat, delay){
|
||||
@@ -369,7 +347,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
|
||||
|
||||
_priorityIn:function (ppList, callback, target, priority, paused) {
|
||||
var self = this,
|
||||
listElement = new cc.ListEntry(null, null, callback, target, priority, paused, false);
|
||||
listElement = new ListEntry(null, null, callback, target, priority, paused, false);
|
||||
|
||||
// empey list ?
|
||||
if (!ppList) {
|
||||
@@ -387,17 +365,17 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
|
||||
}
|
||||
|
||||
//update hash entry for quick access
|
||||
self._hashForUpdates[getTargetId(target)] = new cc.HashUpdateEntry(ppList, listElement, target, null);
|
||||
self._hashForUpdates[getTargetId(target)] = new HashUpdateEntry(ppList, listElement, target, null);
|
||||
|
||||
return ppList;
|
||||
},
|
||||
|
||||
_appendIn:function (ppList, callback, target, paused) {
|
||||
var self = this, listElement = new cc.ListEntry(null, null, callback, target, 0, paused, false);
|
||||
var self = this, listElement = new ListEntry(null, null, callback, target, 0, paused, false);
|
||||
ppList.push(listElement);
|
||||
|
||||
//update hash entry for quicker access
|
||||
self._hashForUpdates[getTargetId(target)] = new cc.HashUpdateEntry(ppList, listElement, target, null, null);
|
||||
self._hashForUpdates[getTargetId(target)] = new HashUpdateEntry(ppList, listElement, target, null, null);
|
||||
},
|
||||
|
||||
//-----------------------public method-------------------------
|
||||
@@ -585,7 +563,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
|
||||
|
||||
if(!element){
|
||||
// Is this the 1st element ? Then set the pause level to all the callback_fns of this target
|
||||
element = new cc.HashTimerEntry(null, target, 0, null, null, paused, null);
|
||||
element = new HashTimerEntry(null, target, 0, null, null, paused, null);
|
||||
this._arrayForTimers.push(element);
|
||||
this._hashForTimers[instanceId] = element;
|
||||
}else{
|
||||
@@ -617,11 +595,11 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
|
||||
}
|
||||
|
||||
if(isSelector === false){
|
||||
timer = new cc.TimerTargetCallback();
|
||||
timer = new TimerTargetCallback();
|
||||
timer.initWithCallback(this, callback, target, key, interval, repeat, delay);
|
||||
element.timers.push(timer);
|
||||
}else{
|
||||
timer = new cc.TimerTargetSelector();
|
||||
timer = new TimerTargetSelector();
|
||||
timer.initWithSelector(this, selector, target, interval, repeat, delay);
|
||||
element.timers.push(timer);
|
||||
}
|
||||
@@ -1074,10 +1052,19 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
|
||||
this.unscheduleAllWithMinPriority(minPriority);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Priority level reserved for system services.
|
||||
* @property PRIORITY_SYSTEM
|
||||
* @final
|
||||
* @type Number
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.Scheduler.PRIORITY_SYSTEM = (-2147483647 - 1);
|
||||
|
||||
/**
|
||||
* Minimum priority level for user scheduling.
|
||||
* @property PRIORITY_NON_SYSTEM
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
cc.Scheduler.PRIORITY_NON_SYSTEM = cc.Scheduler.PRIORITY_SYSTEM + 1;
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
if (this._uniformColor && this._colorF32Array) {
|
||||
context.uniform4fv(this._uniformColor, this._colorF32Array);
|
||||
this._textureAtlas.drawNumberOfQuads(node.quadsToDraw, 0);
|
||||
|
||||
@@ -32,7 +32,7 @@ cc.CustomRenderCmd = function (target, func) {
|
||||
if (!this._callback)
|
||||
return;
|
||||
this._callback.call(this._target, ctx, scaleX, scaleY);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
_ccsg.Node._dirtyFlags = {
|
||||
@@ -404,121 +404,119 @@ _ccsg.Node.RenderCmd.prototype = {
|
||||
|
||||
//-----------------------Canvas ---------------------------
|
||||
|
||||
(function() {
|
||||
//The _ccsg.Node's render command for Canvas
|
||||
_ccsg.Node.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.RenderCmd.call(this, renderable);
|
||||
this._cachedParent = null;
|
||||
this._cacheDirty = false;
|
||||
_ccsg.Node.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.RenderCmd.call(this, renderable);
|
||||
this._cachedParent = null;
|
||||
this._cacheDirty = false;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
var proto = _ccsg.Node.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
|
||||
proto.constructor = _ccsg.Node.CanvasRenderCmd;
|
||||
var proto = _ccsg.Node.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
|
||||
proto.constructor = _ccsg.Node.CanvasRenderCmd;
|
||||
|
||||
proto.transform = function (parentCmd, recursive) {
|
||||
// transform for canvas
|
||||
var t = this.getNodeToParentTransform(),
|
||||
worldT = this._worldTransform; //get the world transform
|
||||
proto.transform = function (parentCmd, recursive) {
|
||||
// transform for canvas
|
||||
var t = this.getNodeToParentTransform(),
|
||||
worldT = this._worldTransform; //get the world transform
|
||||
this._cacheDirty = true;
|
||||
if (parentCmd) {
|
||||
var pt = parentCmd._worldTransform;
|
||||
// cc.AffineTransformConcat is incorrect at get world transform
|
||||
worldT.a = t.a * pt.a + t.b * pt.c; //a
|
||||
worldT.b = t.a * pt.b + t.b * pt.d; //b
|
||||
worldT.c = t.c * pt.a + t.d * pt.c; //c
|
||||
worldT.d = t.c * pt.b + t.d * pt.d; //d
|
||||
|
||||
worldT.tx = pt.a * t.tx + pt.c * t.ty + pt.tx;
|
||||
worldT.ty = pt.d * t.ty + pt.ty + pt.b * t.tx;
|
||||
} else {
|
||||
worldT.a = t.a;
|
||||
worldT.b = t.b;
|
||||
worldT.c = t.c;
|
||||
worldT.d = t.d;
|
||||
worldT.tx = t.tx;
|
||||
worldT.ty = t.ty;
|
||||
}
|
||||
if (recursive) {
|
||||
var locChildren = this._node._children;
|
||||
if (!locChildren || locChildren.length === 0)
|
||||
return;
|
||||
var i, len;
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
locChildren[i]._renderCmd.transform(this, recursive);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
this._syncStatus(parentCmd);
|
||||
this.visitChildren();
|
||||
};
|
||||
|
||||
proto.setDirtyFlag = function (dirtyFlag, child) {
|
||||
_ccsg.Node.RenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag, child);
|
||||
this._setCacheDirty(child); //TODO it should remove from here.
|
||||
if(this._cachedParent)
|
||||
this._cachedParent.setDirtyFlag(dirtyFlag, true);
|
||||
};
|
||||
|
||||
proto._setCacheDirty = function () {
|
||||
if (this._cacheDirty === false) {
|
||||
this._cacheDirty = true;
|
||||
if (parentCmd) {
|
||||
var pt = parentCmd._worldTransform;
|
||||
// cc.AffineTransformConcat is incorrect at get world transform
|
||||
worldT.a = t.a * pt.a + t.b * pt.c; //a
|
||||
worldT.b = t.a * pt.b + t.b * pt.d; //b
|
||||
worldT.c = t.c * pt.a + t.d * pt.c; //c
|
||||
worldT.d = t.c * pt.b + t.d * pt.d; //d
|
||||
var cachedP = this._cachedParent;
|
||||
cachedP && cachedP !== this && cachedP._setNodeDirtyForCache && cachedP._setNodeDirtyForCache();
|
||||
}
|
||||
};
|
||||
|
||||
worldT.tx = pt.a * t.tx + pt.c * t.ty + pt.tx;
|
||||
worldT.ty = pt.d * t.ty + pt.ty + pt.b * t.tx;
|
||||
} else {
|
||||
worldT.a = t.a;
|
||||
worldT.b = t.b;
|
||||
worldT.c = t.c;
|
||||
worldT.d = t.d;
|
||||
worldT.tx = t.tx;
|
||||
worldT.ty = t.ty;
|
||||
}
|
||||
if (recursive) {
|
||||
var locChildren = this._node._children;
|
||||
if (!locChildren || locChildren.length === 0)
|
||||
return;
|
||||
var i, len;
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
locChildren[i]._renderCmd.transform(this, recursive);
|
||||
}
|
||||
}
|
||||
};
|
||||
proto._setCachedParent = function (cachedParent) {
|
||||
if (this._cachedParent === cachedParent)
|
||||
return;
|
||||
|
||||
proto.visit = function (parentCmd) {
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
this._cachedParent = cachedParent;
|
||||
var children = this._node._children;
|
||||
for (var i = 0, len = children.length; i < len; i++)
|
||||
children[i]._renderCmd._setCachedParent(cachedParent);
|
||||
};
|
||||
|
||||
parentCmd = parentCmd || this.getParentRenderCmd();
|
||||
if (parentCmd)
|
||||
this._curLevel = parentCmd._curLevel + 1;
|
||||
this._syncStatus(parentCmd);
|
||||
this.visitChildren();
|
||||
};
|
||||
proto.detachFromParent = function () {
|
||||
this._cachedParent = null;
|
||||
var selChildren = this._node._children, item;
|
||||
for (var i = 0, len = selChildren.length; i < len; i++) {
|
||||
item = selChildren[i];
|
||||
if (item && item._renderCmd)
|
||||
item._renderCmd.detachFromParent();
|
||||
}
|
||||
};
|
||||
|
||||
proto.setDirtyFlag = function (dirtyFlag, child) {
|
||||
_ccsg.Node.RenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag, child);
|
||||
this._setCacheDirty(child); //TODO it should remove from here.
|
||||
if(this._cachedParent)
|
||||
this._cachedParent.setDirtyFlag(dirtyFlag, true);
|
||||
};
|
||||
proto.setShaderProgram = function (shaderProgram) {
|
||||
//do nothing.
|
||||
};
|
||||
|
||||
proto._setCacheDirty = function () {
|
||||
if (this._cacheDirty === false) {
|
||||
this._cacheDirty = true;
|
||||
var cachedP = this._cachedParent;
|
||||
cachedP && cachedP !== this && cachedP._setNodeDirtyForCache && cachedP._setNodeDirtyForCache();
|
||||
}
|
||||
};
|
||||
proto.getShaderProgram = function () {
|
||||
return null;
|
||||
};
|
||||
|
||||
proto._setCachedParent = function (cachedParent) {
|
||||
if (this._cachedParent === cachedParent)
|
||||
return;
|
||||
|
||||
this._cachedParent = cachedParent;
|
||||
var children = this._node._children;
|
||||
for (var i = 0, len = children.length; i < len; i++)
|
||||
children[i]._renderCmd._setCachedParent(cachedParent);
|
||||
};
|
||||
|
||||
proto.detachFromParent = function () {
|
||||
this._cachedParent = null;
|
||||
var selChildren = this._node._children, item;
|
||||
for (var i = 0, len = selChildren.length; i < len; i++) {
|
||||
item = selChildren[i];
|
||||
if (item && item._renderCmd)
|
||||
item._renderCmd.detachFromParent();
|
||||
}
|
||||
};
|
||||
|
||||
proto.setShaderProgram = function (shaderProgram) {
|
||||
//do nothing.
|
||||
};
|
||||
|
||||
proto.getShaderProgram = function () {
|
||||
return null;
|
||||
};
|
||||
|
||||
//util functions
|
||||
_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc = function (blendFunc) {
|
||||
if (!blendFunc)
|
||||
//util functions
|
||||
_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc = function (blendFunc) {
|
||||
if (!blendFunc)
|
||||
return "source-over";
|
||||
else {
|
||||
if (( blendFunc.src === cc.macro.SRC_ALPHA && blendFunc.dst === cc.macro.ONE) || (blendFunc.src === cc.macro.ONE && blendFunc.dst === cc.macro.ONE))
|
||||
return "lighter";
|
||||
else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.SRC_ALPHA)
|
||||
return "destination-in";
|
||||
else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.ONE_MINUS_SRC_ALPHA)
|
||||
return "destination-out";
|
||||
else
|
||||
return "source-over";
|
||||
else {
|
||||
if (( blendFunc.src === cc.macro.SRC_ALPHA && blendFunc.dst === cc.macro.ONE) || (blendFunc.src === cc.macro.ONE && blendFunc.dst === cc.macro.ONE))
|
||||
return "lighter";
|
||||
else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.SRC_ALPHA)
|
||||
return "destination-in";
|
||||
else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.ONE_MINUS_SRC_ALPHA)
|
||||
return "destination-out";
|
||||
else
|
||||
return "source-over";
|
||||
}
|
||||
};
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @fileoverview Java Script Builtins for windows properties.
|
||||
*
|
||||
* @externs
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see https://cocos2d-x.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* cocos2d-html5-only.
|
||||
* @type {string}
|
||||
*/
|
||||
CSSProperties.prototype._super;
|
||||
|
||||
/**
|
||||
* cocos2d-html5-only. We need this because the cc._Class.extend's new
|
||||
* infrastructure requires it.
|
||||
* @type {string}
|
||||
*/
|
||||
CSSProperties.prototype.ctor;
|
||||
|
||||
/**
|
||||
* cocos2d-html5-only.
|
||||
* @type {string}
|
||||
*/
|
||||
CSSProperties.prototype.Inflate;
|
||||
|
||||
/**
|
||||
* cocos2d-html5-only.
|
||||
* @type {string}
|
||||
*/
|
||||
CSSProperties.prototype.decompress;
|
||||
|
||||
/**
|
||||
* Accelerometer api
|
||||
* cocos2d-html5-only.
|
||||
* @type {string}
|
||||
*/
|
||||
CSSProperties.prototype.DeviceOrientationEvent;
|
||||
CSSProperties.prototype.DeviceMotionEvent;
|
||||
CSSProperties.prototype.accelerationIncludingGravity;
|
||||
CSSProperties.prototype.gamma;
|
||||
CSSProperties.prototype.beta;
|
||||
CSSProperties.prototype.alpha;
|
||||
|
||||
|
||||
var gl = gl || {};
|
||||
CSSProperties.prototype.gl;
|
||||
|
||||
CSSProperties.prototype.AudioContext;
|
||||
CSSProperties.prototype.webkitAudioContext;
|
||||
CSSProperties.prototype.mozAudioContext;
|
||||
CSSProperties.prototype.createBufferSource;
|
||||
CSSProperties.prototype.createGain;
|
||||
CSSProperties.prototype.createGainNode;
|
||||
CSSProperties.prototype.destination;
|
||||
CSSProperties.prototype.decodeAudioData;
|
||||
CSSProperties.prototype.gain;
|
||||
CSSProperties.prototype.connect;
|
||||
CSSProperties.prototype.playbackState;
|
||||
CSSProperties.prototype.noteGrainOn;
|
||||
CSSProperties.prototype.noteOn;
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
require('./platform');
|
||||
require('./assets');
|
||||
|
||||
if (!CC_JSB) {
|
||||
require('./sprites/CCSpriteFrameCache');
|
||||
}
|
||||
|
||||
if (!CC_EDITOR || !Editor.isCoreLevel) {
|
||||
if (!CC_JSB) {
|
||||
require('./sprites/CCSpriteFrameCache');
|
||||
}
|
||||
|
||||
require('./CCNode');
|
||||
require('./CCScene');
|
||||
|
||||
|
||||
@@ -30,64 +30,63 @@
|
||||
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
_ccsg.Label.WebGLRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
var ccgl = cc.gl;
|
||||
|
||||
this._labelTexture = new cc.Texture2D();
|
||||
this._quadWebBuffer = cc._renderContext.createBuffer();
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
this._quad = new cc.V3F_C4B_T2F_Quad();
|
||||
_ccsg.Label.WebGLRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
|
||||
this._labelCanvas = document.createElement("canvas");
|
||||
this._labelTexture.initWithElement(this._labelCanvas);
|
||||
this._labelContext = this._labelCanvas.getContext("2d");
|
||||
this._labelTexture = new cc.Texture2D();
|
||||
this._quadWebBuffer = cc._renderContext.createBuffer();
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
this._quad = new cc.V3F_C4B_T2F_Quad();
|
||||
|
||||
this._labelCanvas.width = 1;
|
||||
this._labelCanvas.height = 1;
|
||||
this._quadDirty = true;
|
||||
this._splitedStrings = null;
|
||||
this._drawFontsize = 0;
|
||||
this._realRenderingSize = cc.size(-10, -10);
|
||||
};
|
||||
this._labelCanvas = document.createElement("canvas");
|
||||
this._labelTexture.initWithElement(this._labelCanvas);
|
||||
this._labelContext = this._labelCanvas.getContext("2d");
|
||||
|
||||
var proto = _ccsg.Label.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
cc.js.mixin(proto, _ccsg.Label.TTFLabelBaker.prototype);
|
||||
this._labelCanvas.width = 1;
|
||||
this._labelCanvas.height = 1;
|
||||
this._quadDirty = true;
|
||||
this._splitedStrings = null;
|
||||
this._drawFontsize = 0;
|
||||
this._realRenderingSize = cc.size(-10, -10);
|
||||
};
|
||||
|
||||
proto.constructor = _ccsg.Label.WebGLRenderCmd;
|
||||
var proto = _ccsg.Label.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
cc.js.mixin(proto, _ccsg.Label.TTFLabelBaker.prototype);
|
||||
|
||||
proto.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
this._rebuildLabelSkin();
|
||||
proto.constructor = _ccsg.Label.WebGLRenderCmd;
|
||||
|
||||
this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node);
|
||||
proto.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
this._rebuildLabelSkin();
|
||||
|
||||
if(node._labelType === _ccsg.Label.Type.TTF ||
|
||||
node._labelType === _ccsg.Label.Type.SystemFont){
|
||||
var gl = ctx || cc._renderContext ;
|
||||
this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node);
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
if(node._labelType === _ccsg.Label.Type.TTF ||
|
||||
node._labelType === _ccsg.Label.Type.SystemFont){
|
||||
var gl = ctx || cc._renderContext ;
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src,node._blendFunc.dst);
|
||||
cc.glBindTexture2DN(0,this._labelTexture);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
ccgl.blendFunc(node._blendFunc.src,node._blendFunc.dst);
|
||||
ccgl.bindTexture2DN(0,this._labelTexture);
|
||||
ccgl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
if (this._quadDirty) {
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW);
|
||||
this._quadDirty = false;
|
||||
}
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
|
||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.macro.VERTEX_ATTRIB_POSITION
|
||||
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.macro.VERTEX_ATTRIB_COLOR
|
||||
gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.macro.VERTEX_ATTRIB_TEX_COORDS
|
||||
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
if (this._quadDirty) {
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW);
|
||||
this._quadDirty = false;
|
||||
}
|
||||
|
||||
};
|
||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.macro.VERTEX_ATTRIB_POSITION
|
||||
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.macro.VERTEX_ATTRIB_COLOR
|
||||
gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.macro.VERTEX_ATTRIB_TEX_COORDS
|
||||
|
||||
})();
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -197,7 +197,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
|
||||
OffsetYArray.push(yOffset);
|
||||
}
|
||||
var tmpStatus = {
|
||||
contextTransform:cc.v2f(dx,dy),
|
||||
contextTransform:cc.v2(dx,dy),
|
||||
xOffset:xOffset,
|
||||
OffsetYArray:OffsetYArray
|
||||
};
|
||||
|
||||
@@ -81,8 +81,8 @@
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
|
||||
//
|
||||
// Attributes
|
||||
@@ -285,8 +285,8 @@
|
||||
//draw gradient layer
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
//
|
||||
// Attributes
|
||||
//
|
||||
|
||||
@@ -120,13 +120,13 @@ inputManager.didAccelerate = function (eventData) {
|
||||
mAcceleration.timestamp = eventData.timeStamp || Date.now();
|
||||
|
||||
var tmpX = mAcceleration.x;
|
||||
if(w.orientation === cc.UIOrientation.LANDSCAPE_RIGHT){
|
||||
if(w.orientation === cc.macro.WEB_ORIENTATION_LANDSCAPE_RIGHT){
|
||||
mAcceleration.x = -mAcceleration.y;
|
||||
mAcceleration.y = tmpX;
|
||||
}else if(w.orientation === cc.UIOrientation.LANDSCAPE_LEFT){
|
||||
}else if(w.orientation === cc.macro.WEB_ORIENTATION_LANDSCAPE_LEFT){
|
||||
mAcceleration.x = mAcceleration.y;
|
||||
mAcceleration.y = -tmpX;
|
||||
}else if(w.orientation === cc.UIOrientation.PORTRAIT_UPSIDE_DOWN){
|
||||
}else if(w.orientation === cc.macro.WEB_ORIENTATION_PORTRAIT_UPSIDE_DOWN){
|
||||
mAcceleration.x = -mAcceleration.x;
|
||||
mAcceleration.y = -mAcceleration.y;
|
||||
}
|
||||
|
||||
@@ -23,32 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
Enum = require("../value-types/CCEnum");
|
||||
|
||||
/**
|
||||
* Enum for UIOrientation.
|
||||
* @readOnly
|
||||
* @enum UIOrientation
|
||||
*/
|
||||
cc.UIOrientation = cc.Enum({
|
||||
/**
|
||||
* @property {number} PORTRAIT
|
||||
*/
|
||||
PORTRAIT: 0,
|
||||
/**
|
||||
* @property {number} LANDSCAPE_LEFT
|
||||
*/
|
||||
LANDSCAPE_LEFT: -90,
|
||||
/**
|
||||
* @property {number} LANDSCAPE_RIGHT
|
||||
*/
|
||||
LANDSCAPE_RIGHT: 90,
|
||||
/**
|
||||
* @property {number} PORTRAIT_UPSIDE_DOWN
|
||||
*/
|
||||
PORTRAIT_UPSIDE_DOWN: 180,
|
||||
});
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class manages all events of input. include: touch, mouse, accelerometer, keyboard <br/>
|
||||
|
||||
@@ -737,27 +737,62 @@ cc.ImageFormat = cc.Enum({
|
||||
* @static
|
||||
*/
|
||||
TIFF: 2,
|
||||
/**
|
||||
* Image Format:RAWDATA
|
||||
* @property RAWDATA
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
RAWDATA: 3,
|
||||
/**
|
||||
* Image Format:WEBP
|
||||
* @property WEBP
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
WEBP: 4,
|
||||
WEBP: 3,
|
||||
/**
|
||||
* Image Format:PVR
|
||||
* @property PVR
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
PVR: 4,
|
||||
/**
|
||||
* Image Format:ETC
|
||||
* @property ETC
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
ETC: 5,
|
||||
/**
|
||||
* Image Format:S3TC
|
||||
* @property S3TC
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
S3TC: 6,
|
||||
/**
|
||||
* Image Format:ATITC
|
||||
* @property ATITC
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
ATITC: 7,
|
||||
/**
|
||||
* Image Format:TGA
|
||||
* @property TGA
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
TGA: 8,
|
||||
/**
|
||||
* Image Format:RAWDATA
|
||||
* @property RAWDATA
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
RAWDATA: 9,
|
||||
/**
|
||||
* Image Format:UNKNOWN
|
||||
* @property UNKNOWN
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
UNKNOWN: 5
|
||||
UNKNOWN: 10
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -991,6 +1026,39 @@ cc.macro = {
|
||||
|
||||
|
||||
//Possible device orientations
|
||||
|
||||
/**
|
||||
* Device oriented vertically, home button on the bottom (UIDeviceOrientationPortrait)
|
||||
* @property WEB_ORIENTATION_PORTRAIT
|
||||
* @type {Number}
|
||||
* @readonly
|
||||
*/
|
||||
WEB_ORIENTATION_PORTRAIT: 0,
|
||||
|
||||
/**
|
||||
* Device oriented horizontally, home button on the right (UIDeviceOrientationLandscapeLeft)
|
||||
* @property WEB_ORIENTATION_LANDSCAPE_LEFT
|
||||
* @type {Number}
|
||||
* @readonly
|
||||
*/
|
||||
WEB_ORIENTATION_LANDSCAPE_LEFT: -90,
|
||||
|
||||
/**
|
||||
* Device oriented vertically, home button on the top (UIDeviceOrientationPortraitUpsideDown)
|
||||
* @property WEB_ORIENTATION_PORTRAIT_UPSIDE_DOWN
|
||||
* @type {Number}
|
||||
* @readonly
|
||||
*/
|
||||
WEB_ORIENTATION_PORTRAIT_UPSIDE_DOWN: 180,
|
||||
|
||||
/**
|
||||
* Device oriented horizontally, home button on the left (UIDeviceOrientationLandscapeRight)
|
||||
* @property WEB_ORIENTATION_LANDSCAPE_RIGHT
|
||||
* @type {Number}
|
||||
* @readonly
|
||||
*/
|
||||
WEB_ORIENTATION_LANDSCAPE_RIGHT: 90,
|
||||
|
||||
/**
|
||||
* Device oriented vertically, home button on the bottom (UIDeviceOrientationPortrait)
|
||||
* @property DEVICE_ORIENTATION_PORTRAIT
|
||||
@@ -1543,11 +1611,11 @@ cc.macro = {
|
||||
* <p>
|
||||
* If enabled, cocos2d will maintain an OpenGL state cache internally to avoid unnecessary switches. <br/>
|
||||
* In order to use them, you have to use the following functions, instead of the the GL ones: <br/>
|
||||
* - ccGLUseProgram() instead of glUseProgram() <br/>
|
||||
* - ccGLDeleteProgram() instead of glDeleteProgram() <br/>
|
||||
* - ccGLBlendFunc() instead of glBlendFunc() <br/>
|
||||
* - cc.gl.useProgram() instead of glUseProgram() <br/>
|
||||
* - cc.gl.deleteProgram() instead of glDeleteProgram() <br/>
|
||||
* - cc.gl.blendFunc() instead of glBlendFunc() <br/>
|
||||
* <br/>
|
||||
* If this functionality is disabled, then ccGLUseProgram(), ccGLDeleteProgram(), ccGLBlendFunc() will call the GL ones, without using the cache. <br/>
|
||||
* If this functionality is disabled, then cc.gl.useProgram(), cc.gl.deleteProgram(), cc.gl.blendFunc() will call the GL ones, without using the cache. <br/>
|
||||
* It is recommend to enable whenever possible to improve speed. <br/>
|
||||
* If you are migrating your code from GL ES 1.1, then keep it disabled. Once all your code works as expected, turn it on.
|
||||
* </p>
|
||||
@@ -1605,6 +1673,13 @@ cc.randomMinus1To1 = function () {
|
||||
return (Math.random() - 0.5) * 2;
|
||||
};
|
||||
|
||||
/**
|
||||
* returns a random float between 0 and 1, use Math.random directly
|
||||
* @return {Number}
|
||||
* @method random0To1
|
||||
*/
|
||||
cc.random0To1 = Math.random;
|
||||
|
||||
/**
|
||||
* converts degrees to radians
|
||||
* @param {Number} angle
|
||||
@@ -1631,7 +1706,7 @@ cc.radiansToDegrees = function (angle) {
|
||||
* @method nodeDrawSetup
|
||||
*/
|
||||
cc.nodeDrawSetup = function (node) {
|
||||
//cc.glEnable(node._glServerState);
|
||||
//cc.gl.enable(node._glServerState);
|
||||
if (node._shaderProgram) {
|
||||
//cc._renderContext.useProgram(node._shaderProgram._programObj);
|
||||
node._shaderProgram.use();
|
||||
|
||||
@@ -105,7 +105,7 @@ switch(__BrowserGetter.adaptationType){
|
||||
*
|
||||
* @class View
|
||||
*/
|
||||
cc.EGLView = cc._Class.extend({
|
||||
var View = cc._Class.extend({
|
||||
_delegate: null,
|
||||
// Size of parent node that contains cc.container and cc.game.canvas
|
||||
_frameSize: null,
|
||||
@@ -151,7 +151,7 @@ cc.EGLView = cc._Class.extend({
|
||||
_targetDensityDPI: null,
|
||||
|
||||
/**
|
||||
* Constructor of cc.EGLView
|
||||
* Constructor of View
|
||||
*/
|
||||
ctor: function () {
|
||||
var _t = this, d = document, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy;
|
||||
@@ -443,7 +443,7 @@ cc.EGLView = cc._Class.extend({
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the resolution translate on EGLView.
|
||||
* Sets the resolution translate on View.
|
||||
* @method setContentTranslateLeftTop
|
||||
* @param {Number} offsetLeft
|
||||
* @param {Number} offsetTop
|
||||
@@ -453,7 +453,7 @@ cc.EGLView = cc._Class.extend({
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the resolution translate on EGLView
|
||||
* Returns the resolution translate on View
|
||||
* @method getContentTranslateLeftTop
|
||||
* @return {Size|Object}
|
||||
*/
|
||||
@@ -881,12 +881,12 @@ cc.EGLView = cc._Class.extend({
|
||||
|
||||
/**
|
||||
* @method _getInstance
|
||||
* @return {EGLView}
|
||||
* @return {View}
|
||||
* @private
|
||||
*/
|
||||
cc.EGLView._getInstance = function () {
|
||||
View._getInstance = function () {
|
||||
if (!this._instance) {
|
||||
this._instance = this._instance || new cc.EGLView();
|
||||
this._instance = this._instance || new View();
|
||||
this._instance.initialize();
|
||||
}
|
||||
return this._instance;
|
||||
@@ -1355,3 +1355,5 @@ cc.ResolutionPolicy.FIXED_WIDTH = 4;
|
||||
* @static
|
||||
*/
|
||||
cc.ResolutionPolicy.UNKNOWN = 5;
|
||||
|
||||
module.exports = View;
|
||||
@@ -23,8 +23,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var Attr = require('./attribute');
|
||||
|
||||
// 增加预处理属性这个步骤的目的是降低 CCClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。
|
||||
|
||||
var SerializableAttrs = {
|
||||
@@ -170,16 +168,16 @@ module.exports = function (properties, className, cls) {
|
||||
};
|
||||
}
|
||||
else if (typeof val === 'function') {
|
||||
if (cc.RawAsset.isRawAssetType(val)) {
|
||||
var type = val;
|
||||
if (cc.RawAsset.isRawAssetType(type)) {
|
||||
val = {
|
||||
default: '',
|
||||
url: val
|
||||
url: type
|
||||
};
|
||||
}
|
||||
else {
|
||||
val = {
|
||||
//noinspection JSUnresolvedFunction
|
||||
default: cc.isChildClassOf(val, cc.ValueType) ? (new val()) : null,
|
||||
default: cc.isChildClassOf(type, cc.ValueType) ? (new type()) : null,
|
||||
type: val
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,289 +22,287 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function() {
|
||||
_ccsg.Sprite.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._textureCoord = {
|
||||
renderX: 0, //the x of texture coordinate for render, when texture tinted, its value doesn't equal x.
|
||||
renderY: 0, //the y of texture coordinate for render, when texture tinted, its value doesn't equal y.
|
||||
x: 0, //the x of texture coordinate for node.
|
||||
y: 0, //the y of texture coordinate for node.
|
||||
width: 0,
|
||||
height: 0,
|
||||
validRect: false
|
||||
};
|
||||
this._blendFuncStr = "source-over";
|
||||
this._colorized = false;
|
||||
|
||||
this._textureToRender = null;
|
||||
_ccsg.Sprite.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._textureCoord = {
|
||||
renderX: 0, //the x of texture coordinate for render, when texture tinted, its value doesn't equal x.
|
||||
renderY: 0, //the y of texture coordinate for render, when texture tinted, its value doesn't equal y.
|
||||
x: 0, //the x of texture coordinate for node.
|
||||
y: 0, //the y of texture coordinate for node.
|
||||
width: 0,
|
||||
height: 0,
|
||||
validRect: false
|
||||
};
|
||||
this._blendFuncStr = "source-over";
|
||||
this._colorized = false;
|
||||
|
||||
var proto = _ccsg.Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.Sprite.CanvasRenderCmd;
|
||||
this._textureToRender = null;
|
||||
};
|
||||
|
||||
proto._init = function () {};
|
||||
var proto = _ccsg.Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.Sprite.CanvasRenderCmd;
|
||||
|
||||
proto.setDirtyRecursively = function (value) {};
|
||||
proto._init = function () {};
|
||||
|
||||
proto._resetForBatchNode = function () {};
|
||||
proto.setDirtyRecursively = function (value) {};
|
||||
|
||||
proto._setTexture = function (texture) {
|
||||
var node = this._node;
|
||||
if (node._texture !== texture) {
|
||||
if (texture) {
|
||||
node._textureLoaded = texture._textureLoaded;
|
||||
}else{
|
||||
node._textureLoaded = false;
|
||||
}
|
||||
node._texture = texture;
|
||||
this._updateColor();
|
||||
}
|
||||
};
|
||||
|
||||
proto._setColorDirty = function () {
|
||||
this.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty | _ccsg.Node._dirtyFlags.opacityDirty);
|
||||
};
|
||||
|
||||
proto.isFrameDisplayed = function (frame) { //TODO there maybe has a bug
|
||||
var node = this._node;
|
||||
if (frame.getTexture() !== node._texture)
|
||||
return false;
|
||||
return cc.rectEqualToRect(frame.getRect(), node._rect);
|
||||
};
|
||||
|
||||
proto.updateBlendFunc = function (blendFunc) {
|
||||
this._blendFuncStr = _ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(blendFunc);
|
||||
};
|
||||
|
||||
proto._setBatchNodeForAddChild = function (child) {
|
||||
return true;
|
||||
};
|
||||
|
||||
proto._handleTextureForRotatedTexture = function (texture, rect, rotated, counterclockwise) {
|
||||
if (rotated && texture.isLoaded()) {
|
||||
var tempElement = texture.getHtmlElementObj();
|
||||
tempElement = _ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, rect, counterclockwise);
|
||||
var tempTexture = new cc.Texture2D();
|
||||
tempTexture.initWithElement(tempElement);
|
||||
tempTexture.handleLoadedTexture();
|
||||
texture = tempTexture;
|
||||
rect.x = rect.y = 0;
|
||||
this._node._rect = cc.rect(0, 0, rect.width, rect.height);
|
||||
}
|
||||
return texture;
|
||||
};
|
||||
|
||||
proto._checkTextureBoundary = function (texture, rect, rotated) {
|
||||
if (texture && texture.url) {
|
||||
var _x = rect.x + rect.width, _y = rect.y + rect.height;
|
||||
if (_x > texture.width)
|
||||
cc.error(cc._LogInfos.RectWidth, texture.url);
|
||||
if (_y > texture.height)
|
||||
cc.error(cc._LogInfos.RectHeight, texture.url);
|
||||
}
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var node = this._node;
|
||||
var locTextureCoord = this._textureCoord, alpha = (this._displayedOpacity / 255);
|
||||
|
||||
var texture = this._textureToRender || node._texture;
|
||||
|
||||
if ((texture && (locTextureCoord.width === 0 || locTextureCoord.height === 0|| !texture._textureLoaded)) || alpha === 0)
|
||||
return;
|
||||
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
var locX = node._offsetPosition.x, locHeight = node._rect.height, locWidth = node._rect.width,
|
||||
locY = -node._offsetPosition.y - locHeight, image;
|
||||
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.setCompositeOperation(this._blendFuncStr);
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
|
||||
if(node._flippedX || node._flippedY)
|
||||
wrapper.save();
|
||||
if (node._flippedX) {
|
||||
locX = -locX - locWidth;
|
||||
context.scale(-1, 1);
|
||||
}
|
||||
if (node._flippedY) {
|
||||
locY = node._offsetPosition.y;
|
||||
context.scale(1, -1);
|
||||
}
|
||||
|
||||
var sx, sy, sw, sh, x, y, w, h;
|
||||
if (this._colorized) {
|
||||
sx = 0;
|
||||
sy = 0;
|
||||
}else{
|
||||
sx = locTextureCoord.renderX;
|
||||
sy = locTextureCoord.renderY;
|
||||
}
|
||||
sw = locTextureCoord.width;
|
||||
sh = locTextureCoord.height;
|
||||
|
||||
x = locX * scaleX;
|
||||
y = locY * scaleY;
|
||||
w = locWidth * scaleX;
|
||||
h = locHeight * scaleY;
|
||||
proto._resetForBatchNode = function () {};
|
||||
|
||||
proto._setTexture = function (texture) {
|
||||
var node = this._node;
|
||||
if (node._texture !== texture) {
|
||||
if (texture) {
|
||||
image = texture._htmlElementObj;
|
||||
if (texture._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, texture._pattern));
|
||||
context.fillRect(x, y, w, h);
|
||||
} else {
|
||||
context.drawImage(image,
|
||||
sx, sy, sw, sh,
|
||||
x, y, w, h);
|
||||
}
|
||||
} else {
|
||||
var contentSize = node._contentSize;
|
||||
if (locTextureCoord.validRect) {
|
||||
var curColor = this._displayedColor;
|
||||
wrapper.setFillStyle("rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + ",1)");
|
||||
context.fillRect(x, y, contentSize.width * scaleX, contentSize.height * scaleY);
|
||||
}
|
||||
node._textureLoaded = texture._textureLoaded;
|
||||
}else{
|
||||
node._textureLoaded = false;
|
||||
}
|
||||
if(node._flippedX || node._flippedY)
|
||||
wrapper.restore();
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
|
||||
proto._updateColor = function(){
|
||||
var node = this._node;
|
||||
|
||||
var texture = node._texture, rect = this._textureCoord;
|
||||
var dColor = this._displayedColor;
|
||||
|
||||
if(texture){
|
||||
if(dColor.r !== 255 || dColor.g !== 255 || dColor.b !== 255){
|
||||
this._textureToRender = texture._generateColorTexture(dColor.r, dColor.g, dColor.b, rect);
|
||||
this._colorized = true;
|
||||
}else if(texture){
|
||||
this._textureToRender = texture;
|
||||
this._colorized = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.getQuad = function () {
|
||||
//throw an error. it doesn't support this function.
|
||||
return null;
|
||||
};
|
||||
|
||||
proto._updateForSetSpriteFrame = function (pNewTexture, textureLoaded){
|
||||
this._colorized = false;
|
||||
this._textureCoord.renderX = this._textureCoord.x;
|
||||
this._textureCoord.renderY = this._textureCoord.y;
|
||||
textureLoaded = textureLoaded || pNewTexture._textureLoaded;
|
||||
if (textureLoaded) {
|
||||
var curColor = this._node.getColor();
|
||||
if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255)
|
||||
this._updateColor();
|
||||
}
|
||||
};
|
||||
|
||||
proto.updateTransform = function () { //TODO need delete, because Canvas needn't
|
||||
var _t = this, node = this._node;
|
||||
|
||||
// re-calculate matrix only if it is dirty
|
||||
if (node.dirty) {
|
||||
// If it is not visible, or one of its ancestors is not visible, then do nothing:
|
||||
var locParent = node._parent;
|
||||
if (!node._visible || ( locParent && locParent !== node._batchNode && locParent._shouldBeHidden)) {
|
||||
node._shouldBeHidden = true;
|
||||
} else {
|
||||
node._shouldBeHidden = false;
|
||||
|
||||
if (!locParent || locParent === node._batchNode) {
|
||||
node._transformToBatch = _t.getNodeToParentTransform();
|
||||
} else {
|
||||
//cc.assert(_t._parent instanceof _ccsg.Sprite, "Logic error in CCSprite. Parent must be a CCSprite");
|
||||
node._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch);
|
||||
}
|
||||
}
|
||||
node._recursiveDirty = false;
|
||||
node.dirty = false;
|
||||
}
|
||||
|
||||
// recursively iterate over children
|
||||
if (node._hasChildren)
|
||||
node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
|
||||
};
|
||||
|
||||
proto._updateDisplayColor = function (parentColor) {
|
||||
_ccsg.Node.CanvasRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
|
||||
//this._updateColor();
|
||||
};
|
||||
|
||||
proto._spriteFrameLoadedCallback = function (event) {
|
||||
var node = this._node, spriteFrame = event.currentTarget;
|
||||
node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
|
||||
|
||||
node._texture = texture;
|
||||
this._updateColor();
|
||||
node.emit("load");
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
proto._textureLoadedCallback = function (event) {
|
||||
var node = this._node, sender = event.currentTarget;
|
||||
if (node._textureLoaded)
|
||||
return;
|
||||
proto._setColorDirty = function () {
|
||||
this.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty | _ccsg.Node._dirtyFlags.opacityDirty);
|
||||
};
|
||||
|
||||
node._textureLoaded = true;
|
||||
var texture = node._texture,
|
||||
locRect = node._rect;
|
||||
if (!locRect) {
|
||||
locRect = cc.rect(0, 0, sender.width, sender.height);
|
||||
} else if (cc._rectEqualToZero(locRect)) {
|
||||
locRect.width = sender.width;
|
||||
locRect.height = sender.height;
|
||||
proto.isFrameDisplayed = function (frame) { //TODO there maybe has a bug
|
||||
var node = this._node;
|
||||
if (frame.getTexture() !== node._texture)
|
||||
return false;
|
||||
return cc.rectEqualToRect(frame.getRect(), node._rect);
|
||||
};
|
||||
|
||||
proto.updateBlendFunc = function (blendFunc) {
|
||||
this._blendFuncStr = _ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(blendFunc);
|
||||
};
|
||||
|
||||
proto._setBatchNodeForAddChild = function (child) {
|
||||
return true;
|
||||
};
|
||||
|
||||
proto._handleTextureForRotatedTexture = function (texture, rect, rotated, counterclockwise) {
|
||||
if (rotated && texture.isLoaded()) {
|
||||
var tempElement = texture.getHtmlElementObj();
|
||||
tempElement = _ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, rect, counterclockwise);
|
||||
var tempTexture = new cc.Texture2D();
|
||||
tempTexture.initWithElement(tempElement);
|
||||
tempTexture.handleLoadedTexture();
|
||||
texture = tempTexture;
|
||||
rect.x = rect.y = 0;
|
||||
this._node._rect = cc.rect(0, 0, rect.width, rect.height);
|
||||
}
|
||||
return texture;
|
||||
};
|
||||
|
||||
proto._checkTextureBoundary = function (texture, rect, rotated) {
|
||||
if (texture && texture.url) {
|
||||
var _x = rect.x + rect.width, _y = rect.y + rect.height;
|
||||
if (_x > texture.width)
|
||||
cc.error(cc._LogInfos.RectWidth, texture.url);
|
||||
if (_y > texture.height)
|
||||
cc.error(cc._LogInfos.RectHeight, texture.url);
|
||||
}
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var node = this._node;
|
||||
var locTextureCoord = this._textureCoord, alpha = (this._displayedOpacity / 255);
|
||||
|
||||
var texture = this._textureToRender || node._texture;
|
||||
|
||||
if ((texture && (locTextureCoord.width === 0 || locTextureCoord.height === 0|| !texture._textureLoaded)) || alpha === 0)
|
||||
return;
|
||||
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
var locX = node._offsetPosition.x, locHeight = node._rect.height, locWidth = node._rect.width,
|
||||
locY = -node._offsetPosition.y - locHeight, image;
|
||||
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.setCompositeOperation(this._blendFuncStr);
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
|
||||
if(node._flippedX || node._flippedY)
|
||||
wrapper.save();
|
||||
if (node._flippedX) {
|
||||
locX = -locX - locWidth;
|
||||
context.scale(-1, 1);
|
||||
}
|
||||
if (node._flippedY) {
|
||||
locY = node._offsetPosition.y;
|
||||
context.scale(1, -1);
|
||||
}
|
||||
|
||||
var sx, sy, sw, sh, x, y, w, h;
|
||||
if (this._colorized) {
|
||||
sx = 0;
|
||||
sy = 0;
|
||||
}else{
|
||||
sx = locTextureCoord.renderX;
|
||||
sy = locTextureCoord.renderY;
|
||||
}
|
||||
sw = locTextureCoord.width;
|
||||
sh = locTextureCoord.height;
|
||||
|
||||
x = locX * scaleX;
|
||||
y = locY * scaleY;
|
||||
w = locWidth * scaleX;
|
||||
h = locHeight * scaleY;
|
||||
|
||||
if (texture) {
|
||||
image = texture._htmlElementObj;
|
||||
if (texture._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, texture._pattern));
|
||||
context.fillRect(x, y, w, h);
|
||||
} else {
|
||||
context.drawImage(image,
|
||||
sx, sy, sw, sh,
|
||||
x, y, w, h);
|
||||
}
|
||||
} else {
|
||||
var contentSize = node._contentSize;
|
||||
if (locTextureCoord.validRect) {
|
||||
var curColor = this._displayedColor;
|
||||
wrapper.setFillStyle("rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + ",1)");
|
||||
context.fillRect(x, y, contentSize.width * scaleX, contentSize.height * scaleY);
|
||||
}
|
||||
}
|
||||
if(node._flippedX || node._flippedY)
|
||||
wrapper.restore();
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
|
||||
node.texture = sender;
|
||||
node.setTextureRect(locRect, node._rectRotated);
|
||||
proto._updateColor = function(){
|
||||
var node = this._node;
|
||||
|
||||
//set the texture's color after the it loaded
|
||||
var locColor = this._displayedColor;
|
||||
if (locColor.r !== 255 || locColor.g !== 255 || locColor.b !== 255)
|
||||
var texture = node._texture, rect = this._textureCoord;
|
||||
var dColor = this._displayedColor;
|
||||
|
||||
if(texture){
|
||||
if(dColor.r !== 255 || dColor.g !== 255 || dColor.b !== 255){
|
||||
this._textureToRender = texture._generateColorTexture(dColor.r, dColor.g, dColor.b, rect);
|
||||
this._colorized = true;
|
||||
}else if(texture){
|
||||
this._textureToRender = texture;
|
||||
this._colorized = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.getQuad = function () {
|
||||
//throw an error. it doesn't support this function.
|
||||
return null;
|
||||
};
|
||||
|
||||
proto._updateForSetSpriteFrame = function (pNewTexture, textureLoaded){
|
||||
this._colorized = false;
|
||||
this._textureCoord.renderX = this._textureCoord.x;
|
||||
this._textureCoord.renderY = this._textureCoord.y;
|
||||
textureLoaded = textureLoaded || pNewTexture._textureLoaded;
|
||||
if (textureLoaded) {
|
||||
var curColor = this._node.getColor();
|
||||
if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255)
|
||||
this._updateColor();
|
||||
}
|
||||
};
|
||||
|
||||
// by default use "Self Render".
|
||||
// if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
|
||||
node.setBatchNode(node._batchNode);
|
||||
node.emit("load");
|
||||
};
|
||||
proto.updateTransform = function () { //TODO need delete, because Canvas needn't
|
||||
var _t = this, node = this._node;
|
||||
|
||||
proto._setTextureCoords = function (rect) {
|
||||
var locTextureRect = this._textureCoord;
|
||||
locTextureRect.renderX = locTextureRect.x = 0 | rect.x;
|
||||
locTextureRect.renderY = locTextureRect.y = 0 | rect.y;
|
||||
locTextureRect.width = 0 | rect.width;
|
||||
locTextureRect.height = 0 | rect.height;
|
||||
locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0);
|
||||
};
|
||||
// re-calculate matrix only if it is dirty
|
||||
if (node.dirty) {
|
||||
// If it is not visible, or one of its ancestors is not visible, then do nothing:
|
||||
var locParent = node._parent;
|
||||
if (!node._visible || ( locParent && locParent !== node._batchNode && locParent._shouldBeHidden)) {
|
||||
node._shouldBeHidden = true;
|
||||
} else {
|
||||
node._shouldBeHidden = false;
|
||||
|
||||
_ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas = function (texture, rect, counterclockwise) {
|
||||
if (!texture)
|
||||
return null;
|
||||
if (!locParent || locParent === node._batchNode) {
|
||||
node._transformToBatch = _t.getNodeToParentTransform();
|
||||
} else {
|
||||
//cc.assert(_t._parent instanceof _ccsg.Sprite, "Logic error in CCSprite. Parent must be a CCSprite");
|
||||
node._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch);
|
||||
}
|
||||
}
|
||||
node._recursiveDirty = false;
|
||||
node.dirty = false;
|
||||
}
|
||||
|
||||
if (!rect)
|
||||
return texture;
|
||||
// recursively iterate over children
|
||||
if (node._hasChildren)
|
||||
node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
|
||||
};
|
||||
|
||||
counterclockwise = counterclockwise == null? true: counterclockwise; // texture package is counterclockwise, spine is clockwise
|
||||
proto._updateDisplayColor = function (parentColor) {
|
||||
_ccsg.Node.CanvasRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
|
||||
//this._updateColor();
|
||||
};
|
||||
|
||||
var nCanvas = document.createElement("canvas");
|
||||
nCanvas.width = rect.width;
|
||||
nCanvas.height = rect.height;
|
||||
var ctx = nCanvas.getContext("2d");
|
||||
ctx.translate(nCanvas.width / 2, nCanvas.height / 2);
|
||||
if(counterclockwise)
|
||||
ctx.rotate(-1.5707963267948966);
|
||||
else
|
||||
ctx.rotate(1.5707963267948966);
|
||||
ctx.drawImage(texture, rect.x, rect.y, rect.height, rect.width, -rect.height / 2, -rect.width / 2, rect.height, rect.width);
|
||||
return nCanvas;
|
||||
};
|
||||
})();
|
||||
proto._spriteFrameLoadedCallback = function (event) {
|
||||
var node = this._node, spriteFrame = event.currentTarget;
|
||||
node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
|
||||
|
||||
this._updateColor();
|
||||
node.emit("load");
|
||||
};
|
||||
|
||||
proto._textureLoadedCallback = function (event) {
|
||||
var node = this._node, sender = event.currentTarget;
|
||||
if (node._textureLoaded)
|
||||
return;
|
||||
|
||||
node._textureLoaded = true;
|
||||
var texture = node._texture,
|
||||
locRect = node._rect;
|
||||
if (!locRect) {
|
||||
locRect = cc.rect(0, 0, sender.width, sender.height);
|
||||
} else if (cc._rectEqualToZero(locRect)) {
|
||||
locRect.width = sender.width;
|
||||
locRect.height = sender.height;
|
||||
}
|
||||
|
||||
node.texture = sender;
|
||||
node.setTextureRect(locRect, node._rectRotated);
|
||||
|
||||
//set the texture's color after the it loaded
|
||||
var locColor = this._displayedColor;
|
||||
if (locColor.r !== 255 || locColor.g !== 255 || locColor.b !== 255)
|
||||
this._updateColor();
|
||||
|
||||
// by default use "Self Render".
|
||||
// if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
|
||||
node.setBatchNode(node._batchNode);
|
||||
node.emit("load");
|
||||
};
|
||||
|
||||
proto._setTextureCoords = function (rect) {
|
||||
var locTextureRect = this._textureCoord;
|
||||
locTextureRect.renderX = locTextureRect.x = 0 | rect.x;
|
||||
locTextureRect.renderY = locTextureRect.y = 0 | rect.y;
|
||||
locTextureRect.width = 0 | rect.width;
|
||||
locTextureRect.height = 0 | rect.height;
|
||||
locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0);
|
||||
};
|
||||
|
||||
_ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas = function (texture, rect, counterclockwise) {
|
||||
if (!texture)
|
||||
return null;
|
||||
|
||||
if (!rect)
|
||||
return texture;
|
||||
|
||||
counterclockwise = counterclockwise == null? true: counterclockwise; // texture package is counterclockwise, spine is clockwise
|
||||
|
||||
var nCanvas = document.createElement("canvas");
|
||||
nCanvas.width = rect.width;
|
||||
nCanvas.height = rect.height;
|
||||
var ctx = nCanvas.getContext("2d");
|
||||
ctx.translate(nCanvas.width / 2, nCanvas.height / 2);
|
||||
if(counterclockwise)
|
||||
ctx.rotate(-1.5707963267948966);
|
||||
else
|
||||
ctx.rotate(1.5707963267948966);
|
||||
ctx.drawImage(texture, rect.x, rect.y, rect.height, rect.width, -rect.height / 2, -rect.width / 2, rect.height, rect.width);
|
||||
return nCanvas;
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
var macro = cc.macro;
|
||||
var ccgl = cc.gl;
|
||||
|
||||
//Sprite's WebGL render command
|
||||
_ccsg.Sprite.WebGLRenderCmd = function (renderable) {
|
||||
@@ -434,10 +435,10 @@ proto.rendering = function (ctx) {
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
//optimize performance for javascript
|
||||
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
ccgl.bindTexture2DN(0, locTexture); // = cc.gl.bindTexture2D(locTexture);
|
||||
ccgl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
if (this._quadDirty) {
|
||||
@@ -453,10 +454,10 @@ proto.rendering = function (ctx) {
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.glBindTexture2D(null);
|
||||
ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
ccgl.bindTexture2D(null);
|
||||
|
||||
cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION | macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
ccgl.enableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION | macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
if (this._quadDirty) {
|
||||
|
||||
@@ -22,97 +22,129 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function() {
|
||||
cc.Scale9Sprite.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._state = cc.Scale9Sprite.state.NORMAL;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
cc.Scale9Sprite.CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._state = cc.Scale9Sprite.state.NORMAL;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
|
||||
var proto = cc.Scale9Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.Scale9Sprite.CanvasRenderCmd;
|
||||
var proto = cc.Scale9Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.Scale9Sprite.CanvasRenderCmd;
|
||||
|
||||
proto._updateDisplayOpacity = function(parentOpacity){
|
||||
_ccsg.Node.WebGLRenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity);
|
||||
var node = this._node;
|
||||
};
|
||||
proto._updateDisplayOpacity = function(parentOpacity){
|
||||
_ccsg.Node.WebGLRenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity);
|
||||
var node = this._node;
|
||||
};
|
||||
|
||||
proto._updateDisplayColor = function(parentColor){
|
||||
_ccsg.Node.WebGLRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
|
||||
var node = this._node;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
proto._updateDisplayColor = function(parentColor){
|
||||
_ccsg.Node.WebGLRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
|
||||
var node = this._node;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
|
||||
proto.setState = function(state){
|
||||
if(this._state === state) return;
|
||||
proto.setState = function(state){
|
||||
if(this._state === state) return;
|
||||
|
||||
this._state = state;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
this._state = state;
|
||||
this._originalTexture = this._textureToRender = null;
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var node = this._node;
|
||||
var locDisplayOpacity = this._displayedOpacity;
|
||||
var alpha = locDisplayOpacity/ 255;
|
||||
var locTexture = null;
|
||||
if(node._spriteFrame) locTexture = node._spriteFrame._texture;
|
||||
if (!node.loaded() || locDisplayOpacity === 0)
|
||||
return;
|
||||
if(this._textureToRender === null || this._originalTexture !== locTexture){
|
||||
this._textureToRender = this._originalTexture = locTexture;
|
||||
if (cc.Scale9Sprite.state.GRAY === this._state) {
|
||||
this._textureToRender = this._textureToRender._generateGrayTexture();
|
||||
}
|
||||
var color = node.getDisplayedColor();
|
||||
if(locTexture && (color.r !== 255 || color.g !==255 || color.b !== 255))
|
||||
this._textureToRender = this._textureToRender._generateColorTexture(color.r,color.g,color.b);
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var node = this._node;
|
||||
var locDisplayOpacity = this._displayedOpacity;
|
||||
var alpha = locDisplayOpacity/ 255;
|
||||
var locTexture = null;
|
||||
if(node._spriteFrame) locTexture = node._spriteFrame._texture;
|
||||
if (!node.loaded() || locDisplayOpacity === 0)
|
||||
return;
|
||||
if(this._textureToRender === null || this._originalTexture !== locTexture){
|
||||
this._textureToRender = this._originalTexture = locTexture;
|
||||
if (cc.Scale9Sprite.state.GRAY === this._state) {
|
||||
this._textureToRender = this._textureToRender._generateGrayTexture();
|
||||
}
|
||||
var color = node.getDisplayedColor();
|
||||
if(locTexture && (color.r !== 255 || color.g !==255 || color.b !== 255))
|
||||
this._textureToRender = this._textureToRender._generateColorTexture(color.r,color.g,color.b);
|
||||
}
|
||||
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc));
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc));
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
|
||||
if(this._textureToRender) {
|
||||
if(node._quadsDirty){
|
||||
node._rebuildQuads();
|
||||
if(this._textureToRender) {
|
||||
if(node._quadsDirty){
|
||||
node._rebuildQuads();
|
||||
}
|
||||
var sx,sy,sw,sh;
|
||||
var x, y, w,h;
|
||||
var textureWidth = this._textureToRender.getPixelWidth();
|
||||
var textureHeight = this._textureToRender.getPixelHeight();
|
||||
var image = this._textureToRender._htmlElementObj;
|
||||
|
||||
if(node._isTriangle) {
|
||||
var rawQuad = node._rawQuad;
|
||||
x = rawQuad._bl.vertices.x;
|
||||
y = rawQuad._bl.vertices.y;
|
||||
w = rawQuad._tr.vertices.x - rawQuad._bl.vertices.x;
|
||||
h = rawQuad._tr.vertices.y - rawQuad._bl.vertices.y;
|
||||
y = - y - h;
|
||||
|
||||
sx = rawQuad._tl.texCoords.u * textureWidth;
|
||||
sy = rawQuad._tl.texCoords.v * textureHeight;
|
||||
sw = (rawQuad._tr.texCoords.u - rawQuad._bl.texCoords.u) * textureWidth;
|
||||
sh = (rawQuad._bl.texCoords.v - rawQuad._tr.texCoords.v) * textureHeight;
|
||||
|
||||
x = x * scaleX;
|
||||
y = y * scaleY;
|
||||
w = w * scaleX;
|
||||
h = h * scaleY;
|
||||
|
||||
wrapper.save();
|
||||
context.beginPath();
|
||||
|
||||
var quads = node._quads;
|
||||
for( var i = 0; i < quads.length; ++i) {
|
||||
context.moveTo(quads[i]._tl.vertices.x * scaleX, -quads[i]._tl.vertices.y * scaleY);
|
||||
context.lineTo(quads[i]._bl.vertices.x * scaleX, -quads[i]._bl.vertices.y * scaleY);
|
||||
context.lineTo(quads[i]._tr.vertices.x * scaleX, -quads[i]._tr.vertices.y * scaleY);
|
||||
}
|
||||
var sx,sy,sw,sh;
|
||||
var x, y, w,h;
|
||||
var textureWidth = this._textureToRender.getPixelWidth();
|
||||
var textureHeight = this._textureToRender.getPixelHeight();
|
||||
var image = this._textureToRender._htmlElementObj;
|
||||
|
||||
if(node._isTriangle) {
|
||||
var rawQuad = node._rawQuad;
|
||||
x = rawQuad._bl.vertices.x;
|
||||
y = rawQuad._bl.vertices.y;
|
||||
w = rawQuad._tr.vertices.x - rawQuad._bl.vertices.x;
|
||||
h = rawQuad._tr.vertices.y - rawQuad._bl.vertices.y;
|
||||
context.clip();
|
||||
if (this._textureToRender._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
|
||||
context.fillRect(x, y, w, h);
|
||||
} else {
|
||||
if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
|
||||
context.drawImage(image,
|
||||
sx, sy, sw, sh,
|
||||
x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.restore();
|
||||
|
||||
} else {
|
||||
var quads = node._quads;
|
||||
for( var i = 0; i < quads.length; ++i)
|
||||
{
|
||||
x = quads[i]._bl.vertices.x;
|
||||
y = quads[i]._bl.vertices.y;
|
||||
w = quads[i]._tr.vertices.x - quads[i]._bl.vertices.x;
|
||||
h = quads[i]._tr.vertices.y - quads[i]._bl.vertices.y;
|
||||
y = - y - h;
|
||||
|
||||
sx = rawQuad._tl.texCoords.u * textureWidth;
|
||||
sy = rawQuad._tl.texCoords.v * textureHeight;
|
||||
sw = (rawQuad._tr.texCoords.u - rawQuad._bl.texCoords.u) * textureWidth;
|
||||
sh = (rawQuad._bl.texCoords.v - rawQuad._tr.texCoords.v) * textureHeight;
|
||||
sx = quads[i]._tl.texCoords.u * textureWidth;
|
||||
sy = quads[i]._tl.texCoords.v * textureHeight;
|
||||
sw = (quads[i]._tr.texCoords.u - quads[i]._bl.texCoords.u) * textureWidth;
|
||||
sh = (quads[i]._bl.texCoords.v - quads[i]._tr.texCoords.v) * textureHeight;
|
||||
|
||||
x = x * scaleX;
|
||||
y = y * scaleY;
|
||||
w = w * scaleX;
|
||||
h = h * scaleY;
|
||||
|
||||
wrapper.save();
|
||||
context.beginPath();
|
||||
|
||||
var quads = node._quads;
|
||||
for( var i = 0; i < quads.length; ++i) {
|
||||
context.moveTo(quads[i]._tl.vertices.x * scaleX, -quads[i]._tl.vertices.y * scaleY);
|
||||
context.lineTo(quads[i]._bl.vertices.x * scaleX, -quads[i]._bl.vertices.y * scaleY);
|
||||
context.lineTo(quads[i]._tr.vertices.x * scaleX, -quads[i]._tr.vertices.y * scaleY);
|
||||
}
|
||||
|
||||
context.clip();
|
||||
if (this._textureToRender._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
|
||||
context.fillRect(x, y, w, h);
|
||||
@@ -123,43 +155,9 @@
|
||||
x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.restore();
|
||||
|
||||
} else {
|
||||
var quads = node._quads;
|
||||
for( var i = 0; i < quads.length; ++i)
|
||||
{
|
||||
x = quads[i]._bl.vertices.x;
|
||||
y = quads[i]._bl.vertices.y;
|
||||
w = quads[i]._tr.vertices.x - quads[i]._bl.vertices.x;
|
||||
h = quads[i]._tr.vertices.y - quads[i]._bl.vertices.y;
|
||||
y = - y - h;
|
||||
|
||||
sx = quads[i]._tl.texCoords.u * textureWidth;
|
||||
sy = quads[i]._tl.texCoords.v * textureHeight;
|
||||
sw = (quads[i]._tr.texCoords.u - quads[i]._bl.texCoords.u) * textureWidth;
|
||||
sh = (quads[i]._bl.texCoords.v - quads[i]._tr.texCoords.v) * textureHeight;
|
||||
|
||||
x = x * scaleX;
|
||||
y = y * scaleY;
|
||||
w = w * scaleX;
|
||||
h = h * scaleY;
|
||||
|
||||
if (this._textureToRender._pattern !== "") {
|
||||
wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
|
||||
context.fillRect(x, y, w, h);
|
||||
} else {
|
||||
if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
|
||||
context.drawImage(image,
|
||||
sx, sy, sw, sh,
|
||||
x, y, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cc.g_NumberOfDraws += quads.length;
|
||||
}
|
||||
})();
|
||||
|
||||
}
|
||||
}
|
||||
cc.g_NumberOfDraws += quads.length;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
(function() {
|
||||
if(!_ccsg.Node.WebGLRenderCmd)
|
||||
return;
|
||||
|
||||
var ccgl = cc.gl;
|
||||
|
||||
if (_ccsg.Node.WebGLRenderCmd) {
|
||||
cc.Scale9Sprite.WebGLRenderCmd = function (renderable) {
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
@@ -62,10 +63,10 @@
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
//optimize performance for javascript
|
||||
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
ccgl.bindTexture2DN(0, locTexture); // = cc.gl.bindTexture2D(locTexture);
|
||||
ccgl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
|
||||
@@ -150,4 +151,4 @@
|
||||
+ " gl_FragColor.xyz = vec3(0.2126*c.r + 0.7152*c.g + 0.0722*c.b); \n"
|
||||
+" gl_FragColor.w = c.w ; \n"
|
||||
+ "}";
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -22,79 +22,78 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
//SpriteBatchNode's canvas render command
|
||||
cc.SpriteBatchNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
//SpriteBatchNode's canvas render command
|
||||
cc.SpriteBatchNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
|
||||
this._texture = null;
|
||||
this._textureToRender = null;
|
||||
};
|
||||
this._texture = null;
|
||||
this._textureToRender = null;
|
||||
};
|
||||
|
||||
var proto = cc.SpriteBatchNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.SpriteBatchNode.CanvasRenderCmd;
|
||||
var proto = cc.SpriteBatchNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.SpriteBatchNode.CanvasRenderCmd;
|
||||
|
||||
proto.checkAtlasCapacity = function(){};
|
||||
proto.checkAtlasCapacity = function(){};
|
||||
|
||||
proto.isValidChild = function(child){
|
||||
if (!(child instanceof _ccsg.Sprite)) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_4);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.initWithTexture = function(texture, capacity){
|
||||
this._textureToRender = this._texture = texture;
|
||||
};
|
||||
|
||||
proto.insertQuad = function(sprite, index){};
|
||||
|
||||
proto.increaseAtlasCapacity = function(){};
|
||||
|
||||
proto.removeQuadAtIndex = function(){};
|
||||
|
||||
proto.removeAllQuads = function(){};
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._texture;
|
||||
};
|
||||
|
||||
proto.setTexture = function(texture){
|
||||
this._texture = texture;
|
||||
var locChildren = this._node._children;
|
||||
for (var i = 0; i < locChildren.length; i++)
|
||||
locChildren[i].setTexture(texture);
|
||||
};
|
||||
|
||||
proto.updateChildrenAtlasIndex = function(children){
|
||||
this._node._descendants.length = 0;
|
||||
//update _descendants after sortAllChildren
|
||||
for (var i = 0, len = children.length; i < len; i++)
|
||||
this._updateAtlasIndex(children[i]);
|
||||
};
|
||||
|
||||
proto._updateAtlasIndex = function (sprite) {
|
||||
var locDescendants = this._node._descendants;
|
||||
var pArray = sprite.children, i, len = pArray.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (pArray[i]._localZOrder < 0) {
|
||||
locDescendants.push(pArray[i]);
|
||||
} else
|
||||
break
|
||||
}
|
||||
locDescendants.push(sprite);
|
||||
for (; i < len; i++) {
|
||||
locDescendants.push(pArray[i]);
|
||||
}
|
||||
};
|
||||
|
||||
proto.getTextureAtlas = function(){};
|
||||
|
||||
proto.setTextureAtlas = function(textureAtlas){};
|
||||
|
||||
proto.cutting = function(sprite, index){
|
||||
var node = this._node;
|
||||
node._children.splice(index, 0, sprite);
|
||||
proto.isValidChild = function(child){
|
||||
if (!(child instanceof _ccsg.Sprite)) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_4);
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.initWithTexture = function(texture, capacity){
|
||||
this._textureToRender = this._texture = texture;
|
||||
};
|
||||
|
||||
proto.insertQuad = function(sprite, index){};
|
||||
|
||||
proto.increaseAtlasCapacity = function(){};
|
||||
|
||||
proto.removeQuadAtIndex = function(){};
|
||||
|
||||
proto.removeAllQuads = function(){};
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._texture;
|
||||
};
|
||||
|
||||
proto.setTexture = function(texture){
|
||||
this._texture = texture;
|
||||
var locChildren = this._node._children;
|
||||
for (var i = 0; i < locChildren.length; i++)
|
||||
locChildren[i].setTexture(texture);
|
||||
};
|
||||
|
||||
proto.updateChildrenAtlasIndex = function(children){
|
||||
this._node._descendants.length = 0;
|
||||
//update _descendants after sortAllChildren
|
||||
for (var i = 0, len = children.length; i < len; i++)
|
||||
this._updateAtlasIndex(children[i]);
|
||||
};
|
||||
|
||||
proto._updateAtlasIndex = function (sprite) {
|
||||
var locDescendants = this._node._descendants;
|
||||
var pArray = sprite.children, i, len = pArray.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (pArray[i]._localZOrder < 0) {
|
||||
locDescendants.push(pArray[i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
locDescendants.push(sprite);
|
||||
for (; i < len; i++) {
|
||||
locDescendants.push(pArray[i]);
|
||||
}
|
||||
};
|
||||
|
||||
proto.getTextureAtlas = function(){};
|
||||
|
||||
proto.setTextureAtlas = function(textureAtlas){};
|
||||
|
||||
proto.cutting = function(sprite, index){
|
||||
var node = this._node;
|
||||
node._children.splice(index, 0, sprite);
|
||||
};
|
||||
@@ -22,185 +22,170 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
//SpriteBatchNode's WebGL render command
|
||||
cc.SpriteBatchNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
//SpriteBatchNode's WebGL render command
|
||||
cc.SpriteBatchNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
|
||||
this._textureAtlas = null;
|
||||
};
|
||||
this._textureAtlas = null;
|
||||
};
|
||||
|
||||
var proto = cc.SpriteBatchNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.SpriteBatchNode.WebGLRenderCmd;
|
||||
var proto = cc.SpriteBatchNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.SpriteBatchNode.WebGLRenderCmd;
|
||||
|
||||
proto.isValidChild = function(child){
|
||||
if (!(child instanceof _ccsg.Sprite)) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_4);
|
||||
return false;
|
||||
}
|
||||
if (child.texture != this.getTexture()) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_5);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
proto.isValidChild = function(child){
|
||||
if (!(child instanceof _ccsg.Sprite)) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_4);
|
||||
return false;
|
||||
}
|
||||
if (child.texture != this.getTexture()) {
|
||||
cc.log(cc._LogInfos.Sprite.addChild_5);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.rendering = function () {
|
||||
var node = this._node;
|
||||
if (this._textureAtlas.totalQuads === 0)
|
||||
return;
|
||||
proto.rendering = function () {
|
||||
var node = this._node;
|
||||
if (this._textureAtlas.totalQuads === 0)
|
||||
return;
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
|
||||
this._textureAtlas.drawQuads();
|
||||
};
|
||||
this._textureAtlas.drawQuads();
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// quick return if not visible
|
||||
if (!node._visible)
|
||||
return;
|
||||
|
||||
if (node._parent && node._parent._renderCmd)
|
||||
this._curLevel = node._parent._renderCmd._curLevel + 1;
|
||||
if (node._parent && node._parent._renderCmd)
|
||||
this._curLevel = node._parent._renderCmd._curLevel + 1;
|
||||
|
||||
var currentStack = cc.current_stack;
|
||||
var currentStack = cc.current_stack;
|
||||
|
||||
//optimize performance for javascript
|
||||
currentStack.stack.push(currentStack.top);
|
||||
//optimize performance for javascript
|
||||
currentStack.stack.push(currentStack.top);
|
||||
|
||||
if(!(this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty)) //batchNode's transform must update in visit
|
||||
this.transform(parentCmd);
|
||||
this.updateStatus(parentCmd); //because batchNode doesn't visit its children.
|
||||
currentStack.top = this._stackMatrix;
|
||||
if(!(this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty)) //batchNode's transform must update in visit
|
||||
this.transform(parentCmd);
|
||||
this.updateStatus(parentCmd); //because batchNode doesn't visit its children.
|
||||
currentStack.top = this._stackMatrix;
|
||||
|
||||
node.sortAllChildren();
|
||||
node.sortAllChildren();
|
||||
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
|
||||
this._dirtyFlag = 0;
|
||||
//optimize performance for javascript
|
||||
currentStack.top = currentStack.stack.pop();
|
||||
};
|
||||
this._dirtyFlag = 0;
|
||||
//optimize performance for javascript
|
||||
currentStack.top = currentStack.stack.pop();
|
||||
};
|
||||
|
||||
proto.checkAtlasCapacity = function(index){
|
||||
// make needed room
|
||||
var locAtlas = this._textureAtlas;
|
||||
while (index >= locAtlas.capacity || locAtlas.capacity === locAtlas.totalQuads) {
|
||||
this.increaseAtlasCapacity();
|
||||
}
|
||||
};
|
||||
proto.checkAtlasCapacity = function(index){
|
||||
// make needed room
|
||||
var locAtlas = this._textureAtlas;
|
||||
while (index >= locAtlas.capacity || locAtlas.capacity === locAtlas.totalQuads) {
|
||||
this.increaseAtlasCapacity();
|
||||
}
|
||||
};
|
||||
|
||||
proto.increaseAtlasCapacity = function(){
|
||||
// if we're going beyond the current TextureAtlas's capacity,
|
||||
// all the previously initialized sprites will need to redo their texture coords
|
||||
// this is likely computationally expensive
|
||||
var locCapacity = this._textureAtlas.capacity;
|
||||
var quantity = Math.floor((locCapacity + 1) * 4 / 3);
|
||||
proto.increaseAtlasCapacity = function(){
|
||||
// if we're going beyond the current TextureAtlas's capacity,
|
||||
// all the previously initialized sprites will need to redo their texture coords
|
||||
// this is likely computationally expensive
|
||||
var locCapacity = this._textureAtlas.capacity;
|
||||
var quantity = Math.floor((locCapacity + 1) * 4 / 3);
|
||||
|
||||
cc.log(cc._LogInfos.SpriteBatchNode.increaseAtlasCapacity, locCapacity, quantity);
|
||||
cc.log(cc._LogInfos.SpriteBatchNode.increaseAtlasCapacity, locCapacity, quantity);
|
||||
|
||||
if (!this._textureAtlas.resizeCapacity(quantity)) {
|
||||
// serious problems
|
||||
cc.log(cc._LogInfos.SpriteBatchNode.increaseAtlasCapacity_2);
|
||||
}
|
||||
};
|
||||
if (!this._textureAtlas.resizeCapacity(quantity)) {
|
||||
// serious problems
|
||||
cc.log(cc._LogInfos.SpriteBatchNode.increaseAtlasCapacity_2);
|
||||
}
|
||||
};
|
||||
|
||||
proto.initWithTexture = function(texture, capacity){
|
||||
this._textureAtlas = new cc.TextureAtlas();
|
||||
this._textureAtlas.initWithTexture(texture, capacity);
|
||||
proto.initWithTexture = function(texture, capacity){
|
||||
this._textureAtlas = new cc.TextureAtlas();
|
||||
this._textureAtlas.initWithTexture(texture, capacity);
|
||||
this._updateBlendFunc();
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
|
||||
proto.insertQuad = function(sprite, index){
|
||||
var locTextureAtlas = this._textureAtlas;
|
||||
if (locTextureAtlas.totalQuads >= locTextureAtlas.capacity)
|
||||
this.increaseAtlasCapacity();
|
||||
locTextureAtlas.insertQuad(sprite.quad, index);
|
||||
};
|
||||
|
||||
proto.removeQuadAtIndex = function(index){
|
||||
this._textureAtlas.removeQuadAtIndex(index); // remove from TextureAtlas
|
||||
};
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._textureAtlas.texture;
|
||||
};
|
||||
|
||||
proto.setTexture = function(texture){
|
||||
this._textureAtlas.setTexture(texture);
|
||||
if(texture)
|
||||
this._updateBlendFunc();
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
};
|
||||
|
||||
proto.insertQuad = function(sprite, index){
|
||||
var locTextureAtlas = this._textureAtlas;
|
||||
if (locTextureAtlas.totalQuads >= locTextureAtlas.capacity)
|
||||
this.increaseAtlasCapacity();
|
||||
locTextureAtlas.insertQuad(sprite.quad, index);
|
||||
};
|
||||
proto.removeAllQuads = function(){
|
||||
this._textureAtlas.removeAllQuads();
|
||||
};
|
||||
|
||||
proto.removeQuadAtIndex = function(index){
|
||||
this._textureAtlas.removeQuadAtIndex(index); // remove from TextureAtlas
|
||||
};
|
||||
proto._swap = function (oldIndex, newIndex) {
|
||||
var locDescendants = this._node._descendants;
|
||||
var locTextureAtlas = this._textureAtlas;
|
||||
var quads = locTextureAtlas.quads;
|
||||
var tempItem = locDescendants[oldIndex];
|
||||
var tempIteQuad = cc.V3F_C4B_T2F_QuadCopy(quads[oldIndex]);
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._textureAtlas.texture;
|
||||
};
|
||||
//update the index of other swapped item
|
||||
locDescendants[newIndex].atlasIndex = oldIndex;
|
||||
locDescendants[oldIndex] = locDescendants[newIndex];
|
||||
|
||||
proto.setTexture = function(texture){
|
||||
this._textureAtlas.setTexture(texture);
|
||||
if(texture)
|
||||
this._updateBlendFunc();
|
||||
};
|
||||
locTextureAtlas.updateQuad(quads[newIndex], oldIndex);
|
||||
locDescendants[newIndex] = tempItem;
|
||||
locTextureAtlas.updateQuad(tempIteQuad, newIndex);
|
||||
};
|
||||
|
||||
proto.removeAllQuads = function(){
|
||||
this._textureAtlas.removeAllQuads();
|
||||
};
|
||||
proto._updateAtlasIndex = function (sprite, curIndex) {
|
||||
var count = 0;
|
||||
var pArray = sprite.children;
|
||||
if (pArray)
|
||||
count = pArray.length;
|
||||
|
||||
proto._swap = function (oldIndex, newIndex) {
|
||||
var locDescendants = this._node._descendants;
|
||||
var locTextureAtlas = this._textureAtlas;
|
||||
var quads = locTextureAtlas.quads;
|
||||
var tempItem = locDescendants[oldIndex];
|
||||
var tempIteQuad = cc.V3F_C4B_T2F_QuadCopy(quads[oldIndex]);
|
||||
|
||||
//update the index of other swapped item
|
||||
locDescendants[newIndex].atlasIndex = oldIndex;
|
||||
locDescendants[oldIndex] = locDescendants[newIndex];
|
||||
|
||||
locTextureAtlas.updateQuad(quads[newIndex], oldIndex);
|
||||
locDescendants[newIndex] = tempItem;
|
||||
locTextureAtlas.updateQuad(tempIteQuad, newIndex);
|
||||
};
|
||||
|
||||
proto._updateAtlasIndex = function (sprite, curIndex) {
|
||||
var count = 0;
|
||||
var pArray = sprite.children;
|
||||
if (pArray)
|
||||
count = pArray.length;
|
||||
|
||||
var oldIndex = 0;
|
||||
if (count === 0) {
|
||||
var oldIndex = 0;
|
||||
if (count === 0) {
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
if (oldIndex !== curIndex)
|
||||
this._swap(oldIndex, curIndex);
|
||||
curIndex++;
|
||||
} else {
|
||||
var needNewIndex = true;
|
||||
if (pArray[0].zIndex >= 0) {
|
||||
//all children are in front of the parent
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
if (oldIndex !== curIndex)
|
||||
this._swap(oldIndex, curIndex);
|
||||
curIndex++;
|
||||
} else {
|
||||
var needNewIndex = true;
|
||||
if (pArray[0].zIndex >= 0) {
|
||||
//all children are in front of the parent
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
if (oldIndex !== curIndex)
|
||||
this._swap(oldIndex, curIndex);
|
||||
curIndex++;
|
||||
needNewIndex = false;
|
||||
}
|
||||
for (var i = 0; i < pArray.length; i++) {
|
||||
var child = pArray[i];
|
||||
if (needNewIndex && child.zIndex >= 0) {
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
if (oldIndex !== curIndex) {
|
||||
this._swap(oldIndex, curIndex);
|
||||
}
|
||||
curIndex++;
|
||||
needNewIndex = false;
|
||||
}
|
||||
curIndex = this._updateAtlasIndex(child, curIndex);
|
||||
}
|
||||
|
||||
if (needNewIndex) {
|
||||
//all children have a zOrder < 0)
|
||||
needNewIndex = false;
|
||||
}
|
||||
for (var i = 0; i < pArray.length; i++) {
|
||||
var child = pArray[i];
|
||||
if (needNewIndex && child.zIndex >= 0) {
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
@@ -208,36 +193,49 @@
|
||||
this._swap(oldIndex, curIndex);
|
||||
}
|
||||
curIndex++;
|
||||
needNewIndex = false;
|
||||
}
|
||||
curIndex = this._updateAtlasIndex(child, curIndex);
|
||||
}
|
||||
return curIndex;
|
||||
};
|
||||
|
||||
proto.updateChildrenAtlasIndex = function(children){
|
||||
var index = 0;
|
||||
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
||||
// and at the same time reorder descedants and the quads to the right index
|
||||
for (var i = 0; i < children.length; i++)
|
||||
index = this._updateAtlasIndex(children[i], index);
|
||||
};
|
||||
|
||||
proto._updateBlendFunc = function () {
|
||||
if (!this._textureAtlas.texture.hasPremultipliedAlpha()) {
|
||||
var blendFunc = this._node._blendFunc;
|
||||
blendFunc.src = cc.macro.SRC_ALPHA;
|
||||
blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
|
||||
if (needNewIndex) {
|
||||
//all children have a zOrder < 0)
|
||||
oldIndex = sprite.atlasIndex;
|
||||
sprite.atlasIndex = curIndex;
|
||||
sprite.arrivalOrder = 0;
|
||||
if (oldIndex !== curIndex) {
|
||||
this._swap(oldIndex, curIndex);
|
||||
}
|
||||
curIndex++;
|
||||
}
|
||||
};
|
||||
}
|
||||
return curIndex;
|
||||
};
|
||||
|
||||
proto.getTextureAtlas = function(){
|
||||
return this._textureAtlas;
|
||||
};
|
||||
proto.updateChildrenAtlasIndex = function(children){
|
||||
var index = 0;
|
||||
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
||||
// and at the same time reorder descedants and the quads to the right index
|
||||
for (var i = 0; i < children.length; i++)
|
||||
index = this._updateAtlasIndex(children[i], index);
|
||||
};
|
||||
|
||||
proto.setTextureAtlas = function(textureAtlas){
|
||||
if (textureAtlas !== this._textureAtlas) {
|
||||
this._textureAtlas = textureAtlas;
|
||||
}
|
||||
};
|
||||
proto._updateBlendFunc = function () {
|
||||
if (!this._textureAtlas.texture.hasPremultipliedAlpha()) {
|
||||
var blendFunc = this._node._blendFunc;
|
||||
blendFunc.src = cc.macro.SRC_ALPHA;
|
||||
blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
|
||||
}
|
||||
};
|
||||
|
||||
proto.cutting = function(){};
|
||||
})();
|
||||
proto.getTextureAtlas = function(){
|
||||
return this._textureAtlas;
|
||||
};
|
||||
|
||||
proto.setTextureAtlas = function(textureAtlas){
|
||||
if (textureAtlas !== this._textureAtlas) {
|
||||
this._textureAtlas = textureAtlas;
|
||||
}
|
||||
};
|
||||
|
||||
proto.cutting = function(){};
|
||||
|
||||
@@ -26,15 +26,27 @@
|
||||
var EventTarget = require('../event/event-target');
|
||||
var sys = require('../platform/CCSys');
|
||||
var JS = require('../platform/js');
|
||||
var misc = require('../utils/misc');
|
||||
var game = require('../CCGame');
|
||||
require('../platform/_CCClass');
|
||||
require('../platform/CCClass');
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data. <br/>
|
||||
* The created cc.Texture2D object will always have power-of-two dimensions. <br/>
|
||||
* Depending on how you create the cc.Texture2D object, the actual image area of the texture might be smaller than the texture dimensions <br/>
|
||||
* i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). <br/>
|
||||
* Be aware that the content of the generated textures will be upside-down! </p>
|
||||
|
||||
* @class Texture2D
|
||||
* @extends RawAsset
|
||||
*/
|
||||
|
||||
/**
|
||||
* The texture wrap mode
|
||||
* @class Texture2D.WrapMode
|
||||
* @static
|
||||
* @namespace Texture2D
|
||||
*/
|
||||
var WrapMode = cc.Enum({
|
||||
/**
|
||||
@@ -60,25 +72,16 @@ var WrapMode = cc.Enum({
|
||||
MIRRORED_REPEAT: 0x8370
|
||||
});
|
||||
|
||||
//----------------------Possible texture pixel formats----------------------------
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data. <br/>
|
||||
* The created cc.Texture2D object will always have power-of-two dimensions. <br/>
|
||||
* Depending on how you create the cc.Texture2D object, the actual image area of the texture might be smaller than the texture dimensions <br/>
|
||||
* i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). <br/>
|
||||
* Be aware that the content of the generated textures will be upside-down! </p>
|
||||
|
||||
* @class Texture2D
|
||||
* @extends RawAsset
|
||||
*/
|
||||
var Texture2D = cc.Class(/** @lends cc.Texture2D# */{
|
||||
|
||||
name: 'cc.Texture2D',
|
||||
extends: require('../assets/CCRawAsset'),
|
||||
mixins: [EventTarget],
|
||||
|
||||
statics: {
|
||||
WrapMode: WrapMode
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
this.url = null;
|
||||
this._textureLoaded = false;
|
||||
@@ -736,7 +739,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
}
|
||||
|
||||
self._webTextureObj = gl.createTexture();
|
||||
cc.glBindTexture2D(self);
|
||||
cc.gl.bindTexture2D(self);
|
||||
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
@@ -835,7 +838,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
//upload image to buffer
|
||||
var gl = cc._renderContext;
|
||||
|
||||
cc.glBindTexture2D(self);
|
||||
cc.gl.bindTexture2D(self);
|
||||
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
|
||||
if(premultiplied)
|
||||
@@ -849,7 +852,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
|
||||
cc.glBindTexture2D(null);
|
||||
cc.gl.bindTexture2D(null);
|
||||
if(premultiplied)
|
||||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
||||
|
||||
@@ -874,11 +877,11 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
if(magFilter !== undefined)
|
||||
texParams = {minFilter: texParams, magFilter: magFilter, wrapS: wrapS, wrapT: wrapT};
|
||||
|
||||
cc.assert((_t._pixelsWide === cc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === cc.NextPOT(_t._pixelsHigh)) ||
|
||||
cc.assert((_t._pixelsWide === misc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === misc.NextPOT(_t._pixelsHigh)) ||
|
||||
(texParams.wrapS === gl.CLAMP_TO_EDGE && texParams.wrapT === gl.CLAMP_TO_EDGE),
|
||||
"WebGLRenderingContext.CLAMP_TO_EDGE should be used in NPOT textures");
|
||||
|
||||
cc.glBindTexture2D(_t);
|
||||
cc.gl.bindTexture2D(_t);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texParams.minFilter);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texParams.magFilter);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, texParams.wrapS);
|
||||
@@ -888,7 +891,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
setAntiAliasTexParameters: function () {
|
||||
var gl = cc._renderContext;
|
||||
|
||||
cc.glBindTexture2D(this);
|
||||
cc.gl.bindTexture2D(this);
|
||||
if (!this._hasMipmaps)
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
else
|
||||
@@ -899,7 +902,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
setAliasTexParameters: function () {
|
||||
var gl = cc._renderContext;
|
||||
|
||||
cc.glBindTexture2D(this);
|
||||
cc.gl.bindTexture2D(this);
|
||||
if (!this._hasMipmaps)
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
else
|
||||
@@ -909,9 +912,9 @@ game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
|
||||
generateMipmap: function () {
|
||||
var _t = this;
|
||||
cc.assert(_t._pixelsWide === cc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === cc.NextPOT(_t._pixelsHigh), "Mimpap texture only works in POT textures");
|
||||
cc.assert(_t._pixelsWide === misc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === misc.NextPOT(_t._pixelsHigh), "Mimpap texture only works in POT textures");
|
||||
|
||||
cc.glBindTexture2D(_t);
|
||||
cc.gl.bindTexture2D(_t);
|
||||
cc._renderContext.generateMipmap(cc._renderContext.TEXTURE_2D);
|
||||
_t._hasMipmaps = true;
|
||||
},
|
||||
|
||||
@@ -661,7 +661,7 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) {
|
||||
return;
|
||||
|
||||
var gl = cc._renderContext;
|
||||
cc.glBindTexture2D(_t.texture);
|
||||
cc.gl.bindTexture2D(_t.texture);
|
||||
|
||||
//
|
||||
// Using VBO without VAO
|
||||
@@ -669,7 +669,7 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) {
|
||||
//vertices
|
||||
//gl.bindBuffer(gl.ARRAY_BUFFER, _t._buffersVBO[0]);
|
||||
// XXX: update is done in draw... perhaps it should be done in a timer
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer);
|
||||
if (_t.dirty){
|
||||
|
||||
@@ -54,6 +54,21 @@ misc.propertyDefine = function (ctor, sameNameGetSets, diffNameGetSets) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @return {Number}
|
||||
* Constructor
|
||||
*/
|
||||
misc.NextPOT = function (x) {
|
||||
x = x - 1;
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >> 16);
|
||||
return x + 1;
|
||||
};
|
||||
|
||||
var DirtyFlags = misc.DirtyFlags = {
|
||||
TRANSFORM: 1 << 0,
|
||||
SIZE: 1 << 1,
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.POINT_EPSILON = parseFloat('1.192092896e-07F');
|
||||
var POINT_EPSILON = parseFloat('1.192092896e-07F');
|
||||
|
||||
/**
|
||||
* Returns opposite of point.
|
||||
@@ -356,7 +356,7 @@ cc.pAngleSigned = function (a, b) {
|
||||
var a2 = cc.pNormalize(a);
|
||||
var b2 = cc.pNormalize(b);
|
||||
var angle = Math.atan2(a2.x * b2.y - a2.y * b2.x, cc.pDot(a2, b2));
|
||||
if (Math.abs(angle) < cc.POINT_EPSILON)
|
||||
if (Math.abs(angle) < POINT_EPSILON)
|
||||
return 0.0;
|
||||
return angle;
|
||||
};
|
||||
@@ -369,7 +369,7 @@ cc.pAngleSigned = function (a, b) {
|
||||
*/
|
||||
cc.pAngle = function (a, b) {
|
||||
var angle = Math.acos(cc.pDot(cc.pNormalize(a), cc.pNormalize(b)));
|
||||
if (Math.abs(angle) < cc.POINT_EPSILON) return 0.0;
|
||||
if (Math.abs(angle) < POINT_EPSILON) return 0.0;
|
||||
return angle;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,21 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* @param {Number} x
|
||||
* @return {Number}
|
||||
* Constructor
|
||||
*/
|
||||
var NextPOT = function (x) {
|
||||
x = x - 1;
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >> 16);
|
||||
return x + 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Base class for cc.Grid
|
||||
* @class
|
||||
@@ -188,8 +203,8 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{
|
||||
var director = cc.director;
|
||||
var winSize = director.getWinSizeInPixels();
|
||||
|
||||
var POTWide = cc.NextPOT(winSize.width);
|
||||
var POTHigh = cc.NextPOT(winSize.height);
|
||||
var POTWide = NextPOT(winSize.width);
|
||||
var POTHigh = NextPOT(winSize.height);
|
||||
|
||||
var data = new Uint8Array(POTWide * POTHigh * 4);
|
||||
if (!data) {
|
||||
@@ -267,7 +282,7 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{
|
||||
stackMatrix.multiply(translation);
|
||||
}
|
||||
|
||||
cc.glBindTexture2D(this._texture);
|
||||
cc.gl.bindTexture2D(this._texture);
|
||||
this.beforeBlit();
|
||||
this.blit(target);
|
||||
this.afterBlit();
|
||||
@@ -304,7 +319,7 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{
|
||||
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
cc.math.glLoadIdentity();
|
||||
cc.setProjectionMatrixDirty();
|
||||
cc.gl.setProjectionMatrixDirty();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -436,7 +451,7 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
|
||||
|
||||
blit:function (target) {
|
||||
var n = this._gridSize.width * this._gridSize.height;
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
|
||||
this._shaderProgram.use();
|
||||
//this._shaderProgram.setUniformsForBuiltins();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(target._renderCmd._stackMatrix);
|
||||
@@ -690,7 +705,7 @@ cc.TiledGrid3D = cc.GridBase.extend(/** @lends cc.TiledGrid3D# */{
|
||||
// Attributes
|
||||
//
|
||||
var gl = cc._renderContext, locDirty = this._dirty;
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
|
||||
|
||||
// position
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._verticesBuffer);
|
||||
|
||||
+14
-14
@@ -24,9 +24,9 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
cc._globalFontSize = cc.macro.ITEM_SIZE;
|
||||
cc._globalFontName = "Arial";
|
||||
cc._globalFontNameRelease = false;
|
||||
var _globalFontSize = cc.macro.ITEM_SIZE;
|
||||
var _globalFontName = "Arial";
|
||||
var _globalFontNameRelease = false;
|
||||
|
||||
/**
|
||||
* Subclass cc.MenuItem (or any subclass) to create your custom cc.MenuItem objects.
|
||||
@@ -514,8 +514,8 @@ cc.MenuItemFont = cc.MenuItemLabel.extend(/** @lends cc.MenuItemFont# */{
|
||||
ctor: function (value, callback, target) {
|
||||
var label;
|
||||
if (value && value.length > 0) {
|
||||
this._fontName = cc._globalFontName;
|
||||
this._fontSize = cc._globalFontSize;
|
||||
this._fontName = _globalFontName;
|
||||
this._fontSize = _globalFontSize;
|
||||
label = new cc.LabelTTF(value, this._fontName, this._fontSize);
|
||||
}
|
||||
else {
|
||||
@@ -537,8 +537,8 @@ cc.MenuItemFont = cc.MenuItemLabel.extend(/** @lends cc.MenuItemFont# */{
|
||||
if (!value || value.length === 0)
|
||||
throw new Error("Value should be non-null and its length should be greater than 0");
|
||||
|
||||
this._fontName = cc._globalFontName;
|
||||
this._fontSize = cc._globalFontSize;
|
||||
this._fontName = _globalFontName;
|
||||
this._fontSize = _globalFontSize;
|
||||
|
||||
var label = new cc.LabelTTF(value, this._fontName, this._fontSize);
|
||||
if (this.initWithLabel(label, callback, target)) {
|
||||
@@ -592,7 +592,7 @@ cc.MenuItemFont = cc.MenuItemLabel.extend(/** @lends cc.MenuItemFont# */{
|
||||
* @param {Number} fontSize
|
||||
*/
|
||||
cc.MenuItemFont.setFontSize = function (fontSize) {
|
||||
cc._globalFontSize = fontSize;
|
||||
_globalFontSize = fontSize;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -600,7 +600,7 @@ cc.MenuItemFont.setFontSize = function (fontSize) {
|
||||
* @return {Number}
|
||||
*/
|
||||
cc.MenuItemFont.fontSize = function () {
|
||||
return cc._globalFontSize;
|
||||
return _globalFontSize;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -608,11 +608,11 @@ cc.MenuItemFont.fontSize = function () {
|
||||
* @param name
|
||||
*/
|
||||
cc.MenuItemFont.setFontName = function (name) {
|
||||
if (cc._globalFontNameRelease) {
|
||||
cc._globalFontName = '';
|
||||
if (_globalFontNameRelease) {
|
||||
_globalFontName = '';
|
||||
}
|
||||
cc._globalFontName = name;
|
||||
cc._globalFontNameRelease = true;
|
||||
_globalFontName = name;
|
||||
_globalFontNameRelease = true;
|
||||
};
|
||||
|
||||
var _p = cc.MenuItemFont.prototype;
|
||||
@@ -631,7 +631,7 @@ cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
|
||||
* @return {String}
|
||||
*/
|
||||
cc.MenuItemFont.fontName = function () {
|
||||
return cc._globalFontName;
|
||||
return _globalFontName;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,10 +40,10 @@ cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
|
||||
ctx = ctx || cc._renderContext;
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
|
||||
cc.glBindTexture2D(node.texture);
|
||||
cc.gl.bindTexture2D(node.texture);
|
||||
|
||||
//position
|
||||
ctx.bindBuffer(ctx.ARRAY_BUFFER, node._verticesBuffer);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
* @class
|
||||
* @extends cc._Class
|
||||
*/
|
||||
cc.PointObject = cc._Class.extend(/** @lends cc.PointObject# */{
|
||||
var PointObject = cc._Class.extend(/** @lends PointObject# */{
|
||||
_ratio:null,
|
||||
_offset:null,
|
||||
_child:null,
|
||||
@@ -88,7 +88,7 @@ cc.PointObject = cc._Class.extend(/** @lends cc.PointObject# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* initializes cc.PointObject
|
||||
* initializes PointObject
|
||||
* @param {cc.Vec2} ratio Not point, this is a ratio.
|
||||
* @param {cc.Vec2} offset
|
||||
* @return {Boolean}
|
||||
@@ -101,17 +101,6 @@ cc.PointObject = cc._Class.extend(/** @lends cc.PointObject# */{
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a object to stored parallax data.
|
||||
* @param {cc.Vec2} ratio
|
||||
* @param {cc.Vec2} offset
|
||||
* @return {cc.PointObject}
|
||||
* @deprecated since v3.0 please use new cc.PointObject() instead.
|
||||
*/
|
||||
cc.PointObject.create = function (ratio, offset) {
|
||||
return new cc.PointObject(ratio, offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>cc.ParallaxNode: A node that simulates a parallax scroller<br />
|
||||
* The children will be moved faster / slower than the parent according the the parallax ratio. </p>
|
||||
@@ -169,7 +158,7 @@ cc.ParallaxNode = _ccsg.Node.extend(/** @lends cc.ParallaxNode# */{
|
||||
}
|
||||
if(!child)
|
||||
throw new Error("cc.ParallaxNode.addChild(): child should be non-null");
|
||||
var obj = new cc.PointObject(ratio, offset);
|
||||
var obj = new PointObject(ratio, offset);
|
||||
obj.setChild(child);
|
||||
this.parallaxArray.push(obj);
|
||||
|
||||
@@ -238,15 +227,3 @@ cc.ParallaxNode = _ccsg.Node.extend(/** @lends cc.ParallaxNode# */{
|
||||
return new cc.ParallaxNode.WebGLRenderCmd(this);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Create new parallax node.
|
||||
* @deprecated since v3.0 please use new cc.ParallaxNode() instead.
|
||||
* @return {cc.ParallaxNode}
|
||||
* @example
|
||||
* //example
|
||||
* var voidNode = new cc.ParallaxNode();
|
||||
*/
|
||||
cc.ParallaxNode.create = function () {
|
||||
return new cc.ParallaxNode();
|
||||
};
|
||||
|
||||
@@ -24,25 +24,23 @@
|
||||
|
||||
//TODO find a way to simple these code.
|
||||
|
||||
(function(){
|
||||
cc.ParallaxNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
};
|
||||
cc.ParallaxNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
};
|
||||
|
||||
var proto = cc.ParallaxNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ParallaxNode.CanvasRenderCmd;
|
||||
var proto = cc.ParallaxNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ParallaxNode.CanvasRenderCmd;
|
||||
|
||||
proto.updateStatus = function(){
|
||||
this._node._updateParallaxPosition();
|
||||
_ccsg.Node.CanvasRenderCmd.prototype.updateStatus.call(this);
|
||||
};
|
||||
proto.updateStatus = function(){
|
||||
this._node._updateParallaxPosition();
|
||||
_ccsg.Node.CanvasRenderCmd.prototype.updateStatus.call(this);
|
||||
};
|
||||
|
||||
proto._syncStatus = function(parentCmd){
|
||||
this._node._updateParallaxPosition();
|
||||
_ccsg.Node.CanvasRenderCmd.prototype._syncStatus.call(this, parentCmd);
|
||||
}
|
||||
})();
|
||||
proto._syncStatus = function(parentCmd){
|
||||
this._node._updateParallaxPosition();
|
||||
_ccsg.Node.CanvasRenderCmd.prototype._syncStatus.call(this, parentCmd);
|
||||
};
|
||||
|
||||
cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
if(cc._renderType !== cc.game.RENDER_TYPE_WEBGL)
|
||||
@@ -64,6 +62,5 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
proto._syncStatus = function(parentCmd){
|
||||
this._node._updateParallaxPosition();
|
||||
_ccsg.Node.WebGLRenderCmd.prototype._syncStatus.call(this, parentCmd);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
|
||||
/**
|
||||
* A png file reader
|
||||
* @name cc.tiffReader
|
||||
* @name PNGReader
|
||||
*/
|
||||
cc.PNGReader = cc._Class.extend({
|
||||
var PNGReader = cc._Class.extend({
|
||||
ctor:function(data){
|
||||
var chunkSize, colors, delayDen, delayNum, frame, i, index, key, section, ccshort, text, _i, _j, _ref;
|
||||
this.data = data;
|
||||
@@ -328,3 +328,4 @@ cc.PNGReader = cc._Class.extend({
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = PNGReader;
|
||||
@@ -27,13 +27,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* paticle default capacity
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.PARTICLE_DEFAULT_CAPACITY = 500;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* cc.ParticleBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call <br/>
|
||||
@@ -513,15 +506,3 @@ var _p = cc.ParticleBatchNode.prototype;
|
||||
/** @expose */
|
||||
_p.texture;
|
||||
cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
|
||||
|
||||
|
||||
/**
|
||||
* initializes the particle system with the name of a file on disk (for a list of supported formats look at the cc.Texture2D class), a capacity of particles
|
||||
* @deprecated since v3.0 please use new cc.ParticleBatchNode(filename, capacity) instead.
|
||||
* @param {String|cc.Texture2D} fileImage
|
||||
* @param {Number} capacity
|
||||
* @return {cc.ParticleBatchNode}
|
||||
*/
|
||||
cc.ParticleBatchNode.create = function (fileImage, capacity) {
|
||||
return new cc.ParticleBatchNode(fileImage, capacity);
|
||||
};
|
||||
|
||||
@@ -22,17 +22,15 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
/**
|
||||
* cc.ParticleBatchNode's rendering objects of Canvas
|
||||
*/
|
||||
cc.ParticleBatchNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
};
|
||||
/**
|
||||
* cc.ParticleBatchNode's rendering objects of Canvas
|
||||
*/
|
||||
cc.ParticleBatchNode.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = false;
|
||||
};
|
||||
|
||||
var proto = cc.ParticleBatchNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ParticleBatchNode.CanvasRenderCmd;
|
||||
var proto = cc.ParticleBatchNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.ParticleBatchNode.CanvasRenderCmd;
|
||||
|
||||
proto._initWithTexture = function(){};
|
||||
})();
|
||||
proto._initWithTexture = function(){};
|
||||
|
||||
@@ -22,53 +22,51 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
/**
|
||||
* cc.ParticleBatchNode's rendering objects of WebGL
|
||||
*/
|
||||
cc.ParticleBatchNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
};
|
||||
/**
|
||||
* cc.ParticleBatchNode's rendering objects of WebGL
|
||||
*/
|
||||
cc.ParticleBatchNode.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
};
|
||||
|
||||
var proto = cc.ParticleBatchNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.ParticleBatchNode.WebGLRenderCmd;
|
||||
var proto = cc.ParticleBatchNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.ParticleBatchNode.WebGLRenderCmd;
|
||||
|
||||
proto.rendering = function (ctx) {
|
||||
var _t = this._node;
|
||||
if (_t.textureAtlas.totalQuads === 0)
|
||||
return;
|
||||
proto.rendering = function (ctx) {
|
||||
var _t = this._node;
|
||||
if (_t.textureAtlas.totalQuads === 0)
|
||||
return;
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
|
||||
_t.textureAtlas.drawQuads();
|
||||
};
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
cc.gl.blendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
|
||||
_t.textureAtlas.drawQuads();
|
||||
};
|
||||
|
||||
proto._initWithTexture = function(){
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
proto._initWithTexture = function(){
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// CAREFUL:
|
||||
// This visit is almost identical to _ccsg.Node#visit
|
||||
// with the exception that it doesn't call visit on it's children
|
||||
//
|
||||
// The alternative is to have a void _ccsg.Sprite#visit, but
|
||||
// although this is less mantainable, is faster
|
||||
//
|
||||
if (!node._visible)
|
||||
return;
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
// CAREFUL:
|
||||
// This visit is almost identical to _ccsg.Node#visit
|
||||
// with the exception that it doesn't call visit on it's children
|
||||
//
|
||||
// The alternative is to have a void _ccsg.Sprite#visit, but
|
||||
// although this is less mantainable, is faster
|
||||
//
|
||||
if (!node._visible)
|
||||
return;
|
||||
|
||||
var currentStack = cc.current_stack;
|
||||
currentStack.stack.push(currentStack.top);
|
||||
this._syncStatus(parentCmd);
|
||||
currentStack.top = this._stackMatrix;
|
||||
//this.draw(ctx);
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
var currentStack = cc.current_stack;
|
||||
currentStack.stack.push(currentStack.top);
|
||||
this._syncStatus(parentCmd);
|
||||
currentStack.top = this._stackMatrix;
|
||||
//this.draw(ctx);
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
|
||||
this._dirtyFlag = 0;
|
||||
cc.math.glPopMatrix();
|
||||
};
|
||||
})();
|
||||
this._dirtyFlag = 0;
|
||||
cc.math.glPopMatrix();
|
||||
};
|
||||
@@ -24,6 +24,9 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var PNGReader = require('../cocos2d/particle/CCPNGReader');
|
||||
var tiffReader = require('../cocos2d/particle/CCTIFFReader');
|
||||
|
||||
// ideas taken from:
|
||||
// . The ocean spray in your face [Jeff Lander]
|
||||
// http://www.double.co.nz/dust/col0798.pdf
|
||||
@@ -1381,7 +1384,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
return false;
|
||||
this.setTexture(tex);
|
||||
} else {
|
||||
buffer = cc.unzipBase64AsArray(textureData, 1);
|
||||
buffer = cc.Codec.unzipBase64AsArray(textureData, 1);
|
||||
if (!buffer) {
|
||||
cc.log("_ccsg.ParticleSystem: error decoding or ungzipping textureImageData");
|
||||
return false;
|
||||
@@ -1396,11 +1399,10 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
|
||||
|
||||
var canvasObj = document.createElement("canvas");
|
||||
if(imageFormat === cc.ImageFormat.PNG){
|
||||
var myPngObj = new cc.PNGReader(buffer);
|
||||
var myPngObj = new PNGReader(buffer);
|
||||
myPngObj.render(canvasObj);
|
||||
} else {
|
||||
var myTIFFObj = cc.tiffReader;
|
||||
myTIFFObj.parseTIFF(buffer,canvasObj);
|
||||
tiffReader.parseTIFF(buffer,canvasObj);
|
||||
}
|
||||
|
||||
cc.textureCache.cacheImage(imgPath, canvasObj);
|
||||
@@ -2073,31 +2075,6 @@ _p.texture;
|
||||
cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
|
||||
|
||||
|
||||
/**
|
||||
* <p> return the string found by key in dict. <br/>
|
||||
* This plist files can be create manually or with Particle Designer:<br/>
|
||||
* http://particledesigner.71squared.com/<br/>
|
||||
* </p>
|
||||
* @deprecated since v3.0 please use new cc.ParticleSysytem(plistFile) instead.
|
||||
* @param {String|Number} plistFile
|
||||
* @return {ccsg.ParticleSystem}
|
||||
*/
|
||||
_ccsg.ParticleSystem.create = function (plistFile) {
|
||||
return new _ccsg.ParticleSystem(plistFile);
|
||||
};
|
||||
|
||||
/**
|
||||
* <p> return the string found by key in dict. <br/>
|
||||
* This plist files can be create manually or with Particle Designer:<br/>
|
||||
* http://particledesigner.71squared.com/<br/>
|
||||
* </p>
|
||||
* @deprecated since v3.0 please use new cc.ParticleSysytem(plistFile) instead.
|
||||
* @function
|
||||
* @param {String|Number} plistFile
|
||||
* @return {ccsg.ParticleSystem}
|
||||
*/
|
||||
_ccsg.ParticleSystem.createWithTotalParticles = _ccsg.ParticleSystem.create;
|
||||
|
||||
// Different modes
|
||||
/**
|
||||
* Mode A:Gravity + Tangential Accel + Radial Accel
|
||||
|
||||
@@ -25,175 +25,173 @@
|
||||
/**
|
||||
* ParticleSystem's canvas render command
|
||||
*/
|
||||
(function(){
|
||||
_ccsg.ParticleSystem.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
_ccsg.ParticleSystem.CanvasRenderCmd = function(renderable){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
|
||||
this._drawMode = _ccsg.ParticleSystem.TEXTURE_MODE;
|
||||
this._shapeType = _ccsg.ParticleSystem.BALL_SHAPE;
|
||||
this._drawMode = _ccsg.ParticleSystem.TEXTURE_MODE;
|
||||
this._shapeType = _ccsg.ParticleSystem.BALL_SHAPE;
|
||||
|
||||
this._pointRect = cc.rect(0, 0, 0, 0);
|
||||
this._tintCache = document.createElement("canvas");
|
||||
};
|
||||
var proto = _ccsg.ParticleSystem.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.ParticleSystem.CanvasRenderCmd;
|
||||
this._pointRect = cc.rect(0, 0, 0, 0);
|
||||
this._tintCache = document.createElement("canvas");
|
||||
};
|
||||
var proto = _ccsg.ParticleSystem.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.ParticleSystem.CanvasRenderCmd;
|
||||
|
||||
proto.getDrawMode = function(){
|
||||
return this._drawMode;
|
||||
};
|
||||
proto.getDrawMode = function(){
|
||||
return this._drawMode;
|
||||
};
|
||||
|
||||
proto.setDrawMode = function(drawMode){
|
||||
this._drawMode = drawMode;
|
||||
};
|
||||
proto.setDrawMode = function(drawMode){
|
||||
this._drawMode = drawMode;
|
||||
};
|
||||
|
||||
proto.getShapeType = function(){
|
||||
return this._shapeType;
|
||||
};
|
||||
proto.getShapeType = function(){
|
||||
return this._shapeType;
|
||||
};
|
||||
|
||||
proto.setShapeType = function(shapeType){
|
||||
this._shapeType = shapeType;
|
||||
};
|
||||
proto.setShapeType = function(shapeType){
|
||||
this._shapeType = shapeType;
|
||||
};
|
||||
|
||||
proto.setBatchNode = function(batchNode){
|
||||
if (this._batchNode !== batchNode) {
|
||||
this._node._batchNode = batchNode;
|
||||
proto.setBatchNode = function(batchNode){
|
||||
if (this._batchNode !== batchNode) {
|
||||
this._node._batchNode = batchNode;
|
||||
}
|
||||
};
|
||||
|
||||
proto.updateQuadWithParticle = function (particle, newPosition) {
|
||||
//do nothing
|
||||
};
|
||||
|
||||
proto.updateParticlePosition = function(particle, position){
|
||||
cc.pIn(particle.drawPos, position);
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
//TODO: need refactor rendering for performance
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext(),
|
||||
node = this._node, pointRect = this._pointRect;
|
||||
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.save();
|
||||
if (node.isBlendAdditive())
|
||||
context.globalCompositeOperation = 'lighter';
|
||||
else
|
||||
context.globalCompositeOperation = 'source-over';
|
||||
|
||||
var i, particle, lpx, alpha;
|
||||
var particleCount = this._node.particleCount, particles = this._node._particles;
|
||||
if (node.drawMode !== _ccsg.ParticleSystem.SHAPE_MODE && node._texture) {
|
||||
// Delay drawing until the texture is fully loaded by the browser
|
||||
if (!node._texture._textureLoaded) {
|
||||
wrapper.restore();
|
||||
return;
|
||||
}
|
||||
var element = node._texture.getHtmlElementObj();
|
||||
if (!element.width || !element.height) {
|
||||
wrapper.restore();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
proto.updateQuadWithParticle = function (particle, newPosition) {
|
||||
//do nothing
|
||||
};
|
||||
var drawElement = element;
|
||||
for (i = 0; i < particleCount; i++) {
|
||||
particle = particles[i];
|
||||
lpx = (0 | (particle.size * 0.5));
|
||||
|
||||
proto.updateParticlePosition = function(particle, position){
|
||||
cc.pIn(particle.drawPos, position);
|
||||
};
|
||||
alpha = particle.color.a / 255;
|
||||
if (alpha === 0) continue;
|
||||
context.globalAlpha = alpha;
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
//TODO: need refactor rendering for performance
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext(),
|
||||
node = this._node, pointRect = this._pointRect;
|
||||
context.save();
|
||||
context.translate((0 | particle.drawPos.x), -(0 | particle.drawPos.y));
|
||||
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
wrapper.save();
|
||||
if (node.isBlendAdditive())
|
||||
context.globalCompositeOperation = 'lighter';
|
||||
else
|
||||
context.globalCompositeOperation = 'source-over';
|
||||
var size = Math.floor(particle.size / 4) * 4;
|
||||
var w = pointRect.width;
|
||||
var h = pointRect.height;
|
||||
|
||||
var i, particle, lpx, alpha;
|
||||
var particleCount = this._node.particleCount, particles = this._node._particles;
|
||||
if (node.drawMode !== _ccsg.ParticleSystem.SHAPE_MODE && node._texture) {
|
||||
// Delay drawing until the texture is fully loaded by the browser
|
||||
if (!node._texture._textureLoaded) {
|
||||
wrapper.restore();
|
||||
return;
|
||||
}
|
||||
var element = node._texture.getHtmlElementObj();
|
||||
if (!element.width || !element.height) {
|
||||
wrapper.restore();
|
||||
return;
|
||||
}
|
||||
context.scale(Math.max((1 / w) * size, 0.000001), Math.max((1 / h) * size, 0.000001));
|
||||
if (particle.rotation)
|
||||
context.rotate(cc.degreesToRadians(particle.rotation));
|
||||
|
||||
var drawElement = element;
|
||||
for (i = 0; i < particleCount; i++) {
|
||||
particle = particles[i];
|
||||
lpx = (0 | (particle.size * 0.5));
|
||||
drawElement = particle.isChangeColor ? this._changeTextureColor(node._texture, particle.color, this._pointRect) : element;
|
||||
context.drawImage(drawElement, -(0 | (w / 2)), -(0 | (h / 2)));
|
||||
context.restore();
|
||||
}
|
||||
} else {
|
||||
var drawTool = cc._drawingUtil;
|
||||
for (i = 0; i < particleCount; i++) {
|
||||
particle = particles[i];
|
||||
lpx = (0 | (particle.size * 0.5));
|
||||
alpha = particle.color.a / 255;
|
||||
if (alpha === 0) continue;
|
||||
context.globalAlpha = alpha;
|
||||
|
||||
alpha = particle.color.a / 255;
|
||||
if (alpha === 0) continue;
|
||||
context.globalAlpha = alpha;
|
||||
|
||||
context.save();
|
||||
context.translate((0 | particle.drawPos.x), -(0 | particle.drawPos.y));
|
||||
|
||||
var size = Math.floor(particle.size / 4) * 4;
|
||||
var w = pointRect.width;
|
||||
var h = pointRect.height;
|
||||
|
||||
context.scale(Math.max((1 / w) * size, 0.000001), Math.max((1 / h) * size, 0.000001));
|
||||
context.save();
|
||||
context.translate(0 | particle.drawPos.x, -(0 | particle.drawPos.y));
|
||||
if (node.shapeType === _ccsg.ParticleSystem.STAR_SHAPE) {
|
||||
if (particle.rotation)
|
||||
context.rotate(cc.degreesToRadians(particle.rotation));
|
||||
|
||||
drawElement = particle.isChangeColor ? this._changeTextureColor(node._texture, particle.color, this._pointRect) : element;
|
||||
context.drawImage(drawElement, -(0 | (w / 2)), -(0 | (h / 2)));
|
||||
context.restore();
|
||||
}
|
||||
} else {
|
||||
var drawTool = cc._drawingUtil;
|
||||
for (i = 0; i < particleCount; i++) {
|
||||
particle = particles[i];
|
||||
lpx = (0 | (particle.size * 0.5));
|
||||
alpha = particle.color.a / 255;
|
||||
if (alpha === 0) continue;
|
||||
context.globalAlpha = alpha;
|
||||
|
||||
context.save();
|
||||
context.translate(0 | particle.drawPos.x, -(0 | particle.drawPos.y));
|
||||
if (node.shapeType === _ccsg.ParticleSystem.STAR_SHAPE) {
|
||||
if (particle.rotation)
|
||||
context.rotate(cc.degreesToRadians(particle.rotation));
|
||||
drawTool.drawStar(wrapper, lpx, particle.color);
|
||||
} else
|
||||
drawTool.drawColorBall(wrapper, lpx, particle.color);
|
||||
context.restore();
|
||||
}
|
||||
drawTool.drawStar(wrapper, lpx, particle.color);
|
||||
} else
|
||||
drawTool.drawColorBall(wrapper, lpx, particle.color);
|
||||
context.restore();
|
||||
}
|
||||
wrapper.restore();
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
}
|
||||
wrapper.restore();
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
|
||||
proto._changeTextureColor = function(texture, color, rect){
|
||||
var tintCache = this._tintCache;
|
||||
var textureContentSize = texture.getContentSize();
|
||||
tintCache.width = textureContentSize.width;
|
||||
tintCache.height = textureContentSize.height;
|
||||
return texture._generateColorTexture(color.r, color.g, color.b, rect, tintCache);
|
||||
};
|
||||
proto._changeTextureColor = function(texture, color, rect){
|
||||
var tintCache = this._tintCache;
|
||||
var textureContentSize = texture.getContentSize();
|
||||
tintCache.width = textureContentSize.width;
|
||||
tintCache.height = textureContentSize.height;
|
||||
return texture._generateColorTexture(color.r, color.g, color.b, rect, tintCache);
|
||||
};
|
||||
|
||||
proto.initTexCoordsWithRect = function(pointRect){
|
||||
this._pointRect = pointRect;
|
||||
};
|
||||
proto.initTexCoordsWithRect = function(pointRect){
|
||||
this._pointRect = pointRect;
|
||||
};
|
||||
|
||||
proto.setTotalParticles = function(tp){
|
||||
//cc.assert(tp <= this._allocatedParticles, "Particle: resizing particle array only supported for quads");
|
||||
this._node._totalParticles = (tp < 200) ? tp : 200;
|
||||
};
|
||||
proto.setTotalParticles = function(tp){
|
||||
//cc.assert(tp <= this._allocatedParticles, "Particle: resizing particle array only supported for quads");
|
||||
this._node._totalParticles = (tp < 200) ? tp : 200;
|
||||
};
|
||||
|
||||
proto.addParticle = function(){
|
||||
var node = this._node,
|
||||
particles = node._particles,
|
||||
particle;
|
||||
if (node.particleCount < particles.length) {
|
||||
particle = particles[node.particleCount];
|
||||
} else {
|
||||
particle = new cc.Particle();
|
||||
particles.push(particle);
|
||||
}
|
||||
return particle;
|
||||
};
|
||||
proto.addParticle = function(){
|
||||
var node = this._node,
|
||||
particles = node._particles,
|
||||
particle;
|
||||
if (node.particleCount < particles.length) {
|
||||
particle = particles[node.particleCount];
|
||||
} else {
|
||||
particle = new cc.Particle();
|
||||
particles.push(particle);
|
||||
}
|
||||
return particle;
|
||||
};
|
||||
|
||||
proto._setupVBO = function(){};
|
||||
proto._allocMemory = function(){
|
||||
return true;
|
||||
};
|
||||
proto._setupVBO = function(){};
|
||||
proto._allocMemory = function(){
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.postStep = function(){};
|
||||
proto.postStep = function(){};
|
||||
|
||||
proto._setBlendAdditive = function(){
|
||||
var locBlendFunc = this._node._blendFunc;
|
||||
locBlendFunc.src = cc.macro.BLEND_SRC;
|
||||
locBlendFunc.dst = cc.macro.BLEND_DST;
|
||||
};
|
||||
proto._setBlendAdditive = function(){
|
||||
var locBlendFunc = this._node._blendFunc;
|
||||
locBlendFunc.src = cc.macro.BLEND_SRC;
|
||||
locBlendFunc.dst = cc.macro.BLEND_DST;
|
||||
};
|
||||
|
||||
proto._initWithTotalParticles = function(totalParticles){};
|
||||
proto._updateDeltaColor = function(selParticle, dt){
|
||||
if (!this._node._dontTint) {
|
||||
selParticle.color.r += selParticle.deltaColor.r * dt;
|
||||
selParticle.color.g += selParticle.deltaColor.g * dt;
|
||||
selParticle.color.b += selParticle.deltaColor.b * dt;
|
||||
selParticle.color.a += selParticle.deltaColor.a * dt;
|
||||
selParticle.isChangeColor = true;
|
||||
}
|
||||
};
|
||||
})();
|
||||
proto._initWithTotalParticles = function(totalParticles){};
|
||||
proto._updateDeltaColor = function(selParticle, dt){
|
||||
if (!this._node._dontTint) {
|
||||
selParticle.color.r += selParticle.deltaColor.r * dt;
|
||||
selParticle.color.g += selParticle.deltaColor.g * dt;
|
||||
selParticle.color.b += selParticle.deltaColor.b * dt;
|
||||
selParticle.color.a += selParticle.deltaColor.a * dt;
|
||||
selParticle.isChangeColor = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,373 +22,371 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
/**
|
||||
* ParticleSystem's WebGL render command
|
||||
*/
|
||||
_ccsg.ParticleSystem.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
/**
|
||||
* ParticleSystem's WebGL render command
|
||||
*/
|
||||
_ccsg.ParticleSystem.WebGLRenderCmd = function(renderable){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
|
||||
this._buffersVBO = [0, 0];
|
||||
this._quads = [];
|
||||
this._indices = [];
|
||||
this._quadsArrayBuffer = null;
|
||||
};
|
||||
var proto = _ccsg.ParticleSystem.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.ParticleSystem.WebGLRenderCmd;
|
||||
this._buffersVBO = [0, 0];
|
||||
this._quads = [];
|
||||
this._indices = [];
|
||||
this._quadsArrayBuffer = null;
|
||||
};
|
||||
var proto = _ccsg.ParticleSystem.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.ParticleSystem.WebGLRenderCmd;
|
||||
|
||||
proto.getDrawMode = function(){};
|
||||
proto.setDrawMode = function(drawMode){};
|
||||
proto.getShapeType = function(){};
|
||||
proto.setShapeType = function(shapeType){};
|
||||
proto.getDrawMode = function(){};
|
||||
proto.setDrawMode = function(drawMode){};
|
||||
proto.getShapeType = function(){};
|
||||
proto.setShapeType = function(shapeType){};
|
||||
|
||||
proto.setBatchNode = function(batchNode){
|
||||
var node = this._node;
|
||||
if (node._batchNode !== batchNode) {
|
||||
var oldBatch = node._batchNode;
|
||||
node._batchNode = batchNode; //weak reference
|
||||
proto.setBatchNode = function(batchNode){
|
||||
var node = this._node;
|
||||
if (node._batchNode !== batchNode) {
|
||||
var oldBatch = node._batchNode;
|
||||
node._batchNode = batchNode; //weak reference
|
||||
|
||||
if (batchNode) {
|
||||
var locParticles = node._particles;
|
||||
for (var i = 0; i < node._totalParticles; i++)
|
||||
locParticles[i].atlasIndex = i;
|
||||
}
|
||||
|
||||
// NEW: is self render ?
|
||||
if (!batchNode) {
|
||||
this._allocMemory();
|
||||
this.initIndices(node._totalParticles);
|
||||
node.setTexture(oldBatch.getTexture());
|
||||
this._setupVBO();
|
||||
|
||||
} else if (!oldBatch) {
|
||||
// OLD: was it self render cleanup ?
|
||||
// copy current state to batch
|
||||
node._batchNode.textureAtlas._copyQuadsToTextureAtlas(this._quads, node.atlasIndex);
|
||||
|
||||
//delete buffer
|
||||
cc._renderContext.deleteBuffer(this._buffersVBO[1]); //where is re-bindBuffer code?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.initIndices = function (totalParticles) {
|
||||
var locIndices = this._indices;
|
||||
for (var i = 0, len = totalParticles; i < len; ++i) {
|
||||
var i6 = i * 6;
|
||||
var i4 = i * 4;
|
||||
locIndices[i6 + 0] = i4 + 0;
|
||||
locIndices[i6 + 1] = i4 + 1;
|
||||
locIndices[i6 + 2] = i4 + 2;
|
||||
|
||||
locIndices[i6 + 5] = i4 + 1;
|
||||
locIndices[i6 + 4] = i4 + 2;
|
||||
locIndices[i6 + 3] = i4 + 3;
|
||||
}
|
||||
};
|
||||
|
||||
proto.isDifferentTexture = function(texture1, texture2){
|
||||
return (texture1 === texture2);
|
||||
};
|
||||
|
||||
proto.updateParticlePosition = function(particle, position){
|
||||
// IMPORTANT: newPos may not be used as a reference here! (as it is just the temporary tpa point)
|
||||
// the implementation of updateQuadWithParticle must use
|
||||
// the x and y values directly
|
||||
this.updateQuadWithParticle(particle, position);
|
||||
};
|
||||
|
||||
proto.updateQuadWithParticle = function (particle, newPosition) {
|
||||
var quad = null, node = this._node;
|
||||
if (node._batchNode) {
|
||||
var batchQuads = node._batchNode.textureAtlas.quads;
|
||||
quad = batchQuads[node.atlasIndex + particle.atlasIndex];
|
||||
node._batchNode.textureAtlas.dirty = true;
|
||||
} else
|
||||
quad = this._quads[node._particleIdx];
|
||||
|
||||
var r, g, b, a;
|
||||
if (node._opacityModifyRGB) {
|
||||
r = 0 | (particle.color.r * particle.color.a/255);
|
||||
g = 0 | (particle.color.g * particle.color.a/255);
|
||||
b = 0 | (particle.color.b * particle.color.a/255);
|
||||
} else {
|
||||
r = 0 | (particle.color.r );
|
||||
g = 0 | (particle.color.g );
|
||||
b = 0 | (particle.color.b );
|
||||
}
|
||||
a = 0 | (particle.color.a );
|
||||
|
||||
var blColors = quad.bl.colors, brColors = quad.br.colors, tlColors = quad.tl.colors, trColors = quad.tr.colors;
|
||||
blColors.r = brColors.r = tlColors.r = trColors.r = r;
|
||||
blColors.g = brColors.g = tlColors.g = trColors.g = g;
|
||||
blColors.b = brColors.b = tlColors.b = trColors.b = b;
|
||||
blColors.a = brColors.a = tlColors.a = trColors.a = a;
|
||||
|
||||
// vertices
|
||||
var size_2 = particle.size / 2;
|
||||
if (particle.rotation) {
|
||||
var x1 = -size_2, y1 = -size_2;
|
||||
|
||||
var x2 = size_2, y2 = size_2;
|
||||
var x = newPosition.x, y = newPosition.y;
|
||||
|
||||
var rad = -cc.degreesToRadians(particle.rotation);
|
||||
var cr = Math.cos(rad), sr = Math.sin(rad);
|
||||
var ax = x1 * cr - y1 * sr + x;
|
||||
var ay = x1 * sr + y1 * cr + y;
|
||||
var bx = x2 * cr - y1 * sr + x;
|
||||
var by = x2 * sr + y1 * cr + y;
|
||||
var cx = x2 * cr - y2 * sr + x;
|
||||
var cy = x2 * sr + y2 * cr + y;
|
||||
var dx = x1 * cr - y2 * sr + x;
|
||||
var dy = x1 * sr + y2 * cr + y;
|
||||
|
||||
// bottom-left
|
||||
quad.bl.vertices.x = ax;
|
||||
quad.bl.vertices.y = ay;
|
||||
|
||||
// bottom-right vertex:
|
||||
quad.br.vertices.x = bx;
|
||||
quad.br.vertices.y = by;
|
||||
|
||||
// top-left vertex:
|
||||
quad.tl.vertices.x = dx;
|
||||
quad.tl.vertices.y = dy;
|
||||
|
||||
// top-right vertex:
|
||||
quad.tr.vertices.x = cx;
|
||||
quad.tr.vertices.y = cy;
|
||||
} else {
|
||||
// bottom-left vertex:
|
||||
quad.bl.vertices.x = newPosition.x - size_2;
|
||||
quad.bl.vertices.y = newPosition.y - size_2;
|
||||
|
||||
// bottom-right vertex:
|
||||
quad.br.vertices.x = newPosition.x + size_2;
|
||||
quad.br.vertices.y = newPosition.y - size_2;
|
||||
|
||||
// top-left vertex:
|
||||
quad.tl.vertices.x = newPosition.x - size_2;
|
||||
quad.tl.vertices.y = newPosition.y + size_2;
|
||||
|
||||
// top-right vertex:
|
||||
quad.tr.vertices.x = newPosition.x + size_2;
|
||||
quad.tr.vertices.y = newPosition.y + size_2;
|
||||
}
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
if (!node._texture)
|
||||
return;
|
||||
|
||||
var gl = ctx || cc._renderContext;
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); //;
|
||||
|
||||
cc.glBindTexture2D(node._texture);
|
||||
cc.glBlendFuncForParticle(node._blendFunc.src, node._blendFunc.dst);
|
||||
|
||||
//
|
||||
// Using VBO without VAO
|
||||
//
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]);
|
||||
gl.drawElements(gl.TRIANGLES, node._particleIdx * 6, gl.UNSIGNED_SHORT, 0);
|
||||
};
|
||||
|
||||
proto.initTexCoordsWithRect = function(pointRect){
|
||||
var node = this._node;
|
||||
var texture = node.texture;
|
||||
|
||||
var wide = pointRect.width;
|
||||
var high = pointRect.height;
|
||||
|
||||
if (texture) {
|
||||
wide = texture.getPixelWidth();
|
||||
high = texture.getPixelHeight();
|
||||
}
|
||||
|
||||
var left, bottom, right, top;
|
||||
if (cc.macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
|
||||
left = (pointRect.x * 2 + 1) / (wide * 2);
|
||||
bottom = (pointRect.y * 2 + 1) / (high * 2);
|
||||
right = left + (pointRect.width * 2 - 2) / (wide * 2);
|
||||
top = bottom + (pointRect.height * 2 - 2) / (high * 2);
|
||||
} else {
|
||||
left = pointRect.x / wide;
|
||||
bottom = pointRect.y / high;
|
||||
right = left + pointRect.width / wide;
|
||||
top = bottom + pointRect.height / high;
|
||||
}
|
||||
|
||||
// Important. Texture in cocos2d are inverted, so the Y component should be inverted
|
||||
var temp = top;
|
||||
top = bottom;
|
||||
bottom = temp;
|
||||
|
||||
var quads;
|
||||
var start = 0, end = 0;
|
||||
if (node._batchNode) {
|
||||
quads = node._batchNode.textureAtlas.quads;
|
||||
start = node.atlasIndex;
|
||||
end = node.atlasIndex + node._totalParticles;
|
||||
} else {
|
||||
quads = this._quads;
|
||||
start = 0;
|
||||
end = node._totalParticles;
|
||||
}
|
||||
|
||||
for (var i = start; i < end; i++) {
|
||||
if (!quads[i])
|
||||
quads[i] = cc.V3F_C4B_T2F_QuadZero();
|
||||
|
||||
// bottom-left vertex:
|
||||
var selQuad = quads[i];
|
||||
selQuad.bl.texCoords.u = left;
|
||||
selQuad.bl.texCoords.v = bottom;
|
||||
// bottom-right vertex:
|
||||
selQuad.br.texCoords.u = right;
|
||||
selQuad.br.texCoords.v = bottom;
|
||||
// top-left vertex:
|
||||
selQuad.tl.texCoords.u = left;
|
||||
selQuad.tl.texCoords.v = top;
|
||||
// top-right vertex:
|
||||
selQuad.tr.texCoords.u = right;
|
||||
selQuad.tr.texCoords.v = top;
|
||||
}
|
||||
};
|
||||
|
||||
proto.setTotalParticles = function(tp){
|
||||
var node = this._node;
|
||||
// If we are setting the total numer of particles to a number higher
|
||||
// than what is allocated, we need to allocate new arrays
|
||||
if (tp > node._allocatedParticles) {
|
||||
var quadSize = cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT;
|
||||
// Allocate new memory
|
||||
this._indices = new Uint16Array(tp * 6);
|
||||
var locQuadsArrayBuffer = new ArrayBuffer(tp * quadSize);
|
||||
//TODO need fix
|
||||
// Assign pointers
|
||||
if (batchNode) {
|
||||
var locParticles = node._particles;
|
||||
locParticles.length = 0;
|
||||
var locQuads = this._quads;
|
||||
locQuads.length = 0;
|
||||
for (var j = 0; j < tp; j++) {
|
||||
locParticles[j] = new cc.Particle();
|
||||
locQuads[j] = new cc.V3F_C4B_T2F_Quad(null, null, null, null, locQuadsArrayBuffer, j * quadSize);
|
||||
}
|
||||
node._allocatedParticles = tp;
|
||||
node._totalParticles = tp;
|
||||
for (var i = 0; i < node._totalParticles; i++)
|
||||
locParticles[i].atlasIndex = i;
|
||||
}
|
||||
|
||||
// Init particles
|
||||
if (node._batchNode) {
|
||||
for (var i = 0; i < tp; i++)
|
||||
locParticles[i].atlasIndex = i;
|
||||
}
|
||||
|
||||
this._quadsArrayBuffer = locQuadsArrayBuffer;
|
||||
this.initIndices(tp);
|
||||
// NEW: is self render ?
|
||||
if (!batchNode) {
|
||||
this._allocMemory();
|
||||
this.initIndices(node._totalParticles);
|
||||
node.setTexture(oldBatch.getTexture());
|
||||
this._setupVBO();
|
||||
|
||||
//set the texture coord
|
||||
if(node._texture){
|
||||
this.initTexCoordsWithRect(cc.rect(0, 0, node._texture.width, node._texture.height));
|
||||
}
|
||||
} else
|
||||
node._totalParticles = tp;
|
||||
node.resetSystem();
|
||||
};
|
||||
} else if (!oldBatch) {
|
||||
// OLD: was it self render cleanup ?
|
||||
// copy current state to batch
|
||||
node._batchNode.textureAtlas._copyQuadsToTextureAtlas(this._quads, node.atlasIndex);
|
||||
|
||||
proto.addParticle = function(){
|
||||
var node = this._node,
|
||||
particles = node._particles;
|
||||
return particles[node.particleCount];
|
||||
};
|
||||
|
||||
proto._setupVBO = function(){
|
||||
var node = this;
|
||||
var gl = cc._renderContext;
|
||||
|
||||
//gl.deleteBuffer(this._buffersVBO[0]);
|
||||
this._buffersVBO[0] = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quadsArrayBuffer, gl.DYNAMIC_DRAW);
|
||||
|
||||
this._buffersVBO[1] = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this._indices, gl.STATIC_DRAW);
|
||||
|
||||
//cc.checkGLErrorDebug();
|
||||
};
|
||||
|
||||
proto._allocMemory = function(){
|
||||
var node = this._node;
|
||||
//cc.assert((!this._quads && !this._indices), "Memory already allocated");
|
||||
if(node._batchNode){
|
||||
cc.log("_ccsg.ParticleSystem._allocMemory(): Memory should not be allocated when not using batchNode");
|
||||
return false;
|
||||
//delete buffer
|
||||
cc._renderContext.deleteBuffer(this._buffersVBO[1]); //where is re-bindBuffer code?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.initIndices = function (totalParticles) {
|
||||
var locIndices = this._indices;
|
||||
for (var i = 0, len = totalParticles; i < len; ++i) {
|
||||
var i6 = i * 6;
|
||||
var i4 = i * 4;
|
||||
locIndices[i6 + 0] = i4 + 0;
|
||||
locIndices[i6 + 1] = i4 + 1;
|
||||
locIndices[i6 + 2] = i4 + 2;
|
||||
|
||||
locIndices[i6 + 5] = i4 + 1;
|
||||
locIndices[i6 + 4] = i4 + 2;
|
||||
locIndices[i6 + 3] = i4 + 3;
|
||||
}
|
||||
};
|
||||
|
||||
proto.isDifferentTexture = function(texture1, texture2){
|
||||
return (texture1 === texture2);
|
||||
};
|
||||
|
||||
proto.updateParticlePosition = function(particle, position){
|
||||
// IMPORTANT: newPos may not be used as a reference here! (as it is just the temporary tpa point)
|
||||
// the implementation of updateQuadWithParticle must use
|
||||
// the x and y values directly
|
||||
this.updateQuadWithParticle(particle, position);
|
||||
};
|
||||
|
||||
proto.updateQuadWithParticle = function (particle, newPosition) {
|
||||
var quad = null, node = this._node;
|
||||
if (node._batchNode) {
|
||||
var batchQuads = node._batchNode.textureAtlas.quads;
|
||||
quad = batchQuads[node.atlasIndex + particle.atlasIndex];
|
||||
node._batchNode.textureAtlas.dirty = true;
|
||||
} else
|
||||
quad = this._quads[node._particleIdx];
|
||||
|
||||
var r, g, b, a;
|
||||
if (node._opacityModifyRGB) {
|
||||
r = 0 | (particle.color.r * particle.color.a/255);
|
||||
g = 0 | (particle.color.g * particle.color.a/255);
|
||||
b = 0 | (particle.color.b * particle.color.a/255);
|
||||
} else {
|
||||
r = 0 | (particle.color.r );
|
||||
g = 0 | (particle.color.g );
|
||||
b = 0 | (particle.color.b );
|
||||
}
|
||||
a = 0 | (particle.color.a );
|
||||
|
||||
var blColors = quad.bl.colors, brColors = quad.br.colors, tlColors = quad.tl.colors, trColors = quad.tr.colors;
|
||||
blColors.r = brColors.r = tlColors.r = trColors.r = r;
|
||||
blColors.g = brColors.g = tlColors.g = trColors.g = g;
|
||||
blColors.b = brColors.b = tlColors.b = trColors.b = b;
|
||||
blColors.a = brColors.a = tlColors.a = trColors.a = a;
|
||||
|
||||
// vertices
|
||||
var size_2 = particle.size / 2;
|
||||
if (particle.rotation) {
|
||||
var x1 = -size_2, y1 = -size_2;
|
||||
|
||||
var x2 = size_2, y2 = size_2;
|
||||
var x = newPosition.x, y = newPosition.y;
|
||||
|
||||
var rad = -cc.degreesToRadians(particle.rotation);
|
||||
var cr = Math.cos(rad), sr = Math.sin(rad);
|
||||
var ax = x1 * cr - y1 * sr + x;
|
||||
var ay = x1 * sr + y1 * cr + y;
|
||||
var bx = x2 * cr - y1 * sr + x;
|
||||
var by = x2 * sr + y1 * cr + y;
|
||||
var cx = x2 * cr - y2 * sr + x;
|
||||
var cy = x2 * sr + y2 * cr + y;
|
||||
var dx = x1 * cr - y2 * sr + x;
|
||||
var dy = x1 * sr + y2 * cr + y;
|
||||
|
||||
// bottom-left
|
||||
quad.bl.vertices.x = ax;
|
||||
quad.bl.vertices.y = ay;
|
||||
|
||||
// bottom-right vertex:
|
||||
quad.br.vertices.x = bx;
|
||||
quad.br.vertices.y = by;
|
||||
|
||||
// top-left vertex:
|
||||
quad.tl.vertices.x = dx;
|
||||
quad.tl.vertices.y = dy;
|
||||
|
||||
// top-right vertex:
|
||||
quad.tr.vertices.x = cx;
|
||||
quad.tr.vertices.y = cy;
|
||||
} else {
|
||||
// bottom-left vertex:
|
||||
quad.bl.vertices.x = newPosition.x - size_2;
|
||||
quad.bl.vertices.y = newPosition.y - size_2;
|
||||
|
||||
// bottom-right vertex:
|
||||
quad.br.vertices.x = newPosition.x + size_2;
|
||||
quad.br.vertices.y = newPosition.y - size_2;
|
||||
|
||||
// top-left vertex:
|
||||
quad.tl.vertices.x = newPosition.x - size_2;
|
||||
quad.tl.vertices.y = newPosition.y + size_2;
|
||||
|
||||
// top-right vertex:
|
||||
quad.tr.vertices.x = newPosition.x + size_2;
|
||||
quad.tr.vertices.y = newPosition.y + size_2;
|
||||
}
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
if (!node._texture)
|
||||
return;
|
||||
|
||||
var gl = ctx || cc._renderContext;
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); //;
|
||||
|
||||
cc.gl.bindTexture2D(node._texture);
|
||||
cc.gl.blendFuncForParticle(node._blendFunc.src, node._blendFunc.dst);
|
||||
|
||||
//
|
||||
// Using VBO without VAO
|
||||
//
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
|
||||
gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]);
|
||||
gl.drawElements(gl.TRIANGLES, node._particleIdx * 6, gl.UNSIGNED_SHORT, 0);
|
||||
};
|
||||
|
||||
proto.initTexCoordsWithRect = function(pointRect){
|
||||
var node = this._node;
|
||||
var texture = node.texture;
|
||||
|
||||
var wide = pointRect.width;
|
||||
var high = pointRect.height;
|
||||
|
||||
if (texture) {
|
||||
wide = texture.getPixelWidth();
|
||||
high = texture.getPixelHeight();
|
||||
}
|
||||
|
||||
var left, bottom, right, top;
|
||||
if (cc.macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
|
||||
left = (pointRect.x * 2 + 1) / (wide * 2);
|
||||
bottom = (pointRect.y * 2 + 1) / (high * 2);
|
||||
right = left + (pointRect.width * 2 - 2) / (wide * 2);
|
||||
top = bottom + (pointRect.height * 2 - 2) / (high * 2);
|
||||
} else {
|
||||
left = pointRect.x / wide;
|
||||
bottom = pointRect.y / high;
|
||||
right = left + pointRect.width / wide;
|
||||
top = bottom + pointRect.height / high;
|
||||
}
|
||||
|
||||
// Important. Texture in cocos2d are inverted, so the Y component should be inverted
|
||||
var temp = top;
|
||||
top = bottom;
|
||||
bottom = temp;
|
||||
|
||||
var quads;
|
||||
var start = 0, end = 0;
|
||||
if (node._batchNode) {
|
||||
quads = node._batchNode.textureAtlas.quads;
|
||||
start = node.atlasIndex;
|
||||
end = node.atlasIndex + node._totalParticles;
|
||||
} else {
|
||||
quads = this._quads;
|
||||
start = 0;
|
||||
end = node._totalParticles;
|
||||
}
|
||||
|
||||
for (var i = start; i < end; i++) {
|
||||
if (!quads[i])
|
||||
quads[i] = cc.V3F_C4B_T2F_QuadZero();
|
||||
|
||||
// bottom-left vertex:
|
||||
var selQuad = quads[i];
|
||||
selQuad.bl.texCoords.u = left;
|
||||
selQuad.bl.texCoords.v = bottom;
|
||||
// bottom-right vertex:
|
||||
selQuad.br.texCoords.u = right;
|
||||
selQuad.br.texCoords.v = bottom;
|
||||
// top-left vertex:
|
||||
selQuad.tl.texCoords.u = left;
|
||||
selQuad.tl.texCoords.v = top;
|
||||
// top-right vertex:
|
||||
selQuad.tr.texCoords.u = right;
|
||||
selQuad.tr.texCoords.v = top;
|
||||
}
|
||||
};
|
||||
|
||||
proto.setTotalParticles = function(tp){
|
||||
var node = this._node;
|
||||
// If we are setting the total numer of particles to a number higher
|
||||
// than what is allocated, we need to allocate new arrays
|
||||
if (tp > node._allocatedParticles) {
|
||||
var quadSize = cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT;
|
||||
var totalParticles = node._totalParticles;
|
||||
// Allocate new memory
|
||||
this._indices = new Uint16Array(tp * 6);
|
||||
var locQuadsArrayBuffer = new ArrayBuffer(tp * quadSize);
|
||||
//TODO need fix
|
||||
// Assign pointers
|
||||
var locParticles = node._particles;
|
||||
locParticles.length = 0;
|
||||
var locQuads = this._quads;
|
||||
locQuads.length = 0;
|
||||
this._indices = new Uint16Array(totalParticles * 6);
|
||||
var locQuadsArrayBuffer = new ArrayBuffer(quadSize * totalParticles);
|
||||
|
||||
for (var i = 0; i < totalParticles; i++)
|
||||
locQuads[i] = new cc.V3F_C4B_T2F_Quad(null, null, null, null, locQuadsArrayBuffer, i * quadSize);
|
||||
if (!locQuads || !this._indices) {
|
||||
cc.log("cocos2d: Particle system: not enough memory");
|
||||
return false;
|
||||
for (var j = 0; j < tp; j++) {
|
||||
locParticles[j] = new cc.Particle();
|
||||
locQuads[j] = new cc.V3F_C4B_T2F_Quad(null, null, null, null, locQuadsArrayBuffer, j * quadSize);
|
||||
}
|
||||
node._allocatedParticles = tp;
|
||||
node._totalParticles = tp;
|
||||
|
||||
// Init particles
|
||||
if (node._batchNode) {
|
||||
for (var i = 0; i < tp; i++)
|
||||
locParticles[i].atlasIndex = i;
|
||||
}
|
||||
|
||||
this._quadsArrayBuffer = locQuadsArrayBuffer;
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.postStep = function(){
|
||||
var gl = cc._renderContext;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quadsArrayBuffer, gl.DYNAMIC_DRAW);
|
||||
};
|
||||
|
||||
proto._setBlendAdditive = function(){
|
||||
var locBlendFunc = this._node._blendFunc;
|
||||
if (this._texture && !this._texture.hasPremultipliedAlpha()) {
|
||||
locBlendFunc.src = cc.macro.SRC_ALPHA;
|
||||
locBlendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
|
||||
} else {
|
||||
locBlendFunc.src = cc.macro.BLEND_SRC;
|
||||
locBlendFunc.dst = cc.macro.BLEND_DST;
|
||||
}
|
||||
};
|
||||
|
||||
proto._initWithTotalParticles = function(totalParticles){
|
||||
// allocating data space
|
||||
if (!this._allocMemory())
|
||||
return false;
|
||||
|
||||
this.initIndices(totalParticles);
|
||||
this.initIndices(tp);
|
||||
this._setupVBO();
|
||||
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
//set the texture coord
|
||||
if(node._texture){
|
||||
this.initTexCoordsWithRect(cc.rect(0, 0, node._texture.width, node._texture.height));
|
||||
}
|
||||
} else
|
||||
node._totalParticles = tp;
|
||||
node.resetSystem();
|
||||
};
|
||||
|
||||
proto._updateDeltaColor = function (selParticle, dt) {
|
||||
selParticle.color.r += selParticle.deltaColor.r * dt;
|
||||
selParticle.color.g += selParticle.deltaColor.g * dt;
|
||||
selParticle.color.b += selParticle.deltaColor.b * dt;
|
||||
selParticle.color.a += selParticle.deltaColor.a * dt;
|
||||
selParticle.isChangeColor = true;
|
||||
};
|
||||
})();
|
||||
proto.addParticle = function(){
|
||||
var node = this._node,
|
||||
particles = node._particles;
|
||||
return particles[node.particleCount];
|
||||
};
|
||||
|
||||
proto._setupVBO = function(){
|
||||
var node = this;
|
||||
var gl = cc._renderContext;
|
||||
|
||||
//gl.deleteBuffer(this._buffersVBO[0]);
|
||||
this._buffersVBO[0] = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quadsArrayBuffer, gl.DYNAMIC_DRAW);
|
||||
|
||||
this._buffersVBO[1] = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this._indices, gl.STATIC_DRAW);
|
||||
|
||||
//cc.checkGLErrorDebug();
|
||||
};
|
||||
|
||||
proto._allocMemory = function(){
|
||||
var node = this._node;
|
||||
//cc.assert((!this._quads && !this._indices), "Memory already allocated");
|
||||
if(node._batchNode){
|
||||
cc.log("_ccsg.ParticleSystem._allocMemory(): Memory should not be allocated when not using batchNode");
|
||||
return false;
|
||||
}
|
||||
|
||||
var quadSize = cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT;
|
||||
var totalParticles = node._totalParticles;
|
||||
var locQuads = this._quads;
|
||||
locQuads.length = 0;
|
||||
this._indices = new Uint16Array(totalParticles * 6);
|
||||
var locQuadsArrayBuffer = new ArrayBuffer(quadSize * totalParticles);
|
||||
|
||||
for (var i = 0; i < totalParticles; i++)
|
||||
locQuads[i] = new cc.V3F_C4B_T2F_Quad(null, null, null, null, locQuadsArrayBuffer, i * quadSize);
|
||||
if (!locQuads || !this._indices) {
|
||||
cc.log("cocos2d: Particle system: not enough memory");
|
||||
return false;
|
||||
}
|
||||
this._quadsArrayBuffer = locQuadsArrayBuffer;
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.postStep = function(){
|
||||
var gl = cc._renderContext;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._quadsArrayBuffer, gl.DYNAMIC_DRAW);
|
||||
};
|
||||
|
||||
proto._setBlendAdditive = function(){
|
||||
var locBlendFunc = this._node._blendFunc;
|
||||
if (this._texture && !this._texture.hasPremultipliedAlpha()) {
|
||||
locBlendFunc.src = cc.macro.SRC_ALPHA;
|
||||
locBlendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
|
||||
} else {
|
||||
locBlendFunc.src = cc.macro.BLEND_SRC;
|
||||
locBlendFunc.dst = cc.macro.BLEND_DST;
|
||||
}
|
||||
};
|
||||
|
||||
proto._initWithTotalParticles = function(totalParticles){
|
||||
// allocating data space
|
||||
if (!this._allocMemory())
|
||||
return false;
|
||||
|
||||
this.initIndices(totalParticles);
|
||||
this._setupVBO();
|
||||
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
|
||||
proto._updateDeltaColor = function (selParticle, dt) {
|
||||
selParticle.color.r += selParticle.deltaColor.r * dt;
|
||||
selParticle.color.g += selParticle.deltaColor.g * dt;
|
||||
selParticle.color.b += selParticle.deltaColor.b * dt;
|
||||
selParticle.color.a += selParticle.deltaColor.a * dt;
|
||||
selParticle.isChangeColor = true;
|
||||
};
|
||||
@@ -30,9 +30,9 @@
|
||||
/**
|
||||
* cc.tiffReader is a singleton object, it's a tiff file reader, it can parse byte array to draw into a canvas
|
||||
* @class
|
||||
* @name cc.tiffReader
|
||||
* @name tiffReader
|
||||
*/
|
||||
cc.tiffReader = /** @lends cc.tiffReader# */{
|
||||
var tiffReader = /** @lends tiffReader# */{
|
||||
_littleEndian: false,
|
||||
_tiffData: null,
|
||||
_fileDirectories: [],
|
||||
@@ -689,4 +689,6 @@ cc.tiffReader = /** @lends cc.tiffReader# */{
|
||||
0x000B: 'FLOAT',
|
||||
0x000C: 'DOUBLE'
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = tiffReader;
|
||||
@@ -43,7 +43,7 @@
|
||||
node._space.eachConstraint(cc.DrawConstraint.bind(node));
|
||||
|
||||
//cc.DrawNode.prototype.draw.call(node);
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
node._render();
|
||||
|
||||
@@ -50,10 +50,10 @@
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
|
||||
var blendFunc = node._sprite._blendFunc;
|
||||
cc.glBlendFunc(blendFunc.src, blendFunc.dst);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.gl.blendFunc(blendFunc.src, blendFunc.dst);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
cc.glBindTexture2D(node._sprite.texture);
|
||||
cc.gl.bindTexture2D(node._sprite.texture);
|
||||
|
||||
context.bindBuffer(context.ARRAY_BUFFER, this._vertexWebGLBuffer);
|
||||
if (this._vertexDataDirty) {
|
||||
|
||||
@@ -25,40 +25,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* enum for jpg
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.IMAGE_FORMAT_JPEG = 0;
|
||||
/**
|
||||
* enum for png
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.IMAGE_FORMAT_PNG = 1;
|
||||
/**
|
||||
* enum for raw
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.IMAGE_FORMAT_RAWDATA = 9;
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @return {Number}
|
||||
* Constructor
|
||||
*/
|
||||
cc.NextPOT = function (x) {
|
||||
x = x - 1;
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >> 16);
|
||||
return x + 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* cc.RenderTexture is a generic rendering target. To render things into it,<br/>
|
||||
* simply construct a render target, call begin on it, call visit on any cocos<br/>
|
||||
@@ -103,7 +69,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{
|
||||
* Constructor of cc.RenderTexture for Canvas
|
||||
* @param {Number} width
|
||||
* @param {Number} height
|
||||
* @param {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
|
||||
* @param {cc.ImageFormat.JPEG|cc.ImageFormat.PNG|cc.ImageFormat.RAWDATA} format
|
||||
* @param {Number} depthStencilFormat
|
||||
* @example
|
||||
* // Example
|
||||
@@ -172,7 +138,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{
|
||||
* @function
|
||||
* @param {Number} width
|
||||
* @param {Number} height
|
||||
* @param {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} [format]
|
||||
* @param {cc.ImageFormat.JPEG|cc.ImageFormat.PNG|cc.ImageFormat.RAWDATA} [format]
|
||||
* @param {Number} [depthStencilFormat]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
@@ -397,7 +363,7 @@ cc.defineGetterSetter(_p, "clearColorVal", _p.getClearColor, _p.setClearColor);
|
||||
* @deprecated since v3.0 please use new cc.RenderTexture() instead.
|
||||
* @param {Number} width
|
||||
* @param {Number} height
|
||||
* @param {cc.IMAGE_FORMAT_JPEG|cc.IMAGE_FORMAT_PNG|cc.IMAGE_FORMAT_RAWDATA} format
|
||||
* @param {cc.ImageFormat.JPEG|cc.ImageFormat.PNG|cc.ImageFormat.RAWDATA} format
|
||||
* @param {Number} depthStencilFormat
|
||||
* @return {cc.RenderTexture}
|
||||
*/
|
||||
|
||||
@@ -22,85 +22,83 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
cc.RenderTexture.CanvasRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
this._clearColorStr = "rgba(255,255,255,1)";
|
||||
cc.RenderTexture.CanvasRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
this._clearColorStr = "rgba(255,255,255,1)";
|
||||
|
||||
this._cacheCanvas = document.createElement('canvas');
|
||||
this._cacheContext = new cc.CanvasContextWrapper(this._cacheCanvas.getContext('2d'));
|
||||
};
|
||||
this._cacheCanvas = document.createElement('canvas');
|
||||
this._cacheContext = new cc.CanvasContextWrapper(this._cacheCanvas.getContext('2d'));
|
||||
};
|
||||
|
||||
var proto = cc.RenderTexture.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.RenderTexture.CanvasRenderCmd;
|
||||
var proto = cc.RenderTexture.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
proto.constructor = cc.RenderTexture.CanvasRenderCmd;
|
||||
|
||||
proto.cleanup = function(){
|
||||
this._cacheContext = null;
|
||||
this._cacheCanvas = null;
|
||||
};
|
||||
proto.cleanup = function(){
|
||||
this._cacheContext = null;
|
||||
this._cacheCanvas = null;
|
||||
};
|
||||
|
||||
proto.clearStencil = function (stencilValue) { };
|
||||
proto.clearStencil = function (stencilValue) { };
|
||||
|
||||
proto.setVirtualViewport = function(rtBegin, fullRect, fullViewport) {};
|
||||
proto.setVirtualViewport = function(rtBegin, fullRect, fullViewport) {};
|
||||
|
||||
proto.updateClearColor = function(clearColor){
|
||||
this._clearColorStr = "rgba(" + (0 | clearColor.r) + "," + (0 | clearColor.g) + "," + (0 | clearColor.b) + "," + clearColor.a / 255 + ")";
|
||||
};
|
||||
proto.updateClearColor = function(clearColor){
|
||||
this._clearColorStr = "rgba(" + (0 | clearColor.r) + "," + (0 | clearColor.g) + "," + (0 | clearColor.b) + "," + clearColor.a / 255 + ")";
|
||||
};
|
||||
|
||||
proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){
|
||||
var node = this._node;
|
||||
var locCacheCanvas = this._cacheCanvas;
|
||||
locCacheCanvas.width = 0 | width;
|
||||
locCacheCanvas.height = 0 | height;
|
||||
proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){
|
||||
var node = this._node;
|
||||
var locCacheCanvas = this._cacheCanvas;
|
||||
locCacheCanvas.width = 0 | width;
|
||||
locCacheCanvas.height = 0 | height;
|
||||
|
||||
var texture = new cc.Texture2D();
|
||||
texture.initWithElement(locCacheCanvas);
|
||||
texture.handleLoadedTexture();
|
||||
var texture = new cc.Texture2D();
|
||||
texture.initWithElement(locCacheCanvas);
|
||||
texture.handleLoadedTexture();
|
||||
|
||||
var locSprite = node.sprite = new _ccsg.Sprite(texture);
|
||||
locSprite.setBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_ALPHA);
|
||||
// Disabled by default.
|
||||
node.autoDraw = false;
|
||||
// add sprite for backward compatibility
|
||||
node.addChild(locSprite);
|
||||
return true;
|
||||
};
|
||||
var locSprite = node.sprite = new _ccsg.Sprite(texture);
|
||||
locSprite.setBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_ALPHA);
|
||||
// Disabled by default.
|
||||
node.autoDraw = false;
|
||||
// add sprite for backward compatibility
|
||||
node.addChild(locSprite);
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.begin = function(){};
|
||||
proto.begin = function(){};
|
||||
|
||||
proto._beginWithClear = function(r, g, b, a, depthValue, stencilValue, flags){
|
||||
r = r || 0;
|
||||
g = g || 0;
|
||||
b = b || 0;
|
||||
a = isNaN(a) ? 255 : a;
|
||||
proto._beginWithClear = function(r, g, b, a, depthValue, stencilValue, flags){
|
||||
r = r || 0;
|
||||
g = g || 0;
|
||||
b = b || 0;
|
||||
a = isNaN(a) ? 255 : a;
|
||||
|
||||
var context = this._cacheContext.getContext();
|
||||
var locCanvas = this._cacheCanvas;
|
||||
context.setTransform(1,0,0,1,0,0);
|
||||
this._cacheContext.setFillStyle("rgba(" + (0 | r) + "," + (0 | g) + "," + (0 | b) + "," + a / 255 + ")");
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
context.fillRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
};
|
||||
var context = this._cacheContext.getContext();
|
||||
var locCanvas = this._cacheCanvas;
|
||||
context.setTransform(1,0,0,1,0,0);
|
||||
this._cacheContext.setFillStyle("rgba(" + (0 | r) + "," + (0 | g) + "," + (0 | b) + "," + a / 255 + ")");
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
context.fillRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
};
|
||||
|
||||
proto.end = function(){
|
||||
var node = this._node;
|
||||
proto.end = function(){
|
||||
var node = this._node;
|
||||
|
||||
cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId);
|
||||
};
|
||||
cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId);
|
||||
};
|
||||
|
||||
proto.clearRect = function(x, y, width, height){
|
||||
this._cacheContext.clearRect(x, y, width, -height);
|
||||
};
|
||||
proto.clearRect = function(x, y, width, height){
|
||||
this._cacheContext.clearRect(x, y, width, -height);
|
||||
};
|
||||
|
||||
proto.clearDepth = function(depthValue){
|
||||
cc.log("clearDepth isn't supported on Cocos2d-Html5");
|
||||
};
|
||||
proto.clearDepth = function(depthValue){
|
||||
cc.log("clearDepth isn't supported on Cocos2d-Html5");
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
this._syncStatus(parentCmd);
|
||||
node.sprite.visit(this);
|
||||
this._dirtyFlag = 0;
|
||||
};
|
||||
})();
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
this._syncStatus(parentCmd);
|
||||
node.sprite.visit(this);
|
||||
this._dirtyFlag = 0;
|
||||
};
|
||||
@@ -22,366 +22,366 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
cc.RenderTexture.WebGLRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
var misc = require('../cocos2d/core/utils/misc');
|
||||
|
||||
this._fBO = null;
|
||||
this._oldFBO = null;
|
||||
this._textureCopy = null;
|
||||
this._depthRenderBuffer = null;
|
||||
cc.RenderTexture.WebGLRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
|
||||
this._rtTextureRect = new cc.Rect();
|
||||
this._fullRect = new cc.Rect();
|
||||
this._fullViewport = new cc.Rect();
|
||||
};
|
||||
this._fBO = null;
|
||||
this._oldFBO = null;
|
||||
this._textureCopy = null;
|
||||
this._depthRenderBuffer = null;
|
||||
|
||||
var proto = cc.RenderTexture.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.RenderTexture.WebGLRenderCmd;
|
||||
this._rtTextureRect = new cc.Rect();
|
||||
this._fullRect = new cc.Rect();
|
||||
this._fullViewport = new cc.Rect();
|
||||
};
|
||||
|
||||
proto.setVirtualViewport = function(rtBegin, fullRect, fullViewport) {
|
||||
this._rtTextureRect.x = rtBegin.x;
|
||||
this._rtTextureRect.y = rtBegin.y;
|
||||
var proto = cc.RenderTexture.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
proto.constructor = cc.RenderTexture.WebGLRenderCmd;
|
||||
|
||||
this._fullRect = fullRect;
|
||||
this._fullViewport = fullViewport;
|
||||
};
|
||||
proto.setVirtualViewport = function(rtBegin, fullRect, fullViewport) {
|
||||
this._rtTextureRect.x = rtBegin.x;
|
||||
this._rtTextureRect.y = rtBegin.y;
|
||||
|
||||
proto.rendering = function (ctx) {
|
||||
var gl = ctx || cc._renderContext;
|
||||
var node = this._node;
|
||||
if (node.autoDraw) {
|
||||
node.begin();
|
||||
this._fullRect = fullRect;
|
||||
this._fullViewport = fullViewport;
|
||||
};
|
||||
|
||||
var locClearFlags = node.clearFlags;
|
||||
if (locClearFlags) {
|
||||
var oldClearColor = [0.0, 0.0, 0.0, 0.0];
|
||||
var oldDepthClearValue = 0.0;
|
||||
var oldStencilClearValue = 0;
|
||||
|
||||
// backup and set
|
||||
if (locClearFlags & gl.COLOR_BUFFER_BIT) {
|
||||
oldClearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
|
||||
gl.clearColor(node._clearColor.r / 255, node._clearColor.g / 255, node._clearColor.b / 255, node._clearColor.a / 255);
|
||||
}
|
||||
|
||||
if (locClearFlags & gl.DEPTH_BUFFER_BIT) {
|
||||
oldDepthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
gl.clearDepth(node.clearDepthVal);
|
||||
}
|
||||
|
||||
if (locClearFlags & gl.STENCIL_BUFFER_BIT) {
|
||||
oldStencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
gl.clearStencil(node.clearStencilVal);
|
||||
}
|
||||
|
||||
// clear
|
||||
gl.clear(locClearFlags);
|
||||
|
||||
// restore
|
||||
if (locClearFlags & gl.COLOR_BUFFER_BIT)
|
||||
gl.clearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
|
||||
if (locClearFlags & gl.DEPTH_BUFFER_BIT)
|
||||
gl.clearDepth(oldDepthClearValue);
|
||||
|
||||
if (locClearFlags & gl.STENCIL_BUFFER_BIT)
|
||||
gl.clearStencil(oldStencilClearValue);
|
||||
}
|
||||
|
||||
//! make sure all children are drawn
|
||||
node.sortAllChildren();
|
||||
var locChildren = node._children;
|
||||
for (var i = 0; i < locChildren.length; i++) {
|
||||
var getChild = locChildren[i];
|
||||
if (getChild !== node.sprite){
|
||||
getChild._renderCmd.visit(node.sprite._renderCmd); //TODO it's very Strange
|
||||
}
|
||||
}
|
||||
node.end();
|
||||
}
|
||||
};
|
||||
|
||||
proto.clearStencil = function(stencilValue) {
|
||||
var gl = cc._renderContext;
|
||||
// save old stencil value
|
||||
var stencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
|
||||
gl.clearStencil(stencilValue);
|
||||
gl.clear(gl.STENCIL_BUFFER_BIT);
|
||||
|
||||
// restore clear color
|
||||
gl.clearStencil(stencilClearValue);
|
||||
};
|
||||
|
||||
proto.cleanup = function(){
|
||||
var node = this._node;
|
||||
//node.sprite = null;
|
||||
this._textureCopy = null;
|
||||
|
||||
var gl = cc._renderContext;
|
||||
gl.deleteFramebuffer(this._fBO);
|
||||
if (this._depthRenderBuffer)
|
||||
gl.deleteRenderbuffer(this._depthRenderBuffer);
|
||||
};
|
||||
|
||||
proto.updateClearColor = function(clearColor){ };
|
||||
|
||||
proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){
|
||||
var node = this._node;
|
||||
if(format === cc.Texture2D.PIXEL_FORMAT_A8)
|
||||
cc.log( "cc.RenderTexture._initWithWidthAndHeightForWebGL() : only RGB and RGBA formats are valid for a render texture;");
|
||||
|
||||
var gl = cc._renderContext;
|
||||
this._fullRect = new cc.Rect(0,0, width, height);
|
||||
this._fullViewport = new cc.Rect(0,0, width, height);
|
||||
|
||||
width = 0 | width;
|
||||
height = 0 | height;
|
||||
|
||||
this._oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
||||
|
||||
// textures must be power of two squared
|
||||
var powW , powH;
|
||||
|
||||
if (cc.configuration.supportsNPOT()) {
|
||||
powW = width;
|
||||
powH = height;
|
||||
} else {
|
||||
powW = cc.NextPOT(width);
|
||||
powH = cc.NextPOT(height);
|
||||
}
|
||||
|
||||
//void *data = malloc(powW * powH * 4);
|
||||
var dataLen = powW * powH * 4;
|
||||
var data = new Uint8Array(dataLen);
|
||||
//memset(data, 0, (int)(powW * powH * 4));
|
||||
for (var i = 0; i < powW * powH * 4; i++)
|
||||
data[i] = 0;
|
||||
|
||||
this._pixelFormat = format;
|
||||
|
||||
var locTexture = node._texture = new cc.Texture2D();
|
||||
if (!node._texture)
|
||||
return false;
|
||||
|
||||
locTexture.initWithData(data, node._pixelFormat, powW, powH, cc.size(width, height));
|
||||
//free( data );
|
||||
|
||||
var oldRBO = gl.getParameter(gl.RENDERBUFFER_BINDING);
|
||||
|
||||
if (cc.configuration.checkForGLExtension("GL_QCOM")) {
|
||||
this._textureCopy = new cc.Texture2D();
|
||||
if (!this._textureCopy)
|
||||
return false;
|
||||
this._textureCopy.initWithData(data, node._pixelFormat, powW, powH, cc.size(width, height));
|
||||
}
|
||||
|
||||
// generate FBO
|
||||
this._fBO = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fBO);
|
||||
|
||||
// associate texture with FBO
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, locTexture._webTextureObj, 0);
|
||||
|
||||
if (depthStencilFormat !== 0) {
|
||||
//create and attach depth buffer
|
||||
this._depthRenderBuffer = gl.createRenderbuffer();
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, depthStencilFormat, powW, powH);
|
||||
if(depthStencilFormat === gl.DEPTH_STENCIL)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
else if(depthStencilFormat === gl.STENCIL_INDEX || depthStencilFormat === gl.STENCIL_INDEX8)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
else if(depthStencilFormat === gl.DEPTH_COMPONENT16)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
}
|
||||
|
||||
// check if it worked (probably worth doing :) )
|
||||
if(gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE)
|
||||
cc.log("Could not attach texture to the framebuffer");
|
||||
|
||||
locTexture.setAliasTexParameters();
|
||||
|
||||
var locSprite = node.sprite = new _ccsg.Sprite(locTexture);
|
||||
locSprite.scaleY = -1;
|
||||
locSprite.setBlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, oldRBO);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._oldFBO);
|
||||
|
||||
// Disabled by default.
|
||||
node.autoDraw = false;
|
||||
|
||||
// add sprite for backward compatibility
|
||||
node.addChild(locSprite);
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.begin = function(){
|
||||
var node = this._node;
|
||||
// Save the current matrix
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
cc.math.glPushMatrix();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
cc.math.glPushMatrix();
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
var director = cc.director;
|
||||
director.setProjection(director.getProjection());
|
||||
|
||||
var texSize = node._texture.getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
var size = cc.director.getWinSizeInPixels();
|
||||
var widthRatio = size.width / texSize.width;
|
||||
var heightRatio = size.height / texSize.height;
|
||||
|
||||
var orthoMatrix = cc.math.Matrix4.createOrthographicProjection(-1.0 / widthRatio, 1.0 / widthRatio,
|
||||
-1.0 / heightRatio, 1.0 / heightRatio, -1, 1);
|
||||
cc.math.glMultMatrix(orthoMatrix);
|
||||
|
||||
//calculate viewport
|
||||
var viewport = new cc.Rect(0, 0, 0, 0);
|
||||
viewport.width = this._fullViewport.width;
|
||||
viewport.height = this._fullViewport.height;
|
||||
var viewPortRectWidthRatio = viewport.width / this._fullRect.width;
|
||||
var viewPortRectHeightRatio = viewport.height / this._fullRect.height;
|
||||
viewport.x = (this._fullRect.x - this._rtTextureRect.x) * viewPortRectWidthRatio;
|
||||
viewport.y = (this._fullRect.y - this._rtTextureRect.y) * viewPortRectHeightRatio;
|
||||
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
||||
|
||||
this._oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fBO);//Will direct drawing to the frame buffer created above
|
||||
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture.
|
||||
* The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture.
|
||||
* Create a temporary texture to overcome this. At the end of CCRenderTexture::begin(), switch the attached texture to the second one, call glClear,
|
||||
* and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (cc.configuration.checkForGLExtension("GL_QCOM")) {
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._textureCopy._webTextureObj, 0);
|
||||
//cc.checkGLErrorDebug();
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, node._texture._webTextureObj, 0);
|
||||
}
|
||||
};
|
||||
|
||||
proto._beginWithClear = function(r, g, b, a, depthValue, stencilValue, flags){
|
||||
r = r / 255;
|
||||
g = g / 255;
|
||||
b = b / 255;
|
||||
a = a / 255;
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
// save clear color
|
||||
var clearColor = [0.0, 0.0, 0.0, 0.0];
|
||||
var depthClearValue = 0.0;
|
||||
var stencilClearValue = 0;
|
||||
|
||||
if (flags & gl.COLOR_BUFFER_BIT) {
|
||||
clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
|
||||
gl.clearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
if (flags & gl.DEPTH_BUFFER_BIT) {
|
||||
depthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
gl.clearDepth(depthValue);
|
||||
}
|
||||
|
||||
if (flags & gl.STENCIL_BUFFER_BIT) {
|
||||
stencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
gl.clearStencil(stencilValue);
|
||||
}
|
||||
|
||||
gl.clear(flags);
|
||||
|
||||
// restore
|
||||
if (flags & gl.COLOR_BUFFER_BIT)
|
||||
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
|
||||
if (flags & gl.DEPTH_BUFFER_BIT)
|
||||
gl.clearDepth(depthClearValue);
|
||||
|
||||
if (flags & gl.STENCIL_BUFFER_BIT)
|
||||
gl.clearStencil(stencilClearValue);
|
||||
};
|
||||
|
||||
proto.end = function(){
|
||||
var node = this._node;
|
||||
cc.renderer._renderingToBuffer(node.__instanceId);
|
||||
|
||||
var gl = cc._renderContext;
|
||||
var director = cc.director;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._oldFBO);
|
||||
|
||||
//restore viewport
|
||||
director.setViewport();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
cc.math.glPopMatrix();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
cc.math.glPopMatrix();
|
||||
|
||||
/* var size = director.getWinSizeInPixels();
|
||||
|
||||
// restore viewport
|
||||
gl.viewport(0, 0, size.width, size.height);
|
||||
|
||||
// special viewport for 3d projection + retina display
|
||||
if (director.getProjection() == cc.Director.PROJECTION_3D) {
|
||||
gl.viewport((-size.width / 2), (-size.height / 2), size.width, size.height));
|
||||
}
|
||||
|
||||
director.setProjection(director.getProjection());*/
|
||||
};
|
||||
|
||||
proto.clearRect = function(x, y, width, height){
|
||||
//TODO need to implement
|
||||
};
|
||||
|
||||
proto.clearDepth = function(depthValue){
|
||||
var node = this._node;
|
||||
proto.rendering = function (ctx) {
|
||||
var gl = ctx || cc._renderContext;
|
||||
var node = this._node;
|
||||
if (node.autoDraw) {
|
||||
node.begin();
|
||||
|
||||
var gl = cc._renderContext;
|
||||
//! save old depth value
|
||||
var depthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
var locClearFlags = node.clearFlags;
|
||||
if (locClearFlags) {
|
||||
var oldClearColor = [0.0, 0.0, 0.0, 0.0];
|
||||
var oldDepthClearValue = 0.0;
|
||||
var oldStencilClearValue = 0;
|
||||
|
||||
gl.clearDepth(depthValue);
|
||||
gl.clear(gl.DEPTH_BUFFER_BIT);
|
||||
// backup and set
|
||||
if (locClearFlags & gl.COLOR_BUFFER_BIT) {
|
||||
oldClearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
|
||||
gl.clearColor(node._clearColor.r / 255, node._clearColor.g / 255, node._clearColor.b / 255, node._clearColor.a / 255);
|
||||
}
|
||||
|
||||
// restore clear color
|
||||
gl.clearDepth(depthClearValue);
|
||||
if (locClearFlags & gl.DEPTH_BUFFER_BIT) {
|
||||
oldDepthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
gl.clearDepth(node.clearDepthVal);
|
||||
}
|
||||
|
||||
if (locClearFlags & gl.STENCIL_BUFFER_BIT) {
|
||||
oldStencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
gl.clearStencil(node.clearStencilVal);
|
||||
}
|
||||
|
||||
// clear
|
||||
gl.clear(locClearFlags);
|
||||
|
||||
// restore
|
||||
if (locClearFlags & gl.COLOR_BUFFER_BIT)
|
||||
gl.clearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
|
||||
if (locClearFlags & gl.DEPTH_BUFFER_BIT)
|
||||
gl.clearDepth(oldDepthClearValue);
|
||||
|
||||
if (locClearFlags & gl.STENCIL_BUFFER_BIT)
|
||||
gl.clearStencil(oldStencilClearValue);
|
||||
}
|
||||
|
||||
//! make sure all children are drawn
|
||||
node.sortAllChildren();
|
||||
var locChildren = node._children;
|
||||
for (var i = 0; i < locChildren.length; i++) {
|
||||
var getChild = locChildren[i];
|
||||
if (getChild !== node.sprite){
|
||||
getChild._renderCmd.visit(node.sprite._renderCmd); //TODO it's very Strange
|
||||
}
|
||||
}
|
||||
node.end();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
if (!node._visible)
|
||||
return;
|
||||
cc.kmGLPushMatrix();
|
||||
proto.clearStencil = function(stencilValue) {
|
||||
var gl = cc._renderContext;
|
||||
// save old stencil value
|
||||
var stencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
|
||||
//TODO using GridNode
|
||||
/* var locGrid = this.grid;
|
||||
if (locGrid && locGrid.isActive()) {
|
||||
locGrid.beforeDraw();
|
||||
this.transformAncestors();
|
||||
}*/
|
||||
gl.clearStencil(stencilValue);
|
||||
gl.clear(gl.STENCIL_BUFFER_BIT);
|
||||
|
||||
this._syncStatus(parentCmd);
|
||||
//this.toRenderer();
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
node.sprite.visit(this);
|
||||
// restore clear color
|
||||
gl.clearStencil(stencilClearValue);
|
||||
};
|
||||
|
||||
//TODO GridNode
|
||||
/* if (locGrid && locGrid.isActive())
|
||||
locGrid.afterDraw(this);*/
|
||||
proto.cleanup = function(){
|
||||
var node = this._node;
|
||||
//node.sprite = null;
|
||||
this._textureCopy = null;
|
||||
|
||||
this._dirtyFlag = 0;
|
||||
cc.math.glPopMatrix();
|
||||
};
|
||||
})();
|
||||
var gl = cc._renderContext;
|
||||
gl.deleteFramebuffer(this._fBO);
|
||||
if (this._depthRenderBuffer)
|
||||
gl.deleteRenderbuffer(this._depthRenderBuffer);
|
||||
};
|
||||
|
||||
proto.updateClearColor = function(clearColor){ };
|
||||
|
||||
proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){
|
||||
var node = this._node;
|
||||
if(format === cc.Texture2D.PIXEL_FORMAT_A8)
|
||||
cc.log( "cc.RenderTexture._initWithWidthAndHeightForWebGL() : only RGB and RGBA formats are valid for a render texture;");
|
||||
|
||||
var gl = cc._renderContext;
|
||||
this._fullRect = new cc.Rect(0,0, width, height);
|
||||
this._fullViewport = new cc.Rect(0,0, width, height);
|
||||
|
||||
width = 0 | width;
|
||||
height = 0 | height;
|
||||
|
||||
this._oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
||||
|
||||
// textures must be power of two squared
|
||||
var powW , powH;
|
||||
|
||||
if (cc.configuration.supportsNPOT()) {
|
||||
powW = width;
|
||||
powH = height;
|
||||
} else {
|
||||
powW = misc.NextPOT(width);
|
||||
powH = misc.NextPOT(height);
|
||||
}
|
||||
|
||||
//void *data = malloc(powW * powH * 4);
|
||||
var dataLen = powW * powH * 4;
|
||||
var data = new Uint8Array(dataLen);
|
||||
//memset(data, 0, (int)(powW * powH * 4));
|
||||
for (var i = 0; i < powW * powH * 4; i++)
|
||||
data[i] = 0;
|
||||
|
||||
this._pixelFormat = format;
|
||||
|
||||
var locTexture = node._texture = new cc.Texture2D();
|
||||
if (!node._texture)
|
||||
return false;
|
||||
|
||||
locTexture.initWithData(data, node._pixelFormat, powW, powH, cc.size(width, height));
|
||||
//free( data );
|
||||
|
||||
var oldRBO = gl.getParameter(gl.RENDERBUFFER_BINDING);
|
||||
|
||||
if (cc.configuration.checkForGLExtension("GL_QCOM")) {
|
||||
this._textureCopy = new cc.Texture2D();
|
||||
if (!this._textureCopy)
|
||||
return false;
|
||||
this._textureCopy.initWithData(data, node._pixelFormat, powW, powH, cc.size(width, height));
|
||||
}
|
||||
|
||||
// generate FBO
|
||||
this._fBO = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fBO);
|
||||
|
||||
// associate texture with FBO
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, locTexture._webTextureObj, 0);
|
||||
|
||||
if (depthStencilFormat !== 0) {
|
||||
//create and attach depth buffer
|
||||
this._depthRenderBuffer = gl.createRenderbuffer();
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, depthStencilFormat, powW, powH);
|
||||
if(depthStencilFormat === gl.DEPTH_STENCIL)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
else if(depthStencilFormat === gl.STENCIL_INDEX || depthStencilFormat === gl.STENCIL_INDEX8)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
else if(depthStencilFormat === gl.DEPTH_COMPONENT16)
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthRenderBuffer);
|
||||
}
|
||||
|
||||
// check if it worked (probably worth doing :) )
|
||||
if(gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE)
|
||||
cc.log("Could not attach texture to the framebuffer");
|
||||
|
||||
locTexture.setAliasTexParameters();
|
||||
|
||||
var locSprite = node.sprite = new _ccsg.Sprite(locTexture);
|
||||
locSprite.scaleY = -1;
|
||||
locSprite.setBlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, oldRBO);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._oldFBO);
|
||||
|
||||
// Disabled by default.
|
||||
node.autoDraw = false;
|
||||
|
||||
// add sprite for backward compatibility
|
||||
node.addChild(locSprite);
|
||||
return true;
|
||||
};
|
||||
|
||||
proto.begin = function(){
|
||||
var node = this._node;
|
||||
// Save the current matrix
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
cc.math.glPushMatrix();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
cc.math.glPushMatrix();
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
var director = cc.director;
|
||||
director.setProjection(director.getProjection());
|
||||
|
||||
var texSize = node._texture.getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
var size = cc.director.getWinSizeInPixels();
|
||||
var widthRatio = size.width / texSize.width;
|
||||
var heightRatio = size.height / texSize.height;
|
||||
|
||||
var orthoMatrix = cc.math.Matrix4.createOrthographicProjection(-1.0 / widthRatio, 1.0 / widthRatio,
|
||||
-1.0 / heightRatio, 1.0 / heightRatio, -1, 1);
|
||||
cc.math.glMultMatrix(orthoMatrix);
|
||||
|
||||
//calculate viewport
|
||||
var viewport = new cc.Rect(0, 0, 0, 0);
|
||||
viewport.width = this._fullViewport.width;
|
||||
viewport.height = this._fullViewport.height;
|
||||
var viewPortRectWidthRatio = viewport.width / this._fullRect.width;
|
||||
var viewPortRectHeightRatio = viewport.height / this._fullRect.height;
|
||||
viewport.x = (this._fullRect.x - this._rtTextureRect.x) * viewPortRectWidthRatio;
|
||||
viewport.y = (this._fullRect.y - this._rtTextureRect.y) * viewPortRectHeightRatio;
|
||||
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
||||
|
||||
this._oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._fBO);//Will direct drawing to the frame buffer created above
|
||||
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture.
|
||||
* The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture.
|
||||
* Create a temporary texture to overcome this. At the end of CCRenderTexture::begin(), switch the attached texture to the second one, call glClear,
|
||||
* and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (cc.configuration.checkForGLExtension("GL_QCOM")) {
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._textureCopy._webTextureObj, 0);
|
||||
//cc.checkGLErrorDebug();
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, node._texture._webTextureObj, 0);
|
||||
}
|
||||
};
|
||||
|
||||
proto._beginWithClear = function(r, g, b, a, depthValue, stencilValue, flags){
|
||||
r = r / 255;
|
||||
g = g / 255;
|
||||
b = b / 255;
|
||||
a = a / 255;
|
||||
|
||||
var gl = cc._renderContext;
|
||||
|
||||
// save clear color
|
||||
var clearColor = [0.0, 0.0, 0.0, 0.0];
|
||||
var depthClearValue = 0.0;
|
||||
var stencilClearValue = 0;
|
||||
|
||||
if (flags & gl.COLOR_BUFFER_BIT) {
|
||||
clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
|
||||
gl.clearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
if (flags & gl.DEPTH_BUFFER_BIT) {
|
||||
depthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
gl.clearDepth(depthValue);
|
||||
}
|
||||
|
||||
if (flags & gl.STENCIL_BUFFER_BIT) {
|
||||
stencilClearValue = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
|
||||
gl.clearStencil(stencilValue);
|
||||
}
|
||||
|
||||
gl.clear(flags);
|
||||
|
||||
// restore
|
||||
if (flags & gl.COLOR_BUFFER_BIT)
|
||||
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
|
||||
if (flags & gl.DEPTH_BUFFER_BIT)
|
||||
gl.clearDepth(depthClearValue);
|
||||
|
||||
if (flags & gl.STENCIL_BUFFER_BIT)
|
||||
gl.clearStencil(stencilClearValue);
|
||||
};
|
||||
|
||||
proto.end = function(){
|
||||
var node = this._node;
|
||||
cc.renderer._renderingToBuffer(node.__instanceId);
|
||||
|
||||
var gl = cc._renderContext;
|
||||
var director = cc.director;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this._oldFBO);
|
||||
|
||||
//restore viewport
|
||||
director.setViewport();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
|
||||
cc.math.glPopMatrix();
|
||||
cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
|
||||
cc.math.glPopMatrix();
|
||||
|
||||
/* var size = director.getWinSizeInPixels();
|
||||
|
||||
// restore viewport
|
||||
gl.viewport(0, 0, size.width, size.height);
|
||||
|
||||
// special viewport for 3d projection + retina display
|
||||
if (director.getProjection() == cc.Director.PROJECTION_3D) {
|
||||
gl.viewport((-size.width / 2), (-size.height / 2), size.width, size.height));
|
||||
}
|
||||
|
||||
director.setProjection(director.getProjection());*/
|
||||
};
|
||||
|
||||
proto.clearRect = function(x, y, width, height){
|
||||
//TODO need to implement
|
||||
};
|
||||
|
||||
proto.clearDepth = function(depthValue){
|
||||
var node = this._node;
|
||||
node.begin();
|
||||
|
||||
var gl = cc._renderContext;
|
||||
//! save old depth value
|
||||
var depthClearValue = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
|
||||
|
||||
gl.clearDepth(depthValue);
|
||||
gl.clear(gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
// restore clear color
|
||||
gl.clearDepth(depthClearValue);
|
||||
node.end();
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
if (!node._visible)
|
||||
return;
|
||||
cc.kmGLPushMatrix();
|
||||
|
||||
//TODO using GridNode
|
||||
/* var locGrid = this.grid;
|
||||
if (locGrid && locGrid.isActive()) {
|
||||
locGrid.beforeDraw();
|
||||
this.transformAncestors();
|
||||
}*/
|
||||
|
||||
this._syncStatus(parentCmd);
|
||||
//this.toRenderer();
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
node.sprite.visit(this);
|
||||
|
||||
//TODO GridNode
|
||||
/* if (locGrid && locGrid.isActive())
|
||||
locGrid.afterDraw(this);*/
|
||||
|
||||
this._dirtyFlag = 0;
|
||||
cc.math.glPopMatrix();
|
||||
};
|
||||
@@ -246,7 +246,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
|
||||
var status = this._glContext.getProgramParameter(this._programObj, this._glContext.LINK_STATUS);
|
||||
if (!status) {
|
||||
cc.log("cocos2d: ERROR: Failed to link program: " + this._glContext.getProgramInfoLog(this._programObj));
|
||||
cc.glDeleteProgram(this._programObj);
|
||||
cc.gl.deleteProgram(this._programObj);
|
||||
this._programObj = null;
|
||||
return false;
|
||||
}
|
||||
@@ -256,10 +256,10 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* it will call glUseProgram()
|
||||
* it will call gl.useProgram()
|
||||
*/
|
||||
use: function () {
|
||||
cc.glUseProgram(this._programObj);
|
||||
cc.gl.useProgram(this._programObj);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -691,7 +691,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
|
||||
this._uniforms.length = 0;
|
||||
|
||||
// it is already deallocated by android
|
||||
//ccGLDeleteProgram(m_uProgram);
|
||||
//cc.gl.deleteProgram(m_uProgram);
|
||||
this._glContext.deleteProgram(this._programObj);
|
||||
this._programObj = null;
|
||||
|
||||
@@ -723,17 +723,6 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a cc.GLProgram object
|
||||
* @deprecated since v3.0, please use new cc.GLProgram(vShaderFileName, fShaderFileName) instead
|
||||
* @param {String} vShaderFileName
|
||||
* @param {String} fShaderFileName
|
||||
* @returns {cc.GLProgram}
|
||||
*/
|
||||
cc.GLProgram.create = function (vShaderFileName, fShaderFileName) {
|
||||
return new cc.GLProgram(vShaderFileName, fShaderFileName);
|
||||
};
|
||||
|
||||
cc.GLProgram._highpSupported = null;
|
||||
|
||||
cc.GLProgram._isHighpSupported = function(){
|
||||
@@ -744,27 +733,3 @@ cc.GLProgram._isHighpSupported = function(){
|
||||
}
|
||||
return cc.GLProgram._highpSupported;
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the shader program for this node
|
||||
*
|
||||
* Since v2.0, each rendering node must set its shader program.
|
||||
* It should be set in initialize phase.
|
||||
* </p>
|
||||
* @function
|
||||
* @param {_ccsg.Node} node
|
||||
* @param {cc.GLProgram} program The shader program which fetches from CCShaderCache.
|
||||
* @example
|
||||
* cc.setGLProgram(node, cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
|
||||
*/
|
||||
cc.setProgram = function (node, program) {
|
||||
node.shaderProgram = program;
|
||||
|
||||
var children = node.children;
|
||||
if (!children)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < children.length; i++)
|
||||
cc.setProgram(children[i], program);
|
||||
};
|
||||
|
||||
@@ -24,105 +24,110 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
cc._currentProjectionMatrix = -1;
|
||||
cc._vertexAttribPosition = false;
|
||||
cc._vertexAttribColor = false;
|
||||
cc._vertexAttribTexCoords = false;
|
||||
var _currentProjectionMatrix = -1;
|
||||
var _vertexAttribPosition = false;
|
||||
var _vertexAttribColor = false;
|
||||
var _vertexAttribTexCoords = false;
|
||||
|
||||
var macro = cc.macro;
|
||||
|
||||
var ENABLE_GL_STATE_CACHE = macro.ENABLE_GL_STATE_CACHE;
|
||||
|
||||
var MAX_ACTIVETEXTURE = 0,
|
||||
_currentShaderProgram = 0,
|
||||
_currentBoundTexture = null,
|
||||
_blendingSource = 0,
|
||||
_blendingDest = 0,
|
||||
_GLServerState = 0,
|
||||
_uVAO = 0;
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
cc.MAX_ACTIVETEXTURE = 16;
|
||||
MAX_ACTIVETEXTURE = 16;
|
||||
|
||||
cc._currentShaderProgram = -1;
|
||||
cc._currentBoundTexture = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
|
||||
cc._blendingSource = -1;
|
||||
cc._blendingDest = -1;
|
||||
cc._GLServerState = 0;
|
||||
_currentShaderProgram = -1;
|
||||
_currentBoundTexture = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
|
||||
_blendingSource = -1;
|
||||
_blendingDest = -1;
|
||||
_GLServerState = 0;
|
||||
if(macro.TEXTURE_ATLAS_USE_VAO)
|
||||
cc._uVAO = 0;
|
||||
_uVAO = 0;
|
||||
}
|
||||
|
||||
// GL State Cache functions
|
||||
|
||||
/**
|
||||
cc.gl = {};
|
||||
|
||||
/*
|
||||
* Invalidates the GL state cache.<br/>
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE it will reset the GL state cache.
|
||||
* @function
|
||||
*/
|
||||
cc.glInvalidateStateCache = function () {
|
||||
cc.gl.invalidateStateCache = function () {
|
||||
cc.math.glFreeAll();
|
||||
cc._currentProjectionMatrix = -1;
|
||||
cc._vertexAttribPosition = false;
|
||||
cc._vertexAttribColor = false;
|
||||
cc._vertexAttribTexCoords = false;
|
||||
_currentProjectionMatrix = -1;
|
||||
_vertexAttribPosition = false;
|
||||
_vertexAttribColor = false;
|
||||
_vertexAttribTexCoords = false;
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
cc._currentShaderProgram = -1;
|
||||
for (var i = 0; i < cc.MAX_ACTIVETEXTURE; i++) {
|
||||
cc._currentBoundTexture[i] = -1;
|
||||
_currentShaderProgram = -1;
|
||||
for (var i = 0; i < MAX_ACTIVETEXTURE; i++) {
|
||||
_currentBoundTexture[i] = -1;
|
||||
}
|
||||
cc._blendingSource = -1;
|
||||
cc._blendingDest = -1;
|
||||
cc._GLServerState = 0;
|
||||
_blendingSource = -1;
|
||||
_blendingDest = -1;
|
||||
_GLServerState = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
/*
|
||||
* Uses the GL program in case program is different than the current one.<br/>
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use glContext.useProgram() directly.
|
||||
* @function
|
||||
* @param {WebGLProgram} program
|
||||
*/
|
||||
cc.glUseProgram = function (program) {
|
||||
if (program !== cc._currentShaderProgram) {
|
||||
cc._currentShaderProgram = program;
|
||||
cc.gl.useProgram = ENABLE_GL_STATE_CACHE ? function (program) {
|
||||
if (program !== _currentShaderProgram) {
|
||||
_currentShaderProgram = program;
|
||||
cc._renderContext.useProgram(program);
|
||||
}
|
||||
} : function (program) {
|
||||
cc._renderContext.useProgram(program);
|
||||
};
|
||||
|
||||
if(!ENABLE_GL_STATE_CACHE){
|
||||
cc.glUseProgram = function (program) {
|
||||
cc._renderContext.useProgram(program);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Deletes the GL program. If it is the one that is being used, it invalidates it.<br/>
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use gl.deleteProgram() directly.
|
||||
* @function
|
||||
* @param {WebGLProgram} program
|
||||
*/
|
||||
cc.glDeleteProgram = function (program) {
|
||||
cc.gl.deleteProgram = function (program) {
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
if (program === cc._currentShaderProgram)
|
||||
cc._currentShaderProgram = -1;
|
||||
if (program === _currentShaderProgram)
|
||||
_currentShaderProgram = -1;
|
||||
}
|
||||
gl.deleteProgram(program);
|
||||
};
|
||||
|
||||
/**
|
||||
/*
|
||||
* Uses a blending function in case it not already used.<br/>
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use glContext.blendFunc() directly.
|
||||
* @function
|
||||
* @param {Number} sfactor
|
||||
* @param {Number} dfactor
|
||||
*/
|
||||
cc.glBlendFunc = function (sfactor, dfactor) {
|
||||
if ((sfactor !== cc._blendingSource) || (dfactor !== cc._blendingDest)) {
|
||||
cc._blendingSource = sfactor;
|
||||
cc._blendingDest = dfactor;
|
||||
cc.setBlending(sfactor, dfactor);
|
||||
cc.gl.blendFunc = ENABLE_GL_STATE_CACHE ? function (sfactor, dfactor) {
|
||||
if ((sfactor !== _blendingSource) || (dfactor !== _blendingDest)) {
|
||||
_blendingSource = sfactor;
|
||||
_blendingDest = dfactor;
|
||||
cc.gl.setBlending(sfactor, dfactor);
|
||||
}
|
||||
};
|
||||
} : cc.gl.setBlending;
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @param {Number} sfactor
|
||||
* @param {Number} dfactor
|
||||
*/
|
||||
cc.setBlending = function (sfactor, dfactor) {
|
||||
cc.gl.setBlending = function (sfactor, dfactor) {
|
||||
var ctx = cc._renderContext;
|
||||
if ((sfactor === ctx.ONE) && (dfactor === ctx.ZERO)) {
|
||||
ctx.disable(ctx.BLEND);
|
||||
@@ -139,10 +144,10 @@ cc.setBlending = function (sfactor, dfactor) {
|
||||
* @param {Number} sfactor
|
||||
* @param {Number} dfactor
|
||||
*/
|
||||
cc.glBlendFuncForParticle = function(sfactor, dfactor) {
|
||||
if ((sfactor !== cc._blendingSource) || (dfactor !== cc._blendingDest)) {
|
||||
cc._blendingSource = sfactor;
|
||||
cc._blendingDest = dfactor;
|
||||
cc.gl.blendFuncForParticle = function(sfactor, dfactor) {
|
||||
if ((sfactor !== _blendingSource) || (dfactor !== _blendingDest)) {
|
||||
_blendingSource = sfactor;
|
||||
_blendingDest = dfactor;
|
||||
var ctx = cc._renderContext;
|
||||
if ((sfactor === ctx.ONE) && (dfactor === ctx.ZERO)) {
|
||||
ctx.disable(ctx.BLEND);
|
||||
@@ -154,30 +159,26 @@ cc.glBlendFuncForParticle = function(sfactor, dfactor) {
|
||||
}
|
||||
};
|
||||
|
||||
if(!ENABLE_GL_STATE_CACHE){
|
||||
cc.glBlendFunc = cc.setBlending;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().<br/>
|
||||
* If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
|
||||
* @function
|
||||
*/
|
||||
cc.glBlendResetToCache = function () {
|
||||
cc.gl.blendResetToCache = function () {
|
||||
var ctx = cc._renderContext;
|
||||
ctx.blendEquation(ctx.FUNC_ADD);
|
||||
if (ENABLE_GL_STATE_CACHE)
|
||||
cc.setBlending(cc._blendingSource, cc._blendingDest);
|
||||
cc.gl.setBlending(_blendingSource, _blendingDest);
|
||||
else
|
||||
cc.setBlending(ctx.BLEND_SRC, ctx.BLEND_DST);
|
||||
cc.gl.setBlending(ctx.BLEND_SRC, ctx.BLEND_DST);
|
||||
};
|
||||
|
||||
/**
|
||||
* sets the projection matrix as dirty
|
||||
* @function
|
||||
*/
|
||||
cc.setProjectionMatrixDirty = function () {
|
||||
cc._currentProjectionMatrix = -1;
|
||||
cc.gl.setProjectionMatrixDirty = function () {
|
||||
_currentProjectionMatrix = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -193,36 +194,36 @@ cc.setProjectionMatrixDirty = function () {
|
||||
* @function
|
||||
* @param {cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR | cc.macro.VERTEX_ATTRIB_FLAG_TEX_OORDS} flags
|
||||
*/
|
||||
cc.glEnableVertexAttribs = function (flags) {
|
||||
cc.gl.enableVertexAttribs = function (flags) {
|
||||
/* Position */
|
||||
var ctx = cc._renderContext;
|
||||
var enablePosition = ( flags & macro.VERTEX_ATTRIB_FLAG_POSITION );
|
||||
if (enablePosition !== cc._vertexAttribPosition) {
|
||||
if (enablePosition !== _vertexAttribPosition) {
|
||||
if (enablePosition)
|
||||
ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
else
|
||||
ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
cc._vertexAttribPosition = enablePosition;
|
||||
_vertexAttribPosition = enablePosition;
|
||||
}
|
||||
|
||||
/* Color */
|
||||
var enableColor = (flags & macro.VERTEX_ATTRIB_FLAG_COLOR);
|
||||
if (enableColor !== cc._vertexAttribColor) {
|
||||
if (enableColor !== _vertexAttribColor) {
|
||||
if (enableColor)
|
||||
ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_COLOR);
|
||||
else
|
||||
ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_COLOR);
|
||||
cc._vertexAttribColor = enableColor;
|
||||
_vertexAttribColor = enableColor;
|
||||
}
|
||||
|
||||
/* Tex Coords */
|
||||
var enableTexCoords = (flags & macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
|
||||
if (enableTexCoords !== cc._vertexAttribTexCoords) {
|
||||
if (enableTexCoords !== _vertexAttribTexCoords) {
|
||||
if (enableTexCoords)
|
||||
ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_TEX_COORDS);
|
||||
else
|
||||
ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_TEX_COORDS);
|
||||
cc._vertexAttribTexCoords = enableTexCoords;
|
||||
_vertexAttribTexCoords = enableTexCoords;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,8 +233,8 @@ cc.glEnableVertexAttribs = function (flags) {
|
||||
* @function
|
||||
* @param {cc.Texture2D} textureId
|
||||
*/
|
||||
cc.glBindTexture2D = function (textureId) {
|
||||
cc.glBindTexture2DN(0, textureId);
|
||||
cc.gl.bindTexture2D = function (textureId) {
|
||||
cc.gl.bindTexture2DN(0, textureId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -243,11 +244,18 @@ cc.glBindTexture2D = function (textureId) {
|
||||
* @param {Number} textureUnit
|
||||
* @param {cc.Texture2D} textureId
|
||||
*/
|
||||
cc.glBindTexture2DN = function (textureUnit, textureId) {
|
||||
if (cc._currentBoundTexture[textureUnit] === textureId)
|
||||
cc.gl.bindTexture2DN = ENABLE_GL_STATE_CACHE ? function (textureUnit, textureId) {
|
||||
if (_currentBoundTexture[textureUnit] === textureId)
|
||||
return;
|
||||
cc._currentBoundTexture[textureUnit] = textureId;
|
||||
_currentBoundTexture[textureUnit] = textureId;
|
||||
|
||||
var ctx = cc._renderContext;
|
||||
ctx.activeTexture(ctx.TEXTURE0 + textureUnit);
|
||||
if(textureId)
|
||||
ctx.bindTexture(ctx.TEXTURE_2D, textureId._webTextureObj);
|
||||
else
|
||||
ctx.bindTexture(ctx.TEXTURE_2D, null);
|
||||
} : function (textureUnit, textureId) {
|
||||
var ctx = cc._renderContext;
|
||||
ctx.activeTexture(ctx.TEXTURE0 + textureUnit);
|
||||
if(textureId)
|
||||
@@ -255,16 +263,6 @@ cc.glBindTexture2DN = function (textureUnit, textureId) {
|
||||
else
|
||||
ctx.bindTexture(ctx.TEXTURE_2D, null);
|
||||
};
|
||||
if (!ENABLE_GL_STATE_CACHE){
|
||||
cc.glBindTexture2DN = function (textureUnit, textureId) {
|
||||
var ctx = cc._renderContext;
|
||||
ctx.activeTexture(ctx.TEXTURE0 + textureUnit);
|
||||
if(textureId)
|
||||
ctx.bindTexture(ctx.TEXTURE_2D, textureId._webTextureObj);
|
||||
else
|
||||
ctx.bindTexture(ctx.TEXTURE_2D, null);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* It will delete a given texture. If the texture was bound, it will invalidate the cached. <br/>
|
||||
@@ -272,8 +270,8 @@ if (!ENABLE_GL_STATE_CACHE){
|
||||
* @function
|
||||
* @param {cc.Texture2D} textureId
|
||||
*/
|
||||
cc.glDeleteTexture2D = function (textureId) {
|
||||
cc.glDeleteTexture2DN(0, textureId);
|
||||
cc.gl.deleteTexture2D = function (textureId) {
|
||||
cc.gl.deleteTexture2DN(0, textureId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -283,10 +281,10 @@ cc.glDeleteTexture2D = function (textureId) {
|
||||
* @param {Number} textureUnit
|
||||
* @param {cc.Texture2D} textureId
|
||||
*/
|
||||
cc.glDeleteTexture2DN = function (textureUnit, textureId) {
|
||||
cc.gl.deleteTexture2DN = function (textureUnit, textureId) {
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
if (textureId === cc._currentBoundTexture[ textureUnit ])
|
||||
cc._currentBoundTexture[ textureUnit ] = -1;
|
||||
if (textureId === _currentBoundTexture[ textureUnit ])
|
||||
_currentBoundTexture[ textureUnit ] = -1;
|
||||
}
|
||||
cc._renderContext.deleteTexture(textureId._webTextureObj);
|
||||
};
|
||||
@@ -297,13 +295,13 @@ cc.glDeleteTexture2DN = function (textureUnit, textureId) {
|
||||
* @function
|
||||
* @param {Number} vaoId
|
||||
*/
|
||||
cc.glBindVAO = function (vaoId) {
|
||||
cc.gl.bindVAO = function (vaoId) {
|
||||
if (!macro.TEXTURE_ATLAS_USE_VAO)
|
||||
return;
|
||||
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
if (cc._uVAO !== vaoId) {
|
||||
cc._uVAO = vaoId;
|
||||
if (_uVAO !== vaoId) {
|
||||
_uVAO = vaoId;
|
||||
//TODO need fixed
|
||||
//glBindVertexArray(vaoId);
|
||||
}
|
||||
@@ -318,20 +316,20 @@ cc.glBindVAO = function (vaoId) {
|
||||
* @function
|
||||
* @param {Number} flags
|
||||
*/
|
||||
cc.glEnable = function (flags) {
|
||||
cc.gl.enable = function (flags) {
|
||||
if (ENABLE_GL_STATE_CACHE) {
|
||||
/*var enabled;
|
||||
|
||||
*/
|
||||
/* GL_BLEND */
|
||||
/*
|
||||
if ((enabled = (flags & cc.GL_BLEND)) != (cc._GLServerState & cc.GL_BLEND)) {
|
||||
if ((enabled = (flags & cc.GL_BLEND)) != (_GLServerState & cc.GL_BLEND)) {
|
||||
if (enabled) {
|
||||
cc._renderContext.enable(cc._renderContext.BLEND);
|
||||
cc._GLServerState |= cc.GL_BLEND;
|
||||
_GLServerState |= cc.GL_BLEND;
|
||||
} else {
|
||||
cc._renderContext.disable(cc._renderContext.BLEND);
|
||||
cc._GLServerState &= ~cc.GL_BLEND;
|
||||
_GLServerState &= ~cc.GL_BLEND;
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Chukong Aipu reserves all rights not expressly granted to you.
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCShaders');
|
||||
require('./CCShaderCache');
|
||||
require('./CCGLProgram');
|
||||
require('./CCGLStateCache');
|
||||
@@ -25,58 +25,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* Code copied & pasted from SpacePatrol game https://github.com/slembcke/SpacePatrol
|
||||
*
|
||||
* Renamed and added some changes for cocos2d
|
||||
*
|
||||
*/
|
||||
cc.v2fzero = function () {
|
||||
return {x: 0, y: 0};
|
||||
};
|
||||
|
||||
cc.v2f = function (x, y) {
|
||||
return {x: x, y: y};
|
||||
};
|
||||
|
||||
cc.v2fadd = function (v0, v1) {
|
||||
return cc.v2f(v0.x + v1.x, v0.y + v1.y);
|
||||
};
|
||||
|
||||
cc.v2fsub = function (v0, v1) {
|
||||
return cc.v2f(v0.x - v1.x, v0.y - v1.y);
|
||||
};
|
||||
|
||||
cc.v2fmult = function (v, s) {
|
||||
return cc.v2f(v.x * s, v.y * s);
|
||||
};
|
||||
|
||||
cc.v2fperp = function (p0) {
|
||||
return cc.v2f(-p0.y, p0.x);
|
||||
};
|
||||
|
||||
cc.v2fneg = function (p0) {
|
||||
return cc.v2f(-p0.x, -p0.y);
|
||||
};
|
||||
|
||||
cc.v2fdot = function (p0, p1) {
|
||||
return p0.x * p1.x + p0.y * p1.y;
|
||||
};
|
||||
|
||||
cc.v2fforangle = function (_a_) {
|
||||
return cc.v2f(Math.cos(_a_), Math.sin(_a_));
|
||||
};
|
||||
|
||||
cc.v2fnormalize = function (p) {
|
||||
var r = cc.pNormalize(cc.p(p.x, p.y));
|
||||
return cc.v2f(r.x, r.y);
|
||||
};
|
||||
|
||||
cc.__v2f = function (v) {
|
||||
return cc.v2f(v.x, v.y);
|
||||
};
|
||||
|
||||
cc.__t = function (v) {
|
||||
var __t = function (v) {
|
||||
return {u: v.x, v: v.y};
|
||||
};
|
||||
|
||||
@@ -156,15 +105,6 @@ cc.DrawNode = _ccsg.Node.extend(/** @lends cc.DrawNode# */{
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a DrawNode
|
||||
* @deprecated since v3.0 please use new cc.DrawNode() instead.
|
||||
* @return {cc.DrawNode}
|
||||
*/
|
||||
cc.DrawNode.create = function () {
|
||||
return new cc.DrawNode();
|
||||
};
|
||||
|
||||
cc.DrawNode.TYPE_DOT = 0;
|
||||
cc.DrawNode.TYPE_SEGMENT = 1;
|
||||
cc.DrawNode.TYPE_POLY = 2;
|
||||
@@ -649,7 +589,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
_render:function () {
|
||||
var gl = cc._renderContext;
|
||||
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._trianglesWebBuffer);
|
||||
if (this._dirty) {
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this._trianglesArrayBuffer, gl.STREAM_DRAW);
|
||||
@@ -731,42 +671,42 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
this._ensureCapacity(vertexCount);
|
||||
|
||||
var c4bColor = {r: 0 | color.r, g: 0 | color.g, b: 0 | color.b, a: 0 | color.a};
|
||||
var a = cc.__v2f(from), b = cc.__v2f(to);
|
||||
var n = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(b, a))), t = cc.v2fperp(n);
|
||||
var nw = cc.v2fmult(n, radius), tw = cc.v2fmult(t, radius);
|
||||
var a = cc.v2(from), b = cc.v2(to);
|
||||
var n = cc.pNormalize(cc.pPerp(cc.pSub(b, a))), t = cc.pPerp(n);
|
||||
var nw = cc.pMult(n, radius), tw = cc.pMult(t, radius);
|
||||
|
||||
var v0 = cc.v2fsub(b, cc.v2fadd(nw, tw));
|
||||
var v1 = cc.v2fadd(b, cc.v2fsub(nw, tw));
|
||||
var v2 = cc.v2fsub(b, nw);
|
||||
var v3 = cc.v2fadd(b, nw);
|
||||
var v4 = cc.v2fsub(a, nw);
|
||||
var v5 = cc.v2fadd(a, nw);
|
||||
var v6 = cc.v2fsub(a, cc.v2fsub(nw, tw));
|
||||
var v7 = cc.v2fadd(a, cc.v2fadd(nw, tw));
|
||||
var v0 = cc.pSub(b, cc.pAdd(nw, tw));
|
||||
var v1 = cc.pAdd(b, cc.pSub(nw, tw));
|
||||
var v2 = cc.pSub(b, nw);
|
||||
var v3 = cc.pAdd(b, nw);
|
||||
var v4 = cc.pSub(a, nw);
|
||||
var v5 = cc.pAdd(a, nw);
|
||||
var v6 = cc.pSub(a, cc.pSub(nw, tw));
|
||||
var v7 = cc.pAdd(a, cc.pAdd(nw, tw));
|
||||
|
||||
var TriangleLength = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, triangleBuffer = this._trianglesArrayBuffer, locBuffer = this._buffer;
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(cc.v2fadd(n, t)))},
|
||||
{vertices: v1, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bColor, texCoords: __t(cc.pNeg(cc.pAdd(n, t)))},
|
||||
{vertices: v1, colors: c4bColor, texCoords: __t(cc.pSub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
{vertices: v1, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
|
||||
{vertices: v1, colors: c4bColor, texCoords: __t(cc.pSub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
{vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v2, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
|
||||
{vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
{vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
|
||||
{vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(t, n))},
|
||||
{vertices: v4, colors: c4bColor, texCoords: cc.__t(cc.v2fneg(n))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: __t(cc.pSub(t, n))},
|
||||
{vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: cc.__t(cc.v2fsub(t, n))},
|
||||
{vertices: v7, colors: c4bColor, texCoords: cc.__t(cc.v2fadd(n, t))}, {vertices: v5, colors: c4bColor, texCoords: cc.__t(n)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: __t(cc.pSub(t, n))},
|
||||
{vertices: v7, colors: c4bColor, texCoords: __t(cc.pAdd(n, t))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
|
||||
triangleBuffer, locBuffer.length * TriangleLength));
|
||||
this._dirty = true;
|
||||
},
|
||||
@@ -786,12 +726,12 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a};
|
||||
var extrude = [], i, v0, v1, v2, count = verts.length;
|
||||
for (i = 0; i < count; i++) {
|
||||
v0 = cc.__v2f(verts[(i - 1 + count) % count]);
|
||||
v1 = cc.__v2f(verts[i]);
|
||||
v2 = cc.__v2f(verts[(i + 1) % count]);
|
||||
var n1 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v1, v0)));
|
||||
var n2 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v2, v1)));
|
||||
var offset = cc.v2fmult(cc.v2fadd(n1, n2), 1.0 / (cc.v2fdot(n1, n2) + 1.0));
|
||||
v0 = cc.v2(verts[(i - 1 + count) % count]);
|
||||
v1 = cc.v2(verts[i]);
|
||||
v2 = cc.v2(verts[(i + 1) % count]);
|
||||
var n1 = cc.pNormalize(cc.pPerp(cc.pSub(v1, v0)));
|
||||
var n2 = cc.pNormalize(cc.pPerp(cc.pSub(v2, v1)));
|
||||
var offset = cc.pMult(cc.pAdd(n1, n2), 1.0 / (cc.pDot(n1, n2) + 1.0));
|
||||
extrude[i] = {offset: offset, n: n2};
|
||||
}
|
||||
var outline = (borderWidth > 0.0), triangleCount = 3 * count - 2, vertexCount = 3 * triangleCount;
|
||||
@@ -801,40 +741,40 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
var locBuffer = this._buffer;
|
||||
var inset = (outline == false ? 0.5 : 0.0);
|
||||
for (i = 0; i < count - 2; i++) {
|
||||
v0 = cc.v2fsub(cc.__v2f(verts[0]), cc.v2fmult(extrude[0].offset, inset));
|
||||
v1 = cc.v2fsub(cc.__v2f(verts[i + 1]), cc.v2fmult(extrude[i + 1].offset, inset));
|
||||
v2 = cc.v2fsub(cc.__v2f(verts[i + 2]), cc.v2fmult(extrude[i + 2].offset, inset));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
|
||||
{vertices: v1, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())}, {vertices: v2, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
|
||||
v0 = cc.pSub(cc.v2(verts[0]), cc.pMult(extrude[0].offset, inset));
|
||||
v1 = cc.pSub(cc.v2(verts[i + 1]), cc.pMult(extrude[i + 1].offset, inset));
|
||||
v2 = cc.pSub(cc.v2(verts[i + 2]), cc.pMult(extrude[i + 2].offset, inset));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: v1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: v2, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
var j = (i + 1) % count;
|
||||
v0 = cc.__v2f(verts[i]);
|
||||
v1 = cc.__v2f(verts[j]);
|
||||
v0 = cc.v2(verts[i]);
|
||||
v1 = cc.v2(verts[j]);
|
||||
|
||||
var n0 = extrude[i].n;
|
||||
var offset0 = extrude[i].offset;
|
||||
var offset1 = extrude[j].offset;
|
||||
var inner0 = outline ? cc.v2fsub(v0, cc.v2fmult(offset0, borderWidth)) : cc.v2fsub(v0, cc.v2fmult(offset0, 0.5));
|
||||
var inner1 = outline ? cc.v2fsub(v1, cc.v2fmult(offset1, borderWidth)) : cc.v2fsub(v1, cc.v2fmult(offset1, 0.5));
|
||||
var outer0 = outline ? cc.v2fadd(v0, cc.v2fmult(offset0, borderWidth)) : cc.v2fadd(v0, cc.v2fmult(offset0, 0.5));
|
||||
var outer1 = outline ? cc.v2fadd(v1, cc.v2fmult(offset1, borderWidth)) : cc.v2fadd(v1, cc.v2fmult(offset1, 0.5));
|
||||
var inner0 = outline ? cc.pSub(v0, cc.pMult(offset0, borderWidth)) : cc.pSub(v0, cc.pMult(offset0, 0.5));
|
||||
var inner1 = outline ? cc.pSub(v1, cc.pMult(offset1, borderWidth)) : cc.pSub(v1, cc.pMult(offset1, 0.5));
|
||||
var outer0 = outline ? cc.pAdd(v0, cc.pMult(offset0, borderWidth)) : cc.pAdd(v0, cc.pMult(offset0, 0.5));
|
||||
var outer1 = outline ? cc.pAdd(v1, cc.pMult(offset1, borderWidth)) : cc.pAdd(v1, cc.pMult(offset1, 0.5));
|
||||
|
||||
if (outline) {
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
|
||||
{vertices: inner1, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
|
||||
{vertices: outer0, colors: c4bBorderColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
} else {
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
|
||||
{vertices: inner1, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())}, {vertices: outer1, colors: c4bFillColor, texCoords: cc.__t(n0)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: inner1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: cc.__t(cc.v2fzero())},
|
||||
{vertices: outer0, colors: c4bFillColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bFillColor, texCoords: cc.__t(n0)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())},
|
||||
{vertices: outer0, colors: c4bFillColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
}
|
||||
}
|
||||
@@ -854,12 +794,12 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a };
|
||||
var extrude = [], i, v0, v1, v2, count = verts.length;
|
||||
for (i = 0; i < count; i++) {
|
||||
v0 = cc.__v2f(verts[(i - 1 + count) % count]);
|
||||
v1 = cc.__v2f(verts[i]);
|
||||
v2 = cc.__v2f(verts[(i + 1) % count]);
|
||||
var n1 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v1, v0)));
|
||||
var n2 = cc.v2fnormalize(cc.v2fperp(cc.v2fsub(v2, v1)));
|
||||
var offset = cc.v2fmult(cc.v2fadd(n1, n2), 1.0 / (cc.v2fdot(n1, n2) + 1.0));
|
||||
v0 = cc.v2(verts[(i - 1 + count) % count]);
|
||||
v1 = cc.v2(verts[i]);
|
||||
v2 = cc.v2(verts[(i + 1) % count]);
|
||||
var n1 = cc.pNormalize(cc.pPerp(cc.pSub(v1, v0)));
|
||||
var n2 = cc.pNormalize(cc.pPerp(cc.pSub(v2, v1)));
|
||||
var offset = cc.pMult(cc.pAdd(n1, n2), 1.0 / (cc.pDot(n1, n2) + 1.0));
|
||||
extrude[i] = {offset: offset, n: n2};
|
||||
}
|
||||
|
||||
@@ -871,21 +811,21 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
||||
var len = closePoly ? count : count - 1;
|
||||
for (i = 0; i < len; i++) {
|
||||
var j = (i + 1) % count;
|
||||
v0 = cc.__v2f(verts[i]);
|
||||
v1 = cc.__v2f(verts[j]);
|
||||
v0 = cc.v2(verts[i]);
|
||||
v1 = cc.v2(verts[j]);
|
||||
|
||||
var n0 = extrude[i].n;
|
||||
var offset0 = extrude[i].offset;
|
||||
var offset1 = extrude[j].offset;
|
||||
var inner0 = cc.v2fsub(v0, cc.v2fmult(offset0, borderWidth));
|
||||
var inner1 = cc.v2fsub(v1, cc.v2fmult(offset1, borderWidth));
|
||||
var outer0 = cc.v2fadd(v0, cc.v2fmult(offset0, borderWidth));
|
||||
var outer1 = cc.v2fadd(v1, cc.v2fmult(offset1, borderWidth));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
|
||||
{vertices: inner1, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
|
||||
var inner0 = cc.pSub(v0, cc.pMult(offset0, borderWidth));
|
||||
var inner1 = cc.pSub(v1, cc.pMult(offset1, borderWidth));
|
||||
var outer0 = cc.pAdd(v0, cc.pMult(offset0, borderWidth));
|
||||
var outer1 = cc.pAdd(v1, cc.pMult(offset1, borderWidth));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: cc.__t(cc.v2fneg(n0))},
|
||||
{vertices: outer0, colors: c4bBorderColor, texCoords: cc.__t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: cc.__t(n0)},
|
||||
locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
|
||||
{vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
|
||||
trianglesBuffer, locBuffer.length * triangleBytesLen));
|
||||
}
|
||||
extrude = null;
|
||||
|
||||
@@ -22,110 +22,106 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
cc.DrawNode.CanvasRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
this._buffer = null;
|
||||
this._drawColor = null;
|
||||
this._blendFunc = null;
|
||||
};
|
||||
|
||||
cc.DrawNode.CanvasRenderCmd = function(renderableObject){
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
this._buffer = null;
|
||||
this._drawColor = null;
|
||||
this._blendFunc = null;
|
||||
};
|
||||
cc.DrawNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
cc.DrawNode.CanvasRenderCmd.prototype.constructor = cc.DrawNode.CanvasRenderCmd;
|
||||
cc.js.mixin( cc.DrawNode.CanvasRenderCmd.prototype, {
|
||||
rendering: function (ctx, scaleX, scaleY) {
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext(), node = this._node;
|
||||
var alpha = node._displayedOpacity / 255;
|
||||
if (alpha === 0)
|
||||
return;
|
||||
|
||||
cc.DrawNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
cc.DrawNode.CanvasRenderCmd.prototype.constructor = cc.DrawNode.CanvasRenderCmd;
|
||||
cc.js.mixin( cc.DrawNode.CanvasRenderCmd.prototype, {
|
||||
rendering: function (ctx, scaleX, scaleY) {
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext(), node = this._node;
|
||||
var alpha = node._displayedOpacity / 255;
|
||||
if (alpha === 0)
|
||||
return;
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
|
||||
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
|
||||
|
||||
//context.save();
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
if ((this._blendFunc && (this._blendFunc.src === cc.macro.SRC_ALPHA) && (this._blendFunc.dst === cc.macro.ONE)))
|
||||
wrapper.setCompositeOperation('lighter'); //todo: need refactor
|
||||
var locBuffer = this._buffer;
|
||||
for (var i = 0, len = locBuffer.length; i < len; i++) {
|
||||
var element = locBuffer[i];
|
||||
switch (element.type) {
|
||||
case cc.DrawNode.TYPE_DOT:
|
||||
this._drawDot(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
case cc.DrawNode.TYPE_SEGMENT:
|
||||
this._drawSegment(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
case cc.DrawNode.TYPE_POLY:
|
||||
this._drawPoly(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
}
|
||||
//context.save();
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
if ((this._blendFunc && (this._blendFunc.src === cc.macro.SRC_ALPHA) && (this._blendFunc.dst === cc.macro.ONE)))
|
||||
wrapper.setCompositeOperation('lighter'); //todo: need refactor
|
||||
var locBuffer = this._buffer;
|
||||
for (var i = 0, len = locBuffer.length; i < len; i++) {
|
||||
var element = locBuffer[i];
|
||||
switch (element.type) {
|
||||
case cc.DrawNode.TYPE_DOT:
|
||||
this._drawDot(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
case cc.DrawNode.TYPE_SEGMENT:
|
||||
this._drawSegment(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
case cc.DrawNode.TYPE_POLY:
|
||||
this._drawPoly(wrapper, element, scaleX, scaleY);
|
||||
break;
|
||||
}
|
||||
//context.restore(); //todo It can be reserve
|
||||
},
|
||||
|
||||
_drawDot: function (wrapper, element, scaleX, scaleY) {
|
||||
var locColor = element.fillColor, locPos = element.verts[0], locRadius = element.lineWidth;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
wrapper.setFillStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(locPos.x * scaleX, -locPos.y * scaleY, locRadius * scaleX, 0, Math.PI * 2, false);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
},
|
||||
|
||||
_drawSegment: function (wrapper, element, scaleX, scaleY) {
|
||||
var locColor = element.lineColor;
|
||||
var locFrom = element.verts[0], locTo = element.verts[1];
|
||||
var locLineWidth = element.lineWidth, locLineCap = element.lineCap;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
wrapper.setStrokeStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
|
||||
|
||||
ctx.lineWidth = locLineWidth * scaleX;
|
||||
ctx.beginPath();
|
||||
ctx.lineCap = locLineCap;
|
||||
ctx.moveTo(locFrom.x * scaleX, -locFrom.y * scaleY);
|
||||
ctx.lineTo(locTo.x * scaleX, -locTo.y * scaleY);
|
||||
ctx.stroke();
|
||||
},
|
||||
|
||||
_drawPoly: function (wrapper, element, scaleX, scaleY) {
|
||||
var locVertices = element.verts, locLineCap = element.lineCap;
|
||||
if (locVertices == null)
|
||||
return;
|
||||
|
||||
var locFillColor = element.fillColor, locLineWidth = element.lineWidth;
|
||||
var locLineColor = element.lineColor, locIsClosePolygon = element.isClosePolygon;
|
||||
var locIsFill = element.isFill, locIsStroke = element.isStroke;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
var firstPoint = locVertices[0];
|
||||
ctx.lineCap = locLineCap;
|
||||
if (locFillColor)
|
||||
wrapper.setFillStyle("rgba(" + (0 | locFillColor.r) + "," + (0 | locFillColor.g) + ","
|
||||
+ (0 | locFillColor.b) + "," + locFillColor.a / 255 + ")");
|
||||
if (locLineWidth)
|
||||
ctx.lineWidth = locLineWidth * scaleX;
|
||||
if (locLineColor)
|
||||
wrapper.setStrokeStyle("rgba(" + (0 | locLineColor.r) + "," + (0 | locLineColor.g) + ","
|
||||
+ (0 | locLineColor.b) + "," + locLineColor.a / 255 + ")");
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(firstPoint.x * scaleX, -firstPoint.y * scaleY);
|
||||
for (var i = 1, len = locVertices.length; i < len; i++)
|
||||
ctx.lineTo(locVertices[i].x * scaleX, -locVertices[i].y * scaleY);
|
||||
|
||||
if (locIsClosePolygon)
|
||||
ctx.closePath();
|
||||
if (locIsFill)
|
||||
ctx.fill();
|
||||
if (locIsStroke)
|
||||
ctx.stroke();
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
//context.restore(); //todo It can be reserve
|
||||
},
|
||||
|
||||
_drawDot: function (wrapper, element, scaleX, scaleY) {
|
||||
var locColor = element.fillColor, locPos = element.verts[0], locRadius = element.lineWidth;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
wrapper.setFillStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(locPos.x * scaleX, -locPos.y * scaleY, locRadius * scaleX, 0, Math.PI * 2, false);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
},
|
||||
|
||||
_drawSegment: function (wrapper, element, scaleX, scaleY) {
|
||||
var locColor = element.lineColor;
|
||||
var locFrom = element.verts[0], locTo = element.verts[1];
|
||||
var locLineWidth = element.lineWidth, locLineCap = element.lineCap;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
wrapper.setStrokeStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
|
||||
|
||||
ctx.lineWidth = locLineWidth * scaleX;
|
||||
ctx.beginPath();
|
||||
ctx.lineCap = locLineCap;
|
||||
ctx.moveTo(locFrom.x * scaleX, -locFrom.y * scaleY);
|
||||
ctx.lineTo(locTo.x * scaleX, -locTo.y * scaleY);
|
||||
ctx.stroke();
|
||||
},
|
||||
|
||||
_drawPoly: function (wrapper, element, scaleX, scaleY) {
|
||||
var locVertices = element.verts, locLineCap = element.lineCap;
|
||||
if (locVertices == null)
|
||||
return;
|
||||
|
||||
var locFillColor = element.fillColor, locLineWidth = element.lineWidth;
|
||||
var locLineColor = element.lineColor, locIsClosePolygon = element.isClosePolygon;
|
||||
var locIsFill = element.isFill, locIsStroke = element.isStroke;
|
||||
|
||||
var ctx = wrapper.getContext();
|
||||
var firstPoint = locVertices[0];
|
||||
ctx.lineCap = locLineCap;
|
||||
if (locFillColor)
|
||||
wrapper.setFillStyle("rgba(" + (0 | locFillColor.r) + "," + (0 | locFillColor.g) + ","
|
||||
+ (0 | locFillColor.b) + "," + locFillColor.a / 255 + ")");
|
||||
if (locLineWidth)
|
||||
ctx.lineWidth = locLineWidth * scaleX;
|
||||
if (locLineColor)
|
||||
wrapper.setStrokeStyle("rgba(" + (0 | locLineColor.r) + "," + (0 | locLineColor.g) + ","
|
||||
+ (0 | locLineColor.b) + "," + locLineColor.a / 255 + ")");
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(firstPoint.x * scaleX, -firstPoint.y * scaleY);
|
||||
for (var i = 1, len = locVertices.length; i < len; i++)
|
||||
ctx.lineTo(locVertices[i].x * scaleX, -locVertices[i].y * scaleY);
|
||||
|
||||
if (locIsClosePolygon)
|
||||
ctx.closePath();
|
||||
if (locIsFill)
|
||||
ctx.fill();
|
||||
if (locIsStroke)
|
||||
ctx.stroke();
|
||||
}
|
||||
});
|
||||
@@ -22,20 +22,18 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
cc.DrawNode.WebGLRenderCmd = function (renderableObject) {
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
};
|
||||
cc.DrawNode.WebGLRenderCmd = function (renderableObject) {
|
||||
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
};
|
||||
|
||||
cc.DrawNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
cc.DrawNode.WebGLRenderCmd.prototype.constructor = cc.DrawNode.WebGLRenderCmd;
|
||||
cc.DrawNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
cc.DrawNode.WebGLRenderCmd.prototype.constructor = cc.DrawNode.WebGLRenderCmd;
|
||||
|
||||
cc.DrawNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
node._render();
|
||||
};
|
||||
})();
|
||||
cc.DrawNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
|
||||
var node = this._node;
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
node._render();
|
||||
};
|
||||
@@ -384,7 +384,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
// Bits on the far end of the 32-bit global tile ID are used for tile flags
|
||||
var tile = this.tiles[idx];
|
||||
|
||||
return (tile & cc.TMX_TILE_FLIPPED_MASK) >>> 0;
|
||||
return (tile & cc.TiledMap.TileFlag.FLIPPED_MASK) >>> 0;
|
||||
},
|
||||
// XXX: deprecated
|
||||
// tileGIDAt:getTileGIDAt,
|
||||
@@ -411,7 +411,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
// Bits on the far end of the 32-bit global tile ID are used for tile flags
|
||||
var tile = this.tiles[idx];
|
||||
|
||||
return (tile & cc.TMX_TILE_FLIPPED_ALL) >>> 0;
|
||||
return (tile & cc.TiledMap.TileFlag.FLIPPED_ALL) >>> 0;
|
||||
},
|
||||
// XXX: deprecated
|
||||
// tileFlagAt:getTileFlagsAt,
|
||||
@@ -540,13 +540,13 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
pos = cc.p(pos, y);
|
||||
var ret = cc.p(0,0);
|
||||
switch (this.layerOrientation) {
|
||||
case cc.TMX_ORIENTATION_ORTHO:
|
||||
case cc.TiledMap.Orientation.ORTHO:
|
||||
ret = this._positionForOrthoAt(pos);
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_ISO:
|
||||
case cc.TiledMap.Orientation.ISO:
|
||||
ret = this._positionForIsoAt(pos);
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_HEX:
|
||||
case cc.TiledMap.Orientation.HEX:
|
||||
ret = this._positionForHexAt(pos);
|
||||
break;
|
||||
}
|
||||
@@ -668,14 +668,14 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
_calculateLayerOffset:function (pos) {
|
||||
var ret = cc.p(0,0);
|
||||
switch (this.layerOrientation) {
|
||||
case cc.TMX_ORIENTATION_ORTHO:
|
||||
case cc.TiledMap.Orientation.ORTHO:
|
||||
ret = cc.p(pos.x * this._mapTileSize.width, -pos.y * this._mapTileSize.height);
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_ISO:
|
||||
case cc.TiledMap.Orientation.ISO:
|
||||
ret = cc.p((this._mapTileSize.width / 2) * (pos.x - pos.y),
|
||||
(this._mapTileSize.height / 2 ) * (-pos.x - pos.y));
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_HEX:
|
||||
case cc.TiledMap.Orientation.HEX:
|
||||
if(pos.x !== 0 || pos.y !== 0)
|
||||
cc.log("offset for hexagonal map not implemented yet");
|
||||
break;
|
||||
@@ -796,20 +796,20 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
sprite.setFlippedY(false);
|
||||
|
||||
// Rotation in tiled is achieved using 3 flipped states, flipping across the horizontal, vertical, and diagonal axes of the tiles.
|
||||
if ((gid & cc.TMX_TILE_DIAGONAL_FLAG) >>> 0) {
|
||||
if ((gid & cc.TiledMap.TileFlag.DIAGONAL_FLAG) >>> 0) {
|
||||
// put the anchor in the middle for ease of rotation.
|
||||
sprite.anchorX = 0.5;
|
||||
sprite.anchorY = 0.5;
|
||||
sprite.x = this.getPositionAt(pos).x + sprite.width / 2;
|
||||
sprite.y = this.getPositionAt(pos).y + sprite.height / 2;
|
||||
|
||||
var flag = (gid & (cc.TMX_TILE_HORIZONTAL_FLAG | cc.TMX_TILE_VERTICAL_FLAG) >>> 0) >>> 0;
|
||||
var flag = (gid & (cc.TiledMap.TileFlag.HORIZONTAL | cc.TiledMap.TileFlag.VERTICAL) >>> 0) >>> 0;
|
||||
// handle the 4 diagonally flipped states.
|
||||
if (flag === cc.TMX_TILE_HORIZONTAL_FLAG)
|
||||
if (flag === cc.TiledMap.TileFlag.HORIZONTAL)
|
||||
sprite.rotation = 90;
|
||||
else if (flag === cc.TMX_TILE_VERTICAL_FLAG)
|
||||
else if (flag === cc.TiledMap.TileFlag.VERTICAL)
|
||||
sprite.rotation = 270;
|
||||
else if (flag === (cc.TMX_TILE_VERTICAL_FLAG | cc.TMX_TILE_HORIZONTAL_FLAG) >>> 0) {
|
||||
else if (flag === (cc.TiledMap.TileFlag.VERTICAL | cc.TiledMap.TileFlag.HORIZONTAL) >>> 0) {
|
||||
sprite.rotation = 90;
|
||||
sprite.setFlippedX(true);
|
||||
} else {
|
||||
@@ -817,11 +817,11 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
sprite.setFlippedX(true);
|
||||
}
|
||||
} else {
|
||||
if ((gid & cc.TMX_TILE_HORIZONTAL_FLAG) >>> 0) {
|
||||
if ((gid & cc.TiledMap.TileFlag.HORIZONTAL) >>> 0) {
|
||||
sprite.setFlippedX(true);
|
||||
}
|
||||
|
||||
if ((gid & cc.TMX_TILE_VERTICAL_FLAG) >>> 0) {
|
||||
if ((gid & cc.TiledMap.TileFlag.VERTICAL) >>> 0) {
|
||||
sprite.setFlippedY(true);
|
||||
}
|
||||
}
|
||||
@@ -832,14 +832,14 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
var maxVal = 0;
|
||||
if (this._useAutomaticVertexZ) {
|
||||
switch (this.layerOrientation) {
|
||||
case cc.TMX_ORIENTATION_ISO:
|
||||
case cc.TiledMap.Orientation.ISO:
|
||||
maxVal = this._layerSize.width + this._layerSize.height;
|
||||
ret = -(maxVal - (pos.x + pos.y));
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_ORTHO:
|
||||
case cc.TiledMap.Orientation.ORTHO:
|
||||
ret = -(this._layerSize.height - pos.y);
|
||||
break;
|
||||
case cc.TMX_ORIENTATION_HEX:
|
||||
case cc.TiledMap.Orientation.HEX:
|
||||
cc.log("TMX Hexa zOrder not supported");
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -24,28 +24,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
Orthogonal orientation
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_ORIENTATION_ORTHO = 0;
|
||||
|
||||
/**
|
||||
* Hexagonal orientation
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
|
||||
cc.TMX_ORIENTATION_HEX = 1;
|
||||
|
||||
/**
|
||||
* Isometric orientation
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_ORIENTATION_ISO = 2;
|
||||
|
||||
/**
|
||||
* <p>_ccsg.TMXTiledMap knows how to parse and render a TMX map.</p>
|
||||
*
|
||||
@@ -442,7 +420,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{
|
||||
if (gid !== 0) {
|
||||
// Optimization: quick return
|
||||
// if the layer is invalid (more than 1 tileset per layer) an cc.assert will be thrown later
|
||||
if (((gid & cc.TMX_TILE_FLIPPED_MASK)>>>0) >= tileset.firstGid) {
|
||||
if (((gid & cc.TiledMap.TileFlag.FLIPPED_MASK)>>>0) >= tileset.firstGid) {
|
||||
return tileset;
|
||||
}
|
||||
}
|
||||
@@ -474,16 +452,3 @@ cc.defineGetterSetter(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth);
|
||||
/** @expose */
|
||||
_p.tileHeight;
|
||||
cc.defineGetterSetter(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a TMX Tiled Map with a TMX file or content string.
|
||||
* Implementation _ccsg.TMXTiledMap
|
||||
* @deprecated since v3.0 please use new _ccsg.TMXTiledMap(tmxFile,resourcePath) instead.
|
||||
* @param {String} tmxFile tmxFile fileName or content string
|
||||
* @param {String} resourcePath If tmxFile is a file name ,it is not required.If tmxFile is content string ,it is must required.
|
||||
* @return {_ccsg.TMXTiledMap|undefined}
|
||||
*/
|
||||
_ccsg.TMXTiledMap.create = function (tmxFile,resourcePath) {
|
||||
return new _ccsg.TMXTiledMap(tmxFile,resourcePath);
|
||||
};
|
||||
|
||||
@@ -1,437 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011-2012 cocos2d-x.org
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_OK = 0;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_ERROR_FILE_OPEN = 1;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_ERROR_READING_FILE = 2;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_ERROR_INDEXED_COLOR = 3;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_ERROR_MEMORY = 4;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TGA_ERROR_COMPRESSED_FILE = 5;
|
||||
|
||||
/**
|
||||
* TGA format
|
||||
* @param {Number} status
|
||||
* @param {Number} type
|
||||
* @param {Number} pixelDepth
|
||||
* @param {Number} width map width
|
||||
* @param {Number} height map height
|
||||
* @param {Array} imageData raw data
|
||||
* @param {Number} flipped
|
||||
* @constructor
|
||||
*/
|
||||
cc.ImageTGA = function (status, type, pixelDepth, width, height, imageData, flipped) {
|
||||
this.status = status || 0;
|
||||
this.type = type || 0;
|
||||
this.pixelDepth = pixelDepth || 0;
|
||||
this.width = width || 0;
|
||||
this.height = height || 0;
|
||||
this.imageData = imageData || [];
|
||||
this.flipped = flipped || 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* load the image header field from stream. We only keep those that matter!
|
||||
* @param {Array} buffer
|
||||
* @param {Number} bufSize
|
||||
* @param {cc.ImageTGA} psInfo
|
||||
* @return {Boolean}
|
||||
*/
|
||||
cc.tgaLoadHeader = function (buffer, bufSize, psInfo) {
|
||||
var step = 2;
|
||||
if (step + 1 > bufSize)
|
||||
return false;
|
||||
|
||||
var binaryReader = new cc.BinaryStreamReader(buffer);
|
||||
|
||||
binaryReader.setOffset(step);
|
||||
psInfo.type = binaryReader.readByte();
|
||||
step += 10; // . step += sizeof(unsigned char) * 2; step += sizeof(signed short) * 4;
|
||||
|
||||
if (step + 4 + 1 > bufSize)
|
||||
return false;
|
||||
binaryReader.setOffset(step);
|
||||
psInfo.width = binaryReader.readUnsignedShort();
|
||||
psInfo.height = binaryReader.readUnsignedInteger();
|
||||
psInfo.pixelDepth = binaryReader.readByte();
|
||||
|
||||
step += 5; // . step += sizeof(unsigned char); step += sizeof(signed short) * 2;
|
||||
if (step + 1 > bufSize)
|
||||
return false;
|
||||
|
||||
var garbage = binaryReader.readByte();
|
||||
psInfo.flipped = 0;
|
||||
if (garbage & 0x20)
|
||||
psInfo.flipped = 1;
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* loads the image pixels. You shouldn't call this function directly.
|
||||
* @param {Array} buffer
|
||||
* @param {Number} bufSize
|
||||
* @param {cc.ImageTGA} psInfo
|
||||
* @return {Boolean}
|
||||
*/
|
||||
cc.tgaLoadImageData = function (buffer, bufSize, psInfo) {
|
||||
var mode, total, i, aux;
|
||||
var step = 18; // .size_t step = (sizeof(unsigned char) + sizeof(signed short)) * 6;
|
||||
|
||||
// mode equal the number of components for each pixel
|
||||
mode = 0 | (psInfo.pixelDepth / 2);
|
||||
// total is the number of unsigned chars we'll have to read
|
||||
total = psInfo.height * psInfo.width * mode;
|
||||
|
||||
if (step + total > bufSize)
|
||||
return false;
|
||||
|
||||
psInfo.imageData = cc.__getSubArray(buffer, step, step + total);
|
||||
|
||||
// mode=3 or 4 implies that the image is RGB(A). However TGA
|
||||
// stores it as BGR(A) so we'll have to swap R and B.
|
||||
if (mode >= 3) {
|
||||
for (i = 0; i < total; i += mode) {
|
||||
aux = psInfo.imageData[i];
|
||||
psInfo.imageData[i] = psInfo.imageData[i + 2];
|
||||
psInfo.imageData[i + 2] = aux;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* converts RGB to grayscale
|
||||
* @param {cc.ImageTGA} psInfo
|
||||
*/
|
||||
cc.tgaRGBtogreyscale = function (psInfo) {
|
||||
var i, j;
|
||||
|
||||
// if the image is already grayscale do nothing
|
||||
if (psInfo.pixelDepth === 8)
|
||||
return;
|
||||
|
||||
// compute the number of actual components
|
||||
var mode = psInfo.pixelDepth / 8;
|
||||
|
||||
// allocate an array for the new image data
|
||||
var newImageData = new Uint8Array(psInfo.height * psInfo.width);
|
||||
if (newImageData === null)
|
||||
return;
|
||||
|
||||
// convert pixels: grayscale = o.30 * R + 0.59 * G + 0.11 * B
|
||||
for (i = 0, j = 0; j < psInfo.width * psInfo.height; i += mode, j++)
|
||||
newImageData[j] = (0.30 * psInfo.imageData[i] + 0.59 * psInfo.imageData[i + 1] + 0.11 * psInfo.imageData[i + 2]);
|
||||
|
||||
// reassign pixelDepth and type according to the new image type
|
||||
psInfo.pixelDepth = 8;
|
||||
psInfo.type = 3;
|
||||
// reassigning imageData to the new array.
|
||||
psInfo.imageData = newImageData;
|
||||
};
|
||||
|
||||
/**
|
||||
* releases the memory used for the image
|
||||
* @param {cc.ImageTGA} psInfo
|
||||
*/
|
||||
cc.tgaDestroy = function (psInfo) {
|
||||
if (!psInfo)
|
||||
return;
|
||||
|
||||
psInfo.imageData = null;
|
||||
psInfo = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load RLE image data
|
||||
* @param buffer
|
||||
* @param bufSize
|
||||
* @param psInfo
|
||||
* @returns {boolean}
|
||||
*/
|
||||
cc.tgaLoadRLEImageData = function (buffer, bufSize, psInfo) {
|
||||
var mode, total, i, index = 0 , skip = 0, flag = 0;
|
||||
var aux = [], runlength = 0;
|
||||
|
||||
var step = 18; // . size_t step = (sizeof(unsigned char) + sizeof(signed short)) * 6;
|
||||
|
||||
// mode equal the number of components for each pixel
|
||||
mode = psInfo.pixelDepth / 8;
|
||||
// total is the number of unsigned chars we'll have to read
|
||||
total = psInfo.height * psInfo.width;
|
||||
|
||||
for (i = 0; i < total; i++) {
|
||||
// if we have a run length pending, run it
|
||||
if (runlength !== 0) {
|
||||
// we do, update the run length count
|
||||
runlength--;
|
||||
skip = (flag !== 0);
|
||||
} else {
|
||||
// otherwise, read in the run length token
|
||||
if (step + 1 > bufSize)
|
||||
break;
|
||||
runlength = buffer[step];
|
||||
step += 1;
|
||||
|
||||
// see if it's a RLE encoded sequence
|
||||
flag = runlength & 0x80;
|
||||
if (flag)
|
||||
runlength -= 128;
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
// do we need to skip reading this pixel?
|
||||
if (!skip) {
|
||||
// no, read in the pixel data
|
||||
if (step + mode > bufSize)
|
||||
break;
|
||||
aux = cc.__getSubArray(buffer, step, step + mode);
|
||||
step += mode;
|
||||
|
||||
// mode=3 or 4 implies that the image is RGB(A). However TGA
|
||||
// stores it as BGR(A) so we'll have to swap R and B.
|
||||
if (mode >= 3) {
|
||||
var tmp = aux[0];
|
||||
aux[0] = aux[2];
|
||||
aux[2] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// add the pixel to our image
|
||||
for (var j = 0; j < mode; j++)
|
||||
psInfo.imageData[index + j] = aux[j];
|
||||
|
||||
index += mode;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* ImageTGA Flip
|
||||
* @param {cc.ImageTGA} psInfo
|
||||
*/
|
||||
cc.tgaFlipImage = function (psInfo) {
|
||||
// mode equal the number of components for each pixel
|
||||
var mode = psInfo.pixelDepth / 8;
|
||||
var rowbytes = psInfo.width * mode;
|
||||
|
||||
for (var y = 0; y < (psInfo.height / 2); y++) {
|
||||
var row = cc.__getSubArray(psInfo.imageData, y * rowbytes, y * rowbytes + rowbytes);
|
||||
cc.__setDataToArray(cc.__getSubArray(psInfo.imageData, (psInfo.height - (y + 1)) * rowbytes, rowbytes), psInfo.imageData, y * rowbytes);
|
||||
cc.__setDataToArray(row, psInfo.imageData, (psInfo.height - (y + 1)) * rowbytes);
|
||||
}
|
||||
psInfo.flipped = 0;
|
||||
};
|
||||
|
||||
cc.__getSubArray = function (array, start, end) {
|
||||
if (array instanceof Array)
|
||||
return array.slice(start, end);
|
||||
else
|
||||
return array.subarray(start, end);
|
||||
};
|
||||
|
||||
cc.__setDataToArray = function (sourceData, destArray, startIndex) {
|
||||
for (var i = 0; i < sourceData.length; i++)
|
||||
destArray[startIndex + i] = sourceData[i];
|
||||
};
|
||||
|
||||
/**
|
||||
* Binary Stream Reader
|
||||
*
|
||||
* @class
|
||||
* @param binaryData
|
||||
*/
|
||||
cc.BinaryStreamReader = cc._Class.extend({
|
||||
_binaryData:null,
|
||||
_offset:0,
|
||||
|
||||
/**
|
||||
* <p>The cc.BinaryStreamReader's constructor. <br/>
|
||||
* This function will automatically be invoked when you create a node using new construction: "var node = new cc.BinaryStreamReader()".<br/>
|
||||
* Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
|
||||
* @param binaryData
|
||||
*/
|
||||
ctor:function (binaryData) {
|
||||
this._binaryData = binaryData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the binaryData.
|
||||
* @param binaryData
|
||||
*/
|
||||
setBinaryData:function (binaryData) {
|
||||
this._binaryData = binaryData;
|
||||
this._offset = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the binaryData.
|
||||
* @returns {Object}
|
||||
*/
|
||||
getBinaryData:function () {
|
||||
return this._binaryData;
|
||||
},
|
||||
|
||||
_checkSize:function (neededBits) {
|
||||
if (!(this._offset + Math.ceil(neededBits / 8) < this._data.length))
|
||||
throw new Error("Index out of bound");
|
||||
},
|
||||
|
||||
_decodeFloat:function (precisionBits, exponentBits) {
|
||||
var length = precisionBits + exponentBits + 1;
|
||||
var size = length >> 3;
|
||||
this._checkSize(length);
|
||||
|
||||
var bias = Math.pow(2, exponentBits - 1) - 1;
|
||||
var signal = this._readBits(precisionBits + exponentBits, 1, size);
|
||||
var exponent = this._readBits(precisionBits, exponentBits, size);
|
||||
var significand = 0;
|
||||
var divisor = 2;
|
||||
var curByte = 0; //length + (-precisionBits >> 3) - 1;
|
||||
do {
|
||||
var byteValue = this._readByte(++curByte, size);
|
||||
var startBit = precisionBits % 8 || 8;
|
||||
var mask = 1 << startBit;
|
||||
while (mask >>= 1) {
|
||||
if (byteValue & mask)
|
||||
significand += 1 / divisor;
|
||||
divisor *= 2;
|
||||
}
|
||||
} while (precisionBits -= startBit);
|
||||
|
||||
this._offset += size;
|
||||
|
||||
return exponent === (bias << 1) + 1 ? significand ? NaN : signal ? -Infinity : +Infinity
|
||||
: (1 + signal * -2) * (exponent || significand ? !exponent ? Math.pow(2, -bias + 1) * significand
|
||||
: Math.pow(2, exponent - bias) * (1 + significand) : 0);
|
||||
},
|
||||
|
||||
_readByte:function (i, size) {
|
||||
return this._data[this._offset + size - i - 1];
|
||||
},
|
||||
|
||||
_decodeInt:function (bits, signed) {
|
||||
var x = this._readBits(0, bits, bits / 8), max = Math.pow(2, bits);
|
||||
var result = signed && x >= max / 2 ? x - max : x;
|
||||
|
||||
this._offset += bits / 8;
|
||||
return result;
|
||||
},
|
||||
|
||||
_shl:function (a, b) {
|
||||
for (++b; --b; a = ((a %= 0x7fffffff + 1) & 0x40000000) === 0x40000000 ? a * 2 : (a - 0x40000000) * 2 + 0x7fffffff + 1){};
|
||||
return a;
|
||||
},
|
||||
|
||||
_readBits:function (start, length, size) {
|
||||
var offsetLeft = (start + length) % 8;
|
||||
var offsetRight = start % 8;
|
||||
var curByte = size - (start >> 3) - 1;
|
||||
var lastByte = size + (-(start + length) >> 3);
|
||||
var diff = curByte - lastByte;
|
||||
|
||||
var sum = (this._readByte(curByte, size) >> offsetRight) & ((1 << (diff ? 8 - offsetRight : length)) - 1);
|
||||
|
||||
if (diff && offsetLeft)
|
||||
sum += (this._readByte(lastByte++, size) & ((1 << offsetLeft) - 1)) << (diff-- << 3) - offsetRight;
|
||||
|
||||
while (diff)
|
||||
sum += this._shl(this._readByte(lastByte++, size), (diff-- << 3) - offsetRight);
|
||||
|
||||
return sum;
|
||||
},
|
||||
|
||||
readInteger:function () {
|
||||
return this._decodeInt(32, true);
|
||||
},
|
||||
|
||||
readUnsignedInteger:function () {
|
||||
return this._decodeInt(32, false);
|
||||
},
|
||||
|
||||
readSingle:function () {
|
||||
return this._decodeFloat(23, 8);
|
||||
},
|
||||
|
||||
readShort:function () {
|
||||
return this._decodeInt(16, true);
|
||||
},
|
||||
|
||||
readUnsignedShort:function () {
|
||||
return this._decodeInt(16, false);
|
||||
},
|
||||
|
||||
readByte:function () {
|
||||
var readByte = this._data[this._offset];
|
||||
this._offset += 1;
|
||||
return readByte;
|
||||
},
|
||||
|
||||
readData:function (start, end) {
|
||||
if (this._binaryData instanceof Array) {
|
||||
return this._binaryData.slice(start, end);
|
||||
} else {
|
||||
//typed array
|
||||
return this._binaryData.subarray(start, end);
|
||||
}
|
||||
},
|
||||
|
||||
setOffset:function (offset) {
|
||||
this._offset = offset;
|
||||
},
|
||||
|
||||
getOffset:function () {
|
||||
return this._offset;
|
||||
}
|
||||
});
|
||||
@@ -22,198 +22,196 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
_ccsg.TMXLayer.CanvasRenderCmd = function(renderable){
|
||||
cc.SpriteBatchNode.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._realWorldTransform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
|
||||
_ccsg.TMXLayer.CanvasRenderCmd = function(renderable){
|
||||
cc.SpriteBatchNode.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this._realWorldTransform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
|
||||
|
||||
var locCanvas = cc._canvas;
|
||||
var tmpCanvas = document.createElement('canvas');
|
||||
tmpCanvas.width = locCanvas.width;
|
||||
tmpCanvas.height = locCanvas.height;
|
||||
this._cacheCanvas = tmpCanvas;
|
||||
this._cacheContext = new cc.CanvasContextWrapper(this._cacheCanvas.getContext('2d'));
|
||||
var tempTexture = new cc.Texture2D();
|
||||
tempTexture.initWithElement(tmpCanvas);
|
||||
tempTexture.handleLoadedTexture();
|
||||
this._cacheTexture = tempTexture;
|
||||
// This class uses cache, so its default cachedParent should be himself
|
||||
var locCanvas = cc._canvas;
|
||||
var tmpCanvas = document.createElement('canvas');
|
||||
tmpCanvas.width = locCanvas.width;
|
||||
tmpCanvas.height = locCanvas.height;
|
||||
this._cacheCanvas = tmpCanvas;
|
||||
this._cacheContext = new cc.CanvasContextWrapper(this._cacheCanvas.getContext('2d'));
|
||||
var tempTexture = new cc.Texture2D();
|
||||
tempTexture.initWithElement(tmpCanvas);
|
||||
tempTexture.handleLoadedTexture();
|
||||
this._cacheTexture = tempTexture;
|
||||
// This class uses cache, so its default cachedParent should be himself
|
||||
this._cacheDirty = false;
|
||||
};
|
||||
|
||||
var proto = _ccsg.TMXLayer.CanvasRenderCmd.prototype = Object.create(cc.SpriteBatchNode.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd;
|
||||
|
||||
//set the cache dirty flag for canvas
|
||||
proto._setNodeDirtyForCache = function () {
|
||||
this._cacheDirty = true;
|
||||
};
|
||||
|
||||
proto._renderingChildToCache = function () {
|
||||
if (this._cacheDirty) {
|
||||
var wrapper = this._cacheContext,
|
||||
context = wrapper.getContext(), locCanvas = this._cacheCanvas;
|
||||
|
||||
//wrapper.save();
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
//reset the cache context
|
||||
|
||||
var locChildren = this._node._children;
|
||||
for (var i = 0, len = locChildren.length; i < len; i++) {
|
||||
if (locChildren[i]){
|
||||
var selCmd = locChildren[i]._renderCmd;
|
||||
if(selCmd){
|
||||
selCmd.rendering(wrapper, 1, 1);
|
||||
selCmd._cacheDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//wrapper.restore();
|
||||
this._cacheDirty = false;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var proto = _ccsg.TMXLayer.CanvasRenderCmd.prototype = Object.create(cc.SpriteBatchNode.CanvasRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd;
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var alpha = this._displayedOpacity / 255;
|
||||
if (alpha <= 0)
|
||||
return;
|
||||
|
||||
//set the cache dirty flag for canvas
|
||||
proto._setNodeDirtyForCache = function () {
|
||||
this._cacheDirty = true;
|
||||
};
|
||||
var node = this._node;
|
||||
this._renderingChildToCache();
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
|
||||
proto._renderingChildToCache = function () {
|
||||
if (this._cacheDirty) {
|
||||
var wrapper = this._cacheContext,
|
||||
context = wrapper.getContext(), locCanvas = this._cacheCanvas;
|
||||
|
||||
//wrapper.save();
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
//reset the cache context
|
||||
|
||||
var locChildren = this._node._children;
|
||||
for (var i = 0, len = locChildren.length; i < len; i++) {
|
||||
if (locChildren[i]){
|
||||
var selCmd = locChildren[i]._renderCmd;
|
||||
if(selCmd){
|
||||
selCmd.rendering(wrapper, 1, 1);
|
||||
selCmd._cacheDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//wrapper.restore();
|
||||
this._cacheDirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
proto.rendering = function (ctx, scaleX, scaleY) {
|
||||
var alpha = this._displayedOpacity / 255;
|
||||
if (alpha <= 0)
|
||||
return;
|
||||
|
||||
var node = this._node;
|
||||
this._renderingChildToCache();
|
||||
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
|
||||
wrapper.setGlobalAlpha(alpha);
|
||||
|
||||
var locCacheCanvas = this._cacheCanvas;
|
||||
//direct draw image by canvas drawImage
|
||||
if (locCacheCanvas && locCacheCanvas.width !== 0 && locCacheCanvas.height !== 0) {
|
||||
wrapper.setTransform(this._realWorldTransform, scaleX, scaleY);
|
||||
var locCanvasHeight = locCacheCanvas.height * scaleY;
|
||||
if (node.layerOrientation === cc.TMX_ORIENTATION_HEX) {
|
||||
var halfTileSize = node._mapTileSize.height * 0.5 * scaleY;
|
||||
context.drawImage(locCacheCanvas, 0, 0, locCacheCanvas.width, locCacheCanvas.height,
|
||||
0, -locCanvasHeight + halfTileSize, locCacheCanvas.width * scaleX, locCanvasHeight);
|
||||
} else {
|
||||
context.drawImage(locCacheCanvas, 0, 0, locCacheCanvas.width, locCacheCanvas.height,
|
||||
0, -locCanvasHeight, locCacheCanvas.width * scaleX, locCanvasHeight);
|
||||
}
|
||||
}
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
|
||||
proto._updateCacheContext = function(size, height){
|
||||
var node = this._node,
|
||||
locContentSize = node._contentSize,
|
||||
locCanvas = this._cacheCanvas;
|
||||
locCanvas.width = 0 | (locContentSize.width * 1.5);
|
||||
locCanvas.height = 0 | (locContentSize.height * 1.5);
|
||||
|
||||
//todo: need change the wrapper's height
|
||||
if(node.layerOrientation === cc.TMX_ORIENTATION_HEX)
|
||||
this._cacheContext.setOffset(0, -node._mapTileSize.height * 0.5); //translate for hexagonal
|
||||
else
|
||||
this._cacheContext.setOffset(0, 0);
|
||||
var locTexContentSize = this._cacheTexture._contentSize;
|
||||
locTexContentSize.width = locCanvas.width;
|
||||
locTexContentSize.height = locCanvas.height;
|
||||
};
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._cacheTexture;
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
//TODO: it will implement dynamic compute child cutting automation.
|
||||
var i, len, locChildren = node._children;
|
||||
// quick return if not visible
|
||||
if (!node._visible || !locChildren || locChildren.length === 0)
|
||||
return;
|
||||
|
||||
parentCmd = parentCmd || this.getParentRenderCmd();
|
||||
if (parentCmd)
|
||||
this._curLevel = parentCmd._curLevel + 1;
|
||||
|
||||
this._syncStatus(parentCmd);
|
||||
if (this._cacheDirty) {
|
||||
var wrapper = this._cacheContext, locCanvas = this._cacheCanvas, context = wrapper.getContext(),
|
||||
instanceID = node.__instanceId, renderer = cc.renderer;
|
||||
//begin cache
|
||||
renderer._turnToCacheMode(instanceID);
|
||||
|
||||
node.sortAllChildren();
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
if (locChildren[i]){
|
||||
var selCmd = locChildren[i]._renderCmd;
|
||||
if(selCmd){
|
||||
selCmd.visit(this);
|
||||
selCmd._cacheDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//wrapper.save();
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
//set the wrapper's offset
|
||||
|
||||
//draw to cache canvas
|
||||
renderer._renderingToCacheCanvas(wrapper, instanceID);
|
||||
//wrapper.restore(); //todo: it can be reserve.
|
||||
this._cacheDirty = false
|
||||
}
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
this._dirtyFlag = 0;
|
||||
};
|
||||
|
||||
proto.transform = function (parentCmd, recursive) {
|
||||
// transform for canvas
|
||||
var t = this.getNodeToParentTransform(),
|
||||
worldT = this._realWorldTransform; //get the world transform
|
||||
|
||||
if (parentCmd) {
|
||||
var pt = parentCmd._worldTransform;
|
||||
// cc.AffineTransformConcat is incorrect at get world transform
|
||||
worldT.a = t.a * pt.a + t.b * pt.c; //a
|
||||
worldT.b = t.a * pt.b + t.b * pt.d; //b
|
||||
worldT.c = t.c * pt.a + t.d * pt.c; //c
|
||||
worldT.d = t.c * pt.b + t.d * pt.d; //d
|
||||
|
||||
worldT.tx = pt.a * t.tx + pt.c * t.ty + pt.tx;
|
||||
worldT.ty = pt.d * t.ty + pt.ty + pt.b * t.tx;
|
||||
var locCacheCanvas = this._cacheCanvas;
|
||||
//direct draw image by canvas drawImage
|
||||
if (locCacheCanvas && locCacheCanvas.width !== 0 && locCacheCanvas.height !== 0) {
|
||||
wrapper.setTransform(this._realWorldTransform, scaleX, scaleY);
|
||||
var locCanvasHeight = locCacheCanvas.height * scaleY;
|
||||
if (node.layerOrientation === cc.TiledMap.Orientation.HEX) {
|
||||
var halfTileSize = node._mapTileSize.height * 0.5 * scaleY;
|
||||
context.drawImage(locCacheCanvas, 0, 0, locCacheCanvas.width, locCacheCanvas.height,
|
||||
0, -locCanvasHeight + halfTileSize, locCacheCanvas.width * scaleX, locCanvasHeight);
|
||||
} else {
|
||||
worldT.a = t.a;
|
||||
worldT.b = t.b;
|
||||
worldT.c = t.c;
|
||||
worldT.d = t.d;
|
||||
worldT.tx = t.tx;
|
||||
worldT.ty = t.ty;
|
||||
context.drawImage(locCacheCanvas, 0, 0, locCacheCanvas.width, locCacheCanvas.height,
|
||||
0, -locCanvasHeight, locCacheCanvas.width * scaleX, locCanvasHeight);
|
||||
}
|
||||
if (recursive) {
|
||||
var locChildren = this._node._children;
|
||||
if (!locChildren || locChildren.length === 0)
|
||||
return;
|
||||
var i, len;
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
locChildren[i]._renderCmd.transform(this, recursive);
|
||||
}
|
||||
cc.g_NumberOfDraws++;
|
||||
};
|
||||
|
||||
proto._updateCacheContext = function(size, height){
|
||||
var node = this._node,
|
||||
locContentSize = node._contentSize,
|
||||
locCanvas = this._cacheCanvas;
|
||||
locCanvas.width = 0 | (locContentSize.width * 1.5);
|
||||
locCanvas.height = 0 | (locContentSize.height * 1.5);
|
||||
|
||||
//todo: need change the wrapper's height
|
||||
if(node.layerOrientation === cc.TiledMap.Orientation.HEX)
|
||||
this._cacheContext.setOffset(0, -node._mapTileSize.height * 0.5); //translate for hexagonal
|
||||
else
|
||||
this._cacheContext.setOffset(0, 0);
|
||||
var locTexContentSize = this._cacheTexture._contentSize;
|
||||
locTexContentSize.width = locCanvas.width;
|
||||
locTexContentSize.height = locCanvas.height;
|
||||
};
|
||||
|
||||
proto.getTexture = function(){
|
||||
return this._cacheTexture;
|
||||
};
|
||||
|
||||
proto.visit = function(parentCmd){
|
||||
var node = this._node;
|
||||
//TODO: it will implement dynamic compute child cutting automation.
|
||||
var i, len, locChildren = node._children;
|
||||
// quick return if not visible
|
||||
if (!node._visible || !locChildren || locChildren.length === 0)
|
||||
return;
|
||||
|
||||
parentCmd = parentCmd || this.getParentRenderCmd();
|
||||
if (parentCmd)
|
||||
this._curLevel = parentCmd._curLevel + 1;
|
||||
|
||||
this._syncStatus(parentCmd);
|
||||
if (this._cacheDirty) {
|
||||
var wrapper = this._cacheContext, locCanvas = this._cacheCanvas, context = wrapper.getContext(),
|
||||
instanceID = node.__instanceId, renderer = cc.renderer;
|
||||
//begin cache
|
||||
renderer._turnToCacheMode(instanceID);
|
||||
|
||||
node.sortAllChildren();
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
if (locChildren[i]){
|
||||
var selCmd = locChildren[i]._renderCmd;
|
||||
if(selCmd){
|
||||
selCmd.visit(this);
|
||||
selCmd._cacheDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.initImageSize = function(){
|
||||
var node = this._node;
|
||||
node.tileset.imageSize = this._texture.getContentSizeInPixels();
|
||||
};
|
||||
//wrapper.save();
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
||||
//set the wrapper's offset
|
||||
|
||||
proto._reusedTileWithRect = function(rect){
|
||||
var node = this._node;
|
||||
node._reusedTile = new _ccsg.Sprite();
|
||||
node._reusedTile.initWithTexture(this._texture, rect, false);
|
||||
node._reusedTile.batchNode = node;
|
||||
node._reusedTile.parent = node;
|
||||
node._reusedTile._renderCmd._cachedParent = node._renderCmd;
|
||||
return node._reusedTile;
|
||||
};
|
||||
})();
|
||||
//draw to cache canvas
|
||||
renderer._renderingToCacheCanvas(wrapper, instanceID);
|
||||
//wrapper.restore(); //todo: it can be reserve.
|
||||
this._cacheDirty = false
|
||||
}
|
||||
cc.renderer.pushRenderCommand(this);
|
||||
this._dirtyFlag = 0;
|
||||
};
|
||||
|
||||
proto.transform = function (parentCmd, recursive) {
|
||||
// transform for canvas
|
||||
var t = this.getNodeToParentTransform(),
|
||||
worldT = this._realWorldTransform; //get the world transform
|
||||
|
||||
if (parentCmd) {
|
||||
var pt = parentCmd._worldTransform;
|
||||
// cc.AffineTransformConcat is incorrect at get world transform
|
||||
worldT.a = t.a * pt.a + t.b * pt.c; //a
|
||||
worldT.b = t.a * pt.b + t.b * pt.d; //b
|
||||
worldT.c = t.c * pt.a + t.d * pt.c; //c
|
||||
worldT.d = t.c * pt.b + t.d * pt.d; //d
|
||||
|
||||
worldT.tx = pt.a * t.tx + pt.c * t.ty + pt.tx;
|
||||
worldT.ty = pt.d * t.ty + pt.ty + pt.b * t.tx;
|
||||
} else {
|
||||
worldT.a = t.a;
|
||||
worldT.b = t.b;
|
||||
worldT.c = t.c;
|
||||
worldT.d = t.d;
|
||||
worldT.tx = t.tx;
|
||||
worldT.ty = t.ty;
|
||||
}
|
||||
if (recursive) {
|
||||
var locChildren = this._node._children;
|
||||
if (!locChildren || locChildren.length === 0)
|
||||
return;
|
||||
var i, len;
|
||||
for (i = 0, len = locChildren.length; i < len; i++) {
|
||||
locChildren[i]._renderCmd.transform(this, recursive);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
proto.initImageSize = function(){
|
||||
var node = this._node;
|
||||
node.tileset.imageSize = this._texture.getContentSizeInPixels();
|
||||
};
|
||||
|
||||
proto._reusedTileWithRect = function(rect){
|
||||
var node = this._node;
|
||||
node._reusedTile = new _ccsg.Sprite();
|
||||
node._reusedTile.initWithTexture(this._texture, rect, false);
|
||||
node._reusedTile.batchNode = node;
|
||||
node._reusedTile.parent = node;
|
||||
node._reusedTile._renderCmd._cachedParent = node._renderCmd;
|
||||
return node._reusedTile;
|
||||
};
|
||||
@@ -22,46 +22,44 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
_ccsg.TMXLayer.WebGLRenderCmd = function(renderableObject){
|
||||
cc.SpriteBatchNode.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
};
|
||||
_ccsg.TMXLayer.WebGLRenderCmd = function(renderableObject){
|
||||
cc.SpriteBatchNode.WebGLRenderCmd.call(this, renderableObject);
|
||||
this._needDraw = true;
|
||||
};
|
||||
|
||||
var proto = _ccsg.TMXLayer.WebGLRenderCmd.prototype = Object.create(cc.SpriteBatchNode.WebGLRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.TMXLayer.WebGLRenderCmd;
|
||||
var proto = _ccsg.TMXLayer.WebGLRenderCmd.prototype = Object.create(cc.SpriteBatchNode.WebGLRenderCmd.prototype);
|
||||
proto.constructor = _ccsg.TMXLayer.WebGLRenderCmd;
|
||||
|
||||
proto._updateCacheContext = function(){};
|
||||
proto._updateCacheContext = function(){};
|
||||
|
||||
proto.initImageSize = function(){
|
||||
var node = this._node;
|
||||
node.tileset.imageSize = this._textureAtlas.texture.getContentSizeInPixels();
|
||||
proto.initImageSize = function(){
|
||||
var node = this._node;
|
||||
node.tileset.imageSize = this._textureAtlas.texture.getContentSizeInPixels();
|
||||
|
||||
// By default all the tiles are aliased
|
||||
// pros:
|
||||
// - easier to render
|
||||
// cons:
|
||||
// - difficult to scale / rotate / etc.
|
||||
this._textureAtlas.texture.setAliasTexParameters();
|
||||
};
|
||||
// By default all the tiles are aliased
|
||||
// pros:
|
||||
// - easier to render
|
||||
// cons:
|
||||
// - difficult to scale / rotate / etc.
|
||||
this._textureAtlas.texture.setAliasTexParameters();
|
||||
};
|
||||
|
||||
proto._reusedTileWithRect = function(rect){
|
||||
var node = this._node;
|
||||
if (!node._reusedTile) {
|
||||
node._reusedTile = new _ccsg.Sprite();
|
||||
node._reusedTile.initWithTexture(node.texture, rect, false);
|
||||
node._reusedTile.batchNode = node;
|
||||
} else {
|
||||
// XXX HACK: Needed because if "batch node" is nil,
|
||||
// then the Sprite'squad will be reset
|
||||
node._reusedTile.batchNode = null;
|
||||
proto._reusedTileWithRect = function(rect){
|
||||
var node = this._node;
|
||||
if (!node._reusedTile) {
|
||||
node._reusedTile = new _ccsg.Sprite();
|
||||
node._reusedTile.initWithTexture(node.texture, rect, false);
|
||||
node._reusedTile.batchNode = node;
|
||||
} else {
|
||||
// XXX HACK: Needed because if "batch node" is nil,
|
||||
// then the Sprite'squad will be reset
|
||||
node._reusedTile.batchNode = null;
|
||||
|
||||
// Re-init the sprite
|
||||
node._reusedTile.setTextureRect(rect, false);
|
||||
// Re-init the sprite
|
||||
node._reusedTile.setTextureRect(rect, false);
|
||||
|
||||
// restore the batch node
|
||||
node._reusedTile.batchNode = node;
|
||||
}
|
||||
return node._reusedTile;
|
||||
};
|
||||
})();
|
||||
// restore the batch node
|
||||
node._reusedTile.batchNode = node;
|
||||
}
|
||||
return node._reusedTile;
|
||||
};
|
||||
|
||||
@@ -24,72 +24,18 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_NONE = 0;
|
||||
function uint8ArrayToUint32Array (uint8Arr) {
|
||||
if(uint8Arr.length % 4 !== 0)
|
||||
return null;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_MAP = 1;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_LAYER = 2;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_OBJECTGROUP = 3;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_OBJECT = 4;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_PROPERTY_TILE = 5;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_TILE_HORIZONTAL_FLAG = 0x80000000;
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_TILE_VERTICAL_FLAG = 0x40000000;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_TILE_DIAGONAL_FLAG = 0x20000000;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_TILE_FLIPPED_ALL = (cc.TMX_TILE_HORIZONTAL_FLAG | cc.TMX_TILE_VERTICAL_FLAG | cc.TMX_TILE_DIAGONAL_FLAG) >>> 0;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
*/
|
||||
cc.TMX_TILE_FLIPPED_MASK = (~(cc.TMX_TILE_FLIPPED_ALL)) >>> 0;
|
||||
var arrLen = uint8Arr.length /4;
|
||||
var retArr = window.Uint32Array? new Uint32Array(arrLen) : [];
|
||||
for(var i = 0; i < arrLen; i++){
|
||||
var offset = i * 4;
|
||||
retArr[i] = uint8Arr[offset] + uint8Arr[offset + 1] * (1 << 8) + uint8Arr[offset + 2] * (1 << 16) + uint8Arr[offset + 3] * (1<<24);
|
||||
}
|
||||
return retArr;
|
||||
};
|
||||
|
||||
// Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags
|
||||
|
||||
@@ -204,7 +150,7 @@ cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{
|
||||
var rect = cc.rect(0, 0, 0, 0);
|
||||
rect.width = this._tileSize.width;
|
||||
rect.height = this._tileSize.height;
|
||||
gid &= cc.TMX_TILE_FLIPPED_MASK;
|
||||
gid &= cc.TiledMap.TileFlag.FLIPPED_MASK;
|
||||
gid = gid - parseInt(this.firstGid, 10);
|
||||
var max_x = parseInt((this.imageSize.width - this.margin * 2 + this.spacing) / (this._tileSize.width + this.spacing), 10);
|
||||
rect.x = parseInt((gid % max_x) * (this._tileSize.width + this.spacing) + this.margin, 10);
|
||||
@@ -547,11 +493,11 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
cc.log("cocos2d: TMXFormat: Unsupported TMX version:" + version);
|
||||
|
||||
if (orientationStr === "orthogonal")
|
||||
this.orientation = cc.TMX_ORIENTATION_ORTHO;
|
||||
this.orientation = cc.TiledMap.Orientation.ORTHO;
|
||||
else if (orientationStr === "isometric")
|
||||
this.orientation = cc.TMX_ORIENTATION_ISO;
|
||||
this.orientation = cc.TiledMap.Orientation.ISO;
|
||||
else if (orientationStr === "hexagonal")
|
||||
this.orientation = cc.TMX_ORIENTATION_HEX;
|
||||
this.orientation = cc.TiledMap.Orientation.HEX;
|
||||
else if (orientationStr !== null)
|
||||
cc.log("cocos2d: TMXFomat: Unsupported orientation:" + orientationStr);
|
||||
|
||||
@@ -684,11 +630,11 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
}
|
||||
switch (compression) {
|
||||
case 'gzip':
|
||||
layer._tiles = cc.unzipBase64AsArray(nodeValue, 4);
|
||||
layer._tiles = cc.Codec.unzipBase64AsArray(nodeValue, 4);
|
||||
break;
|
||||
case 'zlib':
|
||||
var inflator = new Zlib.Inflate(cc.Codec.Base64.decodeAsArray(nodeValue, 1));
|
||||
layer._tiles = cc.uint8ArrayToUint32Array(inflator.decompress());
|
||||
layer._tiles = uint8ArrayToUint32Array(inflator.decompress());
|
||||
break;
|
||||
case null:
|
||||
case '':
|
||||
@@ -891,7 +837,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
this.currentString = "";
|
||||
this.storingCharacters = false;
|
||||
this.layerAttrs = cc.TMXLayerInfo.ATTRIB_NONE;
|
||||
this.parentElement = cc.TMX_PROPERTY_NONE;
|
||||
this.parentElement = cc.TiledMap.NONE;
|
||||
this._currentFirstGID = 0;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,6 +28,129 @@
|
||||
* @class TiledMap
|
||||
* @extends Component
|
||||
*/
|
||||
|
||||
/**
|
||||
* The orientation of tiled map
|
||||
* @enum TiledMap.Orientation
|
||||
* @static
|
||||
*/
|
||||
var Orientation = cc.Enum({
|
||||
/**
|
||||
* Orthogonal orientation
|
||||
* @property ORTHO
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
ORTHO: 0,
|
||||
|
||||
/**
|
||||
* Hexagonal orientation
|
||||
* @property HEX
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
HEX: 1,
|
||||
|
||||
/**
|
||||
* Isometric orientation
|
||||
* @property ISO
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
ISO: 2
|
||||
});
|
||||
|
||||
/**
|
||||
* The property type of tiled map
|
||||
* @enum TiledMap.Property
|
||||
* @static
|
||||
*/
|
||||
var Property = cc.Enum({
|
||||
/**
|
||||
* @property NONE
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
NONE: 0,
|
||||
|
||||
/**
|
||||
* @property MAP
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
MAP: 1,
|
||||
|
||||
/**
|
||||
* @property LAYER
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
LAYER: 2,
|
||||
|
||||
/**
|
||||
* @property OBJECTGROUP
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
OBJECTGROUP: 3,
|
||||
|
||||
/**
|
||||
* @property OBJECT
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
OBJECT: 4,
|
||||
|
||||
/**
|
||||
* @property TILE
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
TILE: 5
|
||||
});
|
||||
|
||||
/**
|
||||
* The tile flags of tiled map
|
||||
* @enum TiledMap.TileFlag
|
||||
* @static
|
||||
*/
|
||||
var TileFlag = cc.Enum({
|
||||
/**
|
||||
* @property HORIZONTAL
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
HORIZONTAL: 0x80000000,
|
||||
|
||||
/**
|
||||
* @property VERTICAL
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
VERTICAL: 0x40000000,
|
||||
|
||||
/**
|
||||
* @property DIAGONAL
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
DIAGONAL: 0x20000000,
|
||||
|
||||
/**
|
||||
* @property FLIPPED_ALL
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
FLIPPED_ALL: (0x80000000 | 0x40000000 | 0x20000000) >>> 0,
|
||||
|
||||
/**
|
||||
* @property FLIPPED_MASK
|
||||
* @type {Number}
|
||||
* @static
|
||||
*/
|
||||
FLIPPED_MASK: (~((0x80000000 | 0x40000000 | 0x20000000) >>> 0)) >>> 0
|
||||
});
|
||||
|
||||
var TiledMap = cc.Class({
|
||||
name: 'cc.TiledMap',
|
||||
extends: cc._RendererInSG,
|
||||
@@ -36,6 +159,12 @@ var TiledMap = cc.Class({
|
||||
menu: 'i18n:MAIN_MENU.component.renderers/TiledMap',
|
||||
},
|
||||
|
||||
statics: {
|
||||
Orientation: Orientation,
|
||||
Property: Property,
|
||||
TileFlag: TileFlag
|
||||
},
|
||||
|
||||
properties: {
|
||||
_isLoading: {
|
||||
default: false,
|
||||
|
||||
@@ -38,3 +38,12 @@ if (!(CC_EDITOR && Editor.isCoreLevel)) {
|
||||
}
|
||||
|
||||
require('./extensions/spine');
|
||||
|
||||
if (!(CC_EDITOR && Editor.isCoreLevel)) {
|
||||
if (!CC_JSB) {
|
||||
require('./cocos2d/actions');
|
||||
require('./external/chipmunk/chipmunk.js');
|
||||
}
|
||||
|
||||
require('./extensions/ccpool/CCPool.js');
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
|
||||
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
|
||||
//optimize performance for javascript
|
||||
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
|
||||
cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
cc.gl.bindTexture2DN(0, locTexture); // = cc.gl.bindTexture2D(locTexture);
|
||||
cc.gl.enableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
|
||||
if (this._quadDirty) {
|
||||
|
||||
@@ -45,7 +45,7 @@ proto.rendering = function (ctx) {
|
||||
|
||||
this._shaderProgram.use();
|
||||
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
|
||||
// cc.glBlendFunc(this._blendFunc.src, this._blendFunc.dst);
|
||||
// cc.gl.blendFunc(this._blendFunc.src, this._blendFunc.dst);
|
||||
locSkeleton.r = color.r / 255;
|
||||
locSkeleton.g = color.g / 255;
|
||||
locSkeleton.b = color.b / 255;
|
||||
@@ -86,16 +86,16 @@ proto.rendering = function (ctx) {
|
||||
blendMode = slot.data.blendMode;
|
||||
switch (blendMode) {
|
||||
case spine.BlendMode.additive:
|
||||
cc.glBlendFunc(premultiAlpha ? cc.macro.ONE : cc.macro.SRC_ALPHA, cc.macro.ONE);
|
||||
cc.gl.blendFunc(premultiAlpha ? cc.macro.ONE : cc.macro.SRC_ALPHA, cc.macro.ONE);
|
||||
break;
|
||||
case spine.BlendMode.multiply:
|
||||
cc.glBlendFunc(cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA);
|
||||
cc.gl.blendFunc(cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case spine.BlendMode.screen:
|
||||
cc.glBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR);
|
||||
cc.gl.blendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR);
|
||||
break;
|
||||
default:
|
||||
cc.glBlendFunc(locBlendFunc.src, locBlendFunc.dst);
|
||||
cc.gl.blendFunc(locBlendFunc.src, locBlendFunc.dst);
|
||||
}
|
||||
} else if (regionTextureAtlas != textureAtlas && textureAtlas) {
|
||||
textureAtlas.drawQuads();
|
||||
|
||||
Vendored
-3
@@ -1,4 +1,3 @@
|
||||
(function(){
|
||||
/* Copyright (c) 2007 Scott Lembcke
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@@ -6181,5 +6180,3 @@ SimpleMotor.prototype.getImpulse = function()
|
||||
{
|
||||
return Math.abs(this.jAcc);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -32,11 +32,6 @@ var es = require('event-stream');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
|
||||
var srcs = [
|
||||
'./CCBoot.js',
|
||||
|
||||
'./cocos2d/core/platform/CCSAXParser.js',
|
||||
'./cocos2d/core/platform/CCEGLView.js',
|
||||
'./cocos2d/core/platform/CCScreen.js',
|
||||
|
||||
'./cocos2d/core/base-nodes/BaseNodesPropertyDefine.js',
|
||||
'./cocos2d/core/base-nodes/CCSGNode.js',
|
||||
@@ -64,7 +59,6 @@ var srcs = [
|
||||
'./cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/CCConfiguration.js',
|
||||
'./cocos2d/core/CCScheduler.js',
|
||||
|
||||
'./cocos2d/core/CCDrawingPrimitivesCanvas.js',
|
||||
'./cocos2d/core/CCDrawingPrimitivesWebGL.js',
|
||||
@@ -76,11 +70,6 @@ var srcs = [
|
||||
'./cocos2d/core/editbox/CCSGEditBox.js',
|
||||
'./cocos2d/core/editBox/CCdomNode.js',
|
||||
|
||||
'./cocos2d/shaders/CCShaders.js',
|
||||
'./cocos2d/shaders/CCShaderCache.js',
|
||||
'./cocos2d/shaders/CCGLProgram.js',
|
||||
'./cocos2d/shaders/CCGLStateCache.js',
|
||||
|
||||
'./cocos2d/render-texture/CCRenderTexture.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js',
|
||||
'./cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js',
|
||||
@@ -93,27 +82,14 @@ var srcs = [
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/core/CCActionManager.js',
|
||||
|
||||
'./cocos2d/compression/ZipUtils.js',
|
||||
'./cocos2d/compression/base64.js',
|
||||
'./cocos2d/compression/gzip.js',
|
||||
'./cocos2d/compression/zlib.min.js',
|
||||
|
||||
'./cocos2d/particle/CCPNGReader.js',
|
||||
'./cocos2d/particle/CCTIFFReader.js',
|
||||
'./cocos2d/particle/CCSGParticleSystem.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js',
|
||||
'./cocos2d/particle/CCSGParticleExamples.js',
|
||||
// './cocos2d/particle/CCSGParticleExamples.js',
|
||||
'./cocos2d/particle/CCParticleBatchNode.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js',
|
||||
|
||||
'./cocos2d/menus/CCMenuItem.js',
|
||||
'./cocos2d/menus/CCMenu.js',
|
||||
|
||||
'./cocos2d/tilemap/CCTGAlib.js',
|
||||
'./cocos2d/tilemap/CCSGTMXTiledMap.js',
|
||||
'./cocos2d/tilemap/CCTMXXMLParser.js',
|
||||
'./cocos2d/tilemap/CCTMXObjectGroup.js',
|
||||
@@ -124,13 +100,9 @@ var srcs = [
|
||||
'./cocos2d/parallax/CCParallaxNode.js',
|
||||
'./cocos2d/parallax/CCParallaxNodeRenderCmd.js',
|
||||
|
||||
'./extensions/ccpool/CCPool.js',
|
||||
|
||||
'./cocos2d/physics/CCPhysicsDebugNode.js',
|
||||
'./cocos2d/physics/CCPhysicsDebugNodeCanvasRenderCmd.js',
|
||||
'./cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js',
|
||||
|
||||
'./external/chipmunk/chipmunk.js'
|
||||
'./cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js'
|
||||
];
|
||||
|
||||
var header = new Buffer('(function (cc, ccui, ccs, cp) {\n');
|
||||
|
||||
+7
-5
@@ -327,11 +327,11 @@ cc.Director.EVENT_COMPONENT_UPDATE = 'director_component_update';
|
||||
cc.Director.EVENT_COMPONENT_LATE_UPDATE = 'director_component_late_update';
|
||||
|
||||
cc.eventManager.addCustomListener(cc.Director.EVENT_BEFORE_UPDATE, function () {
|
||||
var dt = 1 / 60;
|
||||
// Call start for new added components
|
||||
cc.director.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Update for components
|
||||
cc.director.emit(cc.Director.EVENT_COMPONENT_UPDATE, dt);
|
||||
var dt = 1 / 60;
|
||||
// Call start for new added components
|
||||
cc.director.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Update for components
|
||||
cc.director.emit(cc.Director.EVENT_COMPONENT_UPDATE, dt);
|
||||
});
|
||||
cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_UPDATE, function () {
|
||||
var dt = 1 / 60;
|
||||
@@ -339,6 +339,8 @@ cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_UPDATE, function () {
|
||||
cc.director.emit(cc.Director.EVENT_COMPONENT_LATE_UPDATE, dt);
|
||||
// User can use this event to do things after update
|
||||
cc.director.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
|
||||
cc.director.emit(cc.Director.EVENT_BEFORE_VISIT, this);
|
||||
});
|
||||
|
||||
@@ -52,6 +52,7 @@ function downloadText (item, callback) {
|
||||
cc.loader.addDownloadHandlers({
|
||||
// JS
|
||||
'js' : downloadScript,
|
||||
'jsc' : downloadScript,
|
||||
|
||||
// Images
|
||||
'png' : empty,
|
||||
|
||||
+10
-1
@@ -68,9 +68,18 @@ if (!CC_JSB) {
|
||||
require('./cocos2d/core/CCDirectorCanvas');
|
||||
|
||||
if (!(CC_EDITOR && Editor.isCoreLevel)) {
|
||||
require('./cocos2d/actions');
|
||||
require('./cocos2d/core/platform/CCSAXParser');
|
||||
require('./cocos2d/core/platform/CCView');
|
||||
require('./cocos2d/core/platform/CCScreen');
|
||||
require('./cocos2d/core/CCActionManager');
|
||||
require('./cocos2d/core/CCScheduler');
|
||||
require('./cocos2d/core/event-manager');
|
||||
require('./cocos2d/core/renderer');
|
||||
require('./cocos2d/shaders');
|
||||
require('./cocos2d/compression');
|
||||
|
||||
require('./CCBoot.js');
|
||||
require('./cocos2d/core/CCGame');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,9 @@ cc.game.run({
|
||||
'../../cocos2d/core/base-nodes/CCAtlasNodeCanvasRenderCmd.js',
|
||||
'../../cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js',
|
||||
|
||||
'../../cocos2d/menus/CCMenuItem.js',
|
||||
'../../cocos2d/menus/CCMenu.js',
|
||||
|
||||
"../../cocos2d/core/labelttf/LabelTTFPropertyDefine.js",
|
||||
"../../cocos2d/core/labelttf/CCLabelTTF.js",
|
||||
"../../cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js",
|
||||
@@ -110,6 +113,8 @@ cc.game.run({
|
||||
"../../cocos2d/labels/CCLabelBMFontCanvasRenderCmd.js",
|
||||
"../../cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js",
|
||||
|
||||
"../../cocos2d/particle/CCSGParticleExamples.js",
|
||||
|
||||
"../../cocos2d/actions/CCActionCatmullRom.js",
|
||||
|
||||
"src/BaseTestLayer/BaseTestLayer.js",
|
||||
|
||||
@@ -622,7 +622,7 @@ var RawStencilBufferTest4 = RawStencilBufferTest.extend({
|
||||
|
||||
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
||||
var alphaValueLocation = gl.getUniformLocation(program.getProgram(),cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
|
||||
cc.glUseProgram(program.getProgram());
|
||||
cc.gl.useProgram(program.getProgram());
|
||||
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
this._sprite.shaderProgram = program;
|
||||
},
|
||||
@@ -646,7 +646,7 @@ var RawStencilBufferTest5 = RawStencilBufferTest.extend({
|
||||
|
||||
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
||||
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
|
||||
cc.glUseProgram(program.getProgram());
|
||||
cc.gl.useProgram(program.getProgram());
|
||||
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
this._sprite.shaderProgram = program;
|
||||
},
|
||||
@@ -682,7 +682,7 @@ var RawStencilBufferTest6 = RawStencilBufferTest.extend({
|
||||
|
||||
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
||||
var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
|
||||
cc.glUseProgram(program.getProgram());
|
||||
cc.gl.useProgram(program.getProgram());
|
||||
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
this._sprite.shaderProgram = program;
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ var GLNodeCCAPITest = OpenGLTestLayer.extend({
|
||||
|
||||
this.shader.use();
|
||||
this.shader.setUniformsForBuiltins();
|
||||
cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_COLOR | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_COLOR | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
|
||||
// Draw fullscreen Square
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
|
||||
@@ -604,7 +604,7 @@ var ShaderNode = cc.GLNode.extend({
|
||||
this.shader.setUniformLocationF32( this.uniformCenter, centerx, centery);
|
||||
this.shader.setUniformLocationF32( this.uniformResolution, 256, 256);
|
||||
|
||||
cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_POSITION );
|
||||
cc.gl.enableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_POSITION );
|
||||
|
||||
// Draw fullscreen Square
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
|
||||
@@ -1088,7 +1088,7 @@ var TexImage2DTest = OpenGLTestLayer.extend({
|
||||
this.shader.setUniformsForBuiltins();
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.my_texture);
|
||||
cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
cc.gl.enableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
|
||||
|
||||
// Draw fullscreen Square
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
|
||||
|
||||
@@ -139,8 +139,8 @@ var RenderTextureSave = RenderTextureBaseLayer.extend({
|
||||
var nameJPG = "image-" + this._counter + ".jpg";
|
||||
|
||||
// You can only save one file at a time (in one frame)
|
||||
this._target.saveToFile(nameJPG, cc.IMAGE_FORMAT_JPEG, false);
|
||||
//this._target.saveToFile(namePNG, cc.IMAGE_FORMAT_PNG);
|
||||
this._target.saveToFile(nameJPG, cc.ImageFormat.JPEG, false);
|
||||
//this._target.saveToFile(namePNG, cc.ImageFormat.PNG);
|
||||
|
||||
cc.log("images saved!");
|
||||
this._counter++;
|
||||
|
||||
@@ -1375,10 +1375,10 @@ var TMXOrthoFlipRunTimeTest = TileDemo.extend({
|
||||
var flags = layer.getTileFlagsAt(tileCoord);
|
||||
var GID = layer.getTileGIDAt(tileCoord);
|
||||
// Vertical
|
||||
if ((flags & cc.TMX_TILE_VERTICAL_FLAG) >>> 0) {
|
||||
flags = (flags & ~cc.TMX_TILE_VERTICAL_FLAG >>> 0) >>> 0;
|
||||
if ((flags & cc.TiledMap.TileFlag.VERTICAL) >>> 0) {
|
||||
flags = (flags & ~cc.TiledMap.TileFlag.VERTICAL >>> 0) >>> 0;
|
||||
} else {
|
||||
flags = (flags | cc.TMX_TILE_VERTICAL_FLAG) >>> 0;
|
||||
flags = (flags | cc.TiledMap.TileFlag.VERTICAL) >>> 0;
|
||||
}
|
||||
layer.setTileGID(GID, tileCoord, flags);
|
||||
|
||||
@@ -1386,20 +1386,20 @@ var TMXOrthoFlipRunTimeTest = TileDemo.extend({
|
||||
flags = layer.getTileFlagsAt(tileCoord);
|
||||
GID = layer.getTileGIDAt(tileCoord);
|
||||
// Vertical
|
||||
if ((flags & cc.TMX_TILE_VERTICAL_FLAG) >>> 0)
|
||||
flags = (flags & ~cc.TMX_TILE_VERTICAL_FLAG >>> 0) >>> 0;
|
||||
if ((flags & cc.TiledMap.TileFlag.VERTICAL) >>> 0)
|
||||
flags = (flags & ~cc.TiledMap.TileFlag.VERTICAL >>> 0) >>> 0;
|
||||
else
|
||||
flags = (flags | cc.TMX_TILE_VERTICAL_FLAG) >>> 0;
|
||||
flags = (flags | cc.TiledMap.TileFlag.VERTICAL) >>> 0;
|
||||
layer.setTileGID(GID, tileCoord, flags);
|
||||
|
||||
tileCoord = cc.p(2, 8);
|
||||
flags = layer.getTileFlagsAt(tileCoord);
|
||||
GID = layer.getTileGIDAt(tileCoord);
|
||||
// Horizontal
|
||||
if ((flags & cc.TMX_TILE_HORIZONTAL_FLAG) >>> 0)
|
||||
flags = (flags & ~cc.TMX_TILE_HORIZONTAL_FLAG >>> 0) >>> 0;
|
||||
if ((flags & cc.TiledMap.TileFlag.HORIZONTAL) >>> 0)
|
||||
flags = (flags & ~cc.TiledMap.TileFlag.HORIZONTAL >>> 0) >>> 0;
|
||||
else
|
||||
flags = (flags | cc.TMX_TILE_HORIZONTAL_FLAG) >>> 0;
|
||||
flags = (flags | cc.TiledMap.TileFlag.HORIZONTAL) >>> 0;
|
||||
layer.setTileGID(GID, tileCoord, flags);
|
||||
},
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user