Gazebo Rendering

API Reference

9.0.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
25#include "gz/rendering/Scene.hh"
27
28namespace 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 {
40
41 public: virtual ~BaseRenderTarget();
42
43 // Documentation inherited.
44 public: virtual void PreRender(const CameraPtr &_camera) override;
45
46 // Documentation inherited.
47 public: virtual void PreRender() override;
48
49 // Documentation inherited.
50 public: virtual void PostRender() override;
51
52 public: virtual unsigned int Width() const override;
53
54 public: virtual void SetWidth(const unsigned int _width) override;
55
56 public: virtual unsigned int Height() const override;
57
58 public: virtual void SetHeight(const unsigned int _height) override;
59
60 public: virtual PixelFormat Format() const override;
61
62 public: virtual void SetFormat(PixelFormat _format,
63 bool _reinterpretable = false) override;
64
65 // Documentation inherited
66 public: virtual bool Reinterpretable() const override;
67
68 // Documentation inherited
69 public: virtual math::Color BackgroundColor() const override;
70
71 // Documentation inherited
72 public: virtual void AddRenderPass(const RenderPassPtr &_pass) override;
73
74 // Documentation inherited
75 public: virtual void RemoveRenderPass(const RenderPassPtr &_pass)
76 override;
77
78 // Documentation inherited
79 public: void RemoveAllRenderPasses() override;
80
81 // Documentation inherited
82 public: virtual unsigned int RenderPassCount() const override;
83
84 // Documentation inherited
85 public: virtual RenderPassPtr RenderPassByIndex(unsigned int _index)
86 const override;
87
88 protected: virtual void Rebuild();
89
90 protected: virtual void RebuildImpl() = 0;
91
92 protected: PixelFormat format = PF_UNKNOWN;
93
94 protected: bool reinterpretable = false;
95
96 protected: bool targetDirty = true;
97
99 protected: bool renderPassDirty = false;
100
101 protected: unsigned int width = 0u;
102
103 protected: unsigned int height = 0u;
104
107 };
108
109 template <class T>
111 public virtual RenderTexture,
112 public virtual T
113 {
115
116 public: virtual ~BaseRenderTexture();
117
118 // Documentation inherited.
119 public: virtual unsigned int GLId() const override;
120
121 // Documentation inherited.
122 public: virtual void MetalId(void *_textureIdPtr) const override;
123 };
124
125 template <class T>
127 public virtual RenderWindow,
128 public virtual T
129 {
131
132 public: virtual ~BaseRenderWindow();
133
134 public: virtual std::string Handle() const;
135
136 public: virtual void SetHandle(const std::string &_handle);
137
138 public: virtual double DevicePixelRatio() const;
139
140 public: virtual void SetDevicePixelRatio(const double _ratio);
141
142 public: virtual void OnResize(const unsigned int _width,
143 const unsigned int _height);
144
145 public: virtual void OnMove();
146
147 protected: std::string handle;
148
149 protected: double ratio = 1.0;
150 };
151
153 // BaseRenderTarget
155 template <class T>
159
161 template <class T>
165
167 template <class T>
169 {
170 this->PreRender();
171 for (auto &pass : this->renderPasses)
172 pass->PreRender(_camera);
173 }
174
176 template <class T>
178 {
179 T::PreRender();
180 this->Rebuild();
181 }
182
184 template <class T>
186 {
187 T::PostRender();
188 }
189
191 template <class T>
193 {
194 if (this->targetDirty)
195 {
196 this->RebuildImpl();
197 this->targetDirty = false;
198 }
199 }
200
202 template <class T>
203 unsigned int BaseRenderTarget<T>::Width() const
204 {
205 return this->width;
206 }
207
209 template <class T>
210 void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
211 {
212 this->width = _width;
213 this->targetDirty = true;
214 }
215
217 template <class T>
218 unsigned int BaseRenderTarget<T>::Height() const
219 {
220 return this->height;
221 }
222
224 template <class T>
225 void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
226 {
227 this->height = _height;
228 this->targetDirty = true;
229 }
230
232 template <class T>
234 {
235 return this->format;
236 }
237
239 template <class T>
241 bool _reinterpretable)
242 {
243 this->format = PixelUtil::Sanitize(_format);
244 this->reinterpretable = _reinterpretable;
245 this->targetDirty = true;
246 }
247
249 template <class T>
251 {
252 return this->reinterpretable;
253 }
254
256 template <class T>
258 {
259 return this->Scene()->BackgroundColor();
260 }
261
263 template <class T>
265 {
266 this->renderPasses.push_back(_pass);
267 this->renderPassDirty = true;
268 }
269
271 template <class T>
273 {
274 auto it = std::find(this->renderPasses.begin(), this->renderPasses.end(),
275 _pass);
276 if (it != this->renderPasses.end())
277 {
278 (*it)->Destroy();
279 this->renderPasses.erase(it);
280 this->renderPassDirty = true;
281 }
282 }
283
285 template <class T>
287 {
288 if (!this->renderPasses.empty())
289 {
290 for (RenderPassPtr &renderPass : this->renderPasses)
291 {
292 renderPass->Destroy();
293 }
294 this->renderPasses.clear();
295 this->renderPassDirty = true;
296 }
297 }
298
300 template <class T>
302 {
303 return this->renderPasses.size();
304 }
305
307 template <class T>
309 const
310 {
311 if (_index > this->renderPasses.size())
312 {
313 gzerr << "RenderPass index out of range: " << _index << std::endl;
314 return RenderPassPtr();
315 }
316 return this->renderPasses[_index];
317 }
318
320 // BaseRenderTexture
322 template <class T>
326
328 template <class T>
332
334 template <class T>
335 unsigned int BaseRenderTexture<T>::GLId() const
336 {
337 return 0u;
338 }
339
341 template <class T>
343 {
344 }
345
347 // BaseRenderWindow
349 template <class T>
353
355 template <class T>
359
361 template <class T>
363 {
364 return this->handle;
365 }
366
368 template <class T>
370 {
371 this->handle = _handle;
372 this->targetDirty = true;
373 }
374
376 template <class T>
378 {
379 return this->ratio;
380 }
381
383 template <class T>
385 {
386 this->ratio = _ratio;
387 this->targetDirty = true;
388 }
389
391 template <class T>
392 void BaseRenderWindow<T>::OnResize(const unsigned int _width,
393 const unsigned int _height)
394 {
395 this->width = _width;
396 this->height = _height;
397 this->targetDirty = true;
398 }
399
401 template <class T>
403 {
404 this->targetDirty = true;
405 }
406 }
407 }
408}
409
410#endif