@@ -64,6 +64,14 @@ var WebGLRenderer = function (game)
6464 this . currentRenderTarget = null ;
6565 this . snapshotCallback = null ;
6666
67+ this . scissor = {
68+ enabled : false ,
69+ x : 0 ,
70+ y : 0 ,
71+ width : 0 ,
72+ height : 0
73+ } ;
74+
6775 this . init ( ) ;
6876} ;
6977
@@ -73,7 +81,7 @@ WebGLRenderer.prototype = {
7381
7482 init : function ( )
7583 {
76- console . log ( 'WebGLRenderer.init' ) ;
84+ // console.log('WebGLRenderer.init');
7785
7886 this . gl = this . view . getContext ( 'webgl' , this . config . WebGLContextOptions ) || this . view . getContext ( 'experimental-webgl' , this . config . WebGLContextOptions ) ;
7987
@@ -93,7 +101,6 @@ WebGLRenderer.prototype = {
93101 gl . enable ( gl . BLEND ) ;
94102 gl . clearColor ( color . redGL , color . greenGL , color . blueGL , color . alphaGL ) ;
95103
96-
97104 // Map Blend Modes
98105
99106 var add = [ gl . SRC_ALPHA , gl . DST_ALPHA ] ;
@@ -263,6 +270,7 @@ WebGLRenderer.prototype = {
263270 preRender : function ( )
264271 {
265272 this . setRenderTarget ( null ) ;
273+
266274 // No point rendering if our context has been blown up!
267275 if ( this . contextLost )
268276 {
@@ -275,6 +283,7 @@ WebGLRenderer.prototype = {
275283 var color = this . game . config . backgroundColor ;
276284
277285 gl . clearColor ( color . redGL , color . greenGL , color . blueGL , color . alphaGL ) ;
286+
278287 // Some drivers require to call glClear
279288 gl . clear ( gl . COLOR_BUFFER_BIT | gl . DEPTH_BUFFER_BIT | gl . STENCIL_BUFFER_BIT ) ;
280289
@@ -294,30 +303,42 @@ WebGLRenderer.prototype = {
294303 {
295304 // Could move to the State Systems or MainLoop
296305 var gl = this . gl ;
297- var scissor = ( camera . x !== 0 || camera . y !== 0 || camera . width !== gl . canvas . width || camera . height !== gl . canvas . height ) ;
306+
307+ this . scissor . enabled = ( camera . x !== 0 || camera . y !== 0 || camera . width !== gl . canvas . width || camera . height !== gl . canvas . height ) ;
298308
299309 this . setRenderTarget ( null ) ;
300- if ( scissor )
310+
311+ if ( this . scissor . enabled )
301312 {
302313 gl . enable ( gl . SCISSOR_TEST ) ;
303- gl . scissor ( camera . x , ( gl . drawingBufferHeight - camera . y - camera . height ) , camera . width , camera . height ) ;
314+
315+ this . scissor . x = camera . x ;
316+ this . scissor . y = gl . drawingBufferHeight - camera . y - camera . height ;
317+ this . scissor . width = camera . width ;
318+ this . scissor . height = camera . height ;
319+
320+ gl . scissor ( this . scissor . x , this . scissor . y , this . scissor . width , this . scissor . height ) ;
304321 }
322+
305323 // We could either clear color or render a quad
306324 var color = this . game . config . backgroundColor ;
307325 gl . clearColor ( color . redGL , color . greenGL , color . blueGL , color . alphaGL ) ;
308326 gl . clear ( gl . COLOR_BUFFER_BIT ) ;
309327
310328 var list = children . list ;
311329 var length = list . length ;
330+
312331 for ( var index = 0 ; index < length ; ++ index )
313332 {
314333 var child = list [ index ] ;
334+
315335 // Setting blend mode if needed
316336 var renderer = this . currentRenderer ;
317337 var newBlendMode = child . blendMode ;
338+
318339 if ( this . blendMode !== newBlendMode )
319340 {
320- if ( renderer )
341+ if ( renderer )
321342 {
322343 renderer . flush ( ) ;
323344 }
@@ -333,6 +354,7 @@ WebGLRenderer.prototype = {
333354 }
334355 this . blendMode = newBlendMode ;
335356 }
357+
336358 // drawing child
337359 child . renderWebGL ( this , child , interpolationPercentage , camera ) ;
338360 renderer = this . currentRenderer ;
@@ -349,6 +371,7 @@ WebGLRenderer.prototype = {
349371 this . setRenderTarget ( null ) ;
350372 var quadBatch = this . quadBatch ;
351373 quadBatch . bind ( ) ;
374+
352375 // fade rendering
353376 quadBatch . add (
354377 camera . x , camera . y , camera . width , camera . height ,
@@ -357,6 +380,7 @@ WebGLRenderer.prototype = {
357380 camera . _fadeBlue ,
358381 camera . _fadeAlpha
359382 ) ;
383+
360384 // flash rendering
361385 quadBatch . add (
362386 camera . x , camera . y , camera . width , camera . height ,
@@ -368,7 +392,8 @@ WebGLRenderer.prototype = {
368392 quadBatch . flush ( ) ;
369393 this . currentRenderer . bind ( ) ;
370394 }
371- if ( scissor )
395+
396+ if ( this . scissor . enabled )
372397 {
373398 gl . disable ( gl . SCISSOR_TEST ) ;
374399 }
@@ -381,7 +406,6 @@ WebGLRenderer.prototype = {
381406
382407 if ( this . snapshotCallback )
383408 {
384-
385409 this . snapshotCallback ( Snapshot . WebGLSnapshot ( this . view ) ) ;
386410 this . snapshotCallback = null ;
387411 }
@@ -413,9 +437,13 @@ WebGLRenderer.prototype = {
413437 if ( this . blendMode !== newBlendMode )
414438 {
415439 if ( renderer )
440+ {
416441 renderer . flush ( ) ;
442+ }
443+
417444 blend = this . blendModes [ newBlendMode ] ;
418445 gl . enable ( gl . BLEND ) ;
446+
419447 if ( blend . length > 2 )
420448 {
421449 gl . blendFuncSeparate ( blend [ 0 ] , blend [ 1 ] , blend [ 2 ] , blend [ 3 ] ) ;
@@ -424,33 +452,41 @@ WebGLRenderer.prototype = {
424452 {
425453 gl . blendFunc ( blend [ 0 ] , blend [ 1 ] ) ;
426454 }
455+
427456 this . blendMode = newBlendMode ;
428457 }
429458 } ,
430459
431460 addRenderer : function ( rendererInstance )
432461 {
433462 var index = this . rendererArray . indexOf ( rendererInstance ) ;
434- if ( index < 0 )
463+
464+ if ( index < 0 )
435465 {
436466 this . rendererArray . push ( rendererInstance ) ;
437467 return rendererInstance ;
438468 }
469+
439470 return null ;
440471 } ,
441472
442473 setTextureFilterMode : function ( texture , filterMode )
443474 {
444475 var gl = this . gl ;
445- var glFilter = [ gl . LINEAR , gl . NEAREST ] [ filterMode ] ;
476+ var glFilter = [ gl . LINEAR , gl . NEAREST ] [ filterMode ] ;
446477
447478 gl . bindTexture ( gl . TEXTURE_2D , texture . texture ) ;
448479 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , glFilter ) ;
449480 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , glFilter ) ;
481+
450482 if ( this . currentTexture !== null )
483+ {
451484 gl . bindTexture ( gl . TEXTURE_2D , this . currentTexture . texture ) ;
485+ }
452486 else
487+ {
453488 gl . bindTexture ( gl . TEXTURE_2D , null ) ;
489+ }
454490
455491 return texture ;
456492 } ,
0 commit comments