@pixi/core
Version:
Core PixiJS
112 lines (107 loc) • 3.98 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var color = require('@pixi/color');
var extensions = require('@pixi/extensions');
var math = require('@pixi/math');
const tempRect = new math.Rectangle();
const tempRect2 = new math.Rectangle();
class RenderTextureSystem {
constructor(renderer) {
this.renderer = renderer;
this.defaultMaskStack = [];
this.current = null;
this.sourceFrame = new math.Rectangle();
this.destinationFrame = new math.Rectangle();
this.viewportFrame = new math.Rectangle();
}
bind(renderTexture = null, sourceFrame, destinationFrame) {
const renderer = this.renderer;
this.current = renderTexture;
let baseTexture;
let framebuffer;
let resolution;
if (renderTexture) {
baseTexture = renderTexture.baseTexture;
resolution = baseTexture.resolution;
if (!sourceFrame) {
tempRect.width = renderTexture.frame.width;
tempRect.height = renderTexture.frame.height;
sourceFrame = tempRect;
}
if (!destinationFrame) {
tempRect2.x = renderTexture.frame.x;
tempRect2.y = renderTexture.frame.y;
tempRect2.width = sourceFrame.width;
tempRect2.height = sourceFrame.height;
destinationFrame = tempRect2;
}
framebuffer = baseTexture.framebuffer;
} else {
resolution = renderer.resolution;
if (!sourceFrame) {
tempRect.width = renderer._view.screen.width;
tempRect.height = renderer._view.screen.height;
sourceFrame = tempRect;
}
if (!destinationFrame) {
destinationFrame = tempRect;
destinationFrame.width = sourceFrame.width;
destinationFrame.height = sourceFrame.height;
}
}
const viewportFrame = this.viewportFrame;
viewportFrame.x = destinationFrame.x * resolution;
viewportFrame.y = destinationFrame.y * resolution;
viewportFrame.width = destinationFrame.width * resolution;
viewportFrame.height = destinationFrame.height * resolution;
if (!renderTexture) {
viewportFrame.y = renderer.view.height - (viewportFrame.y + viewportFrame.height);
}
viewportFrame.ceil();
this.renderer.framebuffer.bind(framebuffer, viewportFrame);
this.renderer.projection.update(destinationFrame, sourceFrame, resolution, !framebuffer);
if (renderTexture) {
this.renderer.mask.setMaskStack(baseTexture.maskStack);
} else {
this.renderer.mask.setMaskStack(this.defaultMaskStack);
}
this.sourceFrame.copyFrom(sourceFrame);
this.destinationFrame.copyFrom(destinationFrame);
}
clear(clearColor, mask) {
const fallbackColor = this.current ? this.current.baseTexture.clear : this.renderer.background.backgroundColor;
const color$1 = clearColor ? color.Color.shared.setValue(clearColor) : fallbackColor;
const destinationFrame = this.destinationFrame;
const baseFrame = this.current ? this.current.baseTexture : this.renderer._view.screen;
const clearMask = destinationFrame.width !== baseFrame.width || destinationFrame.height !== baseFrame.height;
if (clearMask) {
let { x, y, width, height } = this.viewportFrame;
x = Math.round(x);
y = Math.round(y);
width = Math.round(width);
height = Math.round(height);
this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST);
this.renderer.gl.scissor(x, y, width, height);
}
this.renderer.framebuffer.clear(color$1.red, color$1.green, color$1.blue, color$1.alpha, mask);
if (clearMask) {
this.renderer.scissor.pop();
}
}
resize() {
this.bind(null);
}
reset() {
this.bind(null);
}
destroy() {
this.renderer = null;
}
}
RenderTextureSystem.extension = {
type: extensions.ExtensionType.RendererSystem,
name: "renderTexture"
};
extensions.extensions.add(RenderTextureSystem);
exports.RenderTextureSystem = RenderTextureSystem;
//# sourceMappingURL=RenderTextureSystem.js.map