Gazebo Rendering

API Reference

6.7.0
gz/rendering/ogre2/Ogre2RenderTarget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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 #ifndef GZ_RENDERING_OGRE2_OGRE2RENDERTARGET_HH_
18 #define GZ_RENDERING_OGRE2_OGRE2RENDERTARGET_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <gz/math/Color.hh>
24 
30 
31 #ifdef _MSC_VER
32  #pragma warning(push, 0)
33 #endif
34 #include <Compositor/OgreCompositorShadowNode.h>
35 #ifdef _MSC_VER
36  #pragma warning(pop)
37 #endif
38 
39 namespace Ogre
40 {
41  class Camera;
42  class RenderTarget;
43  class Texture;
44 }
45 
46 namespace ignition
47 {
48  namespace rendering
49  {
50  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
51  //
52  // forward declaration
53  class Ogre2RenderTargetPrivate;
54 
56  class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2RenderTarget :
57  public virtual BaseRenderTarget<Ogre2Object>
58  {
60  protected: Ogre2RenderTarget();
61 
63  public: virtual ~Ogre2RenderTarget();
64 
66  public: virtual unsigned int AntiAliasing() const;
67 
70  public: virtual void SetAntiAliasing(unsigned int _aa);
71 
74  public: virtual void Copy(Image &_image) const override;
75 
82  private: bool CopyToBuffer(const PixelBuffer &_dst) const;
83 
86  public: virtual Ogre::Camera *Camera() const;
87 
90  public: virtual void SetCamera(Ogre::Camera *_camera);
91 
92  // Documentation inherited
93  public: virtual math::Color BackgroundColor() const override;
94 
97  public: virtual void SetBackgroundColor(math::Color _color);
98 
101  public: virtual void SetBackgroundMaterial(MaterialPtr _material);
102 
105  public: virtual MaterialPtr BackgroundMaterial() const;
106 
107  // Documentation inherited
108  public: virtual void PreRender() override;
109 
110  // Documentation inherited
111  public: virtual void PostRender() override;
112 
114  public: virtual void Render();
115 
117  public: virtual void Destroy() override = 0;
118 
122  public: void SetMaterial(MaterialPtr _material);
123 
125  public: void SetShadowsNodeDefDirty();
126 
130  protected: uint8_t TargetFSAA() const;
131 
135  protected: Ogre::TextureGpu *RenderTargetImpl() const;
136 
139  public: virtual Ogre::TextureGpu *RenderTarget() const = 0;
140 
143  public: virtual bool IsRenderWindow() const;
144 
145  // Documentation inherited
146  public: unsigned int GLIdImpl() const;
147 
149  protected: void DestroyTargetImpl();
150 
152  protected: void BuildTargetImpl();
153 
157  public: virtual uint32_t VisibilityMask() const;
158 
162  public: virtual void SetVisibilityMask(uint32_t _mask);
163 
165  public: static void UpdateRenderPassChain(
166  Ogre::CompositorWorkspace *_workspace,
167  const std::string &_workspaceDefName,
168  const std::string &_baseNode, const std::string &_finalNode,
169  const std::vector<RenderPassPtr> &_renderPasses,
170  bool _recreateNodes,
171  Ogre::TextureGpu *(*_ogreTextures)[2],
172  bool _isRenderWindow);
173 
175  protected: virtual void UpdateBackgroundColor();
176 
178  protected: virtual void UpdateBackgroundMaterial();
179 
181  protected: virtual void UpdateRenderPassChain();
182 
184  protected: virtual void RebuildImpl() override;
185 
187  protected: virtual void RebuildTarget() = 0;
188 
190  protected: virtual void RebuildCompositor();
191 
193  protected: virtual void BuildCompositor();
194 
196  protected: virtual void DestroyCompositor();
197 
202  protected: void RebuildMaterial();
203 
205  protected: Ogre::Camera *ogreCamera = nullptr;
206 
209  protected: Ogre::CompositorWorkspace *ogreCompositorWorkspace = nullptr;
210 
213 
215  protected: Ogre::ColourValue ogreBackgroundColor;
216 
219 
221  protected: MaterialPtr material;
222 
225 
227  protected: bool colorDirty = true;
228 
231  protected: bool backgroundMaterialDirty = false;
232 
234  protected: unsigned int antiAliasing = 4;
235 
237  protected: uint32_t visibilityMask = IGN_VISIBILITY_ALL;
238 
241  };
242 
244  class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2RenderTexture :
245  public virtual BaseRenderTexture<Ogre2RenderTarget>
246  {
248  protected: Ogre2RenderTexture();
249 
251  public: virtual ~Ogre2RenderTexture();
252 
253  // Documentation inherited.
254  public: virtual void Destroy() override;
255 
256  // Documentation inherited
257  public: virtual void PreRender() override;
258 
259  // Documentation inherited
260  public: virtual void PostRender() override;
261 
262  // Documentation inherited
263  public: virtual unsigned int GLId() const override;
264 
265  // Documentation inherited
266  // TODO(anyone): this function should be removed.
267  // We didn't do it to preserve ABI.
268  public: virtual Ogre::TextureGpu *RenderTarget() const override;
269 
270  // Documentation inherited.
271  protected: virtual void RebuildTarget() override;
272 
274  protected: virtual void DestroyTarget();
275 
277  protected: virtual void BuildTarget();
278 
280  private: friend class Ogre2Scene;
281  };
282 
284  class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2RenderWindow :
285  public virtual BaseRenderWindow<Ogre2RenderTarget>
286  {
288  protected: Ogre2RenderWindow();
289 
291  public: virtual ~Ogre2RenderWindow();
292 
293  // Documentation inherited.
294  public: virtual void Destroy() override;
295 
296  // Documentation inherited.
297  public: virtual bool IsRenderWindow() const override;
298 
299  // Documentation inherited.
300  public: virtual Ogre::TextureGpu *RenderTarget() const override;
301 
302  // Documentation inherited.
303  protected: virtual void RebuildTarget() override;
304 
306  protected: virtual void BuildTarget();
307 
309  protected: Ogre::TextureGpu *ogreRenderWindow = nullptr;
310 
312  private: friend class Ogre2Scene;
313  };
314  }
315  }
316 }
317 #endif
Definition: gz/rendering/base/BaseRenderTarget.hh:38
Definition: gz/rendering/base/BaseRenderTarget.hh:101
Definition: gz/rendering/base/BaseRenderTarget.hh:114
Encapsulates a raw image buffer and relevant properties.
Definition: gz/rendering/Image.hh:40
Ogre2.x implementation of the render target class.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:58
virtual void SetVisibilityMask(uint32_t _mask)
Set visibility mask for the viewport associated with this render target.
virtual void Render()
Main render call.
virtual unsigned int AntiAliasing() const
Get the anti-aliasing level.
virtual void Copy(Image &_image) const override
Copy the render target buffer data to an image.
virtual void SetCamera(Ogre::Camera *_camera)
Set the ogre camera to use for this render target.
MaterialPtr backgroundMaterial
Background material of the render target.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:218
void RebuildMaterial()
Re-initializes render target material to apply a material to everything in the scene....
virtual void UpdateRenderPassChain()
Update the render pass chain.
virtual void SetBackgroundColor(math::Color _color)
Set the background color of the render target.
uint8_t TargetFSAA() const
Returns the FSAA to use based on supported specs by HW and value specified in Ogre2RenderTarget::Anti...
Ogre::ColourValue ogreBackgroundColor
Stores the background color of the render target.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:215
virtual Ogre::TextureGpu * RenderTarget() const =0
Get a pointer to the ogre render target containing the results of the render.
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
virtual void PostRender() override
Post process this object and any of its children after rendering.
virtual void SetBackgroundMaterial(MaterialPtr _material)
Set the background material of this camera.
virtual void RebuildCompositor()
Rebuild the compositor.
virtual bool IsRenderWindow() const
Returns true if this is a render window.
virtual ~Ogre2RenderTarget()
Destructor.
static void UpdateRenderPassChain(Ogre::CompositorWorkspace *_workspace, const std::string &_workspaceDefName, const std::string &_baseNode, const std::string &_finalNode, const std::vector< RenderPassPtr > &_renderPasses, bool _recreateNodes, Ogre::TextureGpu *(*_ogreTextures)[2], bool _isRenderWindow)
Update the render pass chain.
virtual void DestroyCompositor()
Destroy the compositor.
void BuildTargetImpl()
Build the render texture.
void SetMaterial(MaterialPtr _material)
Set a material to render on every object. This method is used for special cases like the render targe...
virtual void RebuildTarget()=0
Rebuild the render target.
Ogre::TextureGpu * RenderTargetImpl() const
Get a pointer to the ogre render target containing the results of the render (implemented separately ...
virtual void BuildCompositor()
Build the compositor.
virtual MaterialPtr BackgroundMaterial() const
Get the background material of this camera.
virtual uint32_t VisibilityMask() const
Get visibility mask for the viewport associated with this render target.
virtual void SetAntiAliasing(unsigned int _aa)
set the anti-aliasing level
void DestroyTargetImpl()
Destroy the render texture.
virtual void Destroy() override=0
Destroy the render target.
std::string ogreCompositorWorkspaceDefName
Ogre's compositor workspace definition name.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:212
virtual void UpdateBackgroundColor()
Update the background color.
Ogre2RenderTargetMaterialPtr materialApplicator
Helper class that applies the material to the render target.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:224
virtual void UpdateBackgroundMaterial()
Update the background material.
virtual math::Color BackgroundColor() const override
Get the background color of the render target. This should be the same as the scene background color.
virtual void RebuildImpl() override
Implementation of the Rebuild function.
virtual Ogre::Camera * Camera() const
Get a pointer to the internal ogre camera.
MaterialPtr material
a material used by for the render target
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:221
Ogre2.x implementation of the render texture class.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:246
virtual void BuildTarget()
Build the render texture.
virtual void RebuildTarget() override
Rebuild the render target.
virtual void DestroyTarget()
Destroy the render texture.
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
virtual void PostRender() override
Post process this object and any of its children after rendering.
virtual ~Ogre2RenderTexture()
Destructor.
virtual void Destroy() override
Destroy the render target.
virtual unsigned int GLId() const override
Returns the OpenGL texture Id. A valid Id is returned only.
virtual Ogre::TextureGpu * RenderTarget() const override
Get a pointer to the ogre render target containing the results of the render.
Ogre2.x implementation of the render window class.
Definition: gz/rendering/ogre2/Ogre2RenderTarget.hh:286
virtual void BuildTarget()
Build the render window.
virtual void RebuildTarget() override
Rebuild the render target.
virtual bool IsRenderWindow() const override
Returns true if this is a render window.
virtual ~Ogre2RenderWindow()
Destructor.
virtual void Destroy() override
Destroy the render target.
virtual Ogre::TextureGpu * RenderTarget() const override
Get a pointer to the ogre render target containing the results of the render.
Ogre2.x implementation of the scene class.
Definition: gz/rendering/ogre2/Ogre2Scene.hh:59
Non owning, writable view of a caller owned pixel buffer.
Definition: gz/rendering/PixelBuffer.hh:49
#define IGN_VISIBILITY_ALL
Render everything visibility mask.
Definition: gz/rendering/RenderTypes.hh:26
Definition: gz/rendering/ogre/OgreCamera.hh:28