   DX11- "initialize a texture and view separately" SDK mistake?
  Im trying to load a texture separately of the view, and on the SDK theres this:ID3D11Texture2D * pTexture = NULL;ID3D11ShaderResourceView *pSRView = NULL;D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;D3D11_TEXTURE2D_DESC desc;// Load the texture and initialize an ID3D11Texture2D object.D3DX11CreateTextureFromFile( pDevice, L"sample.bmp", NULL, NULL, &pTexture, NULL );// Get a texture description to determine the texture// format of the loaded texture.pTexture2D->GetDesc( &desc );But D3DX11CreateTextureFromFile doesnt receive a ID3D11Texture, it receives a ID3D11Resource, with implicates that this example is all wrong, since you cant get a texture description from that like the sdk shows:// Get a texture description to determine the texture// format of the loaded texture.pTexture2D->GetDesc( &desc );So I checked on the DX10 SDK and indeed it does different:ID3D10Resource *pTexture = NULL;D3DX10CreateTextureFromFile( pDevice, L"sample.bmp", NULL, NULL, &pTexture, NULL );And so it takes the description like that:D3D10_TEXTURE2D_DESC desc;   ID3D10Texture2D *pTexture2D = (ID3D10Texture2D*)pTexture;   pTexture2D->GetDesc( &desc );   srvDesc.Format = desc.Format;   srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;   srvDesc.Texture2D.MipLevels = desc.MipLevels;   srvDesc.Texture2D.MostDetailedMip = desc.MipLevels -1;Wich is little more complex..I want know if I can do like the DX11 says but casting the param:ID3D11Texture2D *pTex2D = NULL;D3D11_TEXTURE2D_DESC texdesc = {0};D3DX11CreateTextureFromFile(pDevice_p,szTex,NULL,NULL,(ID3D11Resource**)&pTex2D, NULL );Will it works like expected? It seems to be working, since Im geting the description correctly. Is ok to do that?   
  ID3D11Texture2D inherits from ID3D11Resource, so it is a valid cast.   ;  To be entirely safe - and since the implementation of COM is allowed to change, you should QueryInterface() for the D3D11Texture2D instead of casting.  You're doing a down cast so this method will result in either NULL or the object you requested, which will allow you to detect error conditions.   ;  Casting a pointer to a pointer to a derived class (e.g. ID3D11Texture2D**) to a pointer to a pointer to a base class (e.g. ID3D11Resource**) is generally NOT safe, although it might work in some situations (e.g. if there is only single inheritance).However, to be on the safe side, you should never do this. Just pass a pointer to a real ID3D11Resource* and then use QueryInterface to downcast to ID3D11Texture2D*.   ;  Weird, im getting errors setting the mip levels that Im not understanding..I did like in the DX10 SDK:...//create texture:ID3D11Resource *pTex2D = NULL;//ID3D11Texture2D *pTex2D = NULL;//D3D11_TEXTURE2D_DESC texdesc = {0};if( D3DX11CreateTextureFromFile( pDevice_p, szTex, NULL, NULL, &pTex2D, NULL ) != S_OK ) return E_FAIL;//((ID3D11Texture2D*)pTex2D)->GetDesc( &texdesc );//not very safeID3D11Texture2D *pTex2D_tmp = NULL;pTex2D->QueryInterface( __uuidof(ID3D11Texture2D), (VOID**)&pTex2D_tmp );pTex2D_tmp->GetDesc( &texdesc );donne(pTex2D_tmp);//create shader resource view:D3D11_SHADER_RESOURCE_VIEW_DESC srvdesc; ZeroMemory( &srvdesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC) );srvdesc.Format = texdesc.Format;srvdesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;srvdesc.Texture2D.MipLevels = texdesc.MipLevels;srvdesc.Texture2D.MostDetailedMip = texdesc.MipLevels-1;if( pDevice_p->CreateShaderResourceView( pTex2D, &srvdesc, &pSRV_p ) != S_OK ){donne(pTex2D);return E_FAIL;}donne(pTex2D);...Notice that:srvdesc.Texture2D.MipLevels = texdesc.MipLevels;srvdesc.Texture2D.MostDetailedMip = texdesc.MipLevels-1;Makes sense right? But I get this error:The Dimensions of the View are invalid due to at least one of the following conditions. MostDetailedMip (value = 8) must be between 0 and MipLevels-1(WITCH IS EXACTLY WHAT IM DOING) of the Texture Resource, 8, inclusively. With the current MostDetailedMip, MipLevels (value = 9) must be between 1 and 1(WHAT?? I DONT GET IT..), inclusively, or -1 to default to all mips from MostDetailedMip, in order that the View fit on the Texture.If the miplevels returns 9, means 8 is the most detailed, with is what is being setted,  why it says MipLevels must be between 1 and 1?If i set MipLevels to 1 or -1 and let the mostdetailedmip with 0 it works btw..   