Why can I not map a dynamic texture in D3D?

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 18:04 UTC
Read the original article Hit count: 625

Filed under:
|

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

The resource is declared as a ShaderResource, with Dynamic 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 D3D 10 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 Direct3D 11 or am I looking in the wrong place? Is the MapSubresource() method unsuitable or am I using it wrong?

EDIT: I declared my resource as Dynamic with CPU Write Flags - not Default as I originaly wrote - sorry for the fairly huge 'typo' that changes the entire question!

© Game Development or respective owner

Related posts about directx11

Related posts about sharpdx