@@ -11,6 +11,7 @@ var CreateTexture2DImage = require('./utils/texture/CreateTexture2DImage');
1111var BlitterBatch = require ( './batches/blitter/BlitterBatch' ) ;
1212var SpriteBatch = require ( './batches/sprite/SpriteBatch' ) ;
1313var SpriteBatch32 = require ( './batches/sprite/SpriteBatch32' ) ;
14+ var BlendModes = require ( '../BlendModes' ) ;
1415
1516var WebGLRenderer = function ( game )
1617{
@@ -145,6 +146,8 @@ WebGLRenderer.prototype = {
145146 normal , normal , normal , normal ,
146147 normal , normal , normal , normal
147148 ] ;
149+
150+ this . blendMode = - 1 ;
148151 } ,
149152
150153 createTexture2D : function ( source )
@@ -256,9 +259,7 @@ WebGLRenderer.prototype = {
256259 // clear is needed for the FBO, otherwise corruption ...
257260 gl . clear ( gl . COLOR_BUFFER_BIT ) ;
258261
259- //this.setBlendMode(CONST.blendModes.NORMAL);
260-
261- //this.batch.start();
262+ this . setBlendMode ( BlendModes . NORMAL ) ;
262263
263264 // Could move to the State Systems or MainLoop
264265 for ( var c = 0 ; c < state . sys . children . list . length ; c ++ )
@@ -296,7 +297,25 @@ WebGLRenderer.prototype = {
296297 {
297298 this . gl = null ;
298299 } ,
299- createFBO : function ( ) { }
300+
301+ createFBO : function ( ) { } ,
302+
303+ setBlendMode : function ( newBlendMode )
304+ {
305+ var gl = this . gl ;
306+ var batch = this . batch ;
307+ var blend = null ;
308+
309+ if ( this . blendMode !== newBlendMode )
310+ {
311+ if ( batch )
312+ batch . flush ( ) ;
313+ blend = this . blendModes [ newBlendMode ] ;
314+ gl . enable ( gl . BLEND ) ;
315+ gl . blendFunc ( blend [ 0 ] , blend [ 1 ] ) ;
316+ this . blendMode = newBlendMode ;
317+ }
318+ }
300319} ;
301320
302321module . exports = WebGLRenderer ;
0 commit comments