Skip to content

Commit

Permalink
Fixed bug in reading MSAA textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Helge Hecht committed Aug 18, 2020
1 parent 4e0952e commit 626aa08
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,24 @@ void D3D11RenderSystem::downloadTexture(buw::ReferenceCounted<buw::ITexture2D> i
region.back = 1;

bool copyAll = itexture->width() == dest.getWidth() && itexture->height() == dest.getHeight() && x == 0 && y == 0;
if (!getMSAAEnabled()) {
deviceContext_->CopySubresourceRegion(staging.Get(), 0, x, y, 0, tex.Get(), 0, !copyAll ? &region : nullptr);
if (texture->isMultisampled()) {
if (getMSAAEnabled()) {
const ComPtr<ID3D11Texture2D> msaaStaging = texture->getMSAAStagingTexture();

deviceContext_->ResolveSubresource(msaaStaging.Get(), 0, tex.Get(), 0, texture_2d_desc.Format);
deviceContext_->CopySubresourceRegion(staging.Get(), 0, x, y, 0, msaaStaging.Get(), 0, !copyAll ? &region : nullptr);
} else {
BLUE_LOG(error) << "Invalid state: Multisampled texture while MSAA is disabled.";
}
} else {
const ComPtr<ID3D11Texture2D> msaaStaging = texture->getMSAAStagingTexture();

deviceContext_->ResolveSubresource(msaaStaging.Get(), 0, tex.Get(), 0, texture_2d_desc.Format);
deviceContext_->CopySubresourceRegion(staging.Get(), 0, x, y, 0, msaaStaging.Get(), 0, !copyAll ? &region : nullptr);
deviceContext_->CopySubresourceRegion(staging.Get(), 0, x, y, 0, tex.Get(), 0, !copyAll ? &region : nullptr);
}

D3D11_MAPPED_SUBRESOURCE sub;
const auto result = deviceContext_->Map(staging.Get(), 0, D3D11_MAP_READ, 0, &sub);
if(FAILED(result)) {
if (FAILED(result)) {
BLUE_LOG(error) << "Mapping subresource failed. HRESULT: " << getHRESULTErrorText(result);
}


for (int row = 0; row < dest.getHeight(); row++) {
void* dst = dest.getData() + row * dest.getWidth();
Expand Down

0 comments on commit 626aa08

Please sign in to comment.