So my problem is that I have a buffer called the "lightbuffer", which has a bunch of stuff in it, and I want to be able to modify one or more elements of it, without having to rewrite the whole thing again. Specifically if I do:
result = devicecontext->Map(lightbuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result)) { die("map lightbuffer"); }
dataPtr2 = (dxapp::LightBufferType*)mappedResource.pData;
dataPtr2->diffuse = diffuse;
devicecontext->Unmap(lightbuffer, 0);
This code pretty much deletes everything except "diffuse" because I used "D3D11_MAP_WRITE_DISCARD". I tried using "D3D11_MAP_WRITE", so the rest of the lightbuffer wouldn't get screwed up, but FAILED(result) returned as true, so the mapping didn't work. I read on MSDN that I need to use "D3D11_CPU_ACCESS_WRITE" in the buffer description if I want to do this, but I do, my buffer description is as follows:
lightBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
lightBufferDesc.ByteWidth = sizeof(LightBufferType);
lightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
lightBufferDesc.MiscFlags = 0;
lightBufferDesc.StructureByteStride = 0;
result = mydevice->CreateBuffer(&lightBufferDesc, NULL, &mylightbuffer);
if(FAILED(result)) { return false; }
So what do I need to do to be able to modify elements of the buffer without rewriting the whole thing again?