Archive for April, 2010

Cuda integration with Ogre3D

April 26th, 2010

If you already start to play with Cuda you know that graphic interop is not an easy task. Indeed you need to register graphic ressources using different methods accordings to the Ogre::RenderSytem (DX9, DX10, GL). As Ogre3D main objective is to hide DirectX and OpenGL “specificities”,  I have decided to create a tiny lib for Ogre3D to help registering and mapping ressources for Cuda. This tiny lib, named Ogre::Cuda, helps registering Ogre::Texture and Ogre::HardwareVertexBuffer for Cuda.

This video is just a very basic example showing an integration of two Cuda samples inside Ogre3D. The vertex buffer and the 2D texture cuda kernels are part of the Nvidia GPU Computing SDK.

This library is in beta stage, there is still room for improvement, but the base are settled for a cross-platform and cross-graphics API way to use Cuda thanks to Ogre3D.

Source code and binary demo available on the demo page.

Utilisation example :

Ogre::TexturePtr texture;
Ogre::Cuda::Root* mCudaRoot = Ogre::Cuda::Root::createRoot(renderWindow, renderSystem);
mCudaRoot->init();
Ogre::Cuda::Texture* mCudaTex;
mCudaTex = mCudaRoot->getTextureManager()->createTexture(texture);
//init
mCudaTex->registerForCudaUse();
//on each Cuda update
mCudaTex->map();
Ogre::Cuda::TextureDeviceHandle textureHandle;
textureHandle = mCudaTex->getDeviceHandle(0, 0);
cudaFunction(textureHandle->getPointer());
mCudaTex->update(textureHandle); //reflect changes to the Ogre::Texture
mCudaTex->unmap();
//shutdown
mCudaTex->unregister();
mCudaRoot->shutdown();
Share

Multitouch prototype done using Awesomium and Ogre3D

April 9th, 2010

I just want to present a 3-years prototype done by my company with Ogre3D. I have designed the GUI and the spatio-temporal request manager.

Designing the GUI was particularly challenging because the timeline needs to handle multitouch gesture. I have chosen Awesomium to realize this timeline. The main reason was that I was very familiar with javascript prototyping and HTML5 canvas. I manage to create this timeline with Awesomium, but it turns out to be very hacky because javascript performance were very poor. See yourself on this demo page (working with Google Chrome, Opera 10.51 and maybe with Firefox 3.6).

The timeline was designed with a simple idea : all the gesture recognition are handle by a C++ Layer. Then the cursors events are translated into javascript function calls and the function are executed by the webpage. The main issue was that canvas drawing was slow and I was receiving cursors events every frame (meaning : the timeline needs a graphical update each frame). I finally found a solution to reduce timeline rendering to 25fps. The code can be found bellow :

var Interface = new function() {
   var _that  = this;
   var _rendering = false;
   var _skippedRenderingTime = new Date();
   this.TimeLine = new function() {
      this.render = function() {
         if (!_rendering) {
            _rendering = true;
            TimeLine.render();
            setTimeout(function() {
               _rendering = false;
               if ((new Date() - _skippedRenderingTime) < 45) {
                  _that.TimeLine.render();
               }
            }, 40); //25fps
         }
         else {
            _skippedRenderingTime = new Date();
         }
      };
   };
}
var TimeLine = new function() {
   this.render = function() {
      //do heavy canvas drawing
   };
};

The function “Interface.TimeLine.render();” is called each time the C++ needs a graphical update, but the javascript delay the rendering if it’s exceeds 25fps. It’s kinda hacky but the result is working properly.

Share