forked from magcius/noclip.website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderStatistics.ts
45 lines (39 loc) · 1.35 KB
/
RenderStatistics.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
35
36
37
38
39
40
41
42
43
44
45
import { GfxDebugGroup } from "./gfx/platform/GfxPlatform";
export interface RenderStatistics {
frameStartCPUTime: number;
drawCallCount: number;
textureBindCount: number;
bufferUploadCount: number;
triangleCount: number;
frameCPUTime: number;
fps: number;
}
export class RenderStatisticsTracker {
public drawCallCount: number = 0;
public textureBindCount: number = 0;
public bufferUploadCount: number = 0;
public triangleCount: number = 0;
public frameStartCPUTime: number = 0;
public frameCPUTime: number = 0;
public fps: number = 0;
public beginFrame(): void {
this.frameStartCPUTime = window.performance.now();
this.drawCallCount = 0;
this.textureBindCount = 0;
this.bufferUploadCount = 0;
this.triangleCount = 0;
this.frameCPUTime = 0;
this.fps = 0;
}
public endFrame(): RenderStatistics {
this.frameCPUTime = window.performance.now() - this.frameStartCPUTime;
this.fps = 1000 / this.frameCPUTime;
return this;
}
public applyDebugGroup(debugGroup: GfxDebugGroup): void {
this.drawCallCount += debugGroup.drawCallCount;
this.textureBindCount += debugGroup.textureBindCount;
this.bufferUploadCount += debugGroup.bufferUploadCount;
this.triangleCount += debugGroup.triangleCount;
}
}