66*/
77
88var CONST = require ( '../../const' ) ;
9- var BlitterBatch = require ( './batches/blitter /BlitterBatch' ) ;
10- var AAQuadBatch = require ( './batches/aaquad/AAQuadBatch ' ) ;
11- var SpriteBatch = require ( './batches/sprite /SpriteBatch' ) ;
12- var ShapeBatch = require ( './batches/shape /ShapeBatch' ) ;
9+ var BlitterBatch = require ( './renderers/blitterbatch /BlitterBatch' ) ;
10+ var QuadBatch = require ( './renderers/quadbatch/QuadBatch ' ) ;
11+ var SpriteBatch = require ( './renderers/spritebatch /SpriteBatch' ) ;
12+ var ShapeBatch = require ( './renderers/shapebatch /ShapeBatch' ) ;
1313var BlendModes = require ( '../BlendModes' ) ;
1414var ScaleModes = require ( '../ScaleModes' ) ;
1515var ResourceManager = require ( './ResourceManager' ) ;
16+ var Resources = require ( './resources' ) ;
1617
1718var WebGLRenderer = function ( game )
1819{
@@ -45,13 +46,13 @@ var WebGLRenderer = function (game)
4546 this . blendModes = [ ] ;
4647 this . gl = null ;
4748 this . extensions = null ;
48- this . batches = [ ] ;
49+ this . currentRendereres = [ ] ;
4950 this . blitterBatch = null ;
5051 this . aaQuadBatch = null ;
5152 this . spriteBatch = null ;
5253 this . shapeBatch = null ;
53- this . batch = null ;
54- this . currentTexture2D = null ;
54+ this . currentRenderer = null ;
55+ this . currentTexture = null ;
5556 this . shaderCache = { } ;
5657 this . currentShader = null ;
5758 this . resourceManager = null ;
@@ -103,10 +104,10 @@ WebGLRenderer.prototype = {
103104
104105 this . blendMode = - 1 ;
105106 this . extensions = gl . getSupportedExtensions ( ) ;
106- this . blitterBatch = this . addBatch ( new BlitterBatch ( this . game , gl , this ) ) ;
107- this . aaQuadBatch = this . addBatch ( new AAQuadBatch ( this . game , gl , this ) ) ;
108- this . spriteBatch = this . addBatch ( new SpriteBatch ( this . game , gl , this ) ) ;
109- this . shapeBatch = this . addBatch ( new ShapeBatch ( this . game , gl , this ) ) ;
107+ this . blitterBatch = this . addRenderer ( new BlitterBatch ( this . game , gl , this ) ) ;
108+ this . quadBatch = this . addRenderer ( new QuadBatch ( this . game , gl , this ) ) ;
109+ this . spriteBatch = this . addRenderer ( new SpriteBatch ( this . game , gl , this ) ) ;
110+ this . shapeBatch = this . addRenderer ( new ShapeBatch ( this . game , gl , this ) ) ;
110111 } ,
111112
112113 createTexture : function ( source )
@@ -137,16 +138,16 @@ WebGLRenderer.prototype = {
137138 ) ;
138139 }
139140
140- this . currentTexture2D = source . glTexture ;
141+ this . currentTexture = source . glTexture ;
141142 } ,
142143
143144 setTexture : function ( texture )
144145 {
145- if ( this . currentTexture2D !== texture )
146+ if ( this . currentTexture !== texture )
146147 {
147- if ( this . batch )
148+ if ( this . currentRenderer )
148149 {
149- this . batch . flush ( ) ;
150+ this . currentRenderer . flush ( ) ;
150151 }
151152
152153 var gl = this . gl ;
@@ -161,7 +162,7 @@ WebGLRenderer.prototype = {
161162 gl . bindTexture ( gl . TEXTURE_2D , null ) ;
162163 }
163164
164- this . currentTexture2D = texture ;
165+ this . currentTexture = texture ;
165166 }
166167 } ,
167168
@@ -170,14 +171,14 @@ WebGLRenderer.prototype = {
170171 var gl = this . gl ;
171172 this . setTexture ( texture ) ;
172173
173- if ( this . batch !== batch )
174+ if ( this . currentRenderer !== batch )
174175 {
175- if ( this . batch )
176+ if ( this . currentRenderer )
176177 {
177- this . batch . flush ( ) ;
178+ this . currentRenderer . flush ( ) ;
178179 }
179180
180- this . batch = batch ;
181+ this . currentRenderer = batch ;
181182 }
182183 } ,
183184
@@ -198,14 +199,14 @@ WebGLRenderer.prototype = {
198199 }
199200
200201 this . gl . viewport ( 0 , 0 , this . width , this . height ) ;
201- for ( var i = 0 , l = this . batches . length ; i < l ; ++ i )
202+ for ( var i = 0 , l = this . currentRendereres . length ; i < l ; ++ i )
202203 {
203- this . batches [ i ] . bind ( ) ;
204- this . batches [ i ] . resize ( width , height , resolution ) ;
204+ this . currentRendereres [ i ] . bind ( ) ;
205+ this . currentRendereres [ i ] . resize ( width , height , resolution ) ;
205206 }
206- if ( this . batch )
207+ if ( this . currentRenderer )
207208 {
208- this . batch . bind ( ) ;
209+ this . currentRenderer . bind ( ) ;
209210 }
210211 } ,
211212
@@ -259,7 +260,7 @@ WebGLRenderer.prototype = {
259260 {
260261 var child = list [ index ] ;
261262 // Setting blend mode if needed
262- var batch = this . batch ;
263+ var batch = this . currentRenderer ;
263264 var newBlendMode = child . blendMode ;
264265 if ( this . blendMode !== newBlendMode )
265266 {
@@ -281,38 +282,38 @@ WebGLRenderer.prototype = {
281282 }
282283 // drawing child
283284 child . renderWebGL ( this , child , interpolationPercentage , camera ) ;
284- batch = this . batch ;
285+ batch = this . currentRenderer ;
285286 if ( batch && batch . isFull ( ) )
286287 {
287288 batch . flush ( ) ;
288289 }
289290 }
290- if ( this . batch )
291+ if ( this . currentRenderer )
291292 {
292- this . batch . flush ( ) ;
293+ this . currentRenderer . flush ( ) ;
293294 }
294295 if ( camera . _fadeAlpha > 0 || camera . _flashAlpha > 0 )
295296 {
296- var aaQuadBatch = this . aaQuadBatch ;
297- aaQuadBatch . bind ( ) ;
297+ var quadBatch = this . quadBatch ;
298+ quadBatch . bind ( ) ;
298299 // fade rendering
299- aaQuadBatch . add (
300+ quadBatch . add (
300301 camera . x , camera . y , camera . width , camera . height ,
301302 camera . _fadeRed ,
302303 camera . _fadeGreen ,
303304 camera . _fadeBlue ,
304305 camera . _fadeAlpha
305306 ) ;
306307 // flash rendering
307- aaQuadBatch . add (
308+ quadBatch . add (
308309 camera . x , camera . y , camera . width , camera . height ,
309310 camera . _flashRed ,
310311 camera . _flashGreen ,
311312 camera . _flashBlue ,
312313 camera . _flashAlpha
313314 ) ;
314- aaQuadBatch . flush ( ) ;
315- this . batch . bind ( ) ;
315+ quadBatch . flush ( ) ;
316+ this . currentRenderer . bind ( ) ;
316317 }
317318 if ( scissor )
318319 {
@@ -323,9 +324,9 @@ WebGLRenderer.prototype = {
323324 // Called at the end of the render loop (tidy things up, etc)
324325 postRender : function ( )
325326 {
326- if ( this . batch )
327+ if ( this . currentRenderer )
327328 {
328- this . batch . flush ( ) ;
329+ this . currentRenderer . flush ( ) ;
329330 }
330331 // Add Post-render hook
331332
@@ -342,7 +343,7 @@ WebGLRenderer.prototype = {
342343 setBlendMode : function ( newBlendMode )
343344 {
344345 var gl = this . gl ;
345- var batch = this . batch ;
346+ var batch = this . currentRenderer ;
346347 var blend = null ;
347348
348349 if ( this . blendMode !== newBlendMode )
@@ -363,13 +364,13 @@ WebGLRenderer.prototype = {
363364 }
364365 } ,
365366
366- addBatch : function ( batchInstance )
367+ addRenderer : function ( rendererInstance )
367368 {
368- var index = this . batches . indexOf ( batchInstance ) ;
369+ var index = this . currentRendereres . indexOf ( rendererInstance ) ;
369370 if ( index < 0 )
370371 {
371- this . batches . push ( batchInstance ) ;
372- return batchInstance ;
372+ this . currentRendereres . push ( rendererInstance ) ;
373+ return rendererInstance ;
373374 }
374375 return null ;
375376 } ,
@@ -380,29 +381,33 @@ WebGLRenderer.prototype = {
380381
381382 if ( ! dstTexture )
382383 {
384+ dstTexture = new Resources . Texture ( null , 0 , 0 ) ;
383385 /* only call this once */
384- dstTexture = gl . createTexture ( ) ;
386+ dstTexture . texture = gl . createTexture ( ) ;
385387 }
386388
387389 if ( shouldUpdateResource )
388390 {
389391 /* Update resource */
390- gl . bindTexture ( gl . TEXTURE_2D , dstTexture ) ;
392+ gl . bindTexture ( gl . TEXTURE_2D , dstTexture . texture ) ;
391393 gl . texSubImage2D ( gl . TEXTURE_2D , 0 , 0 , 0 , gl . RGBA , gl . UNSIGNED_BYTE , srcCanvas ) ;
392394 }
393395 else
394396 {
395397 /* Allocate or Reallocate resource */
396- gl . bindTexture ( gl . TEXTURE_2D , dstTexture ) ;
398+ gl . bindTexture ( gl . TEXTURE_2D , dstTexture . texture ) ;
397399 gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , srcCanvas ) ;
398400 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR ) ;
399401 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . LINEAR ) ;
400402 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
401403 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
402404 }
403405
406+ dstTexture . width = srcCanvas . width ;
407+ dstTexture . height = srcCanvas . height ;
408+
404409 /* we must rebind old texture */
405- gl . bindTexture ( gl . TEXTURE_2D , this . currentTexture2D ) ;
410+ gl . bindTexture ( gl . TEXTURE_2D , this . currentTexture . texture ) ;
406411
407412 return dstTexture ;
408413 }
0 commit comments