Skip to content

Commit

Permalink
Ditch frame-limiter, causes flashing on resize due to render loop dif…
Browse files Browse the repository at this point in the history
…ferences.
  • Loading branch information
ProjectSynchro committed May 4, 2024
1 parent 27d3092 commit 88e184d
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions content/js/nebula_shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,16 @@ function init() {
resizeCanvas(); // Call resizeCanvas initially
window.addEventListener('resize', resizeCanvas); // Resize canvas when window is resized

let startTime = performance.now();
let lastRenderTime = 0;
const refreshRate = 1000 / 15; // Limit to 15 frames per second to reduce performance impact

function renderCanvas(currentTime) {
if (currentTime - lastRenderTime >= refreshRate) {
const time = (performance.now() - startTime) / 1000;
gl.uniform1f(gl.getUniformLocation(program, 'u_time'), time);
function renderCanvas() {
gl.uniform1f(gl.getUniformLocation(program, 'u_time'), (performance.now()) / 1000);

gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);

gl.drawArrays(gl.TRIANGLES, 0, 3);

lastRenderTime = currentTime;
}

gl.drawArrays(gl.TRIANGLES, 0, 3);

requestAnimationFrame(renderCanvas);
}

// Start rendering loop
requestAnimationFrame(renderCanvas);
}
Expand Down

0 comments on commit 88e184d

Please sign in to comment.