[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Proper way of rendering only when something changes

Seems like you'd do

 function changeSomething() {
    requestAnimationFrame(redraw, canvas);

function changeSomethingElse() {
    requestAnimationFrame(redraw, canvas);

If you want to not queue up multiple calls then wrap requestAnimationFrame as in

g_drawPending = false;
function requestDraw() {
   if (!g_drawPending) {
      requestAnimationFrame(redraw, canvas);

function redraw() {
   g_drawPending = false; // set this at the top incase something called inside here changes something
   // draw

On Fri, Jun 1, 2012 at 1:49 PM, Mikko Mononen <[email protected]> wrote:


Are there some general guidelines how to build a render loop where the
app only draws the scene when something changes? Pretty much all the
samples out there render in an infinite loop.

Our app currently renders only when something changes to save the
precious battery and fans. We're getting increasing amount of reports
from the users using bleeding edge Firefox or Chrome that rendering
does not work for them anymore. If we render stuff with infinite loop
using requestAnimationFrame(), everything works, but once rendering
only when stuff changes, the WenGL canvas is cleared when any element
state changes in DOM, i.e. hover changes element appearance of a

My diagnosis is a bit Chrome specific, but since we're getting similar
reports from FF users too, I'm worried that I'm missing something more


Mikko Mononen, Software Engineer
http://tinkercad.com - Solid modeling for artists & makers

You are currently subscribed to [email protected].
To unsubscribe, send an email to [email protected] with
the following command in the body of your email:
unsubscribe public_webgl