1
\$\begingroup\$

I'm using a geometry shader to generate polygons for my voxel terrain (marching cubes). The data is output into a buffer using the method shown in the article I link to below.

http://msdn.microsoft.com/en-us/library/bb205122%28v=vs.85%29.aspx

Is there any way to somehow extract the vertex data from the buffer, sort of like the inverse operation of this?

struct Vertex
{
    float x, y, z;
    float tu, tv;
}

Vertex[] data = new[] // this is what I want to get
{
    ...
};

DataStream stream = new DataStream(bufferSize, true, true);
stream.Write(data);
stream.Position = 0;
buffer = new Buffer(device, stream, description);
\$\endgroup\$
  • \$\begingroup\$ To clarify, you want to get access to the generated vertex data on the CPU? \$\endgroup\$ – Nathan Reed Jul 16 '12 at 16:51
  • \$\begingroup\$ Yes, because I want to extract the positions so that I can generate a collision mesh. \$\endgroup\$ – jmegaffin Jul 16 '12 at 17:35
1
\$\begingroup\$

You should be able to get CPU access to the data by using MapSubresource on the buffer (don't forget to unmap it when you're done). Be aware that this will cause a CPU/GPU sync, though: the CPU has to sit and wait for the GPU to finish all previous rendering before it can access the data. This is bad for performance if you're trying to do stuff in real-time.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.