Hi,
I am completely new to the mipmapping technique. I have read some documents over the MSDN, but somehow I cannot connect all of the pieces together.
I'd like to have generated mipmaps for my terrain. I have a DDS texture which is loaded by using:
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device*, _In_z_ const wchar_t*, _Out_opt_ ID3D11Resource**, _Out_opt_ ID3D11ShaderResourceView**, _In_ size_t maxsize = 0 )
from DirectXTK. So, by reading the document http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx I wrote such code:
_result = CreateDDSTextureFromFile( device, filename, &_texture, NULL );
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
D3D11_RESOURCE_DIMENSION type;
_texture->GetType( &type );
if( type == D3D11_RESOURCE_DIMENSION_TEXTURE2D ) {
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D *pTexture2D = (ID3D11Texture2D*)_texture;
pTexture2D->GetDesc( &desc );
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = desc.MipLevels; // when I put here 0 I can't see my terrain
srvDesc.Texture2D.MostDetailedMip = desc.MipLevels - 1;
ID3D11ShaderResourceView *pSRView = NULL; device->CreateShaderResourceView( _texture, &srvDesc, &m_texture );}
after that, in the place where I pass resources to shaders I put:
// ...
deviceContext->Unmap( m_lightBuffer, 0 );
// here is what I add, the "texture" is the "m_texture" from the code above
deviceContext->GenerateMips( texture );
deviceContext->PSSetConstantBuffers( 0, 1, &m_lightBuffer );
deviceContext->PSSetShaderResources(0, 1, &texture);
// ...
but it doesn't work, when I put to MipLevels 0 as it was written in some document to generate mipmaps my terrain doesn't show up. When I leave it with desc.MipLevels there are no mipmaps. What step did I overlook?
Thank you.