2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-02 15:44:09 +00:00
|
|
|
var Utils = require('../../renderer/webgl/Utils');
|
2017-09-12 23:58:25 +00:00
|
|
|
|
2018-02-05 22:08:48 +00:00
|
|
|
/**
|
|
|
|
* Renders this Game Object with the WebGL Renderer to the given Camera.
|
|
|
|
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
|
|
|
|
* This method should not be called directly. It is a utility function of the Render module.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter#renderWebGL
|
|
|
|
* @since 3.0.0
|
|
|
|
* @private
|
|
|
|
*
|
2018-03-28 14:04:09 +00:00
|
|
|
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
|
2018-07-02 15:44:09 +00:00
|
|
|
* @param {Phaser.GameObjects.Blitter} src - The Game Object being rendered in this call.
|
2018-02-05 22:08:48 +00:00
|
|
|
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
|
2018-03-27 17:49:09 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
|
2018-02-05 22:08:48 +00:00
|
|
|
*/
|
2018-07-02 15:44:09 +00:00
|
|
|
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
2017-01-22 22:54:06 +00:00
|
|
|
{
|
2018-07-19 12:19:02 +00:00
|
|
|
var list = src.getRenderList();
|
|
|
|
|
|
|
|
if (list.length === 0)
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:44:09 +00:00
|
|
|
var pipeline = this.pipeline;
|
|
|
|
|
2018-07-11 15:23:44 +00:00
|
|
|
renderer.setPipeline(pipeline, src);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
var cameraScrollX = camera.scrollX * src.scrollFactorX;
|
|
|
|
var cameraScrollY = camera.scrollY * src.scrollFactorY;
|
|
|
|
|
2018-07-26 23:53:00 +00:00
|
|
|
var calcMatrix = pipeline._tempMatrix1;
|
2018-07-02 15:44:09 +00:00
|
|
|
|
2018-07-26 23:53:00 +00:00
|
|
|
calcMatrix.copyFrom(camera.matrix);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
if (parentMatrix)
|
|
|
|
{
|
2018-07-26 23:53:00 +00:00
|
|
|
calcMatrix.multiplyWithOffset(parentMatrix, -cameraScrollX, -cameraScrollY);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
cameraScrollX = 0;
|
|
|
|
cameraScrollY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var blitterX = src.x - cameraScrollX;
|
|
|
|
var blitterY = src.y - cameraScrollY;
|
|
|
|
var prevTextureSourceIndex = -1;
|
|
|
|
var tintEffect = false;
|
|
|
|
var alpha = camera.alpha * src.alpha;
|
|
|
|
var roundPixels = camera.roundPixels;
|
|
|
|
|
|
|
|
for (var index = 0; index < list.length; index++)
|
|
|
|
{
|
|
|
|
var bob = list[index];
|
|
|
|
var frame = bob.frame;
|
|
|
|
var bobAlpha = bob.alpha * alpha;
|
|
|
|
|
|
|
|
if (bobAlpha === 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var width = frame.width;
|
|
|
|
var height = frame.height;
|
|
|
|
|
|
|
|
var x = blitterX + bob.x + frame.x;
|
|
|
|
var y = blitterY + bob.y + frame.y;
|
|
|
|
|
|
|
|
if (bob.flipX)
|
|
|
|
{
|
|
|
|
width *= -1;
|
|
|
|
x += frame.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bob.flipY)
|
|
|
|
{
|
|
|
|
height *= -1;
|
|
|
|
y += frame.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
var xw = x + width;
|
|
|
|
var yh = y + height;
|
|
|
|
|
2018-07-26 23:53:00 +00:00
|
|
|
var tx0 = calcMatrix.getX(x, y);
|
|
|
|
var ty0 = calcMatrix.getY(x, y);
|
|
|
|
|
|
|
|
var tx1 = calcMatrix.getX(xw, yh);
|
|
|
|
var ty1 = calcMatrix.getY(xw, yh);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
2019-10-01 02:17:14 +00:00
|
|
|
var tint = Utils.getTintAppendFloatAlpha(bob.tint, bobAlpha);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
// Bind texture only if the Texture Source is different from before
|
|
|
|
if (frame.sourceIndex !== prevTextureSourceIndex)
|
|
|
|
{
|
|
|
|
pipeline.setTexture2D(frame.glTexture, 0);
|
|
|
|
|
|
|
|
prevTextureSourceIndex = frame.sourceIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roundPixels)
|
|
|
|
{
|
2018-11-30 10:27:25 +00:00
|
|
|
tx0 = Math.round(tx0);
|
|
|
|
ty0 = Math.round(ty0);
|
2018-07-10 12:59:49 +00:00
|
|
|
|
2018-11-30 10:27:25 +00:00
|
|
|
tx1 = Math.round(tx1);
|
|
|
|
ty1 = Math.round(ty1);
|
2018-07-02 15:44:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 16:06:34 +00:00
|
|
|
// TL x/y, BL x/y, BR x/y, TR x/y
|
2018-12-12 11:08:52 +00:00
|
|
|
if (pipeline.batchQuad(tx0, ty0, tx0, ty1, tx1, ty1, tx1, ty0, frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, tintEffect, frame.glTexture, 0))
|
2018-07-02 15:44:09 +00:00
|
|
|
{
|
|
|
|
prevTextureSourceIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
2017-01-22 22:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BlitterWebGLRenderer;
|