UNPKG

@itwin/core-frontend

Version:
87 lines 3.06 kB
/*--------------------------------------------------------------------------------------------- * 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 { ColorDef, WhiteOnWhiteReversalSettings } from "@itwin/core-common"; import { ColorInfo } from "./ColorInfo"; import { FloatRgb, FloatRgba } from "./FloatRGBA"; import { desync, sync } from "./Sync"; /** Maintains state of uniforms associated with the DisplayStyleState. * @internal */ export class StyleUniforms { _bgColor = ColorDef.white; _bgRgba = FloatRgba.fromColorDef(this._bgColor); _bgRgb = FloatRgb.fromColorDef(this._bgColor); _monoColor = ColorDef.white; _monoRgb = FloatRgb.fromColorDef(this._monoColor); _wantWoWReversal = true; _wowReversalSettings = WhiteOnWhiteReversalSettings.fromJSON(); _bgIntensity = 0; syncKey = 0; update(plan) { if (this._bgColor.equals(plan.bgColor) && this._monoColor.equals(plan.monoColor) && this._wowReversalSettings.equals(plan.whiteOnWhiteReversal)) return; 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; desync(this); this.updateBackgroundColor(bgColor); } // vec4 bindBackgroundRgba(uniform) { if (!sync(this, uniform)) this._bgRgba.bind(uniform); } // vec3 bindBackgroundRgb(uniform) { if (!sync(this, uniform)) this._bgRgb.bind(uniform); } // vec3 bindMonochromeRgb(uniform) { if (!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.createUniform(this._bgRgba); } } //# sourceMappingURL=StyleUniforms.js.map