/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Rendering
 */
import { _implementationProhibited } from "../../common/internal/Symbols";
import { InstancedGraphicProps } from "../../common/render/InstancedGraphicParams";
import { InstancedGraphicPropsBuilder } from "../../common/internal/render/InstancedGraphicPropsBuilder";
import { FeatureTable, PackedFeatureTable } from "@itwin/core-common";
class Builder {
    [_implementationProhibited] = undefined;
    _instances = new InstancedGraphicPropsBuilder();
    _modelId;
    _containsFeatures = false;
    constructor(modelId) {
        this._modelId = modelId;
    }
    add(instance) {
        this._instances.add(instance);
        if (undefined !== instance.feature) {
            this._containsFeatures = true;
        }
    }
    finish() {
        const numInstances = this._instances.length;
        if (numInstances === 0) {
            throw new Error("No instances defined");
        }
        let featureTable;
        if (this._containsFeatures) {
            featureTable = new FeatureTable(numInstances, this._modelId);
        }
        const instances = this._instances.finish(featureTable);
        const result = {
            [_implementationProhibited]: "renderInstancesParams",
            instances,
        };
        if (featureTable) {
            const packedTable = PackedFeatureTable.pack(featureTable);
            result.features = {
                data: packedTable.data,
                modelId: packedTable.batchModelId,
                count: packedTable.numFeatures,
            };
        }
        return result;
    }
}
export function createRenderInstancesParamsBuilder(args) {
    return new Builder(args.modelId);
}
export function collectRenderInstancesParamsTransferables(xfers, inParams) {
    const params = inParams;
    if (params.instances) {
        InstancedGraphicProps.collectTransferables(xfers, params.instances);
    }
    if (params.features) {
        xfers.add(params.features.data.buffer);
    }
}
//# sourceMappingURL=RenderInstancesParamsImpl.js.map