/
SetGpuMemoryLimitTool.ts
34 lines (29 loc) · 1.35 KB
/
SetGpuMemoryLimitTool.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Tools
*/
import { GpuMemoryLimit, IModelApp, Tool } from "@itwin/core-frontend";
/** Adjust the value of [TileAdmin.gpuMemoryLimit]($frontend). This controls how much GPU memory is allowed to be consumed
* by tile graphics before the system starts discarding the graphics for the least recently drawn tiles.
* @beta
*/
export class SetGpuMemoryLimitTool extends Tool {
public static override toolId = "SetGpuMemoryLimit";
public static override get minArgs() { return 1; }
public static override get maxArgs() { return 1; }
public override async run(limit?: GpuMemoryLimit): Promise<boolean> {
if (undefined !== limit) {
IModelApp.tileAdmin.gpuMemoryLimit = limit;
IModelApp.requestNextAnimation();
}
return true;
}
public override async parseAndRun(...args: string[]): Promise<boolean> {
const maxBytes = Number.parseInt(args[0], 10);
const limit = Number.isNaN(maxBytes) ? args[0] as GpuMemoryLimit : maxBytes;
return this.run(limit);
}
}