"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.HiliteUniforms = void 0;
const core_common_1 = require("@itwin/core-common");
const FloatRGBA_1 = require("./FloatRGBA");
const Matrix_1 = require("./Matrix");
const Sync_1 = require("./Sync");
/** Maintains state for uniforms related to hilite and emphasis.
 * @internal
 */
class HiliteUniforms {
    _compositeSettings = new Matrix_1.Matrix3();
    _compositeWidths = new Float32Array(2);
    _featureSettings = new Matrix_1.Matrix3();
    _hiliteSettings = new core_common_1.Hilite.Settings();
    _emphasisSettings = new core_common_1.Hilite.Settings();
    _hiliteRgb = FloatRGBA_1.FloatRgb.fromColorDef(this.hiliteSettings.color);
    syncKey = 0;
    get hiliteSettings() { return this._hiliteSettings; }
    get emphasisSettings() { return this._emphasisSettings; }
    get hiliteColor() { return this._hiliteRgb; }
    update(hilite, emphasis) {
        if (core_common_1.Hilite.equalSettings(hilite, this._hiliteSettings) && core_common_1.Hilite.equalSettings(emphasis, this._emphasisSettings))
            return;
        (0, Sync_1.desync)(this);
        this._hiliteSettings = core_common_1.Hilite.cloneSettings(hilite);
        this._emphasisSettings = core_common_1.Hilite.cloneSettings(emphasis);
        const c = this._compositeSettings;
        const f = this._featureSettings;
        const rgb = this._hiliteRgb;
        rgb.setColorDef(emphasis.color);
        c.data[3] = f.data[3] = rgb.red;
        c.data[4] = f.data[4] = rgb.green;
        c.data[5] = f.data[5] = rgb.blue;
        // NB: Must set to hilite color last - is exposed through getter.
        rgb.setColorDef(hilite.color);
        c.data[0] = f.data[0] = rgb.red;
        c.data[1] = f.data[1] = rgb.green;
        c.data[2] = f.data[2] = rgb.blue;
        c.data[6] = hilite.hiddenRatio;
        c.data[7] = emphasis.hiddenRatio;
        f.data[6] = hilite.visibleRatio;
        f.data[7] = emphasis.visibleRatio;
        this._compositeWidths[0] = hilite.silhouette;
        this._compositeWidths[1] = emphasis.silhouette;
    }
    // mat3:
    // hilite.red     hilite.green hilite.blue
    // emph.red       emph.green   emph.blue
    // hilite.hidden  emph.hidden unused
    bindCompositeSettings(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            uniform.setMatrix3(this._compositeSettings);
    }
    // vec2:
    // hilite.silhouette emph.silhouette
    bindCompositeWidths(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            uniform.setUniform2fv(this._compositeWidths);
    }
    // mat3:
    // hilite.red     hilite.green hilite.blue
    // emph.red       emph.green   emph.blue
    // hilite.visible emph.visible unused
    bindFeatureSettings(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            uniform.setMatrix3(this._featureSettings);
    }
}
exports.HiliteUniforms = HiliteUniforms;
//# sourceMappingURL=HiliteUniforms.js.map