@@ -46,15 +46,6 @@ var ForwardDiffuseLightPipeline = new Class({
4646 * @since 3.11.0
4747 */
4848 this . defaultNormalMap ;
49-
50- /**
51- * Collection of batch information
52- *
53- * @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batches
54- * @type {array }
55- * @since 3.1.0
56- */
57- this . batches = [ ] ;
5849 } ,
5950
6051 /**
@@ -92,11 +83,6 @@ var ForwardDiffuseLightPipeline = new Class({
9283
9384 this . mvpUpdate ( ) ;
9485
95- if ( this . batches . length === 0 )
96- {
97- this . pushBatch ( ) ;
98- }
99-
10086 renderer . setInt1 ( program , 'uNormSampler' , 1 ) ;
10187 renderer . setFloat2 ( program , 'uResolution' , this . width , this . height ) ;
10288
@@ -108,78 +94,6 @@ var ForwardDiffuseLightPipeline = new Class({
10894 return this ;
10995 } ,
11096
111- /**
112- * Creates a new batch object and pushes it to a batch array.
113- * The batch object contains information relevant to the current
114- * vertex batch like the offset in the vertex buffer, vertex count and
115- * the textures used by that batch.
116- *
117- * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#pushBatch
118- * @since 3.1.0
119- */
120- pushBatch : function ( )
121- {
122- var batch = {
123- first : this . vertexCount ,
124- texture : null ,
125- textures : [ ]
126- } ;
127-
128- this . batches . push ( batch ) ;
129- } ,
130-
131- /**
132- * Assigns a texture to the current batch. If a texture is already set it creates
133- * a new batch object.
134- *
135- * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#setTexture2D
136- * @since 3.1.0
137- *
138- * @param {WebGLTexture } texture - WebGLTexture that will be assigned to the current batch.
139- * @param {integer } textureUnit - Texture unit to which the texture needs to be bound.
140- *
141- * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline } This pipeline instance.
142- */
143- setTexture2D : function ( texture , unit )
144- {
145- if ( ! texture )
146- {
147- return this ;
148- }
149-
150- var batches = this . batches ;
151-
152- if ( batches . length === 0 )
153- {
154- this . pushBatch ( ) ;
155- }
156-
157- var batch = batches [ batches . length - 1 ] ;
158-
159- if ( unit > 0 )
160- {
161- if ( batch . textures [ unit - 1 ] &&
162- batch . textures [ unit - 1 ] !== texture )
163- {
164- this . pushBatch ( ) ;
165- }
166-
167- batches [ batches . length - 1 ] . textures [ unit - 1 ] = texture ;
168- }
169- else
170- {
171- if ( batch . texture !== null &&
172- batch . texture !== texture )
173- {
174- this . pushBatch ( ) ;
175- }
176-
177- batches [ batches . length - 1 ] . texture = texture ;
178- }
179-
180- return this ;
181- } ,
182-
18397 /**
18498 * This function sets all the needed resources for each camera pass.
18599 *
@@ -245,106 +159,6 @@ var ForwardDiffuseLightPipeline = new Class({
245159 return this ;
246160 } ,
247161
248- /**
249- * Binds, uploads resources and processes all batches generating draw calls.
250- *
251- * @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#flush
252- * @since 3.1.0
253- *
254- * @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline } This pipeline instance.
255- */
256- flush : function ( )
257- {
258- if ( this . flushLocked )
259- {
260- return this ;
261- }
262-
263- this . flushLocked = true ;
264-
265- var gl = this . gl ;
266- var renderer = this . renderer ;
267- var vertexCount = this . vertexCount ;
268- var topology = this . topology ;
269- var vertexSize = this . vertexSize ;
270- var batches = this . batches ;
271- var batchCount = batches . length ;
272- var batchVertexCount = 0 ;
273- var batch = null ;
274- var batchNext ;
275- var textureIndex ;
276- var nTexture ;
277-
278- if ( batchCount === 0 || vertexCount === 0 )
279- {
280- this . flushLocked = false ;
281- return this ;
282- }
283-
284- gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . bytes . subarray ( 0 , vertexCount * vertexSize ) ) ;
285-
286- for ( var index = 0 ; index < batches . length - 1 ; ++ index )
287- {
288- batch = batches [ index ] ;
289- batchNext = batches [ index + 1 ] ;
290-
291- if ( batch . textures . length > 0 )
292- {
293- for ( textureIndex = 0 ; textureIndex < batch . textures . length ; ++ textureIndex )
294- {
295- nTexture = batch . textures [ textureIndex ] ;
296-
297- if ( nTexture )
298- {
299- renderer . setTexture2D ( nTexture , 1 + textureIndex ) ;
300- }
301- }
302-
303- gl . activeTexture ( gl . TEXTURE0 ) ;
304- }
305-
306- batchVertexCount = batchNext . first - batch . first ;
307-
308- if ( batch . texture === null || batchVertexCount <= 0 ) { continue ; }
309-
310- renderer . setTexture2D ( batch . texture , 0 ) ;
311- gl . drawArrays ( topology , batch . first , batchVertexCount ) ;
312- }
313-
314- // Left over data
315- batch = batches [ batches . length - 1 ] ;
316-
317- if ( batch . textures . length > 0 )
318- {
319- for ( textureIndex = 0 ; textureIndex < batch . textures . length ; ++ textureIndex )
320- {
321- nTexture = batch . textures [ textureIndex ] ;
322-
323- if ( nTexture )
324- {
325- renderer . setTexture2D ( nTexture , 1 + textureIndex ) ;
326- }
327- }
328-
329- gl . activeTexture ( gl . TEXTURE0 ) ;
330- }
331-
332- batchVertexCount = vertexCount - batch . first ;
333-
334- if ( batch . texture && batchVertexCount > 0 )
335- {
336- renderer . setTexture2D ( batch . texture , 0 ) ;
337- gl . drawArrays ( topology , batch . first , batchVertexCount ) ;
338- }
339-
340- this . vertexCount = 0 ;
341- batches . length = 0 ;
342- this . pushBatch ( ) ;
343- this . flushLocked = false ;
344-
345- return this ;
346- } ,
347-
348162 /**
349163 * Generic function for batching a textured quad
350164 *
@@ -408,7 +222,11 @@ var ForwardDiffuseLightPipeline = new Class({
408222
409223 var normalTexture ;
410224
411- if ( gameObject . texture )
225+ if ( gameObject . displayTexture )
226+ {
227+ normalTexture = gameObject . displayTexture . dataSource [ gameObject . displayFrame . sourceIndex ] ;
228+ }
229+ else if ( gameObject . texture )
412230 {
413231 normalTexture = gameObject . texture . dataSource [ gameObject . frame . sourceIndex ] ;
414232 }
@@ -419,7 +237,8 @@ var ForwardDiffuseLightPipeline = new Class({
419237
420238 if ( ! normalTexture )
421239 {
422- normalTexture = this . defaultNormalMap ;
240+ console . warn ( 'Normal map missing or invalid' ) ;
241+ return ;
423242 }
424243
425244 this . setTexture2D ( normalTexture . glTexture , 1 ) ;
@@ -428,12 +247,55 @@ var ForwardDiffuseLightPipeline = new Class({
428247 var spriteMatrix = this . _tempMatrix2 ;
429248 var calcMatrix = this . _tempMatrix3 ;
430249
250+ var u0 = ( frameX / textureWidth ) + uOffset ;
251+ var v0 = ( frameY / textureHeight ) + vOffset ;
252+ var u1 = ( frameX + frameWidth ) / textureWidth + uOffset ;
253+ var v1 = ( frameY + frameHeight ) / textureHeight + vOffset ;
254+
431255 var width = srcWidth ;
432256 var height = srcHeight ;
433257
258+ // var x = -displayOriginX + frameX;
259+ // var y = -displayOriginY + frameY;
260+
434261 var x = - displayOriginX ;
435262 var y = - displayOriginY ;
436263
264+ if ( gameObject . isCropped )
265+ {
266+ var crop = gameObject . _crop ;
267+
268+ width = crop . width ;
269+ height = crop . height ;
270+
271+ srcWidth = crop . width ;
272+ srcHeight = crop . height ;
273+
274+ frameX = crop . x ;
275+ frameY = crop . y ;
276+
277+ var ox = frameX ;
278+ var oy = frameY ;
279+
280+ if ( flipX )
281+ {
282+ ox = ( frameWidth - crop . x - crop . width ) ;
283+ }
284+
285+ if ( flipY && ! texture . isRenderTexture )
286+ {
287+ oy = ( frameHeight - crop . y - crop . height ) ;
288+ }
289+
290+ u0 = ( ox / textureWidth ) + uOffset ;
291+ v0 = ( oy / textureHeight ) + vOffset ;
292+ u1 = ( ox + crop . width ) / textureWidth + uOffset ;
293+ v1 = ( oy + crop . height ) / textureHeight + vOffset ;
294+
295+ x = - displayOriginX + frameX ;
296+ y = - displayOriginY + frameY ;
297+ }
298+
437299 // Invert the flipY if this is a RenderTexture
438300 flipY = flipY ^ ( texture . isRenderTexture ? 1 : 0 ) ;
439301
@@ -449,11 +311,12 @@ var ForwardDiffuseLightPipeline = new Class({
449311 y += srcHeight ;
450312 }
451313
452- if ( camera . roundPixels )
453- {
454- x |= 0 ;
455- y |= 0 ;
456- }
314+ // Do we need this? (doubt it)
315+ // if (camera.roundPixels)
316+ // {
317+ // x |= 0;
318+ // y |= 0;
319+ // }
457320
458321 var xw = x + width ;
459322 var yh = y + height ;
@@ -483,17 +346,17 @@ var ForwardDiffuseLightPipeline = new Class({
483346 camMatrix . multiply ( spriteMatrix , calcMatrix ) ;
484347 }
485348
486- var tx0 = x * calcMatrix . a + y * calcMatrix . c + calcMatrix . e ;
487- var ty0 = x * calcMatrix . b + y * calcMatrix . d + calcMatrix . f ;
349+ var tx0 = calcMatrix . getX ( x , y ) ;
350+ var ty0 = calcMatrix . getY ( x , y ) ;
488351
489- var tx1 = x * calcMatrix . a + yh * calcMatrix . c + calcMatrix . e ;
490- var ty1 = x * calcMatrix . b + yh * calcMatrix . d + calcMatrix . f ;
352+ var tx1 = calcMatrix . getX ( x , yh ) ;
353+ var ty1 = calcMatrix . getY ( x , yh ) ;
491354
492- var tx2 = xw * calcMatrix . a + yh * calcMatrix . c + calcMatrix . e ;
493- var ty2 = xw * calcMatrix . b + yh * calcMatrix . d + calcMatrix . f ;
355+ var tx2 = calcMatrix . getX ( xw , yh ) ;
356+ var ty2 = calcMatrix . getY ( xw , yh ) ;
494357
495- var tx3 = xw * calcMatrix . a + y * calcMatrix . c + calcMatrix . e ;
496- var ty3 = xw * calcMatrix . b + y * calcMatrix . d + calcMatrix . f ;
358+ var tx3 = calcMatrix . getX ( xw , y ) ;
359+ var ty3 = calcMatrix . getY ( xw , y ) ;
497360
498361 if ( camera . roundPixels )
499362 {
@@ -510,14 +373,9 @@ var ForwardDiffuseLightPipeline = new Class({
510373 ty3 |= 0 ;
511374 }
512375
513- var u0 = ( frameX / textureWidth ) + uOffset ;
514- var v0 = ( frameY / textureHeight ) + vOffset ;
515- var u1 = ( frameX + frameWidth ) / textureWidth + uOffset ;
516- var v1 = ( frameY + frameHeight ) / textureHeight + vOffset ;
517-
518376 this . setTexture2D ( texture , 0 ) ;
519377
520- this . batchVertices ( tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 , u0 , v0 , u1 , v1 , tintTL , tintTR , tintBL , tintBR , tintEffect ) ;
378+ this . batchQuad ( tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 , u0 , v0 , u1 , v1 , tintTL , tintTR , tintBL , tintBR , tintEffect ) ;
521379 } ,
522380
523381 /**
0 commit comments