I have a big Color ColorMap in memory (1280x720), and I have a Texture2D that I've uploaded this ColorMap to. I update parts of the in-memory ColorMap, and want to upload those changed parts to the texture. I'd rather not reupload the entire texture every time, so I'd like to use
public void SetData<T> ( int level, Nullable<Rectangle> rect, T data, int startIndex, int elementCount )
As far as I can see, I can not use this directly to upload just a part of my in-memory map to the texture since I can't specify a stride in the SetData method.
So say I'd like to update the area specified by DirtyRect, i'd first need to create a temporary in-memory buffer
Color tempBuffer = new Color[DirtyRect.Width*DirtyRect.Height];
then copy the wanted data from my ColorMap to the tempBuffer, and then upload the tempBuffer to my Texture2D like
Text.SetData<Color>(0, DirtyRect, tempBuffer, 0, DirtyRect.Width*DirtyRect.Height);
This seems to work - sometimes... But sometimes it appears in the wrong place ?!
If I get rid of the rectangle code and reupload the entire texture every time using
it works fine, so apparently I must be doing something wrong.
Anyone got any idea ? Or is there any code-example of updating only parts of a texture that I can have a look at (XNA 4) ?