Jump to content
  • Advertisement
Sign in to follow this  
3DModelerMan

Manually creating textures in Direct3D11

This topic is 2142 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 working on texture loading with D3D11 and I want to be able to manually create textures with mip-maps. Basically I want to load textures using libpng and libjpeg and initialize them in D3D11 from an array of pixels (and I also plan to generate textures dynamically). I would like to be able to create textures with mip-maps and textures in the compressed formats, but nothing I've found will allow me to do that. Does anyone know how to initialize textures in D3D11 using an array of pixel values?

Share this post


Link to post
Share on other sites
Advertisement

The ID3D11Device::CreateTexture2D function has all of the functionality in there.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476521(v=vs.85).aspx

 

In particular, the source data is passed into CreateTexture2D via the D3D11_SUBRESOURCE_DATA structure as described in the MSDN page linked above.

How to handle mipmaps is also described in that page, under Remarks.

Note that png/jpeg are not native formats, and so cannot be used directly. They would have to be decompressed into a standard format, and then if you chose, recompressed into any of the BC formats etc.

Share this post


Link to post
Share on other sites

So I have to manually generate mip-maps and recompress as well? If that's the case then I guess I need to start reading up on downsampling algorithms...

Share this post


Link to post
Share on other sites

Okay. So I've been working on my texture loading. I found that the ID3D11DeviceContext has a GenerateMips method, but the resources have to be bound as render targets. Is there any significant overhead if I bind all of my textures as render targets? And also, can I bind 1D, 3D, and cube map textures as render targets to take advantage of the mip generation for them also?

Share this post


Link to post
Share on other sites

Okay. So I've been working on my texture loading. I found that the ID3D11DeviceContext has a GenerateMips method, but the resources have to be bound as render targets. Is there any significant overhead if I bind all of my textures as render targets?

That completely depends on the specific hardware you're using. It's certainly possible, but I would say that in all cases the performance difference would be small.

Share this post


Link to post
Share on other sites

Wait ... am I missing something,  I thought the first API supports automatically generating mip maps for you?

 

To generate mipmap levels automatically, set the number of mipmap levels to 0.

Share this post


Link to post
Share on other sites

So if I do that do I need to pass only the top level full resolution image data to the initData? Or do I use UpdateSubresource on the top mip level?

Share this post


Link to post
Share on other sites

So if I do that do I need to pass only the top level full resolution image data to the initData? Or do I use UpdateSubresource on the top mip level?

My experience is you just pass the top level full resolution image and then the routine internally computes and fills in the mip maps for you. Of course then you don't have control of the mip-map quality, but at least you get the work done for free :)

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!