sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.7k stars 639 forks source link

How should I use mapsubresource method? #821

Closed KySpace closed 8 years ago

KySpace commented 8 years ago

I've looked through a lot of archives but still cannot figure out how it works. Taking this overridden one for example. public DataBox MapSubresource(Buffer resource, MapMode mode, MapFlags flags, out DataStream stream)

  1. Is this method aiming to change the resource with stream. If it is, why would the stream be marked out as if it is an output value rather than input?
  2. If the above one is true, where can I stream my data into the stream to update the buffer? Has it to be between the Map and Unmap methods? And typically how should I stream it (Take vertex buffer for example, what would the format of streaming be like?)
  3. Is it advisable to call the MapSubresource method whenever GPU access is finished(after every frame), and call the UnmapSubresource next frame to allow GPU access so it may save more time when I am keep updating the data?

Thank you!

xoofx commented 8 years ago

First I suggest you to read documentation like "How to: Use dynamic resources" if you haven't seen it, lots of information in it.

Concerning your questions:

  1. yes but this method just return a native pointer to a memory location accessible through DataStream (DataStream is a wrapper around a native pointer). other overrides will return just the native buffer through a DataBox.
  2. between map and unmap through DataStream (or directly through the native pointers if you use different method overrides)
  3. no
KySpace commented 8 years ago

That helps @xoofx