-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.js
32 lines (32 loc) · 959 Bytes
/
util.js
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
export class FPSCounter {
constructor() {
this.index = 0;
this.timeStamps = new Array(20).fill(0);
}
update(timeStamp) {
const delta = timeStamp - this.timeStamps[this.index];
this.timeStamps[this.index] = timeStamp;
if (++this.index >= this.timeStamps.length) this.index = 0;
return (1e3 * this.timeStamps.length) / delta;
}
}
export function resizeCanvas(gl) {
const window = gl.canvas.ownerDocument.defaultView;
const canvasWidth = Math.round(
window.devicePixelRatio * gl.canvas.clientWidth
);
const canvasHeight = Math.round(
window.devicePixelRatio * gl.canvas.clientHeight
);
if (gl.canvas.width != canvasWidth || gl.canvas.height != canvasHeight) {
gl.canvas.width = canvasWidth;
gl.canvas.height = canvasHeight;
}
}
export function downloadFile(url, fileName) {
const a = document.createElement("a");
a.style = "display: none";
a.href = url;
a.download = fileName;
a.click();
}