UNPKG

@pixi/core

Version:
96 lines (93 loc) 2.7 kB
import { MSAA_QUALITY, SCALE_MODES, MIPMAP_MODES, FORMATS, TYPES } from '@pixi/constants'; import { Runner } from '@pixi/runner'; import { BaseTexture } from '../textures/BaseTexture.mjs'; import { DepthResource } from '../textures/resources/DepthResource.mjs'; 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("disposeFramebuffer"); this.multisample = MSAA_QUALITY.NONE; } get colorTexture() { return this.colorTextures[0]; } addColorTexture(index = 0, texture) { this.colorTextures[index] = texture || new BaseTexture(null, { scaleMode: SCALE_MODES.NEAREST, resolution: 1, mipmap: MIPMAP_MODES.OFF, width: this.width, height: this.height }); this.dirtyId++; this.dirtyFormat++; return this; } addDepthTexture(texture) { this.depthTexture = texture || new BaseTexture(new DepthResource(null, { width: this.width, height: this.height }), { scaleMode: SCALE_MODES.NEAREST, resolution: 1, width: this.width, height: this.height, mipmap: MIPMAP_MODES.OFF, format: FORMATS.DEPTH_COMPONENT, type: 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; } } } export { Framebuffer }; //# sourceMappingURL=Framebuffer.mjs.map