dx10 创建CreateShaderResourceView()不成功,我把代码贴出来了,请大家帮忙指点下。
ID3D10Texture2D* depthMap = 0;
D3D10_TEXTURE2D_DESCtexDes;
texDes.Width=m_width;
texDes.Height=m_height;
texDes.Usage =D3D10_USAGE_DEFAULT;
texDes.BindFlags =D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE;
texDes.ArraySize=1;
texDes.MipLevels=1;
texDes.SampleDesc.Count=1;
texDes.SampleDesc.Quality=0;
texDes.MiscFlags=0;
texDes.Format=DXGI_FORMAT_R32_TYPELESS;
texDes.CPUAccessFlags=0;
HR( m_Device->CreateTexture2D( &texDes, 0, &depthMap ) );
D3D10_DEPTH_STENCIL_VIEW_DESCdepthDes;
depthDes.Format=DXGI_FORMAT_D32_FLOAT;
depthDes.ViewDimension=D3D10_DSV_DIMENSION_TEXTURE2D;
depthDes.Texture2D.MipSlice=0;
HR( m_Device->CreateDepthStencilView( depthMap, &depthDes, &m_DepthDSV ) );
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format=DXGI_FORMAT_D32_FLOAT;
srvDesc.ViewDimension=D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels =texDes.MipLevels;
srvDesc.Texture2D.MostDetailedMip =0;
HR( m_Device->CreateShaderResourceView( depthMap, &srvDesc, &m_DepthSRV ) );
ReleaseCOM( depthMap );
m_DepthSRV 为 0;是什么原因没能创建成功呢?
[解决办法]
楼主把srvDesc.Format= DXGI_FORMAT_D32_FLOAT; 改成srvDesc.Format = DXGI_FORMAT_R32_FLOAT;