I have a Texture3D
. I want to read a part of it from CPU side. (I'm using the SharpDX toolkit (v2.5.1).)
My data is always 0, but the output shows no errors.
This is the source texture:
testTex = Texture3D.New<float>(GraphicsDevice, wx, wy, wz, PixelFormat.R32.Float, texDat, TextureFlags.ShaderResource, sdx11.ResourceUsage.Default);
I'm trying to read part of it here:
tempFloat = new float[1];
TextureDescription stagedTexDesc = new TextureDescription()
{
Height = 1,
Width = 1,
Depth = 1,
MipLevels = 1,
ArraySize = 1,
Format = testTex.Format,
Usage = sdx11.ResourceUsage.Staging,
CpuAccessFlags = sdx11.CpuAccessFlags.Read | sdx11.CpuAccessFlags.Write,
};
texNew = Texture3D.New(GraphicsDevice, stagedTexDesc);
deviceContext.CopySubresourceRegion(testTex, 0, new sdx11.ResourceRegion(iHPos.X, iHPos.Y, iHPos.Z, iHPos.X + 1, iHPos.Y + 1, iHPos.Z + 1), texNew, 0);
texNew.GetData(tempFloat);
tempFloat[0]
value is always 0.0. The GetData
method performs Map
and Unmap
of the resource automatically
If I try to call GetData
on the original texture, it seems to get the data correctly.
Also, is there a better way to read the data?