Roger-random / ESP_8_BIT_composite

Color composite video code from ESP_8_BIT as an Arduino library
MIT License
125 stars 15 forks source link

Need a way to keep double buffers in sync with each other #11

Closed Roger-random closed 3 years ago

Roger-random commented 3 years ago

Bug introduced by double-buffering (v1.1.0)

Instead of clearing the screen and redrawing everything on every frame, some rendering libraries are optimized so that they only draw what is changed from one frame to the next. But with two buffers, the default behavior results in each frame being drawn on top of the image data from TWO frames ago. Such libraries require the two buffers be kept in sync so the image deltas are applied correctly.

Roger-random commented 3 years ago

Solution in 79bd668b8eb80ecdee8157b47c62d4042c90a7e2 is to add a new property bool ESP_8_BIT_GFX::copyAfterSwap.

The property defaults to false. If the client application sets it to true anytime after calling begin(), then once the front and back buffers are swapped, the newest data (now in front buffer) is copied over the two-frames-old data (now the back buffer) before returning from waitForFrame(). This memory copy operation will impose a minor performance penalty and is thus optional only for rendering frameworks that need it.

AnimatedGIF was one such framework. We now have an example of using the AnimatedGIF library enabled by the new copyAfterSwap property.

Example features the Cat and Galactic Squid by Emily Velasco. 7875097ad715f511eaf82c5fec8f8143877e98d5