Gazebo Rendering

API Reference

8.2.1
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 // overloaded-virtuals warnings appeared on Ubuntu Noble
29 // GCC-13. it is not easy to fix them without breaking ABI
30 // ignore them to preserve current ABI.
31 #if defined(__GNUC__) || defined(__clang__)
32 # pragma GCC diagnostic push
33 # pragma GCC diagnostic ignored "-Woverloaded-virtual"
34 #endif
35 
36 namespace gz
37 {
38  namespace rendering
39  {
40  inline namespace GZ_RENDERING_VERSION_NAMESPACE {
41  //
42  template <class T>
44  public virtual RenderTarget,
45  public virtual T
46  {
47  public: BaseRenderTarget();
48 
49  public: virtual ~BaseRenderTarget();
50 
51  // Documentation inherited.
52  public: virtual void PreRender(const CameraPtr &_camera) override;
53 
54  // Documentation inherited.
55  public: virtual void PreRender() override;
56 
57  // Documentation inherited.
58  public: virtual void PostRender() override;
59 
60  public: virtual unsigned int Width() const override;
61 
62  public: virtual void SetWidth(const unsigned int _width) override;
63 
64  public: virtual unsigned int Height() const override;
65 
66  public: virtual void SetHeight(const unsigned int _height) override;
67 
68  public: virtual PixelFormat Format() const override;
69 
70  public: virtual void SetFormat(PixelFormat _format,
71  bool _reinterpretable = false) override;
72 
73  // Documentation inherited
74  public: virtual bool Reinterpretable() const override;
75 
76  // Documentation inherited
77  public: virtual math::Color BackgroundColor() const override;
78 
79  // Documentation inherited
80  public: virtual void AddRenderPass(const RenderPassPtr &_pass) override;
81 
82  // Documentation inherited
83  public: virtual void RemoveRenderPass(const RenderPassPtr &_pass)
84  override;
85 
86  // Documentation inherited
87  public: void RemoveAllRenderPasses() override;
88 
89  // Documentation inherited
90  public: virtual unsigned int RenderPassCount() const override;
91 
92  // Documentation inherited
93  public: virtual RenderPassPtr RenderPassByIndex(unsigned int _index)
94  const override;
95 
96  protected: virtual void Rebuild();
97 
98  protected: virtual void RebuildImpl() = 0;
99 
100  protected: PixelFormat format = PF_UNKNOWN;
101 
102  protected: bool reinterpretable = false;
103 
104  protected: bool targetDirty = true;
105 
107  protected: bool renderPassDirty = false;
108 
109  protected: unsigned int width = 0u;
110 
111  protected: unsigned int height = 0u;
112 
115  };
116 
117  template <class T>
119  public virtual RenderTexture,
120  public virtual T
121  {
122  public: BaseRenderTexture();
123 
124  public: virtual ~BaseRenderTexture();
125 
126  // Documentation inherited.
127  public: virtual unsigned int GLId() const override;
128 
129  // Documentation inherited.
130  public: virtual void MetalId(void *_textureIdPtr) const override;
131  };
132 
133  template <class T>
135  public virtual RenderWindow,
136  public virtual T
137  {
138  public: BaseRenderWindow();
139 
140  public: virtual ~BaseRenderWindow();
141 
142  public: virtual std::string Handle() const;
143 
144  public: virtual void SetHandle(const std::string &_handle);
145 
146  public: virtual double DevicePixelRatio() const;
147 
148  public: virtual void SetDevicePixelRatio(const double _ratio);
149 
150  public: virtual void OnResize(const unsigned int _width,
151  const unsigned int _height);
152 
153  public: virtual void OnMove();
154 
155  protected: std::string handle;
156 
157  protected: double ratio = 1.0;
158  };
159 
161  // BaseRenderTarget
163  template <class T>
165  {
166  }
167 
169  template <class T>
171  {
172  }
173 
175  template <class T>
177  {
178  this->PreRender();
179  for (auto &pass : this->renderPasses)
180  pass->PreRender(_camera);
181  }
182 
184  template <class T>
186  {
187  T::PreRender();
188  this->Rebuild();
189  }
190 
192  template <class T>
194  {
195  T::PostRender();
196  }
197 
199  template <class T>
201  {
202  if (this->targetDirty)
203  {
204  this->RebuildImpl();
205  this->targetDirty = false;
206  }
207  }
208 
210  template <class T>
211  unsigned int BaseRenderTarget<T>::Width() const
212  {
213  return this->width;
214  }
215 
217  template <class T>
218  void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
219  {
220  this->width = _width;
221  this->targetDirty = true;
222  }
223 
225  template <class T>
226  unsigned int BaseRenderTarget<T>::Height() const
227  {
228  return this->height;
229  }
230 
232  template <class T>
233  void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
234  {
235  this->height = _height;
236  this->targetDirty = true;
237  }
238 
240  template <class T>
242  {
243  return this->format;
244  }
245 
247  template <class T>
249  bool _reinterpretable)
250  {
251  this->format = PixelUtil::Sanitize(_format);
252  this->reinterpretable = _reinterpretable;
253  this->targetDirty = true;
254  }
255 
257  template <class T>
259  {
260  return this->reinterpretable;
261  }
262 
264  template <class T>
266  {
267  return this->Scene()->BackgroundColor();
268  }
269 
271  template <class T>
273  {
274  this->renderPasses.push_back(_pass);
275  this->renderPassDirty = true;
276  }
277 
279  template <class T>
281  {
282  auto it = std::find(this->renderPasses.begin(), this->renderPasses.end(),
283  _pass);
284  if (it != this->renderPasses.end())
285  {
286  (*it)->Destroy();
287  this->renderPasses.erase(it);
288  this->renderPassDirty = true;
289  }
290  }
291 
293  template <class T>
295  {
296  if (!this->renderPasses.empty())
297  {
298  for (RenderPassPtr &renderPass : this->renderPasses)
299  {
300  renderPass->Destroy();
301  }
302  this->renderPasses.clear();
303  this->renderPassDirty = true;
304  }
305  }
306 
308  template <class T>
310  {
311  return this->renderPasses.size();
312  }
313 
315  template <class T>
317  const
318  {
319  if (_index > this->renderPasses.size())
320  {
321  gzerr << "RenderPass index out of range: " << _index << std::endl;
322  return RenderPassPtr();
323  }
324  return this->renderPasses[_index];
325  }
326 
328  // BaseRenderTexture
330  template <class T>
332  {
333  }
334 
336  template <class T>
338  {
339  }
340 
342  template <class T>
343  unsigned int BaseRenderTexture<T>::GLId() const
344  {
345  return 0u;
346  }
347 
349  template <class T>
350  void BaseRenderTexture<T>::MetalId(void *) const
351  {
352  }
353 
355  // BaseRenderWindow
357  template <class T>
359  {
360  }
361 
363  template <class T>
365  {
366  }
367 
369  template <class T>
371  {
372  return this->handle;
373  }
374 
376  template <class T>
378  {
379  this->handle = _handle;
380  this->targetDirty = true;
381  }
382 
384  template <class T>
386  {
387  return this->ratio;
388  }
389 
391  template <class T>
393  {
394  this->ratio = _ratio;
395  this->targetDirty = true;
396  }
397 
399  template <class T>
400  void BaseRenderWindow<T>::OnResize(const unsigned int _width,
401  const unsigned int _height)
402  {
403  this->width = _width;
404  this->height = _height;
405  this->targetDirty = true;
406  }
407 
409  template <class T>
411  {
412  this->targetDirty = true;
413  }
414  }
415  }
416 }
417 
418 #if defined(__GNUC__) || defined(__clang__)
419 # pragma GCC diagnostic pop
420 #endif
421 
422 #endif