Skip to content

Commit da23087

Browse files
committed
Issue cocos2d#2416: Add AtlasNode RenderCmd
1 parent 936cbea commit da23087

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

cocos2d/core/base-nodes/CCAtlasNode.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ cc.AtlasNode = cc.Node.extend(/** @lends cc.AtlasNode# */{
8484
this._ignoreContentScaleFactor = false;
8585

8686
itemsToRender !== undefined && this.initWithTileFile(tile, tileWidth, tileHeight, itemsToRender);
87-
},
8887

89-
_initRendererCmd: function () {
9088
if(cc._renderType === cc._RENDER_TYPE_WEBGL)
91-
this._rendererCmd = new cc.AtlasNodeRenderCmdWebGL(this);
89+
this._rendererCmd = new cc.AtlasNode.WebGLRenderCmd(this);
9290
},
9391

9492
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
cc.AtlasNode.WebGLRenderCmd = function(renderableObject){
26+
cc.Node.WebGLRenderCmd.call(this, renderableObject);
27+
this._needDraw = true;
28+
};
29+
30+
cc.AtlasNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
31+
cc.AtlasNode.WebGLRenderCmd.prototype.constructor = cc.AtlasNode.WebGLRenderCmd;
32+
33+
cc.AtlasNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
34+
var context = ctx || cc._renderContext, node = this._node;
35+
36+
node._shaderProgram.use();
37+
node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix);
38+
39+
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
40+
if (node._uniformColor && node._colorF32Array) {
41+
context.uniform4fv(node._uniformColor, node._colorF32Array);
42+
node.textureAtlas.drawNumberOfQuads(node.quadsToDraw, 0);
43+
}
44+
};

cocos2d/core/renderer/RendererWebGL.js

-17
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,6 @@ cc.ParticleRenderCmdWebGL.prototype.rendering = function (ctx) {
170170
gl.drawElements(gl.TRIANGLES, _t._particleIdx * 6, gl.UNSIGNED_SHORT, 0);
171171
};
172172

173-
cc.AtlasNodeRenderCmdWebGL = function (node) {
174-
this._node = node;
175-
};
176-
177-
cc.AtlasNodeRenderCmdWebGL.prototype.rendering = function (ctx) {
178-
var context = ctx || cc._renderContext, node = this._node;
179-
180-
node._shaderProgram.use();
181-
node._shaderProgram._setUniformForMVPMatrixWithMat4(node._stackMatrix);
182-
183-
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
184-
if (node._uniformColor && node._colorF32Array) {
185-
context.uniform4fv(node._uniformColor, node._colorF32Array);
186-
node.textureAtlas.drawNumberOfQuads(node.quadsToDraw, 0);
187-
}
188-
};
189-
190173
cc.ArmatureRenderCmdWebGL = function (node) {
191174
this._node = node;
192175
};

moduleConfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"core",
148148

149149
"cocos2d/labels/CCLabelAtlas.js",
150+
"cocos2d/labels/CCAtlasNodeRenderCmd.js",
150151
"cocos2d/labels/CCLabelBMFont.js"
151152
],
152153
"menus" : [

0 commit comments

Comments
 (0)