mirror of
https://github.com/photonstorm/phaser
synced 2024-12-03 18:10:10 +00:00
Render Texture now uses unified drawing functions
This commit is contained in:
parent
c6cb0edf60
commit
d5c558b8e4
2 changed files with 10 additions and 64 deletions
|
@ -14,71 +14,14 @@
|
||||||
* @private
|
* @private
|
||||||
*
|
*
|
||||||
* @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
|
* @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
|
||||||
* @param {Phaser.GameObjects.RenderTexture} renderTexture - The Game Object being rendered in this call.
|
* @param {Phaser.GameObjects.RenderTexture} src - The Game Object being rendered in this call.
|
||||||
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
|
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
|
||||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
|
* @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
|
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
|
||||||
*/
|
*/
|
||||||
var RenderTextureCanvasRenderer = function (renderer, renderTexture, interpolationPercentage, camera, parentMatrix)
|
var RenderTextureCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
||||||
{
|
{
|
||||||
var ctx = renderer.currentContext;
|
renderer.batchSprite(src, src.frame, camera, parentMatrix);
|
||||||
|
|
||||||
// Alpha
|
|
||||||
|
|
||||||
var alpha = camera.alpha * renderTexture.alpha;
|
|
||||||
|
|
||||||
if (alpha === 0)
|
|
||||||
{
|
|
||||||
// Nothing to see, so abort early
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var dx = 0;
|
|
||||||
var dy = 0;
|
|
||||||
|
|
||||||
var fx = 1;
|
|
||||||
var fy = 1;
|
|
||||||
|
|
||||||
if (renderTexture.flipX)
|
|
||||||
{
|
|
||||||
fx = -1;
|
|
||||||
dx -= renderTexture.canvas.width - renderTexture.displayOriginX;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dx -= renderTexture.displayOriginX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (renderTexture.flipY)
|
|
||||||
{
|
|
||||||
fy = -1;
|
|
||||||
dy -= renderTexture.canvas.height - renderTexture.displayOriginY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dy -= renderTexture.displayOriginY;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.save();
|
|
||||||
|
|
||||||
// Blend Mode
|
|
||||||
ctx.globalCompositeOperation = renderer.blendModes[renderTexture.blendMode];
|
|
||||||
|
|
||||||
// Alpha
|
|
||||||
ctx.globalAlpha = alpha;
|
|
||||||
|
|
||||||
if (parentMatrix)
|
|
||||||
{
|
|
||||||
parentMatrix.copyToContext(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.translate(renderTexture.x - camera.scrollX * renderTexture.scrollFactorX, renderTexture.y - camera.scrollY * renderTexture.scrollFactorY);
|
|
||||||
ctx.rotate(renderTexture.rotation);
|
|
||||||
ctx.scale(renderTexture.scaleX, renderTexture.scaleY);
|
|
||||||
ctx.scale(fx, fy);
|
|
||||||
ctx.drawImage(renderTexture.canvas, dx, dy);
|
|
||||||
|
|
||||||
ctx.restore();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = RenderTextureCanvasRenderer;
|
module.exports = RenderTextureCanvasRenderer;
|
||||||
|
|
|
@ -23,20 +23,23 @@ var Utils = require('../../renderer/webgl/Utils');
|
||||||
*/
|
*/
|
||||||
var RenderTextureWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
var RenderTextureWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
||||||
{
|
{
|
||||||
|
var frame = src.frame;
|
||||||
|
var width = frame.width;
|
||||||
|
var height = frame.height;
|
||||||
var getTint = Utils.getTintAppendFloatAlpha;
|
var getTint = Utils.getTintAppendFloatAlpha;
|
||||||
|
|
||||||
this.pipeline.batchTexture(
|
this.pipeline.batchTexture(
|
||||||
src,
|
src,
|
||||||
src.texture,
|
frame.glTexture,
|
||||||
src.texture.width, src.texture.height,
|
width, height,
|
||||||
src.x, src.y,
|
src.x, src.y,
|
||||||
src.width, src.height,
|
width, height,
|
||||||
src.scaleX, src.scaleY,
|
src.scaleX, src.scaleY,
|
||||||
src.rotation,
|
src.rotation,
|
||||||
src.flipX, !src.flipY,
|
src.flipX, !src.flipY,
|
||||||
src.scrollFactorX, src.scrollFactorY,
|
src.scrollFactorX, src.scrollFactorY,
|
||||||
src.displayOriginX, src.displayOriginY,
|
src.displayOriginX, src.displayOriginY,
|
||||||
0, 0, src.texture.width, src.texture.height,
|
0, 0, width, height,
|
||||||
getTint(src._tintTL, camera.alpha * src._alphaTL),
|
getTint(src._tintTL, camera.alpha * src._alphaTL),
|
||||||
getTint(src._tintTR, camera.alpha * src._alphaTR),
|
getTint(src._tintTR, camera.alpha * src._alphaTR),
|
||||||
getTint(src._tintBL, camera.alpha * src._alphaBL),
|
getTint(src._tintBL, camera.alpha * src._alphaBL),
|
||||||
|
|
Loading…
Reference in a new issue