使用 D3D11_MAPPED_SUBRESOURCE 和 Map/Unmap 时纹理输出混乱
Jumbled Texture output when using D3D11_MAPPED_SUBRESOURCE and Map/Unmap
我正在尝试使用 Map/Unmap 更改 Texture2D 中的数据,并且 运行 遇到纹理似乎仅出现在屏幕顶部 5 处而其余部分出现的问题只是随机像素。 (screenshot for clarification)
这是一些代码:
uint32_t* m_colorBuffer; //buffer to fill the texture with random colors
D3D11_SUBRESOURCE_DATA m_textureData;
ID3D11Texture2D* m_texture;
D3D11_MAPPED_SUBRESOURCE mappedResource;
m_deviceContext->Map(m_texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
uint32_t rowSize = 256 * 4;
BYTE* mappedData = reinterpret_cast<BYTE*>(mappedResource.pData);
for (int i = 0; i < 256; i++) {
memcpy(mappedData, &(m_colorBuffer[i*rowSize]), rowSize);
mappedData += mappedResource.RowPitch;
}
m_deviceContext->Unmap(m_texture, 0);
有人可以告诉我我做错了什么吗?
如果需要,我很乐意提供更多代码。
看起来我的 rowSize 是以字节为单位的,我用它来索引 m_colorBuffer。
我正在尝试使用 Map/Unmap 更改 Texture2D 中的数据,并且 运行 遇到纹理似乎仅出现在屏幕顶部 5 处而其余部分出现的问题只是随机像素。 (screenshot for clarification)
这是一些代码:
uint32_t* m_colorBuffer; //buffer to fill the texture with random colors
D3D11_SUBRESOURCE_DATA m_textureData;
ID3D11Texture2D* m_texture;
D3D11_MAPPED_SUBRESOURCE mappedResource;
m_deviceContext->Map(m_texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
uint32_t rowSize = 256 * 4;
BYTE* mappedData = reinterpret_cast<BYTE*>(mappedResource.pData);
for (int i = 0; i < 256; i++) {
memcpy(mappedData, &(m_colorBuffer[i*rowSize]), rowSize);
mappedData += mappedResource.RowPitch;
}
m_deviceContext->Unmap(m_texture, 0);
有人可以告诉我我做错了什么吗? 如果需要,我很乐意提供更多代码。
看起来我的 rowSize 是以字节为单位的,我用它来索引 m_colorBuffer。