Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

Tex.SetData(ColorMap);

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) ?

Cheers.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Never mind, I'll just go stand in the corner with my stupid-hat on :-/

There's nothing wrong with the SetData methods, I accidentally swapped a "point.X" with a "point.Y" in some code that would execute only very rarely. That it only showed up when I was using the SetData without rectangle was pure coincidence.

But one question remains - why do i need to copy part of my big ColorMap into a smaller version before I can upload the partial bit ? That's extremely inefficient ! Why isn't there a version where I can specify an array and a stride so I can copy straight from the source ?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.