BloomVisualPlugin.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2017 Open Source Robotics Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include <gazebo/rendering/Camera.hh>
  18. #include <gazebo/rendering/UserCamera.hh>
  19. #include <gazebo/rendering/Scene.hh>
  20. #include <gazebo/rendering/RenderingIface.hh>
  21. #include "BloomVisualPlugin.hh"
  22. namespace gazebo
  23. {
  24. /// \internal
  25. /// \class BloomVisualPlugin BloomVisualPlugin.hh
  26. /// \brief Private data for the BloomVisualPlugin class.
  27. class BloomVisualPluginPrivate
  28. {
  29. };
  30. }
  31. using namespace gazebo;
  32. GZ_REGISTER_VISUAL_PLUGIN(BloomVisualPlugin)
  33. /////////////////////////////////////////////////
  34. BloomVisualPlugin::BloomVisualPlugin()
  35. : dataPtr(new BloomVisualPluginPrivate)
  36. {
  37. }
  38. /////////////////////////////////////////////////
  39. BloomVisualPlugin::~BloomVisualPlugin()
  40. {
  41. }
  42. /////////////////////////////////////////////////
  43. void BloomVisualPlugin::Load(rendering::VisualPtr _visual,
  44. sdf::ElementPtr /*_sdf*/)
  45. {
  46. if (!_visual)
  47. gzerr << "Invalid visual pointer." << std::endl;
  48. auto scene = _visual->GetScene();
  49. for (unsigned int i = 0; i < scene->CameraCount(); ++i)
  50. {
  51. this->AddBloom(scene->GetCamera(i));
  52. }
  53. for (unsigned int i = 0; i < scene->UserCameraCount(); ++i)
  54. {
  55. rendering::CameraPtr cam =
  56. boost::dynamic_pointer_cast<rendering::Camera>(
  57. scene->GetUserCamera(i));
  58. this->AddBloom(cam);
  59. }
  60. return;
  61. }
  62. /////////////////////////////////////////////////
  63. void BloomVisualPlugin::AddBloom(rendering::CameraPtr _camera)
  64. {
  65. if (!_camera)
  66. return;
  67. Ogre::CompositorInstance *bloomInstance;
  68. bloomInstance =
  69. Ogre::CompositorManager::getSingleton().addCompositor(
  70. _camera->OgreViewport(), "Bloom");
  71. bloomInstance->setEnabled(true);
  72. }