2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2018-04-05 08:02:36 +00:00
|
|
|
* @author Felipe Alfonso <@bitnenfer>
|
2018-02-12 16:01:20 +00:00
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
var Class = require('../../../utils/Class');
|
2018-01-25 05:26:14 +00:00
|
|
|
var ModelViewProjection = require('./components/ModelViewProjection');
|
2018-07-02 15:44:24 +00:00
|
|
|
var TransformMatrix = require('../../../gameobjects/components/TransformMatrix');
|
2018-05-08 22:04:57 +00:00
|
|
|
var ShaderSourceFS = require('../shaders/TextureTint-frag.js');
|
|
|
|
var ShaderSourceVS = require('../shaders/TextureTint-vert.js');
|
2018-02-09 19:19:21 +00:00
|
|
|
var Utils = require('../Utils');
|
|
|
|
var WebGLPipeline = require('../WebGLPipeline');
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-04-25 16:06:19 +00:00
|
|
|
* TextureTintPipeline implements the rendering infrastructure
|
|
|
|
* for displaying textured objects
|
|
|
|
* The config properties are:
|
|
|
|
* - game: Current game instance.
|
|
|
|
* - renderer: Current WebGL renderer.
|
|
|
|
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
|
|
|
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
2018-07-10 15:32:44 +00:00
|
|
|
* - vertShader: Source for vertex shader as a string.
|
2018-04-25 16:06:19 +00:00
|
|
|
* - fragShader: Source for fragment shader as a string.
|
|
|
|
* - vertexCapacity: The amount of vertices that shall be allocated
|
|
|
|
* - vertexSize: The size of a single vertex in bytes.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
|
|
|
* @class TextureTintPipeline
|
|
|
|
* @extends Phaser.Renderer.WebGL.WebGLPipeline
|
2018-04-18 11:13:49 +00:00
|
|
|
* @memberOf Phaser.Renderer.WebGL.Pipelines
|
2018-02-09 19:19:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-05 15:28:59 +00:00
|
|
|
* @param {object} config - [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-22 22:51:15 +00:00
|
|
|
var TextureTintPipeline = new Class({
|
2018-01-22 21:21:47 +00:00
|
|
|
|
|
|
|
Extends: WebGLPipeline,
|
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
Mixins: [
|
|
|
|
ModelViewProjection
|
|
|
|
],
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
initialize:
|
|
|
|
|
2018-03-05 14:29:48 +00:00
|
|
|
function TextureTintPipeline (config)
|
2018-01-22 21:21:47 +00:00
|
|
|
{
|
2018-07-02 11:33:46 +00:00
|
|
|
var rendererConfig = config.renderer.config;
|
|
|
|
|
|
|
|
// Vertex Size = attribute size added together (2 + 2 + 1 + 4)
|
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
WebGLPipeline.call(this, {
|
2018-03-05 14:29:48 +00:00
|
|
|
game: config.game,
|
|
|
|
renderer: config.renderer,
|
|
|
|
gl: config.renderer.gl,
|
2018-07-02 11:33:46 +00:00
|
|
|
topology: config.renderer.gl.TRIANGLES,
|
|
|
|
vertShader: ShaderSourceVS,
|
|
|
|
fragShader: ShaderSourceFS,
|
|
|
|
vertexCapacity: 6 * rendererConfig.batchSize,
|
|
|
|
vertexSize: Float32Array.BYTES_PER_ELEMENT * 5 + Uint8Array.BYTES_PER_ELEMENT * 4,
|
2018-01-22 21:21:47 +00:00
|
|
|
|
|
|
|
attributes: [
|
|
|
|
{
|
|
|
|
name: 'inPosition',
|
|
|
|
size: 2,
|
2018-03-05 14:29:48 +00:00
|
|
|
type: config.renderer.gl.FLOAT,
|
2018-01-22 21:21:47 +00:00
|
|
|
normalized: false,
|
|
|
|
offset: 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'inTexCoord',
|
|
|
|
size: 2,
|
2018-03-05 14:29:48 +00:00
|
|
|
type: config.renderer.gl.FLOAT,
|
2018-01-22 21:21:47 +00:00
|
|
|
normalized: false,
|
|
|
|
offset: Float32Array.BYTES_PER_ELEMENT * 2
|
|
|
|
},
|
2018-06-30 10:33:52 +00:00
|
|
|
{
|
|
|
|
name: 'inTintEffect',
|
|
|
|
size: 1,
|
|
|
|
type: config.renderer.gl.FLOAT,
|
|
|
|
normalized: false,
|
|
|
|
offset: Float32Array.BYTES_PER_ELEMENT * 4
|
|
|
|
},
|
2018-01-22 21:21:47 +00:00
|
|
|
{
|
|
|
|
name: 'inTint',
|
|
|
|
size: 4,
|
2018-03-05 14:29:48 +00:00
|
|
|
type: config.renderer.gl.UNSIGNED_BYTE,
|
2018-01-22 21:21:47 +00:00
|
|
|
normalized: true,
|
2018-06-30 10:33:52 +00:00
|
|
|
offset: Float32Array.BYTES_PER_ELEMENT * 5
|
2018-01-22 21:21:47 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Float32 view of the array buffer containing the pipeline's vertices.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewF32
|
2018-02-09 19:19:21 +00:00
|
|
|
* @type {Float32Array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
this.vertexViewF32 = new Float32Array(this.vertexData);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Uint32 view of the array buffer containing the pipeline's vertices.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewU32
|
2018-02-09 19:19:21 +00:00
|
|
|
* @type {Uint32Array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
this.vertexViewU32 = new Uint32Array(this.vertexData);
|
2018-02-09 19:19:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Size of the batch.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#maxQuads
|
2018-02-09 19:19:21 +00:00
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-07-02 11:33:46 +00:00
|
|
|
this.maxQuads = rendererConfig.batchSize;
|
2018-02-09 19:19:21 +00:00
|
|
|
|
2018-02-14 19:52:37 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Collection of batch information
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batches
|
2018-02-14 19:52:37 +00:00
|
|
|
* @type {array}
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:52:37 +00:00
|
|
|
*/
|
2018-02-14 02:46:34 +00:00
|
|
|
this.batches = [];
|
|
|
|
|
2018-07-02 23:14:23 +00:00
|
|
|
/**
|
|
|
|
* A temporary Transform Matrix, re-used internally during batching.
|
|
|
|
*
|
2018-07-10 12:59:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempMatrix1
|
2018-07-02 23:14:23 +00:00
|
|
|
* @private
|
|
|
|
* @type {Phaser.GameObjects.Components.TransformMatrix}
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
2018-07-10 12:59:49 +00:00
|
|
|
this._tempMatrix1 = new TransformMatrix();
|
2018-07-02 23:14:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A temporary Transform Matrix, re-used internally during batching.
|
|
|
|
*
|
2018-07-10 12:59:49 +00:00
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempMatrix2
|
2018-07-02 23:14:23 +00:00
|
|
|
* @private
|
|
|
|
* @type {Phaser.GameObjects.Components.TransformMatrix}
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
2018-07-10 12:59:49 +00:00
|
|
|
this._tempMatrix2 = new TransformMatrix();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A temporary Transform Matrix, re-used internally during batching.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempMatrix3
|
|
|
|
* @private
|
|
|
|
* @type {Phaser.GameObjects.Components.TransformMatrix}
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
this._tempMatrix3 = new TransformMatrix();
|
2018-07-02 15:44:24 +00:00
|
|
|
|
2018-07-10 15:32:44 +00:00
|
|
|
/**
|
|
|
|
* A temporary Transform Matrix, re-used internally during batching.
|
|
|
|
*
|
|
|
|
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempMatrix4
|
|
|
|
* @private
|
|
|
|
* @type {Phaser.GameObjects.Components.TransformMatrix}
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
|
|
|
this._tempMatrix4 = new TransformMatrix();
|
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.mvpInit();
|
|
|
|
},
|
|
|
|
|
2018-02-14 19:52:37 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Assigns a texture to the current batch. If a texture is already set it creates
|
|
|
|
* a new batch object.
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#setTexture2D
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-25 16:06:19 +00:00
|
|
|
* @param {WebGLTexture} texture - WebGLTexture that will be assigned to the current batch.
|
|
|
|
* @param {integer} textureUnit - Texture unit to which the texture needs to be bound.
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description]
|
2018-02-14 19:52:37 +00:00
|
|
|
*/
|
2018-02-14 02:46:34 +00:00
|
|
|
setTexture2D: function (texture, unit)
|
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
if (!texture)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2018-02-14 02:46:34 +00:00
|
|
|
|
|
|
|
var batches = this.batches;
|
|
|
|
|
|
|
|
if (batches.length === 0)
|
|
|
|
{
|
|
|
|
this.pushBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
var batch = batches[batches.length - 1];
|
|
|
|
|
|
|
|
if (unit > 0)
|
|
|
|
{
|
|
|
|
if (batch.textures[unit - 1] &&
|
|
|
|
batch.textures[unit - 1] !== texture)
|
|
|
|
{
|
|
|
|
this.pushBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
batches[batches.length - 1].textures[unit - 1] = texture;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (batch.texture !== null &&
|
|
|
|
batch.texture !== texture)
|
|
|
|
{
|
|
|
|
this.pushBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
batches[batches.length - 1].texture = texture;
|
|
|
|
}
|
2018-02-14 19:52:37 +00:00
|
|
|
|
|
|
|
return this;
|
2018-02-14 02:46:34 +00:00
|
|
|
},
|
|
|
|
|
2018-02-14 19:52:37 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Creates a new batch object and pushes it to a batch array.
|
|
|
|
* The batch object contains information relevant to the current
|
|
|
|
* vertex batch like the offset in the vertex buffer, vertex count and
|
|
|
|
* the textures used by that batch.
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#pushBatch
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:52:37 +00:00
|
|
|
*/
|
2018-02-14 02:46:34 +00:00
|
|
|
pushBatch: function ()
|
|
|
|
{
|
|
|
|
var batch = {
|
|
|
|
first: this.vertexCount,
|
|
|
|
texture: null,
|
|
|
|
textures: []
|
|
|
|
};
|
|
|
|
|
|
|
|
this.batches.push(batch);
|
|
|
|
},
|
|
|
|
|
2018-02-14 19:52:37 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Binds, uploads resources and processes all batches generating draw calls.
|
2018-02-14 19:52:37 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#flush
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-03-05 21:49:08 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} This Pipeline.
|
2018-02-14 19:52:37 +00:00
|
|
|
*/
|
2018-02-14 02:46:34 +00:00
|
|
|
flush: function ()
|
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
if (this.flushLocked)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:45:22 +00:00
|
|
|
this.flushLocked = true;
|
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
var gl = this.gl;
|
2018-02-14 19:45:22 +00:00
|
|
|
var renderer = this.renderer;
|
2018-02-14 02:46:34 +00:00
|
|
|
var vertexCount = this.vertexCount;
|
|
|
|
var topology = this.topology;
|
|
|
|
var vertexSize = this.vertexSize;
|
|
|
|
var batches = this.batches;
|
|
|
|
var batchCount = batches.length;
|
2018-02-14 16:20:56 +00:00
|
|
|
var batchVertexCount = 0;
|
2018-02-14 02:46:34 +00:00
|
|
|
var batch = null;
|
2018-02-16 18:07:49 +00:00
|
|
|
var batchNext;
|
|
|
|
var textureIndex;
|
|
|
|
var nTexture;
|
2018-02-14 02:46:34 +00:00
|
|
|
|
2018-02-16 18:07:49 +00:00
|
|
|
if (batchCount === 0 || vertexCount === 0)
|
2018-02-14 19:45:22 +00:00
|
|
|
{
|
|
|
|
this.flushLocked = false;
|
|
|
|
return this;
|
|
|
|
}
|
2018-02-16 18:07:49 +00:00
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bytes.subarray(0, vertexCount * vertexSize));
|
|
|
|
|
|
|
|
for (var index = 0; index < batches.length - 1; ++index)
|
|
|
|
{
|
|
|
|
batch = batches[index];
|
|
|
|
batchNext = batches[index + 1];
|
|
|
|
|
|
|
|
if (batch.textures.length > 0)
|
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
for (textureIndex = 0; textureIndex < batch.textures.length; ++textureIndex)
|
2018-02-14 02:46:34 +00:00
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
nTexture = batch.textures[textureIndex];
|
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
if (nTexture)
|
|
|
|
{
|
2018-02-14 19:45:22 +00:00
|
|
|
renderer.setTexture2D(nTexture, 1 + textureIndex);
|
2018-02-14 02:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 18:07:49 +00:00
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
gl.activeTexture(gl.TEXTURE0);
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:20:56 +00:00
|
|
|
batchVertexCount = batchNext.first - batch.first;
|
|
|
|
|
2018-02-16 18:07:49 +00:00
|
|
|
if (batch.texture === null || batchVertexCount <= 0) { continue; }
|
2018-02-14 16:20:56 +00:00
|
|
|
|
2018-02-14 19:45:22 +00:00
|
|
|
renderer.setTexture2D(batch.texture, 0);
|
2018-02-14 16:20:56 +00:00
|
|
|
gl.drawArrays(topology, batch.first, batchVertexCount);
|
2018-02-14 02:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Left over data
|
|
|
|
batch = batches[batches.length - 1];
|
|
|
|
|
|
|
|
if (batch.textures.length > 0)
|
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
for (textureIndex = 0; textureIndex < batch.textures.length; ++textureIndex)
|
2018-02-14 02:46:34 +00:00
|
|
|
{
|
2018-02-16 18:07:49 +00:00
|
|
|
nTexture = batch.textures[textureIndex];
|
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
if (nTexture)
|
|
|
|
{
|
2018-02-14 19:45:22 +00:00
|
|
|
renderer.setTexture2D(nTexture, 1 + textureIndex);
|
2018-02-14 02:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 18:07:49 +00:00
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
gl.activeTexture(gl.TEXTURE0);
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:20:56 +00:00
|
|
|
batchVertexCount = vertexCount - batch.first;
|
|
|
|
|
|
|
|
if (batch.texture && batchVertexCount > 0)
|
|
|
|
{
|
2018-02-14 19:45:22 +00:00
|
|
|
renderer.setTexture2D(batch.texture, 0);
|
2018-02-14 16:20:56 +00:00
|
|
|
gl.drawArrays(topology, batch.first, batchVertexCount);
|
|
|
|
}
|
2018-02-14 02:46:34 +00:00
|
|
|
|
|
|
|
this.vertexCount = 0;
|
|
|
|
batches.length = 0;
|
2018-02-22 23:36:25 +00:00
|
|
|
this.pushBatch();
|
2018-02-14 19:45:22 +00:00
|
|
|
this.flushLocked = false;
|
2018-02-14 02:46:34 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Called every time the pipeline needs to be used.
|
|
|
|
* It binds all necessary resources.
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#onBind
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-25 05:26:14 +00:00
|
|
|
onBind: function ()
|
|
|
|
{
|
|
|
|
WebGLPipeline.prototype.onBind.call(this);
|
2018-04-19 12:28:10 +00:00
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
this.mvpUpdate();
|
|
|
|
|
2018-02-14 02:46:34 +00:00
|
|
|
if (this.batches.length === 0)
|
|
|
|
{
|
|
|
|
this.pushBatch();
|
|
|
|
}
|
|
|
|
|
2018-01-25 05:26:14 +00:00
|
|
|
return this;
|
2018-01-22 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#resize
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} width - [description]
|
|
|
|
* @param {number} height - [description]
|
|
|
|
* @param {number} resolution - [description]
|
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description]
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-22 21:21:47 +00:00
|
|
|
resize: function (width, height, resolution)
|
|
|
|
{
|
|
|
|
WebGLPipeline.prototype.resize.call(this, width, height, resolution);
|
2018-01-25 05:26:14 +00:00
|
|
|
|
2018-07-02 11:07:39 +00:00
|
|
|
this.projOrtho(0, this.width, this.height, 0, -1000.0, 1000.0);
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-02 11:07:39 +00:00
|
|
|
return this;
|
2018-01-22 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
2018-07-02 16:06:49 +00:00
|
|
|
/**
|
|
|
|
* Batches Sprite game object
|
|
|
|
*
|
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchSprite
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Sprite} sprite - [description]
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description]
|
|
|
|
*/
|
2018-07-02 15:44:24 +00:00
|
|
|
batchSprite: function (sprite, camera, parentTransformMatrix)
|
2018-01-22 21:21:47 +00:00
|
|
|
{
|
2018-07-02 15:44:24 +00:00
|
|
|
this.renderer.setPipeline(this);
|
2018-03-26 22:55:38 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
var camMatrix = this._tempMatrix1;
|
|
|
|
var spriteMatrix = this._tempMatrix2;
|
|
|
|
var calcMatrix = this._tempMatrix3;
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var frame = sprite.frame;
|
|
|
|
var texture = frame.glTexture;
|
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
var u0 = frame.u0;
|
|
|
|
var v0 = frame.v0;
|
|
|
|
var u1 = frame.u1;
|
|
|
|
var v1 = frame.v1;
|
|
|
|
var frameX = frame.x;
|
|
|
|
var frameY = frame.y;
|
|
|
|
var frameWidth = frame.width;
|
|
|
|
var frameHeight = frame.height;
|
|
|
|
|
|
|
|
var x = -sprite.displayOriginX + frameX;
|
|
|
|
var y = -sprite.displayOriginY + frameY;
|
|
|
|
|
|
|
|
if (sprite.isCropped)
|
2018-03-27 00:16:36 +00:00
|
|
|
{
|
2018-07-03 15:48:14 +00:00
|
|
|
var crop = sprite._crop;
|
|
|
|
|
2018-07-04 14:18:08 +00:00
|
|
|
if (crop.flipX !== sprite.flipX || crop.flipY !== sprite.flipY)
|
|
|
|
{
|
|
|
|
frame.updateCropUVs(crop, sprite.flipX, sprite.flipY);
|
|
|
|
}
|
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
u0 = crop.u0;
|
|
|
|
v0 = crop.v0;
|
|
|
|
u1 = crop.u1;
|
|
|
|
v1 = crop.v1;
|
2018-07-04 14:18:08 +00:00
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
frameWidth = crop.width;
|
|
|
|
frameHeight = crop.height;
|
2018-07-04 14:18:08 +00:00
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
frameX = crop.x;
|
|
|
|
frameY = crop.y;
|
|
|
|
|
|
|
|
x = -sprite.displayOriginX + frameX;
|
|
|
|
y = -sprite.displayOriginY + frameY;
|
2018-03-27 00:16:36 +00:00
|
|
|
}
|
2018-07-04 13:50:26 +00:00
|
|
|
|
|
|
|
if (sprite.flipX)
|
2018-07-02 15:44:24 +00:00
|
|
|
{
|
2018-07-04 13:50:26 +00:00
|
|
|
x += frameWidth;
|
|
|
|
frameWidth *= -1;
|
2018-07-02 15:44:24 +00:00
|
|
|
}
|
2018-04-18 21:15:43 +00:00
|
|
|
|
2018-07-04 13:50:26 +00:00
|
|
|
if (sprite.flipY)
|
2018-07-02 15:44:24 +00:00
|
|
|
{
|
2018-07-04 13:50:26 +00:00
|
|
|
y += frameHeight;
|
|
|
|
frameHeight *= -1;
|
2018-07-02 15:44:24 +00:00
|
|
|
}
|
2018-05-09 14:13:06 +00:00
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
var xw = x + frameWidth;
|
|
|
|
var yh = y + frameHeight;
|
2018-06-25 15:06:22 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
spriteMatrix.applyITRS(sprite.x, sprite.y, sprite.rotation, sprite.scaleX, sprite.scaleY);
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
camMatrix.copyFrom(camera.matrix);
|
2018-05-09 14:13:06 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
if (parentTransformMatrix)
|
|
|
|
{
|
|
|
|
// Multiply the camera by the parent matrix
|
|
|
|
camMatrix.multiplyWithOffset(parentTransformMatrix, -camera.scrollX * sprite.scrollFactorX, -camera.scrollY * sprite.scrollFactorY);
|
2018-05-09 14:13:06 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
// Undo the camera scroll
|
|
|
|
spriteMatrix.e = sprite.x;
|
|
|
|
spriteMatrix.f = sprite.y;
|
2018-05-09 14:13:06 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
2018-07-02 15:44:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-10 12:59:49 +00:00
|
|
|
spriteMatrix.e -= camera.scrollX * sprite.scrollFactorX;
|
|
|
|
spriteMatrix.f -= camera.scrollY * sprite.scrollFactorY;
|
|
|
|
|
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
2018-07-02 15:44:24 +00:00
|
|
|
}
|
2018-02-14 16:43:35 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var tx0 = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty0 = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var tx1 = x * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty1 = x * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
2018-05-09 14:13:06 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var tx2 = xw * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty2 = xw * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var tx3 = xw * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty3 = xw * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var tintTL = Utils.getTintAppendFloatAlpha(sprite._tintTL, camera.alpha * sprite._alphaTL);
|
|
|
|
var tintTR = Utils.getTintAppendFloatAlpha(sprite._tintTR, camera.alpha * sprite._alphaTR);
|
|
|
|
var tintBL = Utils.getTintAppendFloatAlpha(sprite._tintBL, camera.alpha * sprite._alphaBL);
|
|
|
|
var tintBR = Utils.getTintAppendFloatAlpha(sprite._tintBR, camera.alpha * sprite._alphaBR);
|
2018-01-22 21:21:47 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
if (camera.roundPixels)
|
|
|
|
{
|
|
|
|
tx0 |= 0;
|
|
|
|
ty0 |= 0;
|
2018-07-04 13:50:26 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
tx1 |= 0;
|
|
|
|
ty1 |= 0;
|
2018-07-04 13:50:26 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
tx2 |= 0;
|
|
|
|
ty2 |= 0;
|
2018-07-04 13:50:26 +00:00
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
tx3 |= 0;
|
|
|
|
ty3 |= 0;
|
2018-01-22 21:21:47 +00:00
|
|
|
}
|
2018-07-02 15:44:24 +00:00
|
|
|
|
|
|
|
this.setTexture2D(texture, 0);
|
|
|
|
|
|
|
|
var tintEffect = (sprite._isTinted && sprite.tintFill);
|
|
|
|
|
2018-07-03 15:48:14 +00:00
|
|
|
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);
|
2018-01-23 16:38:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-07-02 16:06:49 +00:00
|
|
|
* Adds the vertices data into the batch and flushes if full.
|
2018-07-02 15:44:24 +00:00
|
|
|
*
|
2018-07-02 16:06:49 +00:00
|
|
|
* Assumes 6 vertices in the following arrangement:
|
|
|
|
*
|
2018-07-02 23:14:23 +00:00
|
|
|
* ```
|
2018-07-02 16:06:49 +00:00
|
|
|
* 0----3
|
|
|
|
* |\ B|
|
|
|
|
* | \ |
|
|
|
|
* | \ |
|
|
|
|
* | A \|
|
|
|
|
* | \
|
|
|
|
* 1----2
|
2018-07-02 23:14:23 +00:00
|
|
|
* ```
|
2018-07-02 16:06:49 +00:00
|
|
|
*
|
|
|
|
* Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3
|
2018-07-02 15:44:24 +00:00
|
|
|
*
|
2018-07-02 16:06:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchVertices
|
2018-07-02 15:44:24 +00:00
|
|
|
* @since 3.11.0
|
|
|
|
*
|
|
|
|
* @param {number} tx0 - The top-left x position.
|
|
|
|
* @param {number} ty0 - The top-left y position.
|
2018-07-02 16:06:49 +00:00
|
|
|
* @param {number} tx1 - The bottom-left x position.
|
|
|
|
* @param {number} ty1 - The bottom-left y position.
|
|
|
|
* @param {number} tx2 - The bottom-right x position.
|
|
|
|
* @param {number} ty2 - The bottom-right y position.
|
|
|
|
* @param {number} tx3 - The top-right x position.
|
|
|
|
* @param {number} ty3 - The top-right y position.
|
2018-07-02 23:14:23 +00:00
|
|
|
* @param {number} u0 - UV u0 value.
|
|
|
|
* @param {number} v0 - UV v0 value.
|
|
|
|
* @param {number} u1 - UV u1 value.
|
|
|
|
* @param {number} v1 - UV v1 value.
|
2018-07-02 15:44:24 +00:00
|
|
|
* @param {number} tintTL - The top-left tint color value.
|
|
|
|
* @param {number} tintTR - The top-right tint color value.
|
|
|
|
* @param {number} tintBL - The bottom-left tint color value.
|
|
|
|
* @param {number} tintBR - The bottom-right tint color value.
|
|
|
|
* @param {(number|boolean)} tintEffect - The tint effect for the shader to use.
|
|
|
|
*
|
|
|
|
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
|
|
|
|
*/
|
2018-07-02 23:14:23 +00:00
|
|
|
batchVertices: function (tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect)
|
2018-07-02 15:44:24 +00:00
|
|
|
{
|
2018-07-11 12:22:07 +00:00
|
|
|
var hasFlushed = false;
|
|
|
|
|
2018-07-03 11:38:45 +00:00
|
|
|
if (this.vertexCount + 6 > this.vertexCapacity)
|
2018-07-02 23:14:23 +00:00
|
|
|
{
|
|
|
|
this.flush();
|
2018-07-11 12:22:07 +00:00
|
|
|
|
|
|
|
hasFlushed = true;
|
2018-07-02 23:14:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 15:44:24 +00:00
|
|
|
var vertexViewF32 = this.vertexViewF32;
|
|
|
|
var vertexViewU32 = this.vertexViewU32;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
2018-07-03 11:38:45 +00:00
|
|
|
var vertexOffset = (this.vertexCount * this.vertexComponentCount) - 1;
|
2018-07-02 15:44:24 +00:00
|
|
|
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tx0;
|
|
|
|
vertexViewF32[++vertexOffset] = ty0;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u0;
|
|
|
|
vertexViewF32[++vertexOffset] = v0;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintTL;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
|
|
|
vertexViewF32[++vertexOffset] = tx1;
|
|
|
|
vertexViewF32[++vertexOffset] = ty1;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u0;
|
|
|
|
vertexViewF32[++vertexOffset] = v1;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintBL;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
|
|
|
vertexViewF32[++vertexOffset] = tx2;
|
|
|
|
vertexViewF32[++vertexOffset] = ty2;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u1;
|
|
|
|
vertexViewF32[++vertexOffset] = v1;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintBR;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
|
|
|
vertexViewF32[++vertexOffset] = tx0;
|
|
|
|
vertexViewF32[++vertexOffset] = ty0;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u0;
|
|
|
|
vertexViewF32[++vertexOffset] = v0;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintTL;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
|
|
|
vertexViewF32[++vertexOffset] = tx2;
|
|
|
|
vertexViewF32[++vertexOffset] = ty2;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u1;
|
|
|
|
vertexViewF32[++vertexOffset] = v1;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintBR;
|
2018-06-30 10:33:52 +00:00
|
|
|
|
|
|
|
vertexViewF32[++vertexOffset] = tx3;
|
|
|
|
vertexViewF32[++vertexOffset] = ty3;
|
2018-07-02 23:14:23 +00:00
|
|
|
vertexViewF32[++vertexOffset] = u1;
|
|
|
|
vertexViewF32[++vertexOffset] = v0;
|
2018-06-30 10:33:52 +00:00
|
|
|
vertexViewF32[++vertexOffset] = tintEffect;
|
2018-07-02 15:44:24 +00:00
|
|
|
vertexViewU32[++vertexOffset] = tintTR;
|
2018-01-23 16:38:58 +00:00
|
|
|
|
|
|
|
this.vertexCount += 6;
|
2018-07-02 15:44:24 +00:00
|
|
|
|
2018-07-03 11:38:45 +00:00
|
|
|
if (this.vertexCapacity - this.vertexCount < 6)
|
2018-07-02 15:44:24 +00:00
|
|
|
{
|
2018-07-03 11:38:45 +00:00
|
|
|
// No more room at the inn
|
2018-07-02 15:44:24 +00:00
|
|
|
this.flush();
|
|
|
|
|
2018-07-11 12:22:07 +00:00
|
|
|
hasFlushed = true;
|
2018-07-02 15:44:24 +00:00
|
|
|
}
|
2018-07-11 12:22:07 +00:00
|
|
|
|
|
|
|
return hasFlushed;
|
2018-01-23 19:29:47 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 19:19:21 +00:00
|
|
|
/**
|
2018-04-25 16:06:19 +00:00
|
|
|
* Generic function for batching a textured quad
|
2018-02-09 19:19:21 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTexture
|
2018-02-09 19:19:21 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-25 16:06:19 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - Source GameObject
|
|
|
|
* @param {WebGLTexture} texture - Raw WebGLTexture associated with the quad
|
|
|
|
* @param {integer} textureWidth - Real texture width
|
|
|
|
* @param {integer} textureHeight - Real texture height
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} srcX - X coordinate of the quad
|
|
|
|
* @param {number} srcY - Y coordinate of the quad
|
|
|
|
* @param {number} srcWidth - Width of the quad
|
|
|
|
* @param {number} srcHeight - Height of the quad
|
|
|
|
* @param {number} scaleX - X component of scale
|
|
|
|
* @param {number} scaleY - Y component of scale
|
|
|
|
* @param {number} rotation - Rotation of the quad
|
2018-04-25 16:06:19 +00:00
|
|
|
* @param {boolean} flipX - Indicates if the quad is horizontally flipped
|
|
|
|
* @param {boolean} flipY - Indicates if the quad is vertically flipped
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} scrollFactorX - By which factor is the quad affected by the camera horizontal scroll
|
|
|
|
* @param {number} scrollFactorY - By which factor is the quad effected by the camera vertical scroll
|
|
|
|
* @param {number} displayOriginX - Horizontal origin in pixels
|
|
|
|
* @param {number} displayOriginY - Vertical origin in pixels
|
|
|
|
* @param {number} frameX - X coordinate of the texture frame
|
|
|
|
* @param {number} frameY - Y coordinate of the texture frame
|
|
|
|
* @param {number} frameWidth - Width of the texture frame
|
|
|
|
* @param {number} frameHeight - Height of the texture frame
|
2018-04-25 16:06:19 +00:00
|
|
|
* @param {integer} tintTL - Tint for top left
|
|
|
|
* @param {integer} tintTR - Tint for top right
|
|
|
|
* @param {integer} tintBL - Tint for bottom left
|
|
|
|
* @param {integer} tintBR - Tint for bottom right
|
2018-07-02 15:44:24 +00:00
|
|
|
* @param {number} tintEffect - The tint effect (0 for additive, 1 for replacement)
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} uOffset - Horizontal offset on texture coordinate
|
|
|
|
* @param {number} vOffset - Vertical offset on texture coordinate
|
2018-04-25 16:06:19 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - Current used camera
|
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - Parent container
|
2018-02-09 19:19:21 +00:00
|
|
|
*/
|
2018-01-30 03:38:31 +00:00
|
|
|
batchTexture: function (
|
|
|
|
gameObject,
|
|
|
|
texture,
|
|
|
|
textureWidth, textureHeight,
|
|
|
|
srcX, srcY,
|
|
|
|
srcWidth, srcHeight,
|
|
|
|
scaleX, scaleY,
|
|
|
|
rotation,
|
|
|
|
flipX, flipY,
|
|
|
|
scrollFactorX, scrollFactorY,
|
|
|
|
displayOriginX, displayOriginY,
|
|
|
|
frameX, frameY, frameWidth, frameHeight,
|
2018-06-30 10:33:52 +00:00
|
|
|
tintTL, tintTR, tintBL, tintBR, tintEffect,
|
2018-01-30 03:38:31 +00:00
|
|
|
uOffset, vOffset,
|
2018-04-05 08:02:36 +00:00
|
|
|
camera,
|
2018-03-26 20:23:18 +00:00
|
|
|
parentTransformMatrix)
|
2018-01-30 03:38:31 +00:00
|
|
|
{
|
2018-07-02 23:14:23 +00:00
|
|
|
this.renderer.setPipeline(this);
|
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
var camMatrix = this._tempMatrix1;
|
|
|
|
var spriteMatrix = this._tempMatrix2;
|
|
|
|
var calcMatrix = this._tempMatrix3;
|
2018-07-02 23:14:23 +00:00
|
|
|
|
|
|
|
var width = srcWidth;
|
|
|
|
var height = srcHeight;
|
|
|
|
|
|
|
|
var x = -displayOriginX;
|
|
|
|
var y = -displayOriginY;
|
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
// Invert the flipY if this is a RenderTexture
|
|
|
|
flipY = flipY ^ (texture.isRenderTexture ? 1 : 0);
|
|
|
|
|
2018-07-02 23:14:23 +00:00
|
|
|
if (flipX)
|
|
|
|
{
|
|
|
|
width *= -1;
|
|
|
|
x += srcWidth;
|
|
|
|
}
|
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
if (flipY)
|
2018-07-02 23:14:23 +00:00
|
|
|
{
|
|
|
|
height *= -1;
|
|
|
|
y += srcHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (camera.roundPixels)
|
|
|
|
{
|
|
|
|
x |= 0;
|
|
|
|
y |= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var xw = x + width;
|
|
|
|
var yh = y + height;
|
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
spriteMatrix.applyITRS(srcX, srcY, rotation, scaleX, scaleY);
|
2018-07-02 23:14:23 +00:00
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
camMatrix.copyFrom(camera.matrix);
|
2018-07-02 23:14:23 +00:00
|
|
|
|
|
|
|
if (parentTransformMatrix)
|
|
|
|
{
|
|
|
|
// Multiply the camera by the parent matrix
|
|
|
|
camMatrix.multiplyWithOffset(parentTransformMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
|
|
|
|
|
|
|
|
// Undo the camera scroll
|
|
|
|
spriteMatrix.e = srcX;
|
|
|
|
spriteMatrix.f = srcY;
|
|
|
|
|
2018-07-10 12:59:49 +00:00
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
2018-07-02 23:14:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-10 12:59:49 +00:00
|
|
|
spriteMatrix.e -= camera.scrollX * scrollFactorX;
|
|
|
|
spriteMatrix.f -= camera.scrollY * scrollFactorY;
|
|
|
|
|
|
|
|
// Multiply by the Sprite matrix, store result in calcMatrix
|
|
|
|
camMatrix.multiply(spriteMatrix, calcMatrix);
|
2018-07-02 23:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var tx0 = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty0 = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx1 = x * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty1 = x * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx2 = xw * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty2 = xw * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx3 = xw * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty3 = xw * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
if (camera.roundPixels)
|
|
|
|
{
|
|
|
|
tx0 |= 0;
|
|
|
|
ty0 |= 0;
|
2018-07-10 12:59:49 +00:00
|
|
|
|
2018-07-02 23:14:23 +00:00
|
|
|
tx1 |= 0;
|
|
|
|
ty1 |= 0;
|
2018-07-10 12:59:49 +00:00
|
|
|
|
2018-07-02 23:14:23 +00:00
|
|
|
tx2 |= 0;
|
|
|
|
ty2 |= 0;
|
2018-07-10 12:59:49 +00:00
|
|
|
|
2018-07-02 23:14:23 +00:00
|
|
|
tx3 |= 0;
|
|
|
|
ty3 |= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var u0 = (frameX / textureWidth) + uOffset;
|
|
|
|
var v0 = (frameY / textureHeight) + vOffset;
|
|
|
|
var u1 = (frameX + frameWidth) / textureWidth + uOffset;
|
|
|
|
var v1 = (frameY + frameHeight) / textureHeight + vOffset;
|
|
|
|
|
|
|
|
this.setTexture2D(texture, 0);
|
|
|
|
|
|
|
|
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);
|
2018-01-30 03:38:31 +00:00
|
|
|
},
|
|
|
|
|
2018-03-05 21:49:08 +00:00
|
|
|
/**
|
2018-07-11 11:34:53 +00:00
|
|
|
* Immediately draws a Texture Frame with no batching.
|
2018-03-05 21:49:08 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawTexture
|
2018-07-11 11:34:53 +00:00
|
|
|
* @since 3.11.0
|
2018-03-05 21:49:08 +00:00
|
|
|
*
|
2018-07-11 11:34:53 +00:00
|
|
|
* @param {WebGLTexture} texture - The WebGL Texture to be rendered.
|
|
|
|
* @param {number} x - The horizontal position to render the texture at.
|
|
|
|
* @param {number} y - The vertical position to render the texture at.
|
|
|
|
* @param {number} tint - The tint color.
|
|
|
|
* @param {number} alpha - The alpha value.
|
|
|
|
* @param {array} transformMatrix - An array of matrix values.
|
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} [parentTransformMatrix] - A parent Transform Matrix.
|
2018-03-05 21:49:08 +00:00
|
|
|
*
|
2018-04-18 11:13:49 +00:00
|
|
|
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} This Pipeline.
|
2018-03-05 21:49:08 +00:00
|
|
|
*/
|
2018-07-11 11:34:53 +00:00
|
|
|
drawTextureFrame: function (
|
|
|
|
frame,
|
2018-07-10 16:18:00 +00:00
|
|
|
x, y,
|
2018-03-05 19:57:41 +00:00
|
|
|
tint, alpha,
|
2018-04-05 08:02:36 +00:00
|
|
|
transformMatrix,
|
2018-03-26 20:23:18 +00:00
|
|
|
parentTransformMatrix
|
2018-02-22 23:36:25 +00:00
|
|
|
)
|
|
|
|
{
|
2018-07-10 16:18:00 +00:00
|
|
|
this.renderer.setPipeline(this);
|
|
|
|
|
|
|
|
if (this.vertexCount + 6 > this.vertexCapacity)
|
|
|
|
{
|
|
|
|
this.flush();
|
|
|
|
}
|
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
var spriteMatrix = this._tempMatrix1.copyFromArray(transformMatrix);
|
2018-07-10 16:18:00 +00:00
|
|
|
var calcMatrix = this._tempMatrix2;
|
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
var xw = x + frame.width;
|
|
|
|
var yh = y + frame.height;
|
2018-07-10 16:18:00 +00:00
|
|
|
|
|
|
|
if (parentTransformMatrix)
|
|
|
|
{
|
|
|
|
spriteMatrix.multiply(parentTransformMatrix, calcMatrix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
calcMatrix = spriteMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tx0 = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty0 = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx1 = x * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty1 = x * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx2 = xw * calcMatrix.a + yh * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty2 = xw * calcMatrix.b + yh * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
var tx3 = xw * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
|
|
|
var ty3 = xw * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
|
|
|
|
|
|
|
if (this.renderer.config.roundPixels)
|
|
|
|
{
|
|
|
|
tx0 |= 0;
|
|
|
|
ty0 |= 0;
|
|
|
|
|
|
|
|
tx1 |= 0;
|
|
|
|
ty1 |= 0;
|
|
|
|
|
|
|
|
tx2 |= 0;
|
|
|
|
ty2 |= 0;
|
|
|
|
|
|
|
|
tx3 |= 0;
|
|
|
|
ty3 |= 0;
|
|
|
|
}
|
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
this.setTexture2D(frame.glTexture, 0);
|
2018-03-27 00:16:36 +00:00
|
|
|
|
2018-03-05 21:49:08 +00:00
|
|
|
tint = Utils.getTintAppendFloatAlpha(tint, alpha);
|
2018-02-22 23:36:25 +00:00
|
|
|
|
2018-07-11 11:34:53 +00:00
|
|
|
if (!this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, 0))
|
2018-02-28 18:08:08 +00:00
|
|
|
{
|
2018-07-11 11:34:53 +00:00
|
|
|
this.flush();
|
2018-02-28 18:08:08 +00:00
|
|
|
}
|
2018-01-22 21:21:47 +00:00
|
|
|
}
|
2018-01-24 22:29:57 +00:00
|
|
|
|
2018-01-22 21:21:47 +00:00
|
|
|
});
|
|
|
|
|
2018-01-22 22:51:15 +00:00
|
|
|
module.exports = TextureTintPipeline;
|