@@ -112,16 +112,13 @@ var GLSLFile = new Class({
112112
113113 if ( block )
114114 {
115- console . log ( 'glsl bundle loaded' ) ;
116-
117115 while ( block )
118116 {
119117 var key = this . getShaderName ( block . header ) ;
120118 var shaderType = this . getShaderType ( block . header ) ;
119+ var uniforms = this . getShaderUniforms ( block . header ) ;
121120 var shaderSrc = block . shader ;
122121
123- console . log ( 'shader: ' , key ) ;
124-
125122 if ( this . cache . has ( key ) )
126123 {
127124 var shader = this . cache . get ( key ) ;
@@ -134,67 +131,133 @@ var GLSLFile = new Class({
134131 {
135132 shader . vertexSrc = shaderSrc ;
136133 }
134+
135+ if ( ! shader . uniforms )
136+ {
137+ shader . uniforms = uniforms ;
138+ }
137139 }
138140 else if ( shaderType === 'fragment' )
139141 {
140- this . cache . add ( key , new Shader ( key , shaderSrc ) ) ;
142+ this . cache . add ( key , new Shader ( key , shaderSrc , '' , uniforms ) ) ;
141143 }
142144 else
143145 {
144- this . cache . add ( key , new Shader ( key , '' , shaderSrc ) ) ;
146+ this . cache . add ( key , new Shader ( key , '' , shaderSrc , uniforms ) ) ;
145147 }
146148
147149 block = this . extractBlock ( data , block . offset ) ;
148150 }
149151 }
150- else
152+ else if ( this . config . shaderType === 'fragment' )
151153 {
152- console . log ( this . key , 'raw glsl' ) ;
153-
154154 // Single shader
155- if ( this . config . shaderType === 'fragment' )
156- {
157- this . cache . add ( this . key , new Shader ( this . key , data ) ) ;
158- }
159- else
160- {
161- this . cache . add ( this . key , new Shader ( this . key , '' , data ) ) ;
162- }
155+ this . cache . add ( this . key , new Shader ( this . key , data ) ) ;
156+ }
157+ else
158+ {
159+ this . cache . add ( this . key , new Shader ( this . key , '' , data ) ) ;
163160 }
164161
165162 this . pendingDestroy ( ) ;
166163 } ,
167164
165+ /**
166+ * Returns the name of the shader from the header block.
167+ *
168+ * @method Phaser.Loader.FileTypes.GLSLFile#getShaderName
169+ * @since 3.17.0
170+ *
171+ * @param {string[] } headerSource - The header data.
172+ *
173+ * @return {string } The shader name.
174+ */
168175 getShaderName : function ( headerSource )
169176 {
170177 for ( var i = 0 ; i < headerSource . length ; i ++ )
171178 {
172179 var line = headerSource [ i ] . trim ( ) ;
173180
174- if ( line . substr ( 0 , 5 ) === 'name:' )
181+ if ( line . substring ( 0 , 5 ) === 'name:' )
175182 {
176- return line . substr ( 5 ) . trim ( ) ;
183+ return line . substring ( 5 ) . trim ( ) ;
177184 }
178185 }
179186
180187 return this . key ;
181188 } ,
182189
190+ /**
191+ * Returns the type of the shader from the header block.
192+ *
193+ * @method Phaser.Loader.FileTypes.GLSLFile#getShaderType
194+ * @since 3.17.0
195+ *
196+ * @param {string[] } headerSource - The header data.
197+ *
198+ * @return {string } The shader type. Either 'fragment' or 'vertex'.
199+ */
183200 getShaderType : function ( headerSource )
184201 {
185202 for ( var i = 0 ; i < headerSource . length ; i ++ )
186203 {
187204 var line = headerSource [ i ] . trim ( ) ;
188205
189- if ( line . substr ( 0 , 5 ) === 'type:' )
206+ if ( line . substring ( 0 , 5 ) === 'type:' )
190207 {
191- return line . substr ( 5 ) . trim ( ) ;
208+ return line . substring ( 5 ) . trim ( ) ;
192209 }
193210 }
194211
195212 return this . config . shaderType ;
196213 } ,
197214
215+ /**
216+ * Returns the shader uniforms from the header block.
217+ *
218+ * @method Phaser.Loader.FileTypes.GLSLFile#getShaderUniforms
219+ * @since 3.17.0
220+ *
221+ * @param {string[] } headerSource - The header data.
222+ *
223+ * @return {any } The shader uniforms object.
224+ */
225+ getShaderUniforms : function ( headerSource )
226+ {
227+ var uniforms = { } ;
228+
229+ for ( var i = 0 ; i < headerSource . length ; i ++ )
230+ {
231+ var line = headerSource [ i ] . trim ( ) ;
232+
233+ if ( line . substring ( 0 , 8 ) === 'uniform.' )
234+ {
235+ var pos = line . indexOf ( ':' ) ;
236+
237+ if ( pos )
238+ {
239+ var key = line . substring ( 8 , pos ) ;
240+
241+ uniforms [ key ] = JSON . parse ( line . substring ( pos + 1 ) . trim ( ) ) ;
242+ }
243+ }
244+ }
245+
246+ return uniforms ;
247+ } ,
248+
249+ /**
250+ * Processes the shader file and extracts the relevant data.
251+ *
252+ * @method Phaser.Loader.FileTypes.GLSLFile#extractBlock
253+ * @private
254+ * @since 3.17.0
255+ *
256+ * @param {string[] } data - The array of shader data to process.
257+ * @param {integer } offset - The offset to start processing from.
258+ *
259+ * @return {any } The processed shader block, or null.
260+ */
198261 extractBlock : function ( data , offset )
199262 {
200263 var headerStart = - 1 ;
@@ -240,15 +303,6 @@ var GLSLFile = new Class({
240303 }
241304 }
242305
243- // console.log('headerStart', headerStart);
244- // console.log('headerEnd', headerEnd);
245- // console.log('headerOpen', headerOpen);
246- // console.log('blockEnd', blockEnd);
247- // console.log('headerSource');
248- // console.log(headerSource);
249- // console.log('shaderSource');
250- // console.log(shaderSource);
251-
252306 if ( ! headerOpen && headerEnd !== - 1 )
253307 {
254308 return { header : headerSource , shader : shaderSource . join ( '\n' ) , offset : blockEnd } ;
0 commit comments