D3D10: ERROR: ID3D10Device::DrawIndexed: The view dimension declared in the shader code does not match the view type bound to slot 0 of the Pixel Shader unit. This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH ]
Here is the resource creation:
//** Depth stencil
D3D10_TEXTURE2D_DESC TEXdesc;
TEXdesc.Width = REFRACMAP_SIZE;
TEXdesc.Height = REFRACMAP_SIZE;
TEXdesc.MipLevels = 1;
TEXdesc.ArraySize = 1;
TEXdesc.SampleDesc.Count = 1;
TEXdesc.SampleDesc.Quality = 0;
TEXdesc.Format = DXGI_FORMAT_D32_FLOAT;
TEXdesc.Usage = D3D10_USAGE_DEFAULT;
TEXdesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
TEXdesc.CPUAccessFlags = 0;
TEXdesc.MiscFlags = 0;
if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapDepth ) ) )
{
return false;
}
//** Depth stencil view
D3D10_DEPTH_STENCIL_VIEW_DESC DSVdesc;
DSVdesc.Format = TEXdesc.Format;
DSVdesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
DSVdesc.Texture2D.MipSlice = 0;
if( FAILED( g_pd3dDevice->CreateDepthStencilView( m_RefracMapDepth, &DSVdesc, &m_RefracMapDSV ) ) )
{
return false;
}
//** Render target view
TEXdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
TEXdesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapTexture ) ) )
{
return false;
}
D3D10_RENDER_TARGET_VIEW_DESC RTVdesc;
RTVdesc.Format = TEXdesc.Format;
RTVdesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
RTVdesc.Texture2D.MipSlice = 0;
if( FAILED( g_pd3dDevice->CreateRenderTargetView( m_RefracMapTexture, &RTVdesc, &m_RefracMapRTV ) ) )
{
return false;
}
//** Shader resource view
D3D10_SHADER_RESOURCE_VIEW_DESC SRVdesc;
SRVdesc.Format = TEXdesc.Format;
SRVdesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
SRVdesc.Texture2D.MipLevels = 1;
SRVdesc.Texture2D.MostDetailedMip = 0;
if( FAILED( g_pd3dDevice->CreateShaderResourceView( m_RefracMapTexture, &SRVdesc, &m_RefracMapSRV ) ) )
{
return false;
}
And setting the render target:
D3D10_VIEWPORT newVP;
newVP.Width = REFRACMAP_SIZE;
newVP.Height = REFRACMAP_SIZE;
newVP.MinDepth = 0;
newVP.MaxDepth = 1;
newVP.TopLeftX = 0;
newVP.TopLeftY = 0;
g_pd3dDevice->RSSetViewports( 1, &newVP );
float clearColour[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
g_pd3dDevice->ClearRenderTargetView( m_RefracMapRTV, clearColour );
g_pd3dDevice->ClearDepthStencilView( m_RefracMapDSV, D3D10_CLEAR_DEPTH, 1.0f, 0 );
g_pd3dDevice->OMSetRenderTargets( 1, &m_RefracMapRTV, m_RefracMapDSV );