I'm writing a Falling Sand Simulator and I'm trying to determine the best way to draw on the screen. I noticed Texture2D.SetData is pretty slow but Im not sure what is making it slow.
I trying to figure out a way to spend up draws.
Which case would be the fastest?
Case A (Currently, What I am doing):
Create a pixel array. Update it, then use the pixel array in the Texture2D.SetData Method
Case B:
Separate the pixel array and texture into small chucks. Each chuck could have its own pixel array and texture. When it's time to draw, only draw a chuck if something changed in that chuck last frame.
Case C (might not be possible):
Have one pixel array but two textures. One texture is called front buffer and the another called back buffer. When the program starts, set both textures with the pixel array. On every draw, run a thread to set the pixel array to the back buffer and when thread finishes, the main thread swaps the front buffer and back buffer textures. The sole idea is to stop the Texture2D.SetData Method from blocking the main thread.
SetDatathat accepts aRectto specify which part of the texture to update