Ogre::Cuda

Presentation

nvidia-cuda.jpg

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).

Utilization scheme :

Simple example with one texture to map

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();

Efficient way to map multiples CudaRessource (texture, vertex buffer) in one call

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();
 All Classes
Generated on Fri Jun 18 13:33:59 2010 for OgreCuda by  doxygen 1.6.3