UNPKG

@itwin/core-frontend

Version:
50 lines 2.22 kB
"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.isSynchronized = isSynchronized; exports.sync = sync; exports.desync = desync; /** Returns true if the target and observer are already synchronized. * @internal */ function isSynchronized(target, observer) { const token = observer.syncToken; return undefined !== token && token.target === target && token.syncKey === target.syncKey; } /** If the observer is already synchronized with the target, returns true. * Otherwise, synchronizes the observer's [[SyncToken]] with the target and returns false. * This is used, for example, to associate uniform variable state with shader programs such that the program can trivially detect if the state has changed since the last time * the variable's value was set. * @internal */ function sync(target, observer) { const syncKey = target.syncKey; const token = observer.syncToken; if (undefined === token) { observer.syncToken = { target, syncKey }; return false; } if (token.syncKey === syncKey && token.target === target) return true; token.syncKey = syncKey; token.target = target; return false; } /** Mark the [[SyncTarget]] as having changed in a way that affects associated [[SyncObserver]]s. * The next time [[sync]] is used, all [[SyncToken]] objects associated with the target will be recognized as out of sync. * @internal */ function desync(target) { // Let's make the relatively safe assumption that we will never roll over, and the even safer assumption that if we do, no outstanding SyncTokens holding a very small value will exist at that time. if (target.syncKey < Number.MAX_SAFE_INTEGER) ++target.syncKey; else target.syncKey = Number.MIN_SAFE_INTEGER; } //# sourceMappingURL=Sync.js.map