I am writing some code to get around the annoying issue of references to RenderTarget2D objects being lost when an Android app is sent to the background. What I am trying to do is cache the raw data for these offscreen images when the app is sent to background using RenderTarget2D.GetData and then recreate them when the app is sent to the foreground using RenderTarget2D.SetData.
This is all kind of working apart from when the texture is recreated with SetData the colours are going all weird like the byte order has been changed or something. if I do the Get/Set process again on recreation it flips everything back to normal and things look fine!
Is this a bug or something I am doing wrong? My render targets are created with SurfaceFormat.Color so I’m guessing UInt32 is the correct format to use for storing the data here? The code is roughly analogous to this kind of thing…
UInt32 data; // on pause data = new UInt32[ texture.Width*texture.Height ]; texture.GetData<UInt32> (data); // on resume // first recreate the texture and then... texture.SetData<UInt32> (data); // all looks weird unless I add this again... texture.GetData<UInt32> (data); texture.SetData<UInt32> (data);
Any help appreciated…