@@ -52,33 +52,40 @@ var TextureTintPipeline = new Class({
5252 {
5353 var rendererConfig = config . renderer . config ;
5454
55- // Vertex Size = attribute size added together (2 + 2 + 1 + 4)
56- // Vertex Size = attribute size added together (2 + 2 + 1 + 1 + 4) inc maxTextures
57-
5855 var maxTextures = config . renderer . maxTextures ;
5956
60- var src = '' ;
61-
62- for ( var i = 0 ; i < maxTextures ; i ++ )
57+ if ( ! config . fragShader )
6358 {
64- if ( i > 0 )
65- {
66- src += '\n\telse ' ;
67- }
59+ var src = '' ;
6860
69- if ( i < maxTextures - 1 )
61+ for ( var i = 0 ; i < maxTextures ; i ++ )
7062 {
71- src += 'if (outTexId < ' + i + '.5)' ;
63+ if ( i > 0 )
64+ {
65+ src += '\n\telse ' ;
66+ }
67+
68+ if ( i < maxTextures - 1 )
69+ {
70+ src += 'if (outTexId < ' + i + '.5)' ;
71+ }
72+
73+ src += '\n\t{' ;
74+ src += '\n\t\ttexture = texture2D(uMainSampler[' + i + '], outTexCoord);' ;
75+ src += '\n\t}' ;
7276 }
7377
74- src += '\n\t{' ;
75- src += '\n\t\ttexture = texture2D(uMainSampler[' + i + '], outTexCoord);' ;
76- src += '\n\t}' ;
77- }
78+ var fragmentShaderSource = ShaderSourceFS . replace ( / % c o u n t % / gi, maxTextures . toString ( ) ) ;
7879
79- var fragmentShaderSource = ShaderSourceFS . replace ( / % c o u n t % / gi, maxTextures . toString ( ) ) ;
80+ fragmentShaderSource = fragmentShaderSource . replace ( / % f o r l o o p % / gi, src ) ;
81+ }
82+ else
83+ {
84+ fragmentShaderSource = config . fragShader ;
85+ }
8086
81- fragmentShaderSource = fragmentShaderSource . replace ( / % f o r l o o p % / gi, src ) ;
87+ // Vertex Size = attribute size added together (2 + 2 + 1 + 4)
88+ // Vertex Size = attribute size added together (2 + 2 + 1 + 1 + 4) inc maxTextures
8289
8390 WebGLPipeline . call ( this , {
8491 game : config . game ,
@@ -406,9 +413,12 @@ var TextureTintPipeline = new Class({
406413 * @param {(Phaser.GameObjects.Image|Phaser.GameObjects.Sprite) } sprite - The texture based Game Object to add to the batch.
407414 * @param {Phaser.Cameras.Scene2D.Camera } camera - The Camera to use for the rendering transform.
408415 * @param {Phaser.GameObjects.Components.TransformMatrix } [parentTransformMatrix] - The transform matrix of the parent container, if set.
416+ * @param {boolean } [forceZero=false] - Force this Sprite to use texture unit zero?
409417 */
410- batchSprite : function ( sprite , camera , parentTransformMatrix )
418+ batchSprite : function ( sprite , camera , parentTransformMatrix , forceZero )
411419 {
420+ if ( forceZero === undefined ) { forceZero = false ; }
421+
412422 // Will cause a flush if this isn't the current pipeline, vertexbuffer or program
413423 this . renderer . setPipeline ( this ) ;
414424
@@ -550,7 +560,16 @@ var TextureTintPipeline = new Class({
550560 this . flush ( ) ;
551561 }
552562
553- var unit = this . renderer . setTextureSource ( textureSource ) ;
563+ var unit = 0 ;
564+
565+ if ( forceZero )
566+ {
567+ this . renderer . setTextureZero ( textureSource . glTexture ) ;
568+ }
569+ else
570+ {
571+ unit = this . renderer . setTextureSource ( textureSource ) ;
572+ }
554573
555574 var tintEffect = ( sprite . _isTinted && sprite . tintFill ) ;
556575
@@ -795,6 +814,7 @@ var TextureTintPipeline = new Class({
795814 * @param {Phaser.Cameras.Scene2D.Camera } camera - Current used camera.
796815 * @param {Phaser.GameObjects.Components.TransformMatrix } parentTransformMatrix - Parent container.
797816 * @param {boolean } [skipFlip=false] - Skip the renderTexture check.
817+ * @param {boolean } [forceZero=false] - Force this Sprite to use texture unit zero?
798818 */
799819 batchTexture : function (
800820 gameObject ,
@@ -812,8 +832,11 @@ var TextureTintPipeline = new Class({
812832 uOffset , vOffset ,
813833 camera ,
814834 parentTransformMatrix ,
815- skipFlip )
835+ skipFlip ,
836+ forceZero )
816837 {
838+ if ( forceZero === undefined ) { forceZero = false ; }
839+
817840 this . renderer . setPipeline ( this , gameObject ) ;
818841
819842 var camMatrix = this . _tempMatrix1 ;
@@ -936,8 +959,16 @@ var TextureTintPipeline = new Class({
936959 ty3 = Math . round ( ty3 ) ;
937960 }
938961
939- // this.setTexture2D(texture, 0);
940- var unit = this . renderer . setTexture2D ( texture ) ;
962+ var unit = 0 ;
963+
964+ if ( forceZero )
965+ {
966+ this . renderer . setTextureZero ( texture ) ;
967+ }
968+ else
969+ {
970+ unit = this . renderer . setTexture2D ( texture ) ;
971+ }
941972
942973 this . batchQuad ( tx0 , ty0 , tx1 , ty1 , tx2 , ty2 , tx3 , ty3 , u0 , v0 , u1 , v1 , tintTL , tintTR , tintBL , tintBR , tintEffect , texture , unit ) ;
943974 } ,
0 commit comments