UNPKG

@pixi/core

Version:
100 lines (95 loc) 2.85 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var constants = require('@pixi/constants'); var runner = require('@pixi/runner'); var BaseTexture = require('../textures/BaseTexture.js'); var DepthResource = require('../textures/resources/DepthResource.js'); class Framebuffer { constructor(width, height) { this.width = Math.round(width || 100); this.height = Math.round(height || 100); this.stencil = false; this.depth = false; this.dirtyId = 0; this.dirtyFormat = 0; this.dirtySize = 0; this.depthTexture = null; this.colorTextures = []; this.glFramebuffers = {}; this.disposeRunner = new runner.Runner("disposeFramebuffer"); this.multisample = constants.MSAA_QUALITY.NONE; } get colorTexture() { return this.colorTextures[0]; } addColorTexture(index = 0, texture) { this.colorTextures[index] = texture || new BaseTexture.BaseTexture(null, { scaleMode: constants.SCALE_MODES.NEAREST, resolution: 1, mipmap: constants.MIPMAP_MODES.OFF, width: this.width, height: this.height }); this.dirtyId++; this.dirtyFormat++; return this; } addDepthTexture(texture) { this.depthTexture = texture || new BaseTexture.BaseTexture(new DepthResource.DepthResource(null, { width: this.width, height: this.height }), { scaleMode: constants.SCALE_MODES.NEAREST, resolution: 1, width: this.width, height: this.height, mipmap: constants.MIPMAP_MODES.OFF, format: constants.FORMATS.DEPTH_COMPONENT, type: constants.TYPES.UNSIGNED_SHORT }); this.dirtyId++; this.dirtyFormat++; return this; } enableDepth() { this.depth = true; this.dirtyId++; this.dirtyFormat++; return this; } enableStencil() { this.stencil = true; this.dirtyId++; this.dirtyFormat++; return this; } resize(width, height) { width = Math.round(width); height = Math.round(height); if (width === this.width && height === this.height) return; this.width = width; this.height = height; this.dirtyId++; this.dirtySize++; for (let i = 0; i < this.colorTextures.length; i++) { const texture = this.colorTextures[i]; const resolution = texture.resolution; texture.setSize(width / resolution, height / resolution); } if (this.depthTexture) { const resolution = this.depthTexture.resolution; this.depthTexture.setSize(width / resolution, height / resolution); } } dispose() { this.disposeRunner.emit(this, false); } destroyDepthTexture() { if (this.depthTexture) { this.depthTexture.destroy(); this.depthTexture = null; ++this.dirtyId; ++this.dirtyFormat; } } } exports.Framebuffer = Framebuffer; //# sourceMappingURL=Framebuffer.js.map