@@ -33,12 +33,10 @@ var LightLayer = new Class({
3333
3434 function LightLayer ( scene )
3535 {
36- GameObject . call ( this , scene , 'LightLayer' ) ;
36+ var _this = this ;
3737
38- var resourceManager = scene . sys . game . renderer . resourceManager ;
39- this . _isDeferred = WebGLSupportedExtensions . has ( 'WEBGL_draw_buffers' ) ;
38+ GameObject . call ( this , scene , 'LightLayer' ) ;
4039
41- this . renderer = scene . sys . game . renderer ;
4240 this . passShader = null ;
4341 this . gl = null ;
4442 this . ambientLightColorR = 0.0 ;
@@ -48,12 +46,35 @@ var LightLayer = new Class({
4846 this . spritePool = [ ] ;
4947 this . lights = [ ] ;
5048 this . sprites = [ ] ;
51- this . lightsLocations = [ ] ;
5249 this . _z = 0 ;
50+ this . setOrigin ( 0 , 0 ) ;
51+
52+ scene . sys . game . renderer . addContextRestoredCallback ( function ( renderer ) {
53+ _this . onContextRestored ( renderer ) ;
54+ } ) ;
55+
56+ this . init ( scene . sys . game . renderer , WebGLSupportedExtensions . has ( 'WEBGL_draw_buffers' ) ) ;
57+ } ,
58+
59+ onContextRestored : function ( renderer )
60+ {
61+ /* It won't allow the use of drawBuffers on restored context */
62+ this . init ( renderer , false ) ;
63+ this . renderWebGL = require ( './ForwardRenderer' ) ;
64+ this . lights . length = Math . min ( this . lights . length , Const . MAX_LIGHTS ) ;
65+ } ,
66+
67+ init : function ( renderer , deferred )
68+ {
69+ var resourceManager = renderer . resourceManager ;
70+
71+ this . _isDeferred = deferred ;
72+ this . renderer = renderer ;
73+ this . lightsLocations = [ ] ;
5374
5475 if ( resourceManager !== undefined && ! this . _isDeferred )
5576 {
56- this . gl = scene . sys . game . renderer . gl ;
77+ this . gl = renderer . gl ;
5778
5879 this . passShader = resourceManager . createShader ( 'Phong2DShaderForward' , {
5980 vert : TexturedAndNormalizedTintedShader . vert ,
@@ -81,9 +102,9 @@ var LightLayer = new Class({
81102 }
82103 else
83104 {
84- var gl = this . gl = scene . sys . game . renderer . gl ;
105+ var gl = this . gl = renderer . gl ;
85106
86- this . ext = scene . sys . game . renderer . getExtension ( 'WEBGL_draw_buffers' ) ;
107+ this . ext = renderer . getExtension ( 'WEBGL_draw_buffers' ) ;
87108
88109 this . gBufferShaderPass = resourceManager . createShader ( 'GBufferShader' , {
89110 vert : TexturedAndNormalizedTintedShader . vert ,
@@ -138,14 +159,14 @@ var LightLayer = new Class({
138159
139160 gl . bindFramebuffer ( gl . FRAMEBUFFER , this . gBufferFbo ) ;
140161 gl . bindTexture ( gl . TEXTURE_2D , this . gBufferColorTex ) ;
141- gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , scene . sys . game . renderer . width , scene . sys . game . renderer . height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
162+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , renderer . width , renderer . height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
142163 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
143164 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
144165 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
145166 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
146167
147168 gl . bindTexture ( gl . TEXTURE_2D , this . gBufferNormalTex ) ;
148- gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , scene . sys . game . renderer . width , scene . sys . game . renderer . height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
169+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , renderer . width , renderer . height , 0 , gl . RGBA , gl . UNSIGNED_BYTE , null ) ;
149170 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
150171 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
151172 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
@@ -172,8 +193,6 @@ var LightLayer = new Class({
172193 gl . bindFramebuffer ( gl . FRAMEBUFFER , null ) ;
173194 VertexBuffer . SetDirty ( ) ;
174195 }
175-
176- this . setOrigin ( 0 , 0 ) ;
177196 } ,
178197
179198 forEachLight : function ( callback )
0 commit comments