Before I start out, this is more of a "What is the best way to do this?" than anything else.
I have a set of proceedurally generated textures that get updated every few frames based on certain parameters. Currently I'm updating the whole texture each frame, but I want to move to only partially updating the textures (so I can increase the size without a massive overhead).
I've set up my quad drawing code to deal with the partial updates, but I'm wondering what the best way to go about doing them is.
Note: all code below is super simplified.
When I was doing full updates I was using something like this.
Texture2D resolvedTarget;
RenderTarget2D renderTarget;
void UpdateTextures()
{
// Setup quads for full update
device.SetRenderTarget(0, renderTarget);
// Draw quads to target
device.SetRenderTarget(0, null);
resolvedTarget = renderTarget.GetTexture();
}
void Draw()
{
effect.Parameters["texture"].SetValue(resolvedTarget)
// Draw texture to screen
}
This however doesn't work as soon as I perform a partial update, as the resolvedTarget then only contains the updated area.
I know in MDX I could pre-fill the render target each frame with resolvedTarget.GetSurfaceLevel(0), then perform my updates on top of that, but XNA doesn't seem to have an equivalent (I'm sure it used to, but that was probably in GS 1.0).
So, my current solution for partial updates is as follows. (Note: I've not had a chance to test this, as I'm away from my dev machine, but I don't see why it wouldn't work?):
RenderTarget2D resolvedTarget;
RenderTarget2D renderTarget;
void UpdateTextures()
{
// Setup quads for partial update
renderTarget = resolvedTarget;
device.SetRenderTarget(0, renderTarget);
// Draw quads to target
device.SetRenderTarget(0, null);
resolvedTarget = renderTarget;
}
void Draw()
{
effect.Parameters["texture"].SetValue(resolvedTarget.GetTexture())
// Draw texture to screen
}
This just seems... messy though, am I missing something obvious here? Is there an XNA equivalent to the GetSurfaceLevel method? Or is there a better way of partially updating a texture? (without drawing it in the background, then drawing my quads on top, which I guess would work)