Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow frame rate to go past monitor refresh rate #2877

Closed
14 tasks
clay53 opened this issue May 10, 2018 · 9 comments
Closed
14 tasks

Allow frame rate to go past monitor refresh rate #2877

clay53 opened this issue May 10, 2018 · 9 comments

Comments

@clay53
Copy link

clay53 commented May 10, 2018

Nature of issue?

  • Found a bug
  • [ x ] Existing feature enhancement
  • New feature request

Most appropriate sub-area of p5.js?

  • Color
  • [ x ] Core/Environment/Rendering
  • Data
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

Which platform were you using when you encountered this?

  • Mobile/Tablet (touch devices)
  • [ x ] Desktop/Laptop
  • Others (specify if possible)

Details about the bug:

Feature enhancement details: Allow frame rates to go higher than the monitor's refresh rate. I think this is the problem because it is stated in issue #2372. In the old issue, it is said that you don't need to do this so it doesn't matter, but otherwise, my sketch would have an exceptionally large loop and the browser stops responding until it is finished. Also, it looks cool. Video of the problem: https://drive.google.com/file/d/1IXIWO-zYlG4n9B1v2Ufj2G1nJiOL4_iw/view?usp=sharing

@clay53 clay53 changed the title How to get frame rate to go past monitor refresh rate Get frame rate to go past monitor refresh rate May 11, 2018
@clay53 clay53 changed the title Get frame rate to go past monitor refresh rate Allow frame rate to go past monitor refresh rate May 11, 2018
@limzykenneth
Copy link
Member

The Google Drive link you shared is not shared publicly so I cannot see it. Can you briefly describe your use case?

@clay53
Copy link
Author

clay53 commented May 11, 2018

@limzykenneth Sorry, accidentally used my org acc - didn't know it was viewable to people in the org only - I'll upload it once I get back on my PC. I was developing a program to make a program to make an image out of other images - without just overlaying the images with a different color - however, looping through all the pixels on an image and drawing a image for each pixel (depending on settings) will cause the browser to be unresponsive for a long time, until it completes.
Edit: video: https://drive.google.com/file/d/1Cv1IQlfQgkSz49D7ITYo0HO_orzh-8Nj/view?usp=sharing

@meiamsome
Copy link
Member

Yeah, with the underlying requestAnimationFrame you are locked into whatever the browser gives you (not this is usually no higher than the monitor refresh rate, but it can be higher).

You can take control of the loop yourself with something along the lines of:

function setup() {
  // rest of setup
  noLoop();
}

function draw() {
  setTimeout(redraw, 10); // where 10 is the minimum time between frames in ms
  // rest of draw
}

or:

function setup() {
  // rest of setup
  noLoop();
  setInterval(redraw, 10); // where 10 is the minimum time between frames in ms
}

But you are not likely to have a stable FPS with this and you might see some browsers capping you harder. There are other performance issues with this, but yes - it is possible to go faster (I was able to achieve ~250 fps on my pc/browser with this by setting the minimum interval to 0ms, but with more complex draws this will inevitably slow down)

@clay53
Copy link
Author

clay53 commented May 26, 2018

@meiamsome Thank You! This solution works for me. However, do you know if this would be possible to enable/disable during runtime? If not then that's fine it doesn't make that huge of a difference.

@meiamsome
Copy link
Member

@clay53 you could try something like:

var customLoop = false;
function enableCustomLoop() {
  noLoop();
  customLoop = true;
}
function disableCustomLoop() {
  loop();
  customLoop = false;
}

function draw() {
  if(customLoop) {
    setTimeout(redraw, 10); // where 10 is the minimum time between frames in ms
  }
  // rest of draw
}

@Spongman
Copy link
Contributor

does the browser ever present the page any quicker than the requestAnimationFrame frequency? if not, it might just be easier to put a for loop inside the draw function.

function draw() {
  for (var i = 200 / frameRate(); i --> 0 ;) {
    myDraw();
  }
}

@clay53
Copy link
Author

clay53 commented May 26, 2018

@meiamsome Thanks! I'll try to implement this concept.

@clay53
Copy link
Author

clay53 commented May 26, 2018

@Spongman You actually anger me.

@clay53 clay53 closed this as completed May 26, 2018
@meiamsome
Copy link
Member

@Spongman I think that's browser dependant... I would be very surprised if they did allow you to render faster than that, but you can definitely simulate more frames, if, for example, you are trying to record the canvas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants