1

I am using OGRE for rendering some objects. At every frame, I would like to pass the resulting depth buffer to CUDA for running some kernels on it and computing a result.

How can I achieve this? How do I get access to the depth buffer in OGRE? How do I pass this to CUDA for processing? I do not need to write to the depth buffer in the CUDA kernels, it can be read-only.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
  • I don't believe you can get direct access to the depth buffer. But you might be able to render it to a texture and access the texture in a CUDA kernel. Also why cross post this on [SO] and Game Development? – talonmies Jun 17 '13 at 05:37
  • @talonmies: Hoping someone at gamedev knows about OGRE :) – Ashwin Nanjappa Jun 17 '13 at 06:02

1 Answers1

2

Passing buffers from Ogre to CUDA is possible like this:

LPDIRECT3DDEVICE9 mDevice;
renderWindow->getCustomAttribute("D3DDEVICE", (void*) &mDevice);

Ogre::HardwareVertexBufferSharedPtr vbuf =
    renderOp.vertexData->vertexBufferBinding->getBuffer(0); // or where your vertexData is stored.

Direct3DVertexBuffer9*  mD3D9VertexBuffer_1 =
static_cast<Ogre::D3D9HardwareVertexBuffer*>(vbuf.get())->getD3D9VertexBuffer(); 

Now you can do a cudaMemcopy(). More info: http://www.ogre3d.org/forums/viewtopic.php?f=5&t=47003&sid=a0b22c741f015e2fdf0a5862d12d2020&start=25

I have this working for the vertex buffer. I am not sure if this works correctly with a DepthBuffer, but at least you can try: IDirect3DSurface9* Ogre::D3D9Device::getDepthBuffer ( D3D9RenderWindow * renderWindow ). However I cannot find Information if this works or not (see http://www.ogre3d.org/docs/api/html/classOgre_1_1D3D9Device.html#a8e195a845ed22e0215d42abbc75d744e)

c_k
  • 1,746
  • 1
  • 20
  • 35
  • Corjin: Thanks. I'm on Linux, so OpenGL :) – Ashwin Nanjappa Jun 18 '13 at 13:15
  • I see your tag now. I don't have experience with that. However, maybe you can combine http://stackoverflow.com/questions/4499999/how-to-get-z-values-from-z-buffer and http://www.ogre3d.org/forums/viewtopic.php?p=296902. I cannot provide support, but maybe it is worthwhile to have look at it. – c_k Jun 20 '13 at 11:25
  • @Corjin: Thanks a lot. You've given enough leads to me to try an OpenGL solution :) – Ashwin Nanjappa Jun 21 '13 at 12:17
  • Sorry, couldn't find a way to do this with OpenGL :( – Ashwin Nanjappa Jul 16 '13 at 09:44