Skip to content

Commit 53c34e7

Browse files
committed
Issue cocos2d#2416: Add MotionStreak RenderCmd
1 parent 55f80be commit 53c34e7

File tree

4 files changed

+77
-43
lines changed

4 files changed

+77
-43
lines changed

cocos2d/core/renderer/RendererWebGL.js

-39
Original file line numberDiff line numberDiff line change
@@ -137,45 +137,6 @@ cc.rendererWebGL = {
137137
if (cc._renderType === cc._RENDER_TYPE_WEBGL)
138138
cc.renderer = cc.rendererWebGL;
139139

140-
141-
cc.MotionStreakCmdWebGL = function (node) {
142-
this._node = node;
143-
};
144-
145-
cc.MotionStreakCmdWebGL.prototype.rendering = function (ctx) {
146-
var _t = this._node;
147-
if (_t._nuPoints <= 1)
148-
return;
149-
150-
if (_t.texture && _t.texture.isLoaded()) {
151-
ctx = ctx || cc._renderContext;
152-
_t._shaderProgram.use();
153-
_t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix);
154-
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
155-
cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst);
156-
157-
cc.glBindTexture2D(_t.texture);
158-
159-
//position
160-
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._verticesBuffer);
161-
ctx.bufferData(ctx.ARRAY_BUFFER, _t._vertices, ctx.DYNAMIC_DRAW);
162-
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
163-
164-
//texcoords
165-
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._texCoordsBuffer);
166-
ctx.bufferData(ctx.ARRAY_BUFFER, _t._texCoords, ctx.DYNAMIC_DRAW);
167-
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
168-
169-
//colors
170-
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._colorPointerBuffer);
171-
ctx.bufferData(ctx.ARRAY_BUFFER, _t._colorPointer, ctx.DYNAMIC_DRAW);
172-
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
173-
174-
ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, _t._nuPoints * 2);
175-
cc.g_NumberOfDraws++;
176-
}
177-
};
178-
179140
cc.ParticleRenderCmdWebGL = function (node) {
180141
this._node = node;
181142
};

cocos2d/motion-streak/CCMotionStreak.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
115115

116116
if(texture !== undefined)
117117
this.initWithFade(fade, minSeg, stroke, color, texture);
118-
},
119118

120-
_initRendererCmd:function(){
121-
this._rendererCmd = new cc.MotionStreakCmdWebGL(this);
119+
this._rendererCmd = new cc.MotionStreak.WebGLRenderCmd(this);
122120
},
123121

124122
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.MotionStreak.WebGLRenderCmd = function(renderableObject){
26+
cc.Node.WebGLRenderCmd.call(this, renderableObject);
27+
this._needDraw = true;
28+
this._textureCoord = {
29+
renderX: 0, //the x of texture coordinate for render, when texture tinted, its value doesn't equal x.
30+
renderY: 0, //the y of texture coordinate for render, when texture tinted, its value doesn't equal y.
31+
x: 0, //the x of texture coordinate for node.
32+
y: 0, //the y of texture coordinate for node.
33+
width: 0,
34+
height: 0,
35+
validRect: false
36+
};
37+
};
38+
39+
cc.MotionStreak.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
40+
cc.MotionStreak.WebGLRenderCmd.prototype.constructor = cc.Sprite.WebGLRenderCmd;
41+
42+
cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
43+
var _t = this._node;
44+
if (_t._nuPoints <= 1)
45+
return;
46+
47+
if (_t.texture && _t.texture.isLoaded()) {
48+
ctx = ctx || cc._renderContext;
49+
_t._shaderProgram.use();
50+
_t._shaderProgram._setUniformForMVPMatrixWithMat4(_t._stackMatrix);
51+
cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
52+
cc.glBlendFunc(_t._blendFunc.src, _t._blendFunc.dst);
53+
54+
cc.glBindTexture2D(_t.texture);
55+
56+
//position
57+
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._verticesBuffer);
58+
ctx.bufferData(ctx.ARRAY_BUFFER, _t._vertices, ctx.DYNAMIC_DRAW);
59+
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
60+
61+
//texcoords
62+
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._texCoordsBuffer);
63+
ctx.bufferData(ctx.ARRAY_BUFFER, _t._texCoords, ctx.DYNAMIC_DRAW);
64+
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
65+
66+
//colors
67+
ctx.bindBuffer(ctx.ARRAY_BUFFER, _t._colorPointerBuffer);
68+
ctx.bufferData(ctx.ARRAY_BUFFER, _t._colorPointer, ctx.DYNAMIC_DRAW);
69+
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
70+
71+
ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, _t._nuPoints * 2);
72+
cc.g_NumberOfDraws++;
73+
}
74+
};

moduleConfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@
157157
"motion-streak" : [
158158
"core", "shaders", "kazmath", "labels",
159159

160-
"cocos2d/motion-streak/CCMotionStreak.js"
160+
"cocos2d/motion-streak/CCMotionStreak.js",
161+
"cocos2d/motion-streak/CCMotionStreakRenderCmd.js"
161162
],
162163
"node-grid" : [
163164
"core",

0 commit comments

Comments
 (0)