Jump to content
  • Advertisement
Gaius Baltar

DX11 Jumbled Texture output when using D3D11_MAPPED_SUBRESOURCE and Map/Unmap

Recommended Posts

Posted (edited)

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.

Edited by Gaius Baltar

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites
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... 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!