I’m developing a 2D game in Monogame. My game only redraws regions that have changed, leaving the contents of the backbuffer from previous draws. On my PC, this works as expected, but on my Droid Turbo 2, the backbuffer is filled with random garbage data between each draw.
To describe the effect further: when something changes, you’ll see it drawn to the screen for a single frame, and then is replaced with garbage the next frame. It looks like colored snow.
Why is this? Is it recreating the backbuffer anew each frame on Android for some reason? Is it possible its device specific behavior?
I understand that changing rendertargets will wipe the backbuffer, but I am not switching render targets. My game does not use any additional rendertargets. Experimentally, I changed the backbuffer to PreserveContents (I know this is slow) in PreparingDeviceSettings, but this does nothing. I assume it only preserves contents on a render target switch, which is not something I’m doing.
If I clear the backbuffer each frame and redraw the whole scene, it shows up correctly.
You cannot assume that the entire contents of the back buffer remains to the next draw. A back buffer is usually comprised of two or three buffers in a swap chain that are rotated every frame. One buffer is displayed while the next buffer is being rendered to. Also, 3D hardware these days is slow at preserving the contents of a back buffer because it has to do a memory copy of the entire buffer while stalling the GPU (no rendering can handle at this time). It is more common and quite often more efficient with modern 3D hardware to render the entire back buffer every frame.
I should have mentioned that I actually do account for multiple back buffers in the swap chain.
From my understanding, PreserveContents is fast on a GPU, but slow on specialized hardware (Xbox) or lack of a GPU:
But again, that’s only in the context of changing rendertargets, which I am not doing. Is there simply no way to reuse the same buffers over and over? I can save a lot of drawing calls since I can isolate the areas that have changed, which seems very useful on the mobile devices I’m targeting