Gazebo Rendering

API Reference

9.3.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 GZ_RENDERING_BASE_BASERENDERTARGET_HH_
18#define GZ_RENDERING_BASE_BASERENDERTARGET_HH_
19
20#include <string>
21#include <vector>
22
23#include <gz/common/Console.hh>
24
27#include "gz/rendering/Scene.hh"
29
30namespace gz
31{
32 namespace rendering
33 {
34 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
35 //
36 template <class T>
38 public virtual RenderTarget,
39 public virtual T
40 {
42
43 public: virtual ~BaseRenderTarget();
44
45 // Documentation inherited.
46 public: virtual void PreRender(const CameraPtr &_camera) override;
47
48 // Documentation inherited.
49 public: virtual void PreRender() override;
50
51 // Documentation inherited.
52 public: virtual void PostRender() override;
53
54 public: virtual unsigned int Width() const override;
55
56 public: virtual void SetWidth(const unsigned int _width) override;
57
58 public: virtual unsigned int Height() const override;
59
60 public: virtual void SetHeight(const unsigned int _height) override;
61
62 public: virtual PixelFormat Format() const override;
63
64 public: virtual void SetFormat(PixelFormat _format,
65 bool _reinterpretable = false) override;
66
67 // Documentation inherited
68 public: virtual bool Reinterpretable() const override;
69
70 // Documentation inherited
71 public: virtual math::Color BackgroundColor() const override;
72
73 // Documentation inherited
74 public: virtual void AddRenderPass(const RenderPassPtr &_pass) override;
75
76 // Documentation inherited
77 public: virtual void RemoveRenderPass(const RenderPassPtr &_pass)
78 override;
79
80 // Documentation inherited
81 public: void RemoveAllRenderPasses() override;
82
83 // Documentation inherited
84 public: virtual unsigned int RenderPassCount() const override;
85
86 // Documentation inherited
87 public: virtual RenderPassPtr RenderPassByIndex(unsigned int _index)
88 const override;
89
90 protected: virtual void Rebuild();
91
92 protected: virtual void RebuildImpl() = 0;
93
94 protected: PixelFormat format = PF_UNKNOWN;
95
96 protected: bool reinterpretable = false;
97
98 protected: bool targetDirty = true;
99
101 protected: bool renderPassDirty = false;
102
103 protected: unsigned int width = 0u;
104
105 protected: unsigned int height = 0u;
106
109 };
110
111 template <class T>
113 public virtual RenderTexture,
114 public virtual T
115 {
117
118 public: virtual ~BaseRenderTexture();
119
120 // Documentation inherited.
121 public: virtual unsigned int GLId() const override;
122
123 // Documentation inherited.
124 public: virtual void MetalId(void *_textureIdPtr) const override;
125 };
126
127 template <class T>
129 public virtual RenderWindow,
130 public virtual T
131 {
133
134 public: virtual ~BaseRenderWindow();
135
136 public: virtual std::string Handle() const;
137
138 public: virtual void SetHandle(const std::string &_handle);
139
140 public: virtual double DevicePixelRatio() const;
141
142 public: virtual void SetDevicePixelRatio(const double _ratio);
143
144 public: virtual void OnResize(const unsigned int _width,
145 const unsigned int _height);
146
147 public: virtual void OnMove();
148
149 protected: std::string handle;
150
151 protected: double ratio = 1.0;
152 };
153
155 // BaseRenderTarget
157 template <class T>
161
163 template <class T>
167
169 template <class T>
171 {
172 this->PreRender();
173 for (auto &pass : this->renderPasses)
174 pass->PreRender(_camera);
175 }
176
178 template <class T>
180 {
181 T::PreRender();
182 this->Rebuild();
183 }
184
186 template <class T>
188 {
189 T::PostRender();
190 }
191
193 template <class T>
195 {
196 if (this->targetDirty)
197 {
198 this->RebuildImpl();
199 this->targetDirty = false;
200 }
201 }
202
204 template <class T>
205 unsigned int BaseRenderTarget<T>::Width() const
206 {
207 return this->width;
208 }
209
211 template <class T>
212 void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
213 {
214 this->width = _width;
215 this->targetDirty = true;
216 }
217
219 template <class T>
220 unsigned int BaseRenderTarget<T>::Height() const
221 {
222 return this->height;
223 }
224
226 template <class T>
227 void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
228 {
229 this->height = _height;
230 this->targetDirty = true;
231 }
232
234 template <class T>
236 {
237 return this->format;
238 }
239
241 template <class T>
243 bool _reinterpretable)
244 {
245 this->format = PixelUtil::Sanitize(_format);
246 this->reinterpretable = _reinterpretable;
247 this->targetDirty = true;
248 }
249
251 template <class T>
253 {
254 return this->reinterpretable;
255 }
256
258 template <class T>
260 {
261 return this->Scene()->BackgroundColor();
262 }
263
265 template <class T>
267 {
268 this->renderPasses.push_back(_pass);
269 this->renderPassDirty = true;
270 }
271
273 template <class T>
275 {
276 auto it = std::find(this->renderPasses.begin(), this->renderPasses.end(),
277 _pass);
278 if (it != this->renderPasses.end())
279 {
280 (*it)->Destroy();
281 this->renderPasses.erase(it);
282 this->renderPassDirty = true;
283 }
284 }
285
287 template <class T>
289 {
290 if (!this->renderPasses.empty())
291 {
292 for (RenderPassPtr &renderPass : this->renderPasses)
293 {
294 renderPass->Destroy();
295 }
296 this->renderPasses.clear();
297 this->renderPassDirty = true;
298 }
299 }
300
302 template <class T>
304 {
305 return this->renderPasses.size();
306 }
307
309 template <class T>
311 const
312 {
313 if (_index > this->renderPasses.size())
314 {
315 gzerr << "RenderPass index out of range: " << _index << std::endl;
316 return RenderPassPtr();
317 }
318 return this->renderPasses[_index];
319 }
320
322 // BaseRenderTexture
324 template <class T>
328
330 template <class T>
334
336 template <class T>
337 unsigned int BaseRenderTexture<T>::GLId() const
338 {
339 return 0u;
340 }
341
343 template <class T>
345 {
346 }
347
349 // BaseRenderWindow
351 template <class T>
355
357 template <class T>
361
363 template <class T>
365 {
366 return this->handle;
367 }
368
370 template <class T>
372 {
373 this->handle = _handle;
374 this->targetDirty = true;
375 }
376
378 template <class T>
380 {
381 return this->ratio;
382 }
383
385 template <class T>
387 {
388 this->ratio = _ratio;
389 this->targetDirty = true;
390 }
391
393 template <class T>
394 void BaseRenderWindow<T>::OnResize(const unsigned int _width,
395 const unsigned int _height)
396 {
397 this->width = _width;
398 this->height = _height;
399 this->targetDirty = true;
400 }
401
403 template <class T>
405 {
406 this->targetDirty = true;
407 }
408 }
409 }
410}
411
412#endif