I have been learning HLSL for DX11 and i am trying to stream the output of my kinect in to a texture, but i can't quite get it, i keep getting a bunch of errors.
I am using SlimDX and here is how i set up my texture.
uint[] rgb = new uint[depthMD.XRes * depthMD.YRes * 4];
ushort* pDepth = (ushort*)m_kinectServer.DepthMapGenerator.DepthMapPtr.ToPointer();
// set pixels
for (int y = 0; y < depthMD.YRes; ++y)
{
//byte* pDest = (byte*)data.Scan0.ToPointer() + y * data.Stride;
for (int x = 0; x < depthMD.XRes; x+=4, ++pDepth)
{
uint pixel = (uint)m_histogram[*pDepth];
rgb[(y * x) + x + 0] = pixel;
rgb[(y * x) + x + 1] = pixel;
rgb[(y * x) + x + 2] = pixel;
rgb[(y * x) + x + 3] = pixel;
}
}
SlimDX.Direct3D11.Texture2DDescription texDesc = new Texture2DDescription();
texDesc.Width = depthMD.XRes;
texDesc.Height = depthMD.YRes;
texDesc.MipLevels = 0;
texDesc.Format = Format.R32G32B32A32_UInt;
texDesc.Usage = ResourceUsage.Default;
texDesc.BindFlags = BindFlags.ShaderResource;
texDesc.CpuAccessFlags = CpuAccessFlags.None;
texDesc.OptionFlags = ResourceOptionFlags.None;
texDesc.ArraySize = 1;
texDesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
DataRectangle dataRect = new DataRectangle(32 * depthMD.XRes * 4, new DataStream(rgb, true, false));
m_kinectTexture = new Texture2D(DX11Context.Device, texDesc, dataRect);
I'm not sure if the format is right, i would have rather have used a direct pointer to the data (m_kinectServer.DepthMapGenerator.DepthMapPtr.ToPointer() but it return a void *
and ShaderResourceView.FromPointer() takes an IntPtr (not sure what this means i'm also pretty new at C#).
Any advice you can give me would be great, i'm getting the errors.
D3D11: ERROR: ID3D11Device::CreateTexture2D: pInitialData[1].pSysMem cannot be NULL. [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA ]
D3D11: ERROR: ID3D11Device::CreateTexture2D: pInitialData[1].SysMemPitch cannot be 0 [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA ]
D3D11: ERROR: ID3D11Device::CreateTexture2D: pInitialData[5].SysMemPitch cannot be 0 [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA ]
D3D11: ERROR: ID3D11Device::CreateTexture2D: pInitialData[7].pSysMem cannot be NULL. [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA ]
D3D11: ERROR: ID3D11Device::CreateTexture2D: pInitialData[8].pSysMem cannot be NULL. [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA ]