Why can I not map a dynamic texture in D3D?
- by sebf
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!