2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
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-10 12:59:49 +00:00
|
|
|
var matrix = pipeline._tempMatrix1;
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
matrix.copyFrom(camera.matrix);
|
|
|
|
|
|
|
|
if (parentMatrix)
|
|
|
|
{
|
|
|
|
matrix.multiplyWithOffset(parentMatrix, -cameraScrollX, -cameraScrollY);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
var tx0 = x * matrix.a + y * matrix.c + matrix.e;
|
|
|
|
var ty0 = x * matrix.b + y * matrix.d + matrix.f;
|
|
|
|
var tx1 = xw * matrix.a + yh * matrix.c + matrix.e;
|
|
|
|
var ty1 = xw * matrix.b + yh * matrix.d + matrix.f;
|
|
|
|
|
2018-07-02 22:52:00 +00:00
|
|
|
var tint = Utils.getTintAppendFloatAlpha(0xffffff, 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)
|
|
|
|
{
|
|
|
|
tx0 |= 0;
|
|
|
|
ty0 |= 0;
|
2018-07-10 12:59:49 +00:00
|
|
|
|
2018-07-02 15:44:09 +00:00
|
|
|
tx1 |= 0;
|
|
|
|
ty1 |= 0;
|
|
|
|
}
|
|
|
|
|
2018-07-02 16:06:34 +00:00
|
|
|
// TL x/y, BL x/y, BR x/y, TR x/y
|
2018-07-26 22:50:54 +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))
|
2018-07-02 15:44:09 +00:00
|
|
|
{
|
|
|
|
prevTextureSourceIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
2017-01-22 22:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BlitterWebGLRenderer;
|