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);