Jump to content
  • Advertisement
Sign in to follow this  
MickeyMouse

DX11 DX11 CreateTexture2D + automatic mips + initial data

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

How shall one create 2D texture in DX11 with automatic mipmaps generation enabled and with initial data containing top mip level data?

Here's my code and it crashes inside CreateTexture2D call:

D3D11_TEXTURE2D_DESC desc;
[...]
desc.MipLevels = 0; // enable mipmaps generation during creation
[...]

D3D11_SUBRESOURCE_DATA initialData;
initialData.pSysMem = my_data;
initialData.SysMemPitch = my_pitch;
initialData.SysMemSlicePitch = 0;

ID3D11Texture2D* handle;
dx11device->CreateTexture2D(&desc, &initialData, &handle);

I guess the cause of the crash is due to CreateTexture2D expecting an array of D3D11_SUBRESOURCE_DATAs, one for each mip level. But this doesn't make any sense, does it? All I want is given top mip level create texture with full mip chain and autogenerate remaining mip levels at startup.

Thanks for any hints from DX11 gurus!

Share this post


Link to post
Share on other sites
Advertisement
You can't partially initialize a resource with data. You either set the data for all subresources, or for none. So you have these options:

1. Use ID3D11DeviceContext::UpdateSubresource to set the data for the first mip level, and then use GPU auto-generation
2. Use ID3D11DeviceContext::UpdateSubresource to set the data for the first mip level, and then use D3DX11FilterTexture to generate the mip maps
3. Create a texture with the same size/format with only 1 mip level that initialized with your data, then use CopyResource to copy it to the first mip level of the texture with the full mip chain
4. Create a texture with the same size/format with only 1 mip level that initialized with your data, then use D3DX11LoadTextureFromTexture to fill the mip levels of the texture with the full mip chain

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!