I'm working on a project when I want to use GPU picking, basically it's all set up fine, assigning unique colors to objects etc. but my current problem is that when creating the 1x1 texture, it doesn't do this where the pointer is for some reason, but about -250 pixels in the x and y.
I start by rendering the scene to my own ID3D11RenderTargetView and then use GetResource() to copy this buffer data to a ID3D11Resource.
This all works fine and I know it is capturing it correctly because I'm using the DirectXTK function SaveWICTextureToFile() to save off this resource to a PNG - which I can open on the desktop and it looks fine.
I then create a D3D11_TEXTURE2D_DESC of height 1px and width 1px and call CreateTexture2D() to create this texture.
I then create a D3D11_BOX whose left is at mouse position X and top is at mouse position Y and whose width and height are both 1.
I then call CopySubresourceRegion() like so:
CopySubresourceRegion(texture1x1, 0, 0, 0, 0, textureFromRenderTargetView, 0, box1x1);
I then look at the pixel RGBA value but it's always wrong.
I thought I might be able to debug it by creating a larger texture and seeing where it thinks the "mouse pointer" is:
So I changed box to be 200x200 pixels rather than 1x1 and use the DirectXTK function to save it to a PNG.
If I compare the original buffer texture PNG and the new 200x200 PNG there is something weird going on. The 200x200's top left corner is nowhere near where the mouse point is, it is about -250 in the X and Y axes. And even weirder, the 200x200 image seems like it has been scaled up, when I overlay it onto the original buffer texture PNG the objects are definitely larger.
Does anyone know what is going on here and what I can do to solve it?
Below is my D3D11_TEXTURE2D_DESC I use for the 1x1 texture and also its D3D11_SUBRESOURCE_DATA:
D3D11_TEXTURE2D_DESC desc;
desc.Width = 1;
desc.Height = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA subData;
float buff[4] = {0,0,0,0};
subData.pSysMem = (void *)buff;
subData.SysMemPitch = 4;
subData.SysMemSlicePitch = 4;
device->CreateTexture2D(&tdesc, &subData, &texture1x1);
I then create the box to have a 1 pixel height and width, starting at the pointer position.
The strange thing is, this works fine on some devices but not others. When on my desktop and laptop it works fine but on my tablet (windows) it does this strange 200pixels off thing. Could it be something to do with resolution or something?
I really can't work out what's going on on this one particular device (which is the target device).
Any ideas?
Thanks for your time.
P.S. disclaimer: this is a cross-post from stackoverflow but I put that question up a week ago and have had no response so I thought I'd try here.