Jump to content
  • Advertisement
Sign in to follow this  
Ivan Peric

SlimDX (D3D10) Texture2PNG

This topic is 1588 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

I have a performance problem with converting Texture2D to PNG. Since I am a total noob at DirectX, I used the Texture2D.ToStream method to map texure data to png data, and it looks kinda slow to me.

 

All application does is draws 1000 random lines to texture and then exports that texture to stream (byte array is the final product). The proces is repeated many times (~100) to get a collection of different images and exporting texture to stream takes ~98% of application run time.

Is there an alternative way to map texture data to image data that will be faster?


 

Share this post


Link to post
Share on other sites
Advertisement

Image format conversion is not supposed to be a real-time operation (maybe except for the DXT format?), if that's what you're expecting. This conversion is also done on the CPU, which means that the texture is first copied from video memory to system memory, making it even slower. Even without the compression, copying the texture to a stream in system-memory or in a file is going to be slow.

Video games usually have special algorithms to predict when they have to pre-load extra textures from disk or from cached memory. You have to do the reverse of that: delay copying all of your data to memory/disk, until you know that somethign has actually changed. Combine that with saving your data as DXT, and you might get some speed improvements, though I can't promise anything spectacular.

Share this post


Link to post
Share on other sites

Thank you for your answer,

but I managed to speed things up on my own by writing my own method which does the following:

1) Creates Staging resource with CPU Read access
2) Copies resource from original Default resource to staging resource

3) Maps Staging resource and uses it's DataPointer to create BitmapResource

4) Creates the png with PngBitmapEncoder and created Bitmap resource.

This improved application run time ~60%.

 

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!