22 * @author Mat Groves http://matgroves.com/ @Doormat23
33 */
44
5+ function _CreateEmptyTexture ( gl , width , height , scaleMode ) {
6+ var texture = gl . createTexture ( ) ;
7+ gl . activeTexture ( gl . TEXTURE0 ) ;
8+ gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
9+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
10+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
11+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR : gl . NEAREST ) ;
12+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , scaleMode === PIXI . scaleModes . LINEAR ? gl . LINEAR : gl . NEAREST ) ;
13+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , width , height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
14+ return texture ;
15+ }
16+
17+ var _fbErrors = {
18+ 36054 : 'Incomplete attachment' ,
19+ 36055 : 'Missing attachment' ,
20+ 36057 : 'Incomplete dimensions' ,
21+ 36061 : 'Framebuffer unsupported'
22+ } ;
23+
24+ function _CreateFramebuffer ( gl , width , height , scaleMode ) {
25+ var framebuffer = gl . createFramebuffer ( ) ;
26+ var depthStencilBuffer = gl . createRenderbuffer ( ) ;
27+ var colorBuffer = null ;
28+ var fbStatus = 0 ;
29+
30+ gl . bindFramebuffer ( gl . FRAMEBUFFER , framebuffer ) ;
31+ gl . bindRenderbuffer ( gl . RENDERBUFFER , depthStencilBuffer ) ;
32+ gl . framebufferRenderbuffer ( gl . FRAMEBUFFER , gl . DEPTH_STENCIL_ATTACHMENT , gl . RENDERBUFFER , this . renderBuffer ) ;
33+ colorBuffer = _CreateEmptyTexture ( gl , width , height , scaleMode ) ;
34+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , colorBuffer , 0 ) ;
35+ fbStatus = gl . checkFramebufferStatus ( gl . FRAMEBUFFER ) ;
36+ if ( fbStatus !== gl . FRAMEBUFFER_COMPLETE ) {
37+ console . error ( 'Incomplete GL framebuffer. ' , _fbErrors [ fbStatus ] ) ;
38+ }
39+ gl . bindTexture ( gl . TEXTURE_2D , null ) ;
40+ gl . bindRenderbuffer ( gl . RENDERBUFFER , null ) ;
41+ gl . bindFramebuffer ( gl . FRAMEBUFFER , null ) ;
42+
43+ framebuffer . width = width ;
44+ framebuffer . height = height ;
45+ framebuffer . targetTexture = colorBuffer ;
46+ framebuffer . renderBuffer = depthStencilBuffer ;
47+ return framebuffer ;
48+ }
49+
550/**
651* @class FilterTexture
752* @constructor
@@ -24,38 +69,43 @@ PIXI.FilterTexture = function(gl, width, height, scaleMode)
2469 * @property frameBuffer
2570 * @type Any
2671 */
27- this . frameBuffer = gl . createFramebuffer ( ) ;
28-
29- /**
72+ this . frameBuffer = _CreateFramebuffer ( gl , width , height , scaleMode || PIXI . scaleModes . DEFAULT ) ;
73+ this . texture = this . frameBuffer . targetTexture ;
74+ this . width = width ;
75+ this . height = height ;
76+ this . renderBuffer = this . frameBuffer . renderBuffer ;
77+ /* this.frameBuffer = gl.createFramebuffer();
78+
79+ / **
3080 * @property texture
3181 * @type Any
32- */
33- this . texture = gl . createTexture ( ) ;
82+ * /
83+ // this.texture = gl.createTexture();
3484
35- /**
85+ / **
3686 * @property scaleMode
3787 * @type Number
38- */
88+ * /
3989 scaleMode = scaleMode || PIXI.scaleModes.DEFAULT;
4090
91+ this.destTexture = gl.createTexture();
4192 gl.activeTexture(gl.TEXTURE0);
4293
43- gl . bindTexture ( gl . TEXTURE_2D , this . texture ) ;
94+ gl.bindTexture(gl.TEXTURE_2D, this.destTexture );
4495 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
4596 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
4697 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
4798 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
48- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . frameBuffer ) ;
4999
50100 gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer );
51- gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , this . texture , 0 ) ;
101+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.destTexture , 0);
52102
53103 // required for masking a mask??
54104 this.renderBuffer = gl.createRenderbuffer();
55105 gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer);
56106 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer);
57107
58- this . resize ( width , height ) ;
108+ this.resize(width, height);*/
59109} ;
60110
61111PIXI . FilterTexture . prototype . constructor = PIXI . FilterTexture ;
@@ -88,7 +138,6 @@ PIXI.FilterTexture.prototype.resize = function(width, height)
88138 this . height = height ;
89139
90140 var gl = this . gl ;
91-
92141 gl . bindTexture ( gl . TEXTURE_2D , this . texture ) ;
93142 gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , width , height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
94143 // update the stencil buffer width and height
0 commit comments