OGRE cannot add compositor to a CameraPlugin's Viewport?

asked 2015-04-29 10:14:23 -0600

Patrick de Kok gravatar image

I tried writing a gazebo::CameraPlugin to generate motion blur for the camera. For this, I wanted to use OGRE's Motion Blur compositor. However, addCompositor returns 0, indicating failure. Could anybody tell me what I am doing wrong here? Is it at all possible what I am trying to do?

Here is a minimal example:

#include "gazebo/gazebo.hh"
#include "gazebo/plugins/CameraPlugin.hh"

#include "OGRE/OgreCompositorManager.h"
#include "OGRE/OgreViewport.h"

#include <iostream>


namespace gazebo
{
  class CameraBlur : public CameraPlugin
  {
    public: CameraBlur() 
            : CameraPlugin() 
    {}

    public: void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
    {
      gzwarn << "Loading CameraBlur\n";
      // Don't forget to load the camera plugin
      CameraPlugin::Load(_parent, _sdf);

      Ogre::Viewport* v = /*CameraPlugin::*/parentSensor->GetCamera()->GetViewport();
      // See if viewport != NULL:
      gzwarn << "viewport ptr:" << v << '\n';
      gzwarn << "add compositor: " << Ogre::CompositorManager::getSingleton().addCompositor(v, "Motion Blur", -1) << '\n';
      // This doesn't do anything when above line fails
      Ogre::CompositorManager::getSingleton().setCompositorEnabled(v, "Motion Blur", true);
    }

    public: void OnNewFrame(const unsigned char *_image,
        unsigned int _width, unsigned int _height, unsigned int _depth,
        const std::string &_format)
    {}
  };

  GZ_REGISTER_SENSOR_PLUGIN(CameraBlur)
}
edit retag flag offensive close merge delete