PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

using of two buffers instead of one in firework example?

Hello,

After what I downloaded PocketHAL 0.7.7 evaluation version, I decided to analyze examples to understand how the library works. Therefore, I looked at Firework example.

I noticed tha the firework is firsty drawn into m_buffer2 buffer, which is at one moment coppied to backbuffer returned by display->GetBackBuffer(), and this is then swapped via display->Swap(); to video RAM.

In other words, instead of using one buffer that would be flipped to the video ram, there is a second buffer used.

Is this approach somehow beneficial to PocketHAL? Logic says to me, that it is most likely a waste of computer resources. I understand the need of one buffer that is coppied to VRAM once, to avoid delays from waiting to vsync, but what that second buffer is good for?

Is is a technique I've read about, called DoubleBuffering?

Thank you,
with Regards,
Rene.
I think the main reason for the two buffers is for the fire routine. It needs access to the last frame as well as the new frame (look closely at DoFire). If you were drawing to the PHal buffer directly, you would still need to keep a copy for the fire to work correctly.
FastRX, hello..

I think I understand. Using two buffers is specific for Firework example.

Despite of this, I recall, when I studied double buffering, that multple buffers can increase frame rate a bit. Is that really correct and is using ot one more buffer worth of it?

Thank you and have a nice day,
Rene.

Btw: I will do some tests soon, firstly I need to construct some reasonable scene for testing.
PHal has the 'backbuffer' and the screen memory (video RAM), so there's your two buffers in relation to double buffering...

Really there's 4 buffers being used in the fireworks example - m_buffer1, m_buffer2, backbuffer, and video RAM.
FastRX,
Thank you. Now I am sure what double-buffering is about.

With regards,
Rene