@itwin/core-frontend
Version:
iTwin.js frontend components
40 lines • 2.25 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* 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 { GL } from "./GL";
import { System } from "./System";
/** Provides facilities for conditionally executing diagnostic/debug code. By default, all facilities are disabled - they must be explicitly enabled.
* @internal
*/
export class Debug {
/** Whether [[Debug.print]] will actually produce output. */
static printEnabled = false;
/** Whether [[Debug.evaluate]] will actually evaluate an expression. */
static evaluateEnabled = false;
/** If [[Debug.printEnabled]] is true, outputs a message using `console.log`.
* @param message A function which returns a string. If [[Debug.printEnabled]] is false, the function is never evaluated.
*/
static print(message) {
if (this.printEnabled)
console.log(message()); // eslint-disable-line no-console
}
/** If [[Debug.evaluate]] is true, executes the supplied function and returns its result; otherwise returns the supplied default value.
* @param evaluate The function to execute
* @param defaultValue The value to return if [[Debug.evaluate]] is false
* @returns The return value of `evaluate` if [[Debug.evaluate]] is true; otherwise, the `defaultValue`.
*/
static evaluate(evaluate, defaultValue) {
return this.evaluateEnabled ? evaluate() : defaultValue;
}
/** If [[Debug.evaluateEnabled]] is true, returns whether the currently-bound framebuffer is complete. */
static get isValidFrameBuffer() { return GL.FrameBuffer.Status.Complete === this.checkFrameBufferStatus(); }
/** If [[Debug.evaluateEnabled]] is true, returns the status of the currently-bound framebuffer. */
static checkFrameBufferStatus() {
return this.evaluate(() => System.instance.context.checkFramebufferStatus(GL.FrameBuffer.TARGET), GL.FrameBuffer.Status.Complete);
}
}
//# sourceMappingURL=Diagnostics.js.map