"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 Rendering
 */
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectRenderInstancesParamsTransferables = exports.createRenderInstancesParamsBuilder = void 0;
const Symbols_1 = require("../../common/internal/Symbols");
const InstancedGraphicParams_1 = require("../../common/render/InstancedGraphicParams");
const InstancedGraphicPropsBuilder_1 = require("../../common/internal/render/InstancedGraphicPropsBuilder");
const core_common_1 = require("@itwin/core-common");
class Builder {
    constructor(modelId) {
        this[_a] = undefined;
        this._instances = new InstancedGraphicPropsBuilder_1.InstancedGraphicPropsBuilder();
        this._containsFeatures = false;
        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 core_common_1.FeatureTable(numInstances, this._modelId);
        }
        const instances = this._instances.finish(featureTable);
        const result = {
            [Symbols_1._implementationProhibited]: "renderInstancesParams",
            instances,
        };
        if (featureTable) {
            const packedTable = core_common_1.PackedFeatureTable.pack(featureTable);
            result.features = {
                data: packedTable.data,
                modelId: packedTable.batchModelId,
                count: packedTable.numFeatures,
            };
        }
        return result;
    }
}
_a = Symbols_1._implementationProhibited;
function createRenderInstancesParamsBuilder(args) {
    return new Builder(args.modelId);
}
exports.createRenderInstancesParamsBuilder = createRenderInstancesParamsBuilder;
function collectRenderInstancesParamsTransferables(xfers, inParams) {
    const params = inParams;
    if (params.instances) {
        InstancedGraphicParams_1.InstancedGraphicProps.collectTransferables(xfers, params.instances);
    }
    if (params.features) {
        xfers.add(params.features.data.buffer);
    }
}
exports.collectRenderInstancesParamsTransferables = collectRenderInstancesParamsTransferables;
//# sourceMappingURL=RenderInstancesParamsImpl.js.map