Jump to content
  • Advertisement
Sign in to follow this  
Automagisk

Quickly update Texture2D on every frame?

This topic is 3083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!