1+ var Frame = require ( '../../textures/Frame' ) ;
12var Utils = require ( '../../renderer/webgl/Utils' ) ;
23
34var RenderTextureWebGL = {
@@ -85,11 +86,11 @@ var RenderTextureWebGL = {
8586 *
8687 * @return {this } This Game Object.
8788 */
88- draw : function ( stamp , x , y , tint )
89+ draw : function ( entries , x , y , tint )
8990 {
90- if ( ! Array . isArray ( stamp ) )
91+ if ( ! Array . isArray ( entries ) )
9192 {
92- stamp = [ stamp ] ;
93+ entries = [ entries ] ;
9394 }
9495
9596 this . renderer . setFramebuffer ( this . framebuffer ) ;
@@ -100,17 +101,7 @@ var RenderTextureWebGL = {
100101
101102 pipeline . projOrtho ( 0 , this . width , 0 , this . height , - 1000.0 , 1000.0 ) ;
102103
103- for ( var i = 0 ; i < stamp . length ; i ++ )
104- {
105- // if (stamp[i].frame)
106- // {
107- this . drawGameObject ( stamp [ i ] , x , y ) ;
108- // }
109- // else
110- // {
111- // this.drawFrame(stamp[i], x, y, tint);
112- // }
113- }
104+ this . drawList ( entries , x , y , tint ) ;
114105
115106 pipeline . flush ( ) ;
116107
@@ -121,6 +112,54 @@ var RenderTextureWebGL = {
121112 return this ;
122113 } ,
123114
115+ drawList : function ( children , x , y , tint )
116+ {
117+ for ( var i = 0 ; i < children . length ; i ++ )
118+ {
119+ var entry = children [ i ] ;
120+
121+ if ( ! entry || entry === this )
122+ {
123+ continue ;
124+ }
125+
126+ if ( entry . renderWebGL )
127+ {
128+ // Game Objects
129+ this . drawGameObject ( entry , x , y ) ;
130+ }
131+ else if ( entry . isParent )
132+ {
133+ // Groups
134+ this . drawGroup ( entry . getChildren ( ) , x , y ) ;
135+ }
136+ else if ( entry instanceof Frame )
137+ {
138+ // Texture Frames
139+ this . drawFrame ( entry , x , y , tint ) ;
140+ }
141+ }
142+ } ,
143+
144+ drawGroup : function ( children , x , y )
145+ {
146+ if ( x === undefined ) { x = 0 ; }
147+ if ( y === undefined ) { y = 0 ; }
148+
149+ for ( var i = 0 ; i < children . length ; i ++ )
150+ {
151+ var entry = children [ i ] ;
152+
153+ if ( entry . renderWebGL )
154+ {
155+ var tx = entry . x + x ;
156+ var ty = entry . y + y ;
157+
158+ this . drawGameObject ( entry , tx , ty ) ;
159+ }
160+ }
161+ } ,
162+
124163 drawGameObject : function ( gameObject , x , y )
125164 {
126165 if ( x === undefined ) { x = gameObject . x ; }
@@ -138,29 +177,43 @@ var RenderTextureWebGL = {
138177 gameObject . setPosition ( prevX , prevY ) ;
139178 } ,
140179
141- NEWdrawGameObject : function ( gameObject , x , y )
180+ drawTexture : function ( key , frame , x , y , alpha , tint )
142181 {
143- if ( x === undefined ) { x = gameObject . x ; }
144- if ( y === undefined ) { y = gameObject . y ; }
182+ if ( x === undefined ) { x = 0 ; }
183+ if ( y === undefined ) { y = 0 ; }
184+ if ( alpha === undefined ) { alpha = this . globalAlpha ; }
185+
186+ if ( tint === undefined )
187+ {
188+ tint = ( this . globalTint >> 16 ) + ( this . globalTint & 0xff00 ) + ( ( this . globalTint & 0xff ) << 16 ) ;
189+ }
190+ else
191+ {
192+ tint = ( tint >> 16 ) + ( tint & 0xff00 ) + ( ( tint & 0xff ) << 16 ) ;
193+ }
145194
146- var getTint = Utils . getTintAppendFloatAlpha ;
147-
148- this . pipeline . batchTextureFrame (
149- gameObject ,
150- gameObject . frame ,
151- x , y ,
152- gameObject . width , gameObject . height ,
153- gameObject . scaleX , gameObject . scaleY ,
154- gameObject . rotation ,
155- gameObject . flipX , gameObject . flipY ,
156- gameObject . displayOriginX , gameObject . displayOriginY ,
157- getTint ( gameObject . _tintTL , this . alpha * gameObject . _alphaTL ) ,
158- getTint ( gameObject . _tintTR , this . alpha * gameObject . _alphaTR ) ,
159- getTint ( gameObject . _tintBL , this . alpha * gameObject . _alphaBL ) ,
160- getTint ( gameObject . _tintBR , this . alpha * gameObject . _alphaBR ) ,
161- ( gameObject . _isTinted && gameObject . tintFill ) ,
162- null
163- ) ;
195+ var textureFrame = this . textureManager . getFrame ( key , frame ) ;
196+
197+ if ( textureFrame )
198+ {
199+ this . renderer . setFramebuffer ( this . framebuffer ) ;
200+
201+ this . camera . preRender ( 1 , 1 , 1 ) ;
202+
203+ var pipeline = this . pipeline ;
204+
205+ pipeline . projOrtho ( 0 , this . width , 0 , this . height , - 1000.0 , 1000.0 ) ;
206+
207+ this . pipeline . batchTextureFrame ( frame , x , y , tint , alpha , this . camera . matrix , null ) ;
208+
209+ pipeline . flush ( ) ;
210+
211+ this . renderer . setFramebuffer ( null ) ;
212+
213+ pipeline . projOrtho ( 0 , pipeline . width , pipeline . height , 0 , - 1000.0 , 1000.0 ) ;
214+ }
215+
216+ return this ;
164217 } ,
165218
166219 drawFrame : function ( frame , x , y , tint )
@@ -177,9 +230,7 @@ var RenderTextureWebGL = {
177230 tint = ( tint >> 16 ) + ( tint & 0xff00 ) + ( ( tint & 0xff ) << 16 ) ;
178231 }
179232
180- this . pipeline . drawTextureFrame ( frame , x , y , tint , this . globalAlpha , this . currentMatrix , null ) ;
181-
182- // pipeline.drawTextureFrame(frame, x, y, tint, this.globalAlpha, [1,0,0,1,0,0,0,0,1], null);
233+ this . pipeline . batchTextureFrame ( frame , x , y , tint , this . globalAlpha , this . camera . matrix , null ) ;
183234 }
184235
185236} ;
0 commit comments