Updating resources in SharpDX - why can I not map a dynamic texture?

Posted by sebf on Game Development See other posts from Game Development or by sebf
Published on 2011-11-28T21:39:36Z Indexed on 2011/11/29 2:10 UTC
Read the original article Hit count: 1989

Filed under:
|
|
|

I am trying to map a Texture2D resource in DirectX11 via SharpDX.

The resource is declared as a ShaderResource, with Default usage and the 'Write' CPU flag specified.

My call however fails with a generic exception from SharpDX:

_Parent.Context.MapSubresource(_Resource, 0, SharpDX.Direct3D11.MapMode.Write, SharpDX.Direct3D11.MapFlags.None, out stream);

I see from this question that it is supported. The MSDN docs and this other question hint that instead of using Context.MapSubresource() I should be using Texture2D.Map(), however, the DirectX11 Texture2D class does not define Map() (though it does for the DX10 equivalent).

If I call the above with MapMode.WriteDiscard, the call succeeds but in this case the previous content of the texture is lost, which is no good when I only want to update a section of it.

Has the Map() method been removed in DirectX11 or am I looking in the wrong place? Is the MapSubresource() method unsuitable or am I using it wrong?

© Game Development or respective owner

Related posts about directx

Related posts about directx11