So here's my problem, I have a 2D array filled with values that I want to be accessed on the GPU. Firstly I thought it was best to use a texture2d to achieve this. This needs to be updated when I need to pass new values over to the GPU.
Having looked around for a solution I came across this: http://www.gamedev.net/topic/606100-solved-dx11-updating-texture-data/
This gave me a further idea of how to achieve something like this but I am still having trouble actually doing it.
At the moment there's not much code to show other than creation of a texture and the array that I need to pass over. I've tried many different options with them all resulting in either completely wrong textures or crashes. I'll show what I have so far though:
D3D11_TEXTURE2D_DESC desc2;
ZeroMemory(&desc2, sizeof(desc2));
desc2.Width = width;
desc2.Height = height;
desc2.ArraySize = 1;
desc2.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc2.Usage = D3D11_USAGE_DYNAMIC;
desc2.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc2.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc2.MipLevels = 1;
desc2.SampleDesc.Count = 1;
desc2.SampleDesc.Quality = 0;
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = grid;
data.SysMemPitch = desc2.Width * 16;
data.SysMemSlicePitch = 0;
device->CreateTexture2D(&desc2, NULL, &textureBuffer);
D3D11_MAPPED_SUBRESOURCE mappedResource;
deviceContext->Map(textureBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
memcpy(&mappedResource.pData, &data, width);
deviceContext->Unmap(textureBuffer, 0);
I know most of this is completely wrong. But hopefully it helps with visualising what I want. 'grid' is the 2D array data. Each value in the array is a float4 value.