Ich versuche gerade eine Textur die als ShaderResourceView vorliegt zu klonen aber das ganze funktioniert irgendwie nicht und CopyResource hängt sich auf.
Hier mein Code:
Code: Alles auswählen
ID3D10Texture2D* texture = NULL;
UINT* textureData = NULL;
D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
source->second->TextureResourceView->GetDesc(&SRVDesc);
textureData = (UINT*) calloc(pOwnerSource.GetXSize()*pOwnerSource.GetYSize(),sizeof(UINT));
if(!textureData)
return Core::Logging::LogError(L"Error allocating memory!");
for(UINT i=0;i<pOwnerSource.GetYSize();i++)
for(UINT j=0;j<pOwnerSource.GetXSize();j++)
*(textureData+pOwnerSource.GetXSize()*i+j) = 0xFFFFFFFF;
D3D10_TEXTURE2D_DESC textureDesc;
SecureZeroMemory(&textureDesc,sizeof(textureDesc));
textureDesc.Width = pOwnerSource.GetXSize();
textureDesc.Height = pOwnerSource.GetYSize();
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D10_USAGE_DEFAULT;
textureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA subResDesc;
subResDesc.pSysMem = textureData;
subResDesc.SysMemPitch = pOwnerSource.GetXSize()*sizeof(UINT);
subResDesc.SysMemSlicePitch = 0;
if(FAILED(d3DDevice->CreateTexture2D(&textureDesc,NULL,&texture)))
{
delete textureData;
return Core::Logging::LogError(L"CreateTexture2D failed!");
}
delete textureData;
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
SRVDesc.Format = textureDesc.Format;
SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = textureDesc.MipLevels;
if (FAILED(d3DDevice->CreateShaderResourceView(const_cast<ID3D10Texture2D *>(texture), &SRVDesc, &(destination->second->TextureResourceView))))
return Core::Logging::LogError(L"CreateShaderResourceView for texture failed!");
d3DDevice->CopyResource((ID3D10Resource*)(destination->second->TextureResourceView), (ID3D10Resource*)(source->second->TextureResourceView));
destination->second->Texture = source->second->Texture;
Karl
PS: Die Source-Textur wurde ursprünglich aus einer Datei geladen.