|
@@ -604,16 +604,58 @@ bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
|
|
|
|
|
|
|
|
int levelWidth = GetLevelWidth(level);
|
|
int levelWidth = GetLevelWidth(level);
|
|
|
int levelHeight = GetLevelHeight(level);
|
|
int levelHeight = GetLevelHeight(level);
|
|
|
-
|
|
|
|
|
- int height = levelHeight;
|
|
|
|
|
- if (IsCompressed())
|
|
|
|
|
- height = (height + 3) >> 2;
|
|
|
|
|
-
|
|
|
|
|
- unsigned char* destPtr = (unsigned char*)dest;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ D3D11_TEXTURE2D_DESC textureDesc;
|
|
|
|
|
+ memset(&textureDesc, 0, sizeof textureDesc);
|
|
|
|
|
+ textureDesc.Width = levelWidth;
|
|
|
|
|
+ textureDesc.Height = levelHeight;
|
|
|
|
|
+ textureDesc.MipLevels = 1;
|
|
|
|
|
+ textureDesc.ArraySize = 1;
|
|
|
|
|
+ textureDesc.Format = (DXGI_FORMAT)format_;
|
|
|
|
|
+ textureDesc.SampleDesc.Count = 1;
|
|
|
|
|
+ textureDesc.SampleDesc.Quality = 0;
|
|
|
|
|
+ textureDesc.Usage = D3D11_USAGE_STAGING;
|
|
|
|
|
+ textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
|
|
|
+
|
|
|
|
|
+ ID3D11Texture2D* stagingTexture = 0;
|
|
|
|
|
+ graphics_->GetImpl()->GetDevice()->CreateTexture2D(&textureDesc, 0, &stagingTexture);
|
|
|
|
|
+ if (!stagingTexture)
|
|
|
|
|
+ {
|
|
|
|
|
+ LOGERROR("Failed to create staging texture for GetData");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unsigned srcSubResource = D3D11CalcSubresource(level, face, levels_);
|
|
|
|
|
+ D3D11_BOX srcBox;
|
|
|
|
|
+ srcBox.left = 0;
|
|
|
|
|
+ srcBox.right = levelWidth;
|
|
|
|
|
+ srcBox.top = 0;
|
|
|
|
|
+ srcBox.bottom = levelHeight;
|
|
|
|
|
+ srcBox.front = 0;
|
|
|
|
|
+ srcBox.back = 1;
|
|
|
|
|
+ graphics_->GetImpl()->GetDeviceContext()->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, (ID3D11Resource*)object_,
|
|
|
|
|
+ srcSubResource, &srcBox);
|
|
|
|
|
+
|
|
|
|
|
+ D3D11_MAPPED_SUBRESOURCE mappedData;
|
|
|
|
|
+ mappedData.pData = 0;
|
|
|
unsigned rowSize = GetRowDataSize(levelWidth);
|
|
unsigned rowSize = GetRowDataSize(levelWidth);
|
|
|
|
|
+ unsigned numRows = IsCompressed() ? (levelHeight + 3) >> 2 : levelHeight;
|
|
|
|
|
|
|
|
- /// \todo Implement
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ graphics_->GetImpl()->GetDeviceContext()->Map((ID3D11Resource*)stagingTexture, 0, D3D11_MAP_READ, 0, &mappedData);
|
|
|
|
|
+ if (mappedData.pData)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (unsigned row = 0; row < numRows; ++row)
|
|
|
|
|
+ memcpy((unsigned char*)dest + row * rowSize, (unsigned char*)mappedData.pData + row * mappedData.RowPitch, rowSize);
|
|
|
|
|
+ graphics_->GetImpl()->GetDeviceContext()->Unmap((ID3D11Resource*)stagingTexture, 0);
|
|
|
|
|
+ stagingTexture->Release();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ LOGERROR("Failed to map staging texture for GetData");
|
|
|
|
|
+ stagingTexture->Release();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool TextureCube::Create()
|
|
bool TextureCube::Create()
|