(sorry deleted my first message as I realized there was a bug in the code, so I wanted to fix this before posting in case it fixed the issue).
I wanted to test ` CopyTextureToBuffer` functionality but have failed so far. I used the code below, which I copied for the most part from `CopyCommandValidationTests`.
When I look at the value of `WGPUBufferMapAsyncStatus` in SaveToFile the callback function called by ` MapAsync` I constantly get an error message.
- I create a basic texture (empty).
- Create a buffer to copy the data to.
- use CopyTextureToBuffer for the cmd.
- push the command to the queue.
- call MapAsync on the buffer so that it calls SaveToFile once the command has been fully executed.
I would appreciate your input as to what I need to do better here (if that's obvious) or how I should be doing it. Thank you.
```
void CaptureScreen()
{
uint64_t offset = 0;
uint32_t bytesPerPixel = GetTexelBlockSizeInBytes(kColorFormat);
uint32_t bytesPerRow = Align(width * bytesPerPixel, kTextureBytesPerRowAlignment);
uint32_t rowsPerImage = height;
// these are declared as globals
/* uint64_t */ bufferSize = BufferSizeForTextureCopy(width, height, 1);
/* wgpu::Buffer */ destination = CreateBuffer(bufferSize, wgpu::BufferUsage::CopyDst);
wgpu::ImageCopyBuffer imageCopyBuffer = CreateImageCopyBuffer(destination, offset, bytesPerRow, rowsPerImage);
wgpu::Texture source = Create2DTexture(device, wgpu::TextureDimension::e2D,
kColorFormat, width, height, 1, 1, 1);
wgpu::ImageCopyTexture imageCopyTexture = CreateImageCopyTexture(source, 1, {0, 0, 0});
wgpu::Extent3D extent3D = {width, height, 1};
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&imageCopyTexture, &imageCopyBuffer, &extent3D);
wgpu::CommandBuffer commands = encoder.Finish();
device.GetQueue().Submit(1, &commands);
destination.MapAsync(wgpu::MapMode::Read, 0, bufferSize, StoreImage, nullptr);
}
```