Skip to content

Commit 69d0228

Browse files
committed
Issue cocos2d#2416: Add Armature RenderCmd
1 parent da23087 commit 69d0228

File tree

4 files changed

+138
-97
lines changed

4 files changed

+138
-97
lines changed

cocos2d/core/renderer/RendererWebGL.js

-64
Original file line numberDiff line numberDiff line change
@@ -169,67 +169,3 @@ cc.ParticleRenderCmdWebGL.prototype.rendering = function (ctx) {
169169
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]);
170170
gl.drawElements(gl.TRIANGLES, _t._particleIdx * 6, gl.UNSIGNED_SHORT, 0);
171171
};
172-
173-
cc.ArmatureRenderCmdWebGL = function (node) {
174-
this._node = node;
175-
};
176-
177-
cc.ArmatureRenderCmdWebGL.prototype.rendering = function (ctx) {
178-
var _t = this._node;
179-
180-
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
181-
cc.kmGLPushMatrix();
182-
cc.kmGLLoadMatrix(_t._stackMatrix);
183-
184-
//TODO REMOVE THIS FUNCTION
185-
if (_t._parentBone == null && _t._batchNode == null) {
186-
// CC_NODE_DRAW_SETUP();
187-
}
188-
189-
var locChildren = _t._children;
190-
var alphaPremultiplied = cc.BlendFunc.ALPHA_PREMULTIPLIED, alphaNonPremultipled = cc.BlendFunc.ALPHA_NON_PREMULTIPLIED;
191-
for (var i = 0, len = locChildren.length; i < len; i++) {
192-
var selBone = locChildren[i];
193-
if (selBone && selBone.getDisplayRenderNode) {
194-
var node = selBone.getDisplayRenderNode();
195-
196-
if (null == node)
197-
continue;
198-
199-
node.setShaderProgram(_t._shaderProgram);
200-
201-
switch (selBone.getDisplayRenderNodeType()) {
202-
case ccs.DISPLAY_TYPE_SPRITE:
203-
if (node instanceof ccs.Skin) {
204-
node.updateTransform();
205-
206-
var func = selBone.getBlendFunc();
207-
if (func.src != alphaPremultiplied.src || func.dst != alphaPremultiplied.dst)
208-
node.setBlendFunc(selBone.getBlendFunc());
209-
else {
210-
if ((_t._blendFunc.src == alphaPremultiplied.src && _t._blendFunc.dst == alphaPremultiplied.dst)
211-
&& !node.getTexture().hasPremultipliedAlpha())
212-
node.setBlendFunc(alphaNonPremultipled);
213-
else
214-
node.setBlendFunc(_t._blendFunc);
215-
}
216-
node.draw(ctx);
217-
}
218-
break;
219-
case ccs.DISPLAY_TYPE_ARMATURE:
220-
node.draw(ctx);
221-
break;
222-
default:
223-
node.visit(ctx); //TODO need fix soon
224-
break;
225-
}
226-
} else if (selBone instanceof cc.Node) {
227-
selBone.setShaderProgram(_t._shaderProgram); //TODO need fix soon
228-
selBone.visit(ctx);
229-
// CC_NODE_DRAW_SETUP();
230-
}
231-
}
232-
233-
cc.kmGLPopMatrix();
234-
};
235-
//}

extensions/cocostudio/armature/CCArmature.js

+3-32
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{
7575

7676
_initRendererCmd:function () {
7777
if(cc._renderType === cc._RENDER_TYPE_CANVAS){
78-
this._rendererStartCmd = new cc.CustomRenderCmdCanvas(this, this._startRendererCmdForCanvas);
79-
this._rendererEndCmd = new cc.CustomRenderCmdCanvas(this, this._endRendererCmdForCanvas);
78+
this._rendererStartCmd = new ccs.Armature.CanvasRenderCmd(this);
79+
this._rendererEndCmd = new ccs.Armature.CanvasRestoreRenderCmd(this);
8080
}else{
81-
this._rendererCmd = new cc.ArmatureRenderCmdWebGL(this);
81+
this._rendererCmd = new ccs.Armature.WebGLRenderCmd(this);
8282
}
8383
},
8484

@@ -484,35 +484,6 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{
484484
context.restore();
485485
},
486486

487-
_startRendererCmdForCanvas: function(ctx, scaleX, scaleY){
488-
var context = ctx || cc._renderContext;
489-
context.save();
490-
this.transform(context);
491-
var t = this._transformWorld;
492-
ctx.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY);
493-
494-
var locChildren = this._children;
495-
for (var i = 0, len = locChildren.length; i< len; i++) {
496-
var selBone = locChildren[i];
497-
if (selBone && selBone.getDisplayRenderNode) {
498-
var node = selBone.getDisplayRenderNode();
499-
500-
if (null == node)
501-
continue;
502-
503-
node._transformForRenderer();
504-
}
505-
}
506-
},
507-
508-
_endRendererCmdForCanvas: function(ctx){
509-
var context = ctx || cc._renderContext;
510-
511-
this._cacheDirty = false;
512-
513-
context.restore();
514-
},
515-
516487
_visitForWebGL: function(){
517488
// quick return if not visible. children won't be drawn.
518489
if (!this._visible)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/****************************************************************************
2+
Copyright (c) 2013-2014 Chukong Technologies Inc.
3+
4+
http://www.cocos2d-x.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
****************************************************************************/
24+
25+
ccs.Armature.CanvasRenderCmd = function(renderableObject){
26+
cc.Node.CanvasRenderCmd.call(this, renderableObject);
27+
this._needDraw = true;
28+
};
29+
30+
ccs.Armature.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
31+
ccs.Armature.CanvasRenderCmd.prototype.constructor = ccs.Armature.CanvasRenderCmd;
32+
33+
ccs.Armature.CanvasRenderCmd.prototype.rendering = function(ctx, scaleX, scaleY){
34+
var context = ctx || cc._renderContext;
35+
context.save();
36+
this.transform(context);
37+
var t = this._transformWorld;
38+
ctx.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY);
39+
40+
var locChildren = this._children;
41+
for (var i = 0, len = locChildren.length; i< len; i++) {
42+
var selBone = locChildren[i];
43+
if (selBone && selBone.getDisplayRenderNode) {
44+
var node = selBone.getDisplayRenderNode();
45+
46+
if (null == node)
47+
continue;
48+
49+
node._transformForRenderer();
50+
}
51+
}
52+
};
53+
54+
ccs.Armature.CanvasRestoreRenderCmd = function(renderableObject){
55+
cc.Node.CanvasRenderCmd.call(this, renderableObject);
56+
this._needDraw = true;
57+
};
58+
59+
ccs.Armature.CanvasRestoreRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
60+
ccs.Armature.CanvasRestoreRenderCmd.prototype.constructor = ccs.Armature.CanvasRestoreRenderCmd;
61+
62+
ccs.Armature.CanvasRestoreRenderCmd.prototype.rendering = function(ctx, scaleX, scaleY){
63+
var context = ctx || cc._renderContext;
64+
this._cacheDirty = false;
65+
context.restore();
66+
};
67+
68+
ccs.Armature.WebGLRenderCmd = function(renderableObject){
69+
cc.Node.WebGLRenderCmd.call(this, renderableObject);
70+
this._needDraw = true;
71+
};
72+
73+
ccs.Armature.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
74+
ccs.Armature.WebGLRenderCmd.prototype.constructor = ccs.Armature.WebGLRenderCmd;
75+
76+
ccs.Armature.WebGLRenderCmd.prototype.rendering = function (ctx) {
77+
var _t = this._node;
78+
79+
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
80+
cc.kmGLPushMatrix();
81+
cc.kmGLLoadMatrix(_t._stackMatrix);
82+
83+
//TODO REMOVE THIS FUNCTION
84+
if (_t._parentBone == null && _t._batchNode == null) {
85+
// CC_NODE_DRAW_SETUP();
86+
}
87+
88+
var locChildren = _t._children;
89+
var alphaPremultiplied = cc.BlendFunc.ALPHA_PREMULTIPLIED, alphaNonPremultipled = cc.BlendFunc.ALPHA_NON_PREMULTIPLIED;
90+
for (var i = 0, len = locChildren.length; i < len; i++) {
91+
var selBone = locChildren[i];
92+
if (selBone && selBone.getDisplayRenderNode) {
93+
var node = selBone.getDisplayRenderNode();
94+
95+
if (null == node)
96+
continue;
97+
98+
node.setShaderProgram(_t._shaderProgram);
99+
100+
switch (selBone.getDisplayRenderNodeType()) {
101+
case ccs.DISPLAY_TYPE_SPRITE:
102+
if (node instanceof ccs.Skin) {
103+
node.updateTransform();
104+
105+
var func = selBone.getBlendFunc();
106+
if (func.src != alphaPremultiplied.src || func.dst != alphaPremultiplied.dst)
107+
node.setBlendFunc(selBone.getBlendFunc());
108+
else {
109+
if ((_t._blendFunc.src == alphaPremultiplied.src && _t._blendFunc.dst == alphaPremultiplied.dst)
110+
&& !node.getTexture().hasPremultipliedAlpha())
111+
node.setBlendFunc(alphaNonPremultipled);
112+
else
113+
node.setBlendFunc(_t._blendFunc);
114+
}
115+
node.draw(ctx);
116+
}
117+
break;
118+
case ccs.DISPLAY_TYPE_ARMATURE:
119+
node.draw(ctx);
120+
break;
121+
default:
122+
node.visit(ctx); //TODO need fix soon
123+
break;
124+
}
125+
} else if (selBone instanceof cc.Node) {
126+
selBone.setShaderProgram(_t._shaderProgram); //TODO need fix soon
127+
selBone.visit(ctx);
128+
// CC_NODE_DRAW_SETUP();
129+
}
130+
}
131+
132+
cc.kmGLPopMatrix();
133+
};

moduleConfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"cocos2d/core/base-nodes/CCNode.js",
8080
"cocos2d/core/base-nodes/CCNodeRenderCmd.js",
8181
"cocos2d/core/base-nodes/CCAtlasNode.js",
82+
"cocos2d/core/base-nodes/CCAtlasNodeRenderCmd.js",
8283

8384
"cocos2d/core/textures/TexturesWebGL.js",
8485
"cocos2d/core/textures/TexturesPropertyDefine.js",
@@ -147,7 +148,6 @@
147148
"core",
148149

149150
"cocos2d/labels/CCLabelAtlas.js",
150-
"cocos2d/labels/CCAtlasNodeRenderCmd.js",
151151
"cocos2d/labels/CCLabelBMFont.js"
152152
],
153153
"menus" : [
@@ -333,6 +333,7 @@
333333
"extensions/cocostudio/armature/animation/CCTween.js",
334334
"extensions/cocostudio/armature/physics/CCColliderDetector.js",
335335
"extensions/cocostudio/armature/CCArmature.js",
336+
"extensions/cocostudio/armature/CCArmatureRenderCmd.js",
336337
"extensions/cocostudio/armature/CCBone.js",
337338

338339
"extensions/cocostudio/action/CCActionFrame.js",

0 commit comments

Comments
 (0)