Gazebo Rendering

API Reference

7.4.2
gz/rendering/base/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 GZ_RENDERING_BASE_BASERENDERTARGET_HH_
18 #define GZ_RENDERING_BASE_BASERENDERTARGET_HH_
19 
20 #include <string>
21 #include <vector>
22 
25 #include "gz/rendering/Scene.hh"
27 
28 namespace gz
29 {
30  namespace rendering
31  {
32  inline namespace GZ_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  // Documentation inherited.
110  public: virtual void MetalId(void *_textureIdPtr) const override;
111  };
112 
113  template <class T>
115  public virtual RenderWindow,
116  public virtual T
117  {
118  public: BaseRenderWindow();
119 
120  public: virtual ~BaseRenderWindow();
121 
122  public: virtual std::string Handle() const;
123 
124  public: virtual void SetHandle(const std::string &_handle);
125 
126  public: virtual double DevicePixelRatio() const;
127 
128  public: virtual void SetDevicePixelRatio(const double _ratio);
129 
130  public: virtual void OnResize(const unsigned int _width,
131  const unsigned int _height);
132 
133  public: virtual void OnMove();
134 
135  protected: std::string handle;
136 
137  protected: double ratio = 1.0;
138  };
139 
141  // BaseRenderTarget
143  template <class T>
145  {
146  }
147 
149  template <class T>
151  {
152  }
153 
155  template <class T>
157  {
158  T::PreRender();
159  this->Rebuild();
160  for (auto &pass : this->renderPasses)
161  pass->PreRender();
162  }
163 
165  template <class T>
167  {
168  T::PostRender();
169  }
170 
172  template <class T>
174  {
175  if (this->targetDirty)
176  {
177  this->RebuildImpl();
178  this->targetDirty = false;
179  }
180  }
181 
183  template <class T>
184  unsigned int BaseRenderTarget<T>::Width() const
185  {
186  return this->width;
187  }
188 
190  template <class T>
191  void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
192  {
193  this->width = _width;
194  this->targetDirty = true;
195  }
196 
198  template <class T>
199  unsigned int BaseRenderTarget<T>::Height() const
200  {
201  return this->height;
202  }
203 
205  template <class T>
206  void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
207  {
208  this->height = _height;
209  this->targetDirty = true;
210  }
211 
213  template <class T>
215  {
216  return this->format;
217  }
218 
220  template <class T>
222  {
223  this->format = PixelUtil::Sanitize(_format);
224  this->targetDirty = true;
225  }
226 
228  template <class T>
230  {
231  return this->Scene()->BackgroundColor();
232  }
233 
235  template <class T>
237  {
238  this->renderPasses.push_back(_pass);
239  this->renderPassDirty = true;
240  }
241 
243  template <class T>
245  {
246  auto it = std::find(this->renderPasses.begin(), this->renderPasses.end(),
247  _pass);
248  if (it != this->renderPasses.end())
249  {
250  (*it)->Destroy();
251  this->renderPasses.erase(it);
252  this->renderPassDirty = true;
253  }
254  }
255 
257  template <class T>
259  {
260  return this->renderPasses.size();
261  }
262 
264  template <class T>
266  const
267  {
268  if (_index > this->renderPasses.size())
269  {
270  gzerr << "RenderPass index out of range: " << _index << std::endl;
271  return RenderPassPtr();
272  }
273  return this->renderPasses[_index];
274  }
275 
277  // BaseRenderTexture
279  template <class T>
281  {
282  }
283 
285  template <class T>
287  {
288  }
289 
291  template <class T>
292  unsigned int BaseRenderTexture<T>::GLId() const
293  {
294  return 0u;
295  }
296 
298  template <class T>
299  void BaseRenderTexture<T>::MetalId(void *) const
300  {
301  }
302 
304  // BaseRenderWindow
306  template <class T>
308  {
309  }
310 
312  template <class T>
314  {
315  }
316 
318  template <class T>
320  {
321  return this->handle;
322  }
323 
325  template <class T>
327  {
328  this->handle = _handle;
329  this->targetDirty = true;
330  }
331 
333  template <class T>
335  {
336  return this->ratio;
337  }
338 
340  template <class T>
342  {
343  this->ratio = _ratio;
344  this->targetDirty = true;
345  }
346 
348  template <class T>
349  void BaseRenderWindow<T>::OnResize(const unsigned int _width,
350  const unsigned int _height)
351  {
352  this->width = _width;
353  this->height = _height;
354  this->targetDirty = true;
355  }
356 
358  template <class T>
360  {
361  this->targetDirty = true;
362  }
363  }
364  }
365 }
366 #endif