Fix taking screenshot not working when limiting FPS

This commit is contained in:
redphx
2024-10-19 18:04:05 +07:00
parent 602c31dc7f
commit 8664c1a60f
4 changed files with 32 additions and 26 deletions

View File

@@ -94,20 +94,22 @@ export class WebGL2Player {
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.options.saturation);
}
drawFrame() {
// Don't draw when FPS is 0
if (this.targetFps === 0) {
return;
}
// Limit FPS
if (this.targetFps < 60) {
const currentTime = performance.now();
const timeSinceLastFrame = currentTime - this.lastFrameTime;
if (timeSinceLastFrame < this.frameInterval) {
drawFrame(force=false) {
if (!force) {
// Don't draw when FPS is 0
if (this.targetFps === 0) {
return;
}
this.lastFrameTime = currentTime;
// Limit FPS
if (this.targetFps < 60) {
const currentTime = performance.now();
const timeSinceLastFrame = currentTime - this.lastFrameTime;
if (timeSinceLastFrame < this.frameInterval) {
return;
}
this.lastFrameTime = currentTime;
}
}
const gl = this.gl!;