/*---------------------------------------------------------------------------------------------
* 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 { Hilite } from "@itwin/core-common";
import { FloatRgb } from "./FloatRGBA";
import { Matrix3 } from "./Matrix";
import { desync, sync } from "./Sync";
/** Maintains state for uniforms related to hilite and emphasis.
 * @internal
 */
export class HiliteUniforms {
    constructor() {
        this._compositeSettings = new Matrix3();
        this._compositeWidths = new Float32Array(2);
        this._featureSettings = new Matrix3();
        this._hiliteSettings = new Hilite.Settings();
        this._emphasisSettings = new Hilite.Settings();
        this._hiliteRgb = FloatRgb.fromColorDef(this.hiliteSettings.color);
        this.syncKey = 0;
    }
    get hiliteSettings() { return this._hiliteSettings; }
    get emphasisSettings() { return this._emphasisSettings; }
    get hiliteColor() { return this._hiliteRgb; }
    update(hilite, emphasis) {
        if (Hilite.equalSettings(hilite, this._hiliteSettings) && Hilite.equalSettings(emphasis, this._emphasisSettings))
            return;
        desync(this);
        this._hiliteSettings = Hilite.cloneSettings(hilite);
        this._emphasisSettings = 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 (!sync(this, uniform))
            uniform.setMatrix3(this._compositeSettings);
    }
    // vec2:
    // hilite.silhouette emph.silhouette
    bindCompositeWidths(uniform) {
        if (!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 (!sync(this, uniform))
            uniform.setMatrix3(this._featureSettings);
    }
}
//# sourceMappingURL=HiliteUniforms.js.map