UNPKG

@itwin/core-frontend

Version:
108 lines 4.83 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AttributeMap = void 0; class AttributeMapEntry { uninstanced = new Map(); instanced = new Map(); constructor(attributes) { for (const attr of attributes) { const detail = { location: attr[1], type: attr[2] }; this.uninstanced.set(attr[0], detail); this.instanced.set(attr[0], detail); } const instanceAttrs = [ ["a_instanceMatrixRow0", 5 /* VariableType.Vec4 */], ["a_instanceMatrixRow1", 5 /* VariableType.Vec4 */], ["a_instanceMatrixRow2", 5 /* VariableType.Vec4 */], ["a_instanceOverrides", 5 /* VariableType.Vec4 */], ["a_instanceRgba", 5 /* VariableType.Vec4 */], ["a_featureId", 4 /* VariableType.Vec3 */], ["a_patternX", 2 /* VariableType.Float */], ["a_patternY", 2 /* VariableType.Float */], ]; let location = attributes.length; for (const attr of instanceAttrs) { this.instanced.set(attr[0], { location, type: attr[1] }); ++location; } } } /** * A class with static methods which provide access to a global mapping between techniques and attribute details (location and variable type). * These details are used when constructing shaders and when setting up buffers through implementations of the BuffersContainer abstract class. * @internal */ class AttributeMap { _attrMaps; constructor() { const posOnly = new AttributeMapEntry([["a_pos", 0, 4 /* VariableType.Vec3 */]]); const skySphere = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_worldPos", 1, 4 /* VariableType.Vec3 */], ]); const polyline = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_prevIndex", 1, 4 /* VariableType.Vec3 */], ["a_nextIndex", 2, 4 /* VariableType.Vec3 */], ["a_param", 3, 2 /* VariableType.Float */], ]); const edge = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_endPointAndQuadIndices", 1, 5 /* VariableType.Vec4 */], ]); const silhouette = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_endPointAndQuadIndices", 1, 5 /* VariableType.Vec4 */], ["a_normals", 2, 5 /* VariableType.Vec4 */], ]); const pointCloud = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_color", 1, 4 /* VariableType.Vec3 */], ]); const realityMesh = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_norm", 1, 3 /* VariableType.Vec2 */], ["a_uvParam", 2, 3 /* VariableType.Vec2 */], ]); const planarGrid = new AttributeMapEntry([ ["a_pos", 0, 4 /* VariableType.Vec3 */], ["a_uvParam", 1, 3 /* VariableType.Vec2 */], ]); const screenPoints = new AttributeMapEntry([ ["a_pos", 0, 3 /* VariableType.Vec2 */], ]); this._attrMaps = new Map([ [undefined, posOnly], [24 /* TechniqueId.SkySphereGradient */, skySphere], [25 /* TechniqueId.SkySphereTexture */, skySphere], [1 /* TechniqueId.Polyline */, polyline], [4 /* TechniqueId.Edge */, edge], [5 /* TechniqueId.SilhouetteEdge */, silhouette], [2 /* TechniqueId.PointCloud */, pointCloud], [31 /* TechniqueId.VolClassCopyZ */, screenPoints], [7 /* TechniqueId.RealityMesh */, realityMesh], [8 /* TechniqueId.PlanarGrid */, planarGrid], ]); } static findAttributeMap(techniqueId, instanced) { let entry = attributeMap._attrMaps.get(techniqueId); if (undefined === entry) { entry = attributeMap._attrMaps.get(undefined); attributeMap._attrMaps.set(techniqueId, entry); } return instanced ? entry.instanced : entry.uninstanced; } static findAttribute(attributeName, techniqueId, instanced) { return AttributeMap.findAttributeMap(techniqueId, instanced).get(attributeName); } } exports.AttributeMap = AttributeMap; const attributeMap = new AttributeMap(); //# sourceMappingURL=AttributeMap.js.map