diff --git a/packages/core/src/framebuffer/FrameBuffer.js b/packages/core/src/framebuffer/FrameBuffer.js index 84e9fcc..5803f13 100644 --- a/packages/core/src/framebuffer/FrameBuffer.js +++ b/packages/core/src/framebuffer/FrameBuffer.js @@ -10,8 +10,8 @@ { constructor(width, height) { - this.width = width || 100; - this.height = height || 100; + this.width = Math.ceil(width || 100); + this.height = Math.ceil(height || 100); this.stencil = false; this.depth = false; @@ -85,6 +85,9 @@ resize(width, height) { + width = Math.ceil(width); + height = Math.ceil(height); + if (width === this.width && height === this.height) return; this.width = width; diff --git a/packages/core/src/framebuffer/FrameBuffer.js b/packages/core/src/framebuffer/FrameBuffer.js index 84e9fcc..5803f13 100644 --- a/packages/core/src/framebuffer/FrameBuffer.js +++ b/packages/core/src/framebuffer/FrameBuffer.js @@ -10,8 +10,8 @@ { constructor(width, height) { - this.width = width || 100; - this.height = height || 100; + this.width = Math.ceil(width || 100); + this.height = Math.ceil(height || 100); this.stencil = false; this.depth = false; @@ -85,6 +85,9 @@ resize(width, height) { + width = Math.ceil(width); + height = Math.ceil(height); + if (width === this.width && height === this.height) return; this.width = width; diff --git a/packages/core/src/renderTexture/BaseRenderTexture.js b/packages/core/src/renderTexture/BaseRenderTexture.js index 88eb83b..0afbfc5 100644 --- a/packages/core/src/renderTexture/BaseRenderTexture.js +++ b/packages/core/src/renderTexture/BaseRenderTexture.js @@ -93,7 +93,8 @@ this.clearColor = [0, 0, 0, 0]; this.frameBuffer = new FrameBuffer(width * this.resolution, height * this.resolution) - .addColorTexture(0, this); + .addColorTexture(0, this) + .enableStencil(); // TODO - could this be added the systems? diff --git a/packages/core/src/framebuffer/FrameBuffer.js b/packages/core/src/framebuffer/FrameBuffer.js index 84e9fcc..5803f13 100644 --- a/packages/core/src/framebuffer/FrameBuffer.js +++ b/packages/core/src/framebuffer/FrameBuffer.js @@ -10,8 +10,8 @@ { constructor(width, height) { - this.width = width || 100; - this.height = height || 100; + this.width = Math.ceil(width || 100); + this.height = Math.ceil(height || 100); this.stencil = false; this.depth = false; @@ -85,6 +85,9 @@ resize(width, height) { + width = Math.ceil(width); + height = Math.ceil(height); + if (width === this.width && height === this.height) return; this.width = width; diff --git a/packages/core/src/renderTexture/BaseRenderTexture.js b/packages/core/src/renderTexture/BaseRenderTexture.js index 88eb83b..0afbfc5 100644 --- a/packages/core/src/renderTexture/BaseRenderTexture.js +++ b/packages/core/src/renderTexture/BaseRenderTexture.js @@ -93,7 +93,8 @@ this.clearColor = [0, 0, 0, 0]; this.frameBuffer = new FrameBuffer(width * this.resolution, height * this.resolution) - .addColorTexture(0, this); + .addColorTexture(0, this) + .enableStencil(); // TODO - could this be added the systems? diff --git a/packages/core/src/textures/BaseRenderTexture.js b/packages/core/src/textures/BaseRenderTexture.js deleted file mode 100644 index 77c44f5..0000000 --- a/packages/core/src/textures/BaseRenderTexture.js +++ /dev/null @@ -1,137 +0,0 @@ -import BaseTexture from './BaseTexture'; -import FrameBuffer from '../framebuffer/FrameBuffer'; - -/** - * A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it. - * - * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded - * otherwise black rectangles will be drawn instead. - * - * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position - * and rotation of the given Display Objects is ignored. For example: - * - * ```js - * let renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 }); - * let baseRenderTexture = new PIXI.BaseRenderTexture(renderer, 800, 600); - * let sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - * - * sprite.position.x = 800/2; - * sprite.position.y = 600/2; - * sprite.anchor.x = 0.5; - * sprite.anchor.y = 0.5; - * - * baseRenderTexture.render(sprite); - * ``` - * - * The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0 - * you can clear the transform - * - * ```js - * - * sprite.setTransform() - * - * let baseRenderTexture = new PIXI.BaseRenderTexture(100, 100); - * let renderTexture = new PIXI.RenderTexture(baseRenderTexture); - * - * renderer.render(sprite, renderTexture); // Renders to center of RenderTexture - * ``` - * - * @class - * @extends PIXI.BaseTexture - * @memberof PIXI - */ -export default class BaseRenderTexture extends BaseTexture -{ - /** - * @param {object} [options] - * @param {number} [options.width=100] - The width of the base render texture - * @param {number} [options.height=100] - The height of the base render texture - * @param {PIXI.SCALE_MODES} [options.scaleMode] - See {@link PIXI.SCALE_MODES} for possible values - * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the texture being generated - */ - constructor(options) - { - if (typeof options === 'number') - { - /* eslint-disable prefer-rest-params */ - // Backward compatibility of signature - const width = arguments[0]; - const height = arguments[1]; - const scaleMode = arguments[2]; - const resolution = arguments[3]; - - options = { width, height, scaleMode, resolution }; - /* eslint-enable prefer-rest-params */ - } - - super(null, options); - - const { width, height } = options || {}; - - // Set defaults - this.mipmap = false; - this.width = Math.ceil(width) || 100; - this.height = Math.ceil(height) || 100; - this.valid = true; - - /** - * A map of renderer IDs to webgl renderTargets - * - * @private - * @member {object} - */ - // this._glRenderTargets = {}; - - /** - * A reference to the canvas render target (we only need one as this can be shared across renderers) - * - * @private - * @member {object} - */ - this._canvasRenderTarget = null; - - this.clearColor = [0, 0, 0, 0]; - - this.frameBuffer = new FrameBuffer(width * this.resolution, height * this.resolution) - .addColorTexture(0, this); - - // TODO - could this be added the systems? - - /** - * The data structure for the stencil masks - * - * @member {PIXI.Graphics[]} - */ - this.stencilMaskStack = []; - - /** - * The data structure for the filters - * - * @member {PIXI.Graphics[]} - */ - this.filterStack = [{}]; - } - - /** - * Resizes the BaseRenderTexture. - * - * @param {number} width - The width to resize to. - * @param {number} height - The height to resize to. - */ - resize(width, height) - { - width = Math.ceil(width); - height = Math.ceil(height); - this.frameBuffer.resize(width * this.resolution, height * this.resolution); - } - - /** - * Destroys this texture - * - */ - destroy() - { - super.destroy(true); - this.renderer = null; - } -}