The purpose of this libray is to abstract DirectX & OpenGL interop with Cuda.
It means that you can use Ogre::Texture and Ogre::HardwareVertexBuffer
with Cuda without having to bother which Ogre::RenderSystem is active (DX9, DX10 or GL).
Ogre::TexturePtr tex; Ogre::Cuda::Root* mCudaRoot = Ogre::Cuda::Root::createRoot(renderWindow, renderSystem); mCudaRoot->init();
Ogre::Cuda::Texture* mCudaTex = mCudaRoot->getTextureManager()->createTexture(tex);
//init mCudaTex->registerForCudaUse();
//on each Cuda update mCudaTex->map(); Ogre::Cuda::TextureDeviceHandle textureHandle = mCudaTex->getDeviceHandle(0, 0); mCudaTex->updateReading(textureHandle); cudaFunction(textureHandle->getPointer()); mCudaTex->updateWriting(textureHandle); mCudaTex->unmap();
//shutdown mCudaTex->unregister(); mCudaRoot->getTextureManager()->destroyTexture(mCudaTex); mCudaRoot->shutdown();
std::vector<Ogre::TexturePtr> textures; std::vector<Ogre::Cuda::CudaRessource*> ressources; Ogre::Cuda::Root* mCudaRoot = Ogre::Cuda::Root::createRoot(renderWindow, renderSystem); mCudaRoot->init();
for (unsigned int i=0; i<textures.size(); ++i) ressources.push_back(mCudaRoot->getTextureManager()->createTexture(textures[i]);
//init for (unsigned int i=0; i<ressources.size(); ++i) ressources[i]->registerForCudaUse();
//on each Cuda update mCudaRoot->map(ressources); //efficient way to map multiple ressources in one call for (unsigned int i=0; i<ressources.size(); ++i) { if (ressources[i]->getType() == Ogre::Cuda::TEXTURE_RESSOURCE) { Ogre::Cuda::TextureDeviceHandle textureHandle = static_cast<Ogre::Cuda::Texture*>(ressources[i])->getDeviceHandle(0, 0); ressources[i]->updateReading(textureHandle); cudaTextureFunction(textureHandle->getPointer()); ressources[i]->updateWriting(textureHandle); } else cudaVertexBufferFunction(static_cast<Ogre::Cuda::VertexBuffer*>(ressources[i])->getPointer()); } mCudaRoot->unmap(ressources);
//shutdown for (unsigned int i=0; i<ressources.size(); ++i) { ressources[i]->unregister(); if (ressources[i]->getType() == Ogre::Cuda::TEXTURE_RESSOURCE) { mCudaRoot->getTextureManager()->destroyTexture(ressources[i]); } else mCudaRoot->getVertexBufferManager ()->destroyVertexBuffer(ressources[i]); } mCudaRoot->shutdown();