Advertisement Jump to content
Sign in to follow this  

Loading a texture array a layer at a time

This topic is 1759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a piece of code that loads several textures into the layers of a texture array (which was created with a usage flag of D3D11_USAGE_STAGING).  Right now, I call:


D3D11DeviceContext->Map(Texture2DResource, 0, D3D11_MAP_WRITE, 0, &mappedResource)


Then I do a memcpy to the mappedResource.pData, with an offset based on the layer of the texture I want to load.  Then I Unmap.  (Every layer has the same dimensions and depth of course).


The problem is, I only see the last texture I loaded.  I had thought that since I wasn't using D3D11_MAP_WRITE_DISCARD, it would leave the untouched contents of the texture resource alone.


Is there a way to do what I want?  Or do I have to rework my architecture.  I understand that it would be faster and more efficient to have all my data at one time, Map once, and copy it all... but I'm still wondering if it's possible to load the layers individually.

Share this post

Link to post
Share on other sites

Ah!  So I was mistaken in my first analysis, it was only showing me the first texture i'd loaded!  Thanks mhagain, your response led me to the function D3D11CalcSubresource, which in turn led me to realize that the problem wasn't in the portion of my code where I mapped, memcpy'd, and unmapped (after I updated it per your response of specifying the subresource).  It was in the portion after, where I created the shader resource view and copied my texture set up as D3D11_USAGE_STAGING to one set up as D3D11_USAGE_DEFAULT.  I was only copying the first subresource.


Thanks again!

Edited by Funkymunky

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!