@@ -133,7 +133,7 @@ Phaser.Renderer.WebGL = function (game)
133133 * @property filterManager
134134 * @type WebGLFilterManager
135135 */
136- // this.filterManager = new PIXI.WebGLFilterManager( );
136+ this . filterManager = new Phaser . Renderer . WebGL . FilterManager ( this ) ;
137137
138138 /**
139139 * Manages the stencil buffer
@@ -151,6 +151,13 @@ Phaser.Renderer.WebGL = function (game)
151151 this . drawCount = 0 ;
152152 this . flipY = 1 ;
153153
154+ this . _fbErrors = {
155+ 36054 : 'Incomplete attachment' ,
156+ 36055 : 'Missing attachment' ,
157+ 36057 : 'Incomplete dimensions' ,
158+ 36061 : 'Framebuffer unsupported'
159+ } ;
160+
154161 this . init ( ) ;
155162
156163} ;
@@ -610,6 +617,58 @@ Phaser.Renderer.WebGL.prototype = {
610617 return shaderProgram ;
611618 } ,
612619
620+ createEmptyTexture : function ( width , height , scaleMode )
621+ {
622+ var gl = this . gl ;
623+ var texture = gl . createTexture ( ) ;
624+ var glScaleMode = ( scaleMode === Phaser . scaleModes . LINEAR ) ? gl . LINEAR : gl . NEAREST ;
625+
626+ gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
627+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
628+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
629+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , glScaleMode ) ;
630+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , glScaleMode ) ;
631+
632+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , width , height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
633+
634+ return texture ;
635+ } ,
636+
637+ createFramebuffer : function ( width , height , scaleMode , textureUnit )
638+ {
639+ var gl = this . gl ;
640+ var framebuffer = gl . createFramebuffer ( ) ;
641+ var depthStencilBuffer = gl . createRenderbuffer ( ) ;
642+ var colorBuffer = null ;
643+ var fbStatus = 0 ;
644+
645+ gl . activeTexture ( gl . TEXTURE0 + textureUnit ) ;
646+
647+ gl . bindFramebuffer ( gl . FRAMEBUFFER , framebuffer ) ;
648+ gl . bindRenderbuffer ( gl . RENDERBUFFER , depthStencilBuffer ) ;
649+
650+ // `this.renderBuffer` = undefined? FilterTexture has a renderBuffer, but `this` doesn't.
651+ gl . framebufferRenderbuffer ( gl . FRAMEBUFFER , gl . DEPTH_STENCIL_ATTACHMENT , gl . RENDERBUFFER , this . renderBuffer ) ;
652+
653+ colorBuffer = this . createEmptyTexture ( width , height , scaleMode ) ;
654+
655+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , colorBuffer , 0 ) ;
656+
657+ fbStatus = gl . checkFramebufferStatus ( gl . FRAMEBUFFER ) ;
658+
659+ if ( fbStatus !== gl . FRAMEBUFFER_COMPLETE )
660+ {
661+ console . error ( 'Incomplete GL framebuffer. ' , this . _fbErrors [ fbStatus ] ) ;
662+ }
663+
664+ framebuffer . width = width ;
665+ framebuffer . height = height ;
666+ framebuffer . targetTexture = colorBuffer ;
667+ framebuffer . renderBuffer = depthStencilBuffer ;
668+
669+ return framebuffer ;
670+ } ,
671+
613672 destroy : function ( )
614673 {
615674 PIXI . glContexts [ this . glContextId ] = null ;
0 commit comments