2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 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
|
|
|
*/
|
|
|
|
|
2020-11-06 09:44:29 +00:00
|
|
|
var TransformMatrix = require('../components/TransformMatrix');
|
2018-07-02 15:44:09 +00:00
|
|
|
var Utils = require('../../renderer/webgl/Utils');
|
2017-09-12 23:58:25 +00:00
|
|
|
|
2020-11-06 09:44:29 +00:00
|
|
|
var tempMatrix = new TransformMatrix();
|
|
|
|
|
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 {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
|
|
|
*/
|
2020-09-14 14:33:58 +00:00
|
|
|
var BlitterWebGLRenderer = function (renderer, src, camera, parentMatrix)
|
2017-01-22 22:54:06 +00:00
|
|
|
{
|
2018-07-19 12:19:02 +00:00
|
|
|
var list = src.getRenderList();
|
2021-01-14 17:09:04 +00:00
|
|
|
var alpha = camera.alpha * src.alpha;
|
|
|
|
|
2022-10-09 20:40:22 +00:00
|
|
|
if (list.length === 0 || alpha === 0)
|
2021-01-14 17:09:04 +00:00
|
|
|
{
|
|
|
|
// Nothing to see, so abort early
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera.addToRenderList(src);
|
2021-01-07 12:31:31 +00:00
|
|
|
|
2020-09-09 12:03:46 +00:00
|
|
|
var pipeline = renderer.pipelines.set(this.pipeline, src);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
var cameraScrollX = camera.scrollX * src.scrollFactorX;
|
|
|
|
var cameraScrollY = camera.scrollY * src.scrollFactorY;
|
|
|
|
|
2020-11-06 09:44:29 +00:00
|
|
|
var calcMatrix = tempMatrix.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 roundPixels = camera.roundPixels;
|
|
|
|
|
2020-11-26 09:51:40 +00:00
|
|
|
renderer.pipelines.preBatch(src);
|
2020-11-23 16:17:13 +00:00
|
|
|
|
2022-10-09 20:40:22 +00:00
|
|
|
for (var i = 0; i < list.length; i++)
|
2018-07-02 15:44:09 +00:00
|
|
|
{
|
2022-10-09 20:40:22 +00:00
|
|
|
var bob = list[i];
|
2018-07-02 15:44:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-10-09 20:40:22 +00:00
|
|
|
var quad = calcMatrix.setQuad(x, y, x + width, y + height, roundPixels);
|
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)
|
|
|
|
{
|
2020-07-16 14:15:33 +00:00
|
|
|
var textureUnit = pipeline.setGameObject(src, frame);
|
2018-07-02 15:44:09 +00:00
|
|
|
|
|
|
|
prevTextureSourceIndex = frame.sourceIndex;
|
|
|
|
}
|
|
|
|
|
2022-10-09 20:40:22 +00:00
|
|
|
if (pipeline.batchQuad(src, quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7], frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, tintEffect, frame.glTexture, textureUnit))
|
2018-07-02 15:44:09 +00:00
|
|
|
{
|
|
|
|
prevTextureSourceIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
2020-11-23 16:17:13 +00:00
|
|
|
|
2020-11-26 09:51:40 +00:00
|
|
|
renderer.pipelines.postBatch(src);
|
2017-01-22 22:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BlitterWebGLRenderer;
|