2022-12-02 18:07:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
2022-12-02 18:07:20 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var GetCalcMatrix = require('../GetCalcMatrix');
|
2022-12-07 18:30:08 +00:00
|
|
|
var Utils = require('../../renderer/webgl/Utils');
|
2022-12-02 18:07:20 +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.Mesh#renderWebGL
|
|
|
|
* @since 3.0.0
|
|
|
|
* @private
|
|
|
|
*
|
|
|
|
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
|
|
|
|
* @param {Phaser.GameObjects.Mesh} src - The Game Object being rendered in this call.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
|
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
|
|
|
|
*/
|
|
|
|
var NineSliceWebGLRenderer = function (renderer, src, camera, parentMatrix)
|
|
|
|
{
|
2022-12-06 18:02:16 +00:00
|
|
|
var verts = src.vertices;
|
|
|
|
var totalVerts = verts.length;
|
2022-12-02 18:07:20 +00:00
|
|
|
|
2022-12-06 18:02:16 +00:00
|
|
|
if (totalVerts === 0)
|
2022-12-02 18:07:20 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera.addToRenderList(src);
|
|
|
|
|
|
|
|
var pipeline = renderer.pipelines.set(src.pipeline, src);
|
|
|
|
|
2022-12-08 16:19:29 +00:00
|
|
|
var calcMatrix = GetCalcMatrix(src, camera, parentMatrix, false).calc;
|
2022-12-02 18:07:20 +00:00
|
|
|
|
|
|
|
var textureUnit = pipeline.setGameObject(src);
|
|
|
|
|
|
|
|
var F32 = pipeline.vertexViewF32;
|
|
|
|
var U32 = pipeline.vertexViewU32;
|
|
|
|
|
|
|
|
var vertexOffset = (pipeline.vertexCount * pipeline.currentShader.vertexComponentCount) - 1;
|
|
|
|
|
|
|
|
var roundPixels = camera.roundPixels;
|
2022-12-07 18:30:08 +00:00
|
|
|
|
|
|
|
var tintEffect = src.tintFill;
|
2022-12-02 18:07:20 +00:00
|
|
|
var alpha = camera.alpha * src.alpha;
|
2022-12-07 18:30:08 +00:00
|
|
|
var color = Utils.getTintAppendFloatAlpha(src.tint, alpha);
|
2022-12-02 18:07:20 +00:00
|
|
|
|
|
|
|
renderer.pipelines.preBatch(src);
|
|
|
|
|
2022-12-07 18:30:08 +00:00
|
|
|
var available = pipeline.vertexAvailable();
|
|
|
|
var flushCount = -1;
|
|
|
|
|
|
|
|
if (available < totalVerts)
|
|
|
|
{
|
|
|
|
flushCount = available;
|
|
|
|
}
|
|
|
|
|
2022-12-06 18:02:16 +00:00
|
|
|
for (var i = 0; i < totalVerts; i++)
|
2022-12-02 18:07:20 +00:00
|
|
|
{
|
2022-12-08 16:19:29 +00:00
|
|
|
var vert = verts[i];
|
2022-12-02 18:07:20 +00:00
|
|
|
|
2022-12-07 18:30:08 +00:00
|
|
|
if (i === flushCount)
|
2022-12-02 18:07:20 +00:00
|
|
|
{
|
|
|
|
pipeline.flush();
|
|
|
|
|
|
|
|
if (!pipeline.currentBatch)
|
|
|
|
{
|
|
|
|
textureUnit = pipeline.setGameObject(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
vertexOffset = 0;
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:19:29 +00:00
|
|
|
F32[++vertexOffset] = calcMatrix.getXRound(vert.vx, vert.vy, roundPixels);
|
|
|
|
F32[++vertexOffset] = calcMatrix.getYRound(vert.vx, vert.vy, roundPixels);
|
2022-12-07 18:30:08 +00:00
|
|
|
F32[++vertexOffset] = vert.u;
|
|
|
|
F32[++vertexOffset] = vert.v;
|
|
|
|
F32[++vertexOffset] = textureUnit;
|
|
|
|
F32[++vertexOffset] = tintEffect;
|
|
|
|
U32[++vertexOffset] = color;
|
2022-12-02 18:07:20 +00:00
|
|
|
|
2022-12-06 18:02:16 +00:00
|
|
|
pipeline.vertexCount++;
|
2022-12-02 18:07:20 +00:00
|
|
|
|
|
|
|
pipeline.currentBatch.count = (pipeline.vertexCount - pipeline.currentBatch.start);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.pipelines.postBatch(src);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = NineSliceWebGLRenderer;
|