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