@@ -49,7 +49,7 @@ var WebGLRenderer = function (game)
4949 this . blendModes = [ ] ;
5050 this . gl = null ;
5151 this . extensions = null ;
52- this . currentRendereres = [ ] ;
52+ this . rendererArray = [ ] ;
5353 this . blitterBatch = null ;
5454 this . aaQuadBatch = null ;
5555 this . spriteBatch = null ;
@@ -92,7 +92,6 @@ WebGLRenderer.prototype = {
9292 gl . enable ( gl . BLEND ) ;
9393 gl . clearColor ( color . redGL , color . greenGL , color . blueGL , color . alphaGL ) ;
9494
95- this . resize ( this . width , this . height ) ;
9695
9796 // Map Blend Modes
9897
@@ -116,7 +115,9 @@ WebGLRenderer.prototype = {
116115 this . shapeBatch = this . addRenderer ( new ShapeBatch ( this . game , gl , this ) ) ;
117116 this . effectRenderer = this . addRenderer ( new EffectRenderer ( this . game , gl , this ) ) ;
118117 this . tileBatch = this . addRenderer ( new TileBatch ( this . game , gl , this ) ) ;
118+ this . currentRenderer = this . spriteBatch ;
119119 this . setBlendMode ( 0 ) ;
120+ this . resize ( this . width , this . height ) ;
120121 } ,
121122
122123 createTexture : function ( source , width , height )
@@ -170,14 +171,12 @@ WebGLRenderer.prototype = {
170171 {
171172 if ( this . currentTexture !== texture )
172173 {
173- if ( this . currentRenderer )
174- {
175- this . currentRenderer . flush ( ) ;
176- }
177-
178174 var gl = this . gl ;
179175
176+ this . currentRenderer . flush ( ) ;
177+
180178 gl . activeTexture ( gl . TEXTURE0 ) ;
179+
181180 if ( texture !== null )
182181 {
183182 gl . bindTexture ( gl . TEXTURE_2D , texture . texture ) ;
@@ -196,13 +195,9 @@ WebGLRenderer.prototype = {
196195 this . setTexture ( texture ) ;
197196 this . setRenderTarget ( renderTarget ) ;
198197
199- if ( this . currentRenderer !== renderer )
198+ if ( this . currentRenderer !== renderer || this . currentRenderer . shouldFlush ( ) )
200199 {
201- if ( this . currentRenderer )
202- {
203- this . currentRenderer . flush ( ) ;
204- }
205-
200+ this . currentRenderer . flush ( ) ;
206201 this . currentRenderer = renderer ;
207202 }
208203 } ,
@@ -213,10 +208,7 @@ WebGLRenderer.prototype = {
213208
214209 if ( this . currentRenderTarget !== renderTarget )
215210 {
216- if ( this . currentRenderer )
217- {
218- this . currentRenderer . flush ( ) ;
219- }
211+ this . currentRenderer . flush ( ) ;
220212
221213 if ( renderTarget !== null )
222214 {
@@ -239,30 +231,27 @@ WebGLRenderer.prototype = {
239231
240232 resize : function ( width , height )
241233 {
242- var res = this . game . config . resolution ;
234+ var resolution = this . game . config . resolution ;
243235
244- this . width = width * res ;
245- this . height = height * res ;
236+ this . width = width * resolution ;
237+ this . height = height * resolution ;
246238
247239 this . view . width = this . width ;
248240 this . view . height = this . height ;
249241
250242 if ( this . autoResize )
251243 {
252- this . view . style . width = ( this . width / res ) + 'px' ;
253- this . view . style . height = ( this . height / res ) + 'px' ;
244+ this . view . style . width = ( this . width / resolution ) + 'px' ;
245+ this . view . style . height = ( this . height / resolution ) + 'px' ;
254246 }
255247
256248 this . gl . viewport ( 0 , 0 , this . width , this . height ) ;
257- for ( var i = 0 , l = this . currentRendereres . length ; i < l ; ++ i )
258- {
259- this . currentRendereres [ i ] . bind ( ) ;
260- this . currentRendereres [ i ] . resize ( width , height , resolution ) ;
261- }
262- if ( this . currentRenderer )
249+ for ( var i = 0 , l = this . rendererArray . length ; i < l ; ++ i )
263250 {
264- this . currentRenderer . bind ( ) ;
251+ this . rendererArray [ i ] . bind ( ) ;
252+ this . rendererArray [ i ] . resize ( width , height , resolution ) ;
265253 }
254+ this . currentRenderer . bind ( ) ;
266255 } ,
267256
268257 // Call at the start of the render loop
@@ -342,15 +331,14 @@ WebGLRenderer.prototype = {
342331 // drawing child
343332 child . renderWebGL ( this , child , interpolationPercentage , camera ) ;
344333 renderer = this . currentRenderer ;
345- if ( renderer && renderer . isFull ( ) )
334+ if ( renderer . isFull ( ) || renderer . shouldFlush ( ) )
346335 {
347336 renderer . flush ( ) ;
348337 }
349338 }
350- if ( this . currentRenderer )
351- {
352- this . currentRenderer . flush ( ) ;
353- }
339+
340+ this . currentRenderer . flush ( ) ;
341+
354342 if ( camera . _fadeAlpha > 0 || camera . _flashAlpha > 0 )
355343 {
356344 this . setRenderTarget ( null ) ;
@@ -384,10 +372,7 @@ WebGLRenderer.prototype = {
384372 // Called at the end of the render loop (tidy things up, etc)
385373 postRender : function ( )
386374 {
387- if ( this . currentRenderer )
388- {
389- this . currentRenderer . flush ( ) ;
390- }
375+ this . currentRenderer . flush ( ) ;
391376
392377 if ( this . snapshotCallback )
393378 {
@@ -440,10 +425,10 @@ WebGLRenderer.prototype = {
440425
441426 addRenderer : function ( rendererInstance )
442427 {
443- var index = this . currentRendereres . indexOf ( rendererInstance ) ;
428+ var index = this . rendererArray . indexOf ( rendererInstance ) ;
444429 if ( index < 0 )
445430 {
446- this . currentRendereres . push ( rendererInstance ) ;
431+ this . rendererArray . push ( rendererInstance ) ;
447432 return rendererInstance ;
448433 }
449434 return null ;
0 commit comments