"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.StyleUniforms = void 0;
const core_common_1 = require("@itwin/core-common");
const ColorInfo_1 = require("./ColorInfo");
const FloatRGBA_1 = require("./FloatRGBA");
const Sync_1 = require("./Sync");
/** Maintains state of uniforms associated with the DisplayStyleState.
 * @internal
 */
class StyleUniforms {
    constructor() {
        this._bgColor = core_common_1.ColorDef.white;
        this._bgRgba = FloatRGBA_1.FloatRgba.fromColorDef(this._bgColor);
        this._bgRgb = FloatRGBA_1.FloatRgb.fromColorDef(this._bgColor);
        this._monoColor = core_common_1.ColorDef.white;
        this._monoRgb = FloatRGBA_1.FloatRgb.fromColorDef(this._monoColor);
        this._wantWoWReversal = true;
        this._wowReversalSettings = core_common_1.WhiteOnWhiteReversalSettings.fromJSON();
        this._bgIntensity = 0;
        this.syncKey = 0;
    }
    update(plan) {
        if (this._bgColor.equals(plan.bgColor) && this._monoColor.equals(plan.monoColor) && this._wowReversalSettings.equals(plan.whiteOnWhiteReversal))
            return;
        (0, Sync_1.desync)(this);
        this._monoColor = plan.monoColor;
        this._monoRgb.setColorDef(plan.monoColor);
        this._wowReversalSettings = plan.whiteOnWhiteReversal;
        this.updateBackgroundColor(plan.bgColor);
    }
    updateBackgroundColor(bgColor) {
        this._bgColor = bgColor;
        this._bgRgba.setColorDef(bgColor);
        this._bgRgb.setColorDef(bgColor);
        this._wantWoWReversal = this._wowReversalSettings.ignoreBackgroundColor || this._bgRgb.isWhite;
        this._bgIntensity = this._bgRgb.red * 0.3 + this._bgRgb.green * 0.59 + this._bgRgb.blue * 0.11;
    }
    changeBackgroundColor(bgColor) {
        if (bgColor.equals(this._bgColor))
            return;
        (0, Sync_1.desync)(this);
        this.updateBackgroundColor(bgColor);
    }
    // vec4
    bindBackgroundRgba(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            this._bgRgba.bind(uniform);
    }
    //  vec3
    bindBackgroundRgb(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            this._bgRgb.bind(uniform);
    }
    // vec3
    bindMonochromeRgb(uniform) {
        if (!(0, Sync_1.sync)(this, uniform))
            this._monoRgb.bind(uniform);
    }
    get backgroundIntensity() {
        return this._bgIntensity;
    }
    get backgroundTbgr() {
        return this._bgColor.tbgr;
    }
    get backgroundHexString() {
        return this._bgColor.toHexString();
    }
    get backgroundAlpha() {
        return this._bgRgba.alpha;
    }
    get backgroundColor() {
        return this._bgColor;
    }
    cloneBackgroundRgba(result) {
        this._bgRgba.clone(result);
    }
    get wantWoWReversal() {
        return this._wantWoWReversal;
    }
    get backgroundColorInfo() {
        return ColorInfo_1.ColorInfo.createUniform(this._bgRgba);
    }
}
exports.StyleUniforms = StyleUniforms;
//# sourceMappingURL=StyleUniforms.js.map