Skip to content

Commit a71bd8e

Browse files
committed
Issue cocos2d#2416: Add ParticleBatchNode RenderCmd
1 parent 53c34e7 commit a71bd8e

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

cocos2d/core/renderer/RendererWebGL.js

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

173-
cc.ParticleBatchNodeRenderCmdWebGL = function (node) {
174-
this._node = node;
175-
};
176-
177-
cc.ParticleBatchNodeRenderCmdWebGL.prototype.rendering = function (ctx) {
178-
var _t = this._node;
179-
if (_t.textureAtlas.totalQuads == 0)
180-
return;
181-
182-
_t._shaderProgram.use();
183-
_t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix);
184-
cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
185-
_t.textureAtlas.drawQuads();
186-
};
187-
188173
//RenderTexture render command
189174
cc.RenderTextureRenderCmdWebGL = function (node) {
190175
this._node = node;

cocos2d/particle/CCParticleBatchNode.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{
101101
} else if (fileImage instanceof cc.Texture2D) {
102102
this.initWithTexture(fileImage, capacity);
103103
}
104+
if(cc._renderType === cc._RENDER_TYPE_WEBGL)
105+
this._rendererCmd = new cc.ParticleBatchNode.WebGLRenderCmd(this);
104106
},
105107

106108
/**
@@ -555,11 +557,6 @@ cc.ParticleBatchNode = cc.Node.extend(/** @lends cc.ParticleBatchNode# */{
555557
*/
556558
setTextureAtlas:function (textureAtlas) {
557559
this.textureAtlas = textureAtlas;
558-
},
559-
560-
_initRendererCmd:function(){
561-
if(cc._renderType === cc._RENDER_TYPE_WEBGL)
562-
this._rendererCmd = new cc.ParticleBatchNodeRenderCmdWebGL(this);
563560
}
564561
});
565562

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.ParticleBatchNode.WebGLRenderCmd = function(renderableObject){
26+
cc.Node.WebGLRenderCmd.call(this, renderableObject);
27+
this._needDraw = true;
28+
};
29+
30+
cc.ParticleBatchNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
31+
cc.ParticleBatchNode.WebGLRenderCmd.prototype.constructor = cc.ParticleBatchNode.WebGLRenderCmd;
32+
33+
cc.ParticleBatchNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
34+
var _t = this._node;
35+
if (_t.textureAtlas.totalQuads == 0)
36+
return;
37+
38+
_t._shaderProgram.use();
39+
_t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix);
40+
cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
41+
_t.textureAtlas.drawQuads();
42+
};

moduleConfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@
178178
"cocos2d/particle/CCParticleSystem.js",
179179
"cocos2d/particle/CCParticleSystemRenderCmd.js",
180180
"cocos2d/particle/CCParticleExamples.js",
181-
"cocos2d/particle/CCParticleBatchNode.js"
181+
"cocos2d/particle/CCParticleBatchNode.js",
182+
"cocos2d/particle/CCParticleBatchNodeRenderCmd.js"
182183
],
183184
"physics" : [
184185
"core", "shape-nodes",

0 commit comments

Comments
 (0)