UNPKG

@itwin/core-frontend

Version:
95 lines 4.22 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module WebGL */ import { dispose } from "@itwin/core-bentley"; import { ColorInfo } from "./ColorInfo"; import { qorigin3dToArray, qparams2dToArray, qscale3dToArray } from "./AttributeBuffers"; import { TextureHandle } from "./Texture"; /** @internal */ export class AuxChannelLUT { texture; numVertices; numBytesPerVertex; displacements; normals; params; constructor(texture, table) { this.texture = texture; this.numVertices = table.numVertices; this.numBytesPerVertex = table.numBytesPerVertex; this.initChannels(table, "displacements"); this.initChannels(table, "normals"); this.initChannels(table, "params"); } initChannels(table, name) { const channels = table[name]; if (undefined === channels) return; const map = new Map(); // TS2322: Type 'Map<string, T>' is not assignable to type 'Map<string, AuxChannel> & Map<string, AuxDisplacementChannel> & Map<string, AuxParamChannel>'. // (Compiler cannot detect that the specific property name is matched to the correct subtype at each call site - but we know that). this[name] = map; for (const channel of channels) map.set(channel.name, channel); } get bytesUsed() { return this.texture.bytesUsed; } get hasScalarAnimation() { return undefined !== this.params; } get isDisposed() { return this.texture.isDisposed; } [Symbol.dispose]() { dispose(this.texture); } static create(table) { const texture = TextureHandle.createForData(table.width, table.height, table.data); return undefined !== texture ? new AuxChannelLUT(texture, table) : undefined; } } /** Represents the finished lookup table ready for submission to GPU. * @internal */ export class VertexLUT { texture; // Texture containing vertex data numVertices; numRgbaPerVertex; colorInfo; usesQuantizedPositions; // If true, positions are 16-bit integers quantized to qOrigin and qScale; otherwise they are unquantized 32-bit floats. qOrigin; // Origin of quantized range qScale; // Scale of quantized range uvQParams; // If vertices contain texture UV params, quantization parameters as [origin.x, origin.y, scale.x, scale.y ] auxChannels; get hasAnimation() { return undefined !== this.auxChannels; } get hasScalarAnimation() { return undefined !== this.auxChannels && this.auxChannels.hasScalarAnimation; } get bytesUsed() { let bytesUsed = this.texture.bytesUsed; if (undefined !== this.auxChannels) bytesUsed += this.auxChannels.bytesUsed; return bytesUsed; } static createFromVertexTable(vt, aux) { const texture = TextureHandle.createForData(vt.width, vt.height, vt.data); if (undefined === texture) return undefined; const auxLUT = undefined !== aux ? AuxChannelLUT.create(aux) : undefined; return new VertexLUT(texture, vt, ColorInfo.createFromVertexTable(vt), vt.qparams, !vt.usesUnquantizedPositions, vt.uvParams, auxLUT); } constructor(texture, table, colorInfo, qparams, positionsAreQuantized, uvParams, auxChannels) { this.texture = texture; this.numVertices = table.numVertices; this.numRgbaPerVertex = table.numRgbaPerVertex; this.colorInfo = colorInfo; this.qOrigin = qorigin3dToArray(qparams.origin); this.qScale = qscale3dToArray(qparams.scale); this.usesQuantizedPositions = positionsAreQuantized; this.auxChannels = auxChannels; if (undefined !== uvParams) this.uvQParams = qparams2dToArray(uvParams); } get isDisposed() { return this.texture.isDisposed; } [Symbol.dispose]() { dispose(this.texture); } } //# sourceMappingURL=VertexLUT.js.map