| 24 | } |
| 25 | |
| 26 | bool DX11Texture::Update(ID3D11DeviceContext* context, uint32_t sri) |
| 27 | { |
| 28 | Texture* texture = GetTexture(); |
| 29 | LogAssert(sri < texture->GetNumSubresources(), "Subresource index out of range."); |
| 30 | LogAssert(texture->GetUsage() == Resource::Usage::DYNAMIC_UPDATE, "Texture must be dynamic-update."); |
| 31 | |
| 32 | // Map the texture. |
| 33 | ID3D11Resource* dxTexture = GetDXResource(); |
| 34 | D3D11_MAPPED_SUBRESOURCE sub; |
| 35 | DX11Log(context->Map(dxTexture, sri, D3D11_MAP_WRITE_DISCARD, 0, &sub)); |
| 36 | |
| 37 | // Copy from CPU memory. |
| 38 | auto sr = texture->GetSubresource(sri); |
| 39 | uint32_t numDimensions = texture->GetNumDimensions(); |
| 40 | if (numDimensions == 1) |
| 41 | { |
| 42 | std::memcpy(sub.pData, sr.data, texture->GetNumBytesFor(sr.level)); |
| 43 | } |
| 44 | else if (numDimensions == 2) |
| 45 | { |
| 46 | CopyPitched2(texture->GetDimensionFor(sr.level, 1), sr.rowPitch, |
| 47 | sr.data, sub.RowPitch, sub.pData); |
| 48 | } |
| 49 | else // numDimensions == 3 |
| 50 | { |
| 51 | CopyPitched3(texture->GetDimensionFor(sr.level, 1), |
| 52 | texture->GetDimensionFor(sr.level, 2), sr.rowPitch, sr.slicePitch, |
| 53 | sr.data, sub.RowPitch, sub.DepthPitch, sub.pData); |
| 54 | } |
| 55 | context->Unmap(dxTexture, sri); |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | bool DX11Texture::Update(ID3D11DeviceContext* context) |
| 60 | { |
nothing calls this directly
no test coverage detected