Jump to content
  • Advertisement
Sign in to follow this  
sebi707

How does D3DX10CreateTextureFromFile work?

This topic is 2129 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'm currently trying to get rid of all D3DX functions since those are deprecated in the Windows 8 SDK. So I want to replace the D3DX10CreateTextureFromFile with basic DX10 functions. The main problem I'm currently facing is to generate the mipmaps for the loaded texture. Things I've tried so far:

 

1) ID3D10Device::CreateTexture2D with D3D10_TEXTURE2D_DESC::MipLevels set to 1 and setting pInitialData to the image data.

2) ID3D10Device::CreateTexture2D with D3D10_TEXTURE2D_DESC::MipLevels set to 0 and uploading texture data through ID3D10Device::UpdateSubresource

 

The first gives me a texture without any mipmaps and the second gives me a texture with only the base image set and empty mipmaps. I've also looked at the ID3D10Device::GenerateMips function but this requires that I set the D3D10_BIND_RENDER_TARGET and D3D10_RESOURCE_MISC_GENERATE_MIPS flags and I'm woried that this degrades performance. If you look at the texture description of the texture created by D3DX10CreateTextureFromFile you will see that none of these flags are set so I wonder how does D3DX10CreateTextureFromFile create textures?

Share this post


Link to post
Share on other sites
Advertisement

Use ID3D10Device::GenerateMips to generate mips. Since you're worried about those flags you'll need to create texture with desired flags, then use ID3D10Device::CopyResource to copy data. You could look at DXTK to see how they function is actually implemented ( http://directxtk.codeplex.com/ ).

Share this post


Link to post
Share on other sites
I took a look at DXTK. It seems that the DDS loader only loads mipmaps already stored in the file. The WIC based image loader generates the mipmaps using the ID3D10Device::GenerateMips function and setting the required flags. I did a quick test and generated mipmaps in the same way and it doesn't look that there is a big performance hit. But I'm going to perform some more exact tests.

Edit: Well it looks like the is no measurable performance difference if the D3D10_BIND_RENDER_TARGET and D3D10_RESOURCE_MISC_GENERATE_MIPS flags are set.

Share this post


Link to post
Share on other sites

The main issue with using GenerateMips is that it won't work if you try to use a compressed texture format. If you decide that you want to use compression, you should use an offline tool (DirectXTex has one that you can use) to generate the mips, compress all of them, and save them to a DDS file.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!