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
+ } ;
0 commit comments