| 17 | } |
| 18 | |
| 19 | bool DX11Buffer::Update(ID3D11DeviceContext* context) |
| 20 | { |
| 21 | Buffer* buffer = GetBuffer(); |
| 22 | LogAssert(buffer->GetUsage() == Resource::Usage::DYNAMIC_UPDATE, "Buffer must be dynamic-update."); |
| 23 | |
| 24 | UINT numActiveBytes = buffer->GetNumActiveBytes(); |
| 25 | if (numActiveBytes > 0) |
| 26 | { |
| 27 | // Map the buffer. |
| 28 | ID3D11Buffer* dxBuffer = GetDXBuffer(); |
| 29 | D3D11_MAPPED_SUBRESOURCE sub; |
| 30 | DX11Log(context->Map(dxBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &sub)); |
| 31 | |
| 32 | // Copy from CPU memory. |
| 33 | if (mUpdateMapMode != D3D11_MAP_WRITE_DISCARD) |
| 34 | { |
| 35 | uint32_t offsetInBytes = buffer->GetOffset() * buffer->GetElementSize(); |
| 36 | char const* source = buffer->GetData() + offsetInBytes; |
| 37 | char* target = (char*)sub.pData + offsetInBytes; |
| 38 | std::memcpy(target, source, numActiveBytes); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | std::memcpy(sub.pData, buffer->GetData(), buffer->GetNumBytes()); |
| 43 | } |
| 44 | context->Unmap(dxBuffer, 0); |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | bool DX11Buffer::CopyCpuToGpu(ID3D11DeviceContext* context) |
| 50 | { |
nothing calls this directly
no test coverage detected