Advertisement

Jumbled Texture output when using D3D11_MAPPED_SUBRESOURCE and Map/Unmap

Started by May 05, 2019 04:08 PM
2 comments, last by Gaius Baltar 5 years, 8 months ago

I'm trying to change the data in a Texture2D with Map/Unmap and am running into an issue where the texture seems to only appear in the top 5th of the screen and the rest is just random pixels. (screenshot for clarification)

ZDjWgRH.png

Here's some code:

   


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

Can Someone please tell me what I'm doing wrong here?
I'd be happy to supply more code if needed.

Your rowSize is in bytes and you are using it as an index for a uint32_t array.

Advertisement
2 minutes ago, Magogan said:

Your rowSize is in bytes and you are using it as an index for a uint32_t array.

Thanks... I knew it was gonna be something simple... 

This topic is closed to new replies.

Advertisement