4

What does it mean by Page-Flipping?

Why do we need it in graphics programming?

user366312
  • 16,949
  • 65
  • 235
  • 452
  • 1
    http://en.wikipedia.org/wiki/Multiple_buffering#Page_flipping – Greg Hewgill Dec 26 '11 at 22:05
  • Short answer: draw the page in a buffer, so that it can be displayed once it's available. "Flipping" a page means swapping between a complete buffer and an in-progress buffer. – D.N. Dec 26 '11 at 22:06

2 Answers2

5

Page flipping is a simple hardware-assisted technique for flicker-free graphics which has been with us for decades.

It requires support from the hardware:

  • The video subsystem must have at least two areas of memory (pages) that can potentially be visible, of which only one is visible at any given moment.

  • The video subsystem supports some means whereby the software can select which of the two pages is visible. This is usually just a single instruction to the hardware, and the switch is instantaneous, because the hardware simply stops scanning one page and starts scanning the other page.

So, the idea is that at any given moment we keep one page visible, while on the other page we are doing the rendering of our next frame. Once we are done rendering the frame, we send the hardware instruction that instantaneously "flips" the visible page, which means that the page where we did our rendering now becomes visible, while the page that used to be visible becomes invisible and available for us to render the next frame in it. We repeat the process for each frame, always rendering on the invisible page while the user is seeing the visible page.

More elaborately, it works as follows:

  • We have two pages, A and B. In the beginning both pages are blank, page A is visible, page B is invisible.

  • We render our graphics frame on page B, which is invisible, so initially the user does not see it.

  • Once we are done rendering our frame in page B, we send the hardware instruction to flip the pages, so the user now starts seeing our rendering on page B.

  • We render our next frame on invisible page A, so the user does not see the rendering taking place. (That would be perceived as flicker.)

  • Once we are done rendering on page A, we flip the pages again, so now the user can see our newly rendered page, while the previously visible page now becomes invisible and available for rendering the next frame in it.

  • We keep repeating this procedure for each frame.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • 4
    Not just decades ago, it's still a completely relevant technique today. – Greg Hewgill Dec 26 '11 at 22:21
  • What is the modern alternative for page flipping is use? – user366312 Dec 26 '11 at 22:25
  • 2
    Isn't this the same as double-buffering? – Seth Carnegie Dec 26 '11 at 22:29
  • @Saqib I would say that double-buffering is the modern alternative of page flipping. (Without doubting what Greg Hewgill says.) – Mike Nakis Dec 26 '11 at 22:42
  • 2
    @Seth Carnegie it is very similar to double-buffering, but not the same. In double-buffering the video RAM is always in one place, and the CPU is always rendering in some area of system RAM which is off-screen, and then it copies that area onto the video RAM. – Mike Nakis Dec 26 '11 at 22:45
  • 1
    @MikeNakis: Double Buffering is usually implemented using page flipping. – datenwolf Dec 27 '11 at 13:22
  • @datenwolf well, perhaps nowadays, in games, and under full-screen scenarios only. But the concept of double-buffering is also used for example in the context of individual winforms controls, where of course there is no page flipping: the control renders itself in a buffer and then sends that buffer only to be displayed. – Mike Nakis Dec 27 '11 at 13:31
  • 1
    @MikeNakis: The latest windowing systems (AIGLX, Windows Aero, Quartz Extreme) are compositing. Programms no longer have to double buffer their individual widgets, but draw them single buffered into a off-screen buffer. From there the full screen image is composited into a page flipped double buffer. – datenwolf Dec 27 '11 at 13:34
  • @datenwolf I edited my answer to get rid of the incorrect bit about page flipping not being used anymore. – Mike Nakis Dec 27 '11 at 13:39
1

often its too slow to draw directly on the screen, visually, you see the drawing. So you draw on one page while showing another. then when its ready to be shown you 'page flip' to the fully drawn page, then you can start drawing on another page.

Makes for smooth animation.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156