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!
DX11 CreateTexture2D + automatic mips + initial data
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement