Quickly update Texture2D on every frame?

Started by
2 comments, last by Discard_One 14 years, 2 months ago
Im trying to implement a 2D fluid simulation based on a paper by Jos Stam (grid based fluid) where I need to be able to update a grid of pixels (512x512) on the screen at each frame. Im a bit new to XNA but I have understood that pixels and lines etc doesnt exist in the world of a 3d-engine, its only triangles. But what is the best method to render a set of pixels like this? I have tried using a Texture2D but it is extremely slow to update for some reason. Is it really the best option? All pixels will change on every frame so the texture will be completely new every time. Is it better to draw each pixel with two triangles instead?
Advertisement
update shoud by fine as long you not READ from it
reading is catastrophal from graphic memory

i can easily play 50 real time 515x512 video streams on my comp
there also each freame needs to get to graphic memory
Maybee its my implementation thats not right:

protected override void Update(GameTime gameTime)
{
// for testing:
for (int y = 0; y < pixels.Height; ++y)
{
for (int x = 0; x < pixels.Width; ++x)
{
data[y * pixels.Width + x] = (based on gameTime)
}
}

GraphicsDevice.Textures[0] = null; // I seem to have to do this first...
pixels.SetData<Color>(data);

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.None);
spriteBatch.Draw(pixels, new Vector2(0, 0), null, Color.White);
spriteBatch.End();

base.Draw(gameTime);
}
data[y * pixels.Width + x] =

is executed 262,144 times
thats a lot

depending on what platform your target is DX11 compute shader is the perfect thing for this

EDIT

but the problem is not to copy the data to the graphic memory but to generate the data

This topic is closed to new replies.

Advertisement