2
我試圖將像素數據作爲字節數組映射到使用direct3d的動態紋理,由於某些原因導致的像素數據是黑色的並且沒有被轉移。我之前已經使用updatesubresource直接轉換了這段代碼,但現在我正在使用map/unmap。Direct3D映射像素黑色
ID3D11Texture2D* d3dtex = (ID3D11Texture2D*)textureHandle;
assert(d3dtex);
ID3D11DeviceContext* ctx = NULL;
m_Device->GetImmediateContext(&ctx);
D3D11_MAPPED_SUBRESOURCE mappedResource;
ZeroMemory(&mappedResource, sizeof(D3D11_MAPPED_SUBRESOURCE));
// Disable GPU access to the vertex buffer data.
ctx->Map(d3dtex, 0, D3D11_MAP_WRITE, 0, &mappedResource);
// Update the vertex buffer here.
memcpy(mappedResource.pData, dataPtr, textureWidth * textureHeight * 4);
// Reenable GPU access to the vertex buffer data.
ctx->Unmap(d3dtex, 0);