Skip to content

Commit 187328e

Browse files
committed
UVs are passed directly now
1 parent afec945 commit 187328e

1 file changed

Lines changed: 134 additions & 22 deletions

File tree

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 134 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,24 @@ var TextureTintPipeline = new Class({
129129
*/
130130
this.batches = [];
131131

132-
// Temporary containers for calculation values
133-
132+
/**
133+
* A temporary Transform Matrix, re-used internally during batching.
134+
*
135+
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempCameraMatrix
136+
* @private
137+
* @type {Phaser.GameObjects.Components.TransformMatrix}
138+
* @since 3.11.0
139+
*/
134140
this._tempCameraMatrix = new TransformMatrix();
141+
142+
/**
143+
* A temporary Transform Matrix, re-used internally during batching.
144+
*
145+
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempSpriteMatrix
146+
* @private
147+
* @type {Phaser.GameObjects.Components.TransformMatrix}
148+
* @since 3.11.0
149+
*/
135150
this._tempSpriteMatrix = new TransformMatrix();
136151

137152
this.mvpInit();
@@ -598,11 +613,6 @@ var TextureTintPipeline = new Class({
598613
{
599614
this.renderer.setPipeline(this);
600615

601-
if (this.vertexCount + 6 > this.vertexCapacity)
602-
{
603-
this.flush();
604-
}
605-
606616
var camMatrix = this._tempCameraMatrix;
607617
var spriteMatrix = this._tempSpriteMatrix;
608618

@@ -692,21 +702,23 @@ var TextureTintPipeline = new Class({
692702

693703
var tintEffect = (sprite._isTinted && sprite.tintFill);
694704

695-
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.uvs, tintTL, tintTR, tintBL, tintBR, tintEffect);
705+
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, tintTL, tintTR, tintBL, tintBR, tintEffect);
696706
},
697707

698708
/**
699709
* Adds the vertices data into the batch and flushes if full.
700710
*
701711
* Assumes 6 vertices in the following arrangement:
702712
*
713+
* ```
703714
* 0----3
704715
* |\ B|
705716
* | \ |
706717
* | \ |
707718
* | A \|
708719
* | \
709720
* 1----2
721+
* ```
710722
*
711723
* Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3
712724
*
@@ -721,7 +733,10 @@ var TextureTintPipeline = new Class({
721733
* @param {number} ty2 - The bottom-right y position.
722734
* @param {number} tx3 - The top-right x position.
723735
* @param {number} ty3 - The top-right y position.
724-
* @param {object} uvs - An object containing the vertice UV coordinates in properties named `x0` and `y0` through to `x3` and `y3`.
736+
* @param {number} u0 - UV u0 value.
737+
* @param {number} v0 - UV v0 value.
738+
* @param {number} u1 - UV u1 value.
739+
* @param {number} v1 - UV v1 value.
725740
* @param {number} tintTL - The top-left tint color value.
726741
* @param {number} tintTR - The top-right tint color value.
727742
* @param {number} tintBL - The bottom-left tint color value.
@@ -730,52 +745,57 @@ var TextureTintPipeline = new Class({
730745
*
731746
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
732747
*/
733-
batchVertices: function (tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, uvs, tintTL, tintTR, tintBL, tintBR, tintEffect)
748+
batchVertices: function (tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect)
734749
{
750+
if (this.vertexCount + 6 >= this.vertexCapacity)
751+
{
752+
this.flush();
753+
}
754+
735755
var vertexViewF32 = this.vertexViewF32;
736756
var vertexViewU32 = this.vertexViewU32;
737757

738758
var vertexOffset = this.vertexCount * this.vertexComponentCount - 1;
739759

740760
vertexViewF32[++vertexOffset] = tx0;
741761
vertexViewF32[++vertexOffset] = ty0;
742-
vertexViewF32[++vertexOffset] = uvs.x0;
743-
vertexViewF32[++vertexOffset] = uvs.y0;
762+
vertexViewF32[++vertexOffset] = u0;
763+
vertexViewF32[++vertexOffset] = v0;
744764
vertexViewF32[++vertexOffset] = tintEffect;
745765
vertexViewU32[++vertexOffset] = tintTL;
746766

747767
vertexViewF32[++vertexOffset] = tx1;
748768
vertexViewF32[++vertexOffset] = ty1;
749-
vertexViewF32[++vertexOffset] = uvs.x1;
750-
vertexViewF32[++vertexOffset] = uvs.y1;
769+
vertexViewF32[++vertexOffset] = u0;
770+
vertexViewF32[++vertexOffset] = v1;
751771
vertexViewF32[++vertexOffset] = tintEffect;
752772
vertexViewU32[++vertexOffset] = tintBL;
753773

754774
vertexViewF32[++vertexOffset] = tx2;
755775
vertexViewF32[++vertexOffset] = ty2;
756-
vertexViewF32[++vertexOffset] = uvs.x2;
757-
vertexViewF32[++vertexOffset] = uvs.y2;
776+
vertexViewF32[++vertexOffset] = u1;
777+
vertexViewF32[++vertexOffset] = v1;
758778
vertexViewF32[++vertexOffset] = tintEffect;
759779
vertexViewU32[++vertexOffset] = tintBR;
760780

761781
vertexViewF32[++vertexOffset] = tx0;
762782
vertexViewF32[++vertexOffset] = ty0;
763-
vertexViewF32[++vertexOffset] = uvs.x0;
764-
vertexViewF32[++vertexOffset] = uvs.y0;
783+
vertexViewF32[++vertexOffset] = u0;
784+
vertexViewF32[++vertexOffset] = v0;
765785
vertexViewF32[++vertexOffset] = tintEffect;
766786
vertexViewU32[++vertexOffset] = tintTL;
767787

768788
vertexViewF32[++vertexOffset] = tx2;
769789
vertexViewF32[++vertexOffset] = ty2;
770-
vertexViewF32[++vertexOffset] = uvs.x2;
771-
vertexViewF32[++vertexOffset] = uvs.y2;
790+
vertexViewF32[++vertexOffset] = u1;
791+
vertexViewF32[++vertexOffset] = v1;
772792
vertexViewF32[++vertexOffset] = tintEffect;
773793
vertexViewU32[++vertexOffset] = tintBR;
774794

775795
vertexViewF32[++vertexOffset] = tx3;
776796
vertexViewF32[++vertexOffset] = ty3;
777-
vertexViewF32[++vertexOffset] = uvs.x3;
778-
vertexViewF32[++vertexOffset] = uvs.y3;
797+
vertexViewF32[++vertexOffset] = u1;
798+
vertexViewF32[++vertexOffset] = v0;
779799
vertexViewF32[++vertexOffset] = tintEffect;
780800
vertexViewU32[++vertexOffset] = tintTR;
781801

@@ -1630,6 +1650,97 @@ var TextureTintPipeline = new Class({
16301650
camera,
16311651
parentTransformMatrix)
16321652
{
1653+
this.renderer.setPipeline(this);
1654+
1655+
var camMatrix = this._tempCameraMatrix;
1656+
var spriteMatrix = this._tempSpriteMatrix;
1657+
1658+
spriteMatrix.applyITRS(srcX - camera.scrollX * scrollFactorX, srcY - camera.scrollY * scrollFactorY, rotation, scaleX, scaleY);
1659+
1660+
var width = srcWidth;
1661+
var height = srcHeight;
1662+
1663+
var x = -displayOriginX;
1664+
var y = -displayOriginY;
1665+
1666+
if (flipX)
1667+
{
1668+
width *= -1;
1669+
x += srcWidth;
1670+
}
1671+
1672+
if (flipY || texture.isRenderTexture)
1673+
{
1674+
height *= -1;
1675+
y += srcHeight;
1676+
}
1677+
1678+
if (camera.roundPixels)
1679+
{
1680+
x |= 0;
1681+
y |= 0;
1682+
}
1683+
1684+
var xw = x + width;
1685+
var yh = y + height;
1686+
1687+
camMatrix.copyFrom(camera.matrix);
1688+
1689+
var calcMatrix;
1690+
1691+
if (parentTransformMatrix)
1692+
{
1693+
// Multiply the camera by the parent matrix
1694+
camMatrix.multiplyWithOffset(parentTransformMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
1695+
1696+
// Undo the camera scroll
1697+
spriteMatrix.e = srcX;
1698+
spriteMatrix.f = srcY;
1699+
1700+
// Multiply by the Sprite matrix
1701+
calcMatrix = camMatrix.multiply(spriteMatrix);
1702+
}
1703+
else
1704+
{
1705+
calcMatrix = spriteMatrix.multiply(camMatrix);
1706+
}
1707+
1708+
var tx0 = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
1709+
var ty0 = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
1710+
1711+
var tx1 = x * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
1712+
var ty1 = x * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
1713+
1714+
var tx2 = xw * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
1715+
var ty2 = xw * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
1716+
1717+
var tx3 = xw * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
1718+
var ty3 = xw * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
1719+
1720+
if (camera.roundPixels)
1721+
{
1722+
tx0 |= 0;
1723+
ty0 |= 0;
1724+
tx1 |= 0;
1725+
ty1 |= 0;
1726+
tx2 |= 0;
1727+
ty2 |= 0;
1728+
tx3 |= 0;
1729+
ty3 |= 0;
1730+
}
1731+
1732+
var u0 = (frameX / textureWidth) + uOffset;
1733+
var v0 = (frameY / textureHeight) + vOffset;
1734+
var u1 = (frameX + frameWidth) / textureWidth + uOffset;
1735+
var v1 = (frameY + frameHeight) / textureHeight + vOffset;
1736+
1737+
this.setTexture2D(texture, 0);
1738+
1739+
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);
1740+
1741+
// var texture = frame.glTexture;
1742+
1743+
/*
16331744
var parentMatrix = null;
16341745
16351746
if (parentTransformMatrix)
@@ -1788,6 +1899,7 @@ var TextureTintPipeline = new Class({
17881899
vertexViewU32[++vertexOffset] = tintBR;
17891900
17901901
this.vertexCount += 6;
1902+
*/
17911903
},
17921904

17931905
/**

0 commit comments

Comments
 (0)