Ignition Rendering

API Reference

5.1.0
BaseRenderTarget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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 IGNITION_RENDERING_BASE_BASERENDERTARGET_HH_
18 #define IGNITION_RENDERING_BASE_BASERENDERTARGET_HH_
19 
20 #include <string>
21 #include <vector>
22 
27 
28 namespace ignition
29 {
30  namespace rendering
31  {
32  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
33  //
34  template <class T>
36  public virtual RenderTarget,
37  public virtual T
38  {
39  public: BaseRenderTarget();
40 
41  public: virtual ~BaseRenderTarget();
42 
43  // Documentation inherited.
44  public: virtual void PreRender() override;
45 
46  // Documentation inherited.
47  public: virtual void PostRender() override;
48 
49  public: virtual unsigned int Width() const override;
50 
51  public: virtual void SetWidth(const unsigned int _width) override;
52 
53  public: virtual unsigned int Height() const override;
54 
55  public: virtual void SetHeight(const unsigned int _height) override;
56 
57  public: virtual PixelFormat Format() const override;
58 
59  public: virtual void SetFormat(PixelFormat _format) override;
60 
61  // Documentation inherited
62  public: virtual math::Color BackgroundColor() const override;
63 
64  // Documentation inherited
65  public: virtual void AddRenderPass(const RenderPassPtr &_pass) override;
66 
67  // Documentation inherited
68  public: virtual void RemoveRenderPass(const RenderPassPtr &_pass)
69  override;
70 
71  // Documentation inherited
72  public: virtual unsigned int RenderPassCount() const override;
73 
74  // Documentation inherited
75  public: virtual RenderPassPtr RenderPassByIndex(unsigned int _index)
76  const override;
77 
78  protected: virtual void Rebuild();
79 
80  protected: virtual void RebuildImpl() = 0;
81 
82  protected: PixelFormat format = PF_UNKNOWN;
83 
84  protected: bool targetDirty = true;
85 
87  protected: bool renderPassDirty = false;
88 
89  protected: unsigned int width = 0u;
90 
91  protected: unsigned int height = 0u;
92 
95  };
96 
97  template <class T>
99  public virtual RenderTexture,
100  public virtual T
101  {
102  public: BaseRenderTexture();
103 
104  public: virtual ~BaseRenderTexture();
105 
106  // Documentation inherited.
107  public: virtual unsigned int GLId() const override;
108  };
109 
110  template <class T>
112  public virtual RenderWindow,
113  public virtual T
114  {
115  public: BaseRenderWindow();
116 
117  public: virtual ~BaseRenderWindow();
118 
119  public: virtual std::string Handle() const;
120 
121  public: virtual void SetHandle(const std::string &_handle);
122 
123  public: virtual double DevicePixelRatio() const;
124 
125  public: virtual void SetDevicePixelRatio(const double _ratio);
126 
127  public: virtual void OnResize(const unsigned int _width,
128  const unsigned int _height);
129 
130  public: virtual void OnMove();
131 
132  protected: std::string handle;
133 
134  protected: double ratio = 1.0;
135  };
136 
138  // BaseRenderTarget
140  template <class T>
142  {
143  }
144 
146  template <class T>
148  {
149  }
150 
152  template <class T>
154  {
155  T::PreRender();
156  this->Rebuild();
157  for (auto &pass : this->renderPasses)
158  pass->PreRender();
159  }
160 
162  template <class T>
164  {
165  T::PostRender();
166  }
167 
169  template <class T>
171  {
172  if (this->targetDirty)
173  {
174  this->RebuildImpl();
175  this->targetDirty = false;
176  }
177  }
178 
180  template <class T>
181  unsigned int BaseRenderTarget<T>::Width() const
182  {
183  return this->width;
184  }
185 
187  template <class T>
188  void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
189  {
190  this->width = _width;
191  this->targetDirty = true;
192  }
193 
195  template <class T>
196  unsigned int BaseRenderTarget<T>::Height() const
197  {
198  return this->height;
199  }
200 
202  template <class T>
203  void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
204  {
205  this->height = _height;
206  this->targetDirty = true;
207  }
208 
210  template <class T>
212  {
213  return this->format;
214  }
215 
217  template <class T>
219  {
220  this->format = PixelUtil::Sanitize(_format);
221  this->targetDirty = true;
222  }
223 
225  template <class T>
227  {
228  return this->Scene()->BackgroundColor();
229  }
230 
232  template <class T>
234  {
235  this->renderPasses.push_back(_pass);
236  this->renderPassDirty = true;
237  }
238 
240  template <class T>
242  {
243  auto it = std::find(this->renderPasses.begin(), this->renderPasses.end(),
244  _pass);
245  if (it != this->renderPasses.end())
246  {
247  (*it)->Destroy();
248  this->renderPasses.erase(it);
249  this->renderPassDirty = true;
250  }
251  }
252 
254  template <class T>
256  {
257  return this->renderPasses.size();
258  }
259 
261  template <class T>
263  const
264  {
265  if (_index > this->renderPasses.size())
266  {
267  ignerr << "RenderPass index out of range: " << _index << std::endl;
268  return RenderPassPtr();
269  }
270  return this->renderPasses[_index];
271  }
272 
274  // BaseRenderTexture
276  template <class T>
278  {
279  }
280 
282  template <class T>
284  {
285  }
286 
288  template <class T>
289  unsigned int BaseRenderTexture<T>::GLId() const
290  {
291  return 0u;
292  }
293 
295  // BaseRenderWindow
297  template <class T>
299  {
300  }
301 
303  template <class T>
305  {
306  }
307 
309  template <class T>
311  {
312  return this->handle;
313  }
314 
316  template <class T>
318  {
319  this->handle = _handle;
320  this->targetDirty = true;
321  }
322 
324  template <class T>
326  {
327  return this->ratio;
328  }
329 
331  template <class T>
333  {
334  this->ratio = _ratio;
335  this->targetDirty = true;
336  }
337 
339  template <class T>
340  void BaseRenderWindow<T>::OnResize(const unsigned int _width,
341  const unsigned int _height)
342  {
343  this->width = _width;
344  this->height = _height;
345  this->targetDirty = true;
346  }
347 
349  template <class T>
351  {
352  this->targetDirty = true;
353  }
354  }
355  }
356 }
357 #endif
virtual ~BaseRenderTarget()
Definition: BaseRenderTarget.hh:147
virtual unsigned int GLId() const override
Returns the OpenGL texture Id. A valid Id is returned only.
Definition: BaseRenderTarget.hh:289
virtual PixelFormat Format() const override
Set the render target image format.
Definition: BaseRenderTarget.hh:211
virtual void SetHeight(const unsigned int _height) override
Set the render target height in pixels.
Definition: BaseRenderTarget.hh:203
Definition: BaseRenderTarget.hh:98
virtual void AddRenderPass(const RenderPassPtr &_pass) override
Add a render pass to the render target.
Definition: BaseRenderTarget.hh:233
virtual math::Color BackgroundColor() const =0
Get the scene background color.
virtual void PostRender() override
Post process this object and any of its children after rendering.
Definition: BaseRenderTarget.hh:163
std::vector< RenderPassPtr > renderPasses
A chain of render passes applied to the render target.
Definition: BaseRenderTarget.hh:94
virtual RenderPassPtr RenderPassByIndex(unsigned int _index) const override
Get a render pass by index.
Definition: BaseRenderTarget.hh:262
T endl(T... args)
virtual ~BaseRenderWindow()
Definition: BaseRenderTarget.hh:304
Definition: BaseRenderTarget.hh:35
virtual void RemoveRenderPass(const RenderPassPtr &_pass) override
Remove a render pass from the render target.
Definition: BaseRenderTarget.hh:241
virtual unsigned int RenderPassCount() const override
Get the number of render passes applied to the render target.
Definition: BaseRenderTarget.hh:255
virtual math::Color BackgroundColor() const override
Get the background color of the render target. This should be the same as the scene background color...
Definition: BaseRenderTarget.hh:226
STL class.
virtual void SetWidth(const unsigned int _width) override
Set the render target width in pixels.
Definition: BaseRenderTarget.hh:188
Represents a render-target to which cameras can render images.
Definition: RenderTarget.hh:37
virtual void SetDevicePixelRatio(const double _ratio)
Set the device to pixel ratio.
Definition: BaseRenderTarget.hh:332
virtual void SetHandle(const std::string &_handle)
Set the window handle to attach the render window to.
Definition: BaseRenderTarget.hh:317
virtual void Rebuild()
Definition: BaseRenderTarget.hh:170
shared_ptr< RenderPass > RenderPassPtr
Shared pointer to RenderPass.
Definition: RenderTypes.hh:202
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseRenderTarget.hh:153
virtual unsigned int Height() const override
Get render target height in pixels.
Definition: BaseRenderTarget.hh:196
Definition: BaseRenderTarget.hh:111
virtual unsigned int Width() const override
Get render target width in pixels.
Definition: BaseRenderTarget.hh:181
virtual double DevicePixelRatio() const
Get the device to pixel ratio.
Definition: BaseRenderTarget.hh:325
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:49
PixelFormat
Image pixel format types.
Definition: PixelFormat.hh:32
virtual std::string Handle() const
Get the window handle that the render window is attached to.
Definition: BaseRenderTarget.hh:310
Represents a off-screen render-texture to which cameras can render images.
Definition: RenderTarget.hh:103
std::string handle
Definition: BaseRenderTarget.hh:132
T find(T... args)
STL class.
Represents a on-screen render-window to which cameras can render images.
Definition: RenderTarget.hh:119
#define ignerr
virtual void SetFormat(PixelFormat _format) override
Set the render target image format.
Definition: BaseRenderTarget.hh:218
< Unknown or errant type
Definition: PixelFormat.hh:35
static PixelFormat Sanitize(PixelFormat _format)
Sanitize given format. If the given value is invalid, PF_UNKNOWN will be returned, otherwise input will be returned unchanged.
BaseRenderTarget()
Definition: BaseRenderTarget.hh:141
virtual ~BaseRenderTexture()
Definition: BaseRenderTarget.hh:283
BaseRenderTexture()
Definition: BaseRenderTarget.hh:277
virtual void OnMove()
Alert the window of a window move event.
Definition: BaseRenderTarget.hh:350
BaseRenderWindow()
Definition: BaseRenderTarget.hh:298
virtual void OnResize(const unsigned int _width, const unsigned int _height)
Alert the window of a window resize event.
Definition: BaseRenderTarget.hh:340