0
\$\begingroup\$

How does the HTML5 canvas know that all the drawing operations are complete and it's time to swap the buffer ? Program can have multiple draw calls at different places so how will it know when is the right time to swap the front and back buffers ?

\$\endgroup\$
1
  • \$\begingroup\$ why do you think it's double buffered? It just displays the stuff you draw to it the second it has some downtime \$\endgroup\$
    – Bálint
    Commented Apr 2, 2018 at 22:28

1 Answer 1

1
\$\begingroup\$

In HTML5, the browser lets you know when it's ready to paint the next frame via requestAnimationFrame. Usually, your "draw" calls happen within this callback.

In traditional games using double-buffering, the game loop itself dictates when the page flip occurs. A simple game loop might look like this:

loop {
    update()
    draw()
        // all the draw calls happen here
    flip()
}

So it doesn't matter where the draw calls are, at the game loop level it's well defined when they occur - usually between the update and flip.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .