Gazebo Rendering
API Reference
9.0.0
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-rendering
include
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
23
#include "
gz/rendering/RenderPass.hh
"
24
#include "
gz/rendering/RenderTarget.hh
"
25
#include "
gz/rendering/Scene.hh
"
26
#include "
gz/rendering/base/BaseRenderTypes.hh
"
27
28
namespace
gz
29
{
30
namespace
rendering
31
{
32
inline
namespace
GZ_RENDERING_VERSION_NAMESPACE {
33
//
34
template
<
class
T>
35
class
BaseRenderTarget
:
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
(
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
106
protected
:
std::vector<RenderPassPtr>
renderPasses
;
107
};
108
109
template
<
class
T>
110
class
BaseRenderTexture
:
111
public
virtual
RenderTexture
,
112
public
virtual
T
113
{
114
public
:
BaseRenderTexture
();
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>
126
class
BaseRenderWindow
:
127
public
virtual
RenderWindow
,
128
public
virtual
T
129
{
130
public
:
BaseRenderWindow
();
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>
156
BaseRenderTarget<T>::BaseRenderTarget
()
157
{
158
}
159
161
template
<
class
T>
162
BaseRenderTarget<T>::~BaseRenderTarget
()
163
{
164
}
165
167
template
<
class
T>
168
void
BaseRenderTarget<T>::PreRender
(
const
CameraPtr
&_camera)
169
{
170
this->PreRender();
171
for
(
auto
&pass : this->renderPasses)
172
pass->PreRender(_camera);
173
}
174
176
template
<
class
T>
177
void
BaseRenderTarget<T>::PreRender
()
178
{
179
T::PreRender();
180
this->Rebuild();
181
}
182
184
template
<
class
T>
185
void
BaseRenderTarget<T>::PostRender
()
186
{
187
T::PostRender();
188
}
189
191
template
<
class
T>
192
void
BaseRenderTarget<T>::Rebuild
()
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>
233
PixelFormat
BaseRenderTarget<T>::Format
()
const
234
{
235
return
this->format;
236
}
237
239
template
<
class
T>
240
void
BaseRenderTarget<T>::SetFormat
(
PixelFormat
_format,
241
bool
_reinterpretable)
242
{
243
this->format =
PixelUtil::Sanitize
(_format);
244
this->reinterpretable = _reinterpretable;
245
this->targetDirty =
true
;
246
}
247
249
template
<
class
T>
250
bool
BaseRenderTarget<T>::Reinterpretable
()
const
251
{
252
return
this->reinterpretable;
253
}
254
256
template
<
class
T>
257
math::Color
BaseRenderTarget<T>::BackgroundColor
()
const
258
{
259
return
this->
Scene
()->
BackgroundColor
();
260
}
261
263
template
<
class
T>
264
void
BaseRenderTarget<T>::AddRenderPass
(
const
RenderPassPtr
&_pass)
265
{
266
this->renderPasses.push_back(_pass);
267
this->renderPassDirty =
true
;
268
}
269
271
template
<
class
T>
272
void
BaseRenderTarget<T>::RemoveRenderPass
(
const
RenderPassPtr
&_pass)
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>
286
void
BaseRenderTarget<T>::RemoveAllRenderPasses
()
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>
301
unsigned
int
BaseRenderTarget<T>::RenderPassCount
()
const
302
{
303
return
this->renderPasses.size();
304
}
305
307
template
<
class
T>
308
RenderPassPtr
BaseRenderTarget<T>::RenderPassByIndex
(
unsigned
int
_index)
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>
323
BaseRenderTexture<T>::BaseRenderTexture
()
324
{
325
}
326
328
template
<
class
T>
329
BaseRenderTexture<T>::~BaseRenderTexture
()
330
{
331
}
332
334
template
<
class
T>
335
unsigned
int
BaseRenderTexture<T>::GLId
()
const
336
{
337
return
0u;
338
}
339
341
template
<
class
T>
342
void
BaseRenderTexture<T>::MetalId
(
void
*)
const
343
{
344
}
345
347
// BaseRenderWindow
349
template
<
class
T>
350
BaseRenderWindow<T>::BaseRenderWindow
()
351
{
352
}
353
355
template
<
class
T>
356
BaseRenderWindow<T>::~BaseRenderWindow
()
357
{
358
}
359
361
template
<
class
T>
362
std::string
BaseRenderWindow<T>::Handle
()
const
363
{
364
return
this->handle;
365
}
366
368
template
<
class
T>
369
void
BaseRenderWindow<T>::SetHandle
(
const
std::string
&_handle)
370
{
371
this->handle = _handle;
372
this->targetDirty =
true
;
373
}
374
376
template
<
class
T>
377
double
BaseRenderWindow<T>::DevicePixelRatio
()
const
378
{
379
return
this->ratio;
380
}
381
383
template
<
class
T>
384
void
BaseRenderWindow<T>::SetDevicePixelRatio
(
const
double
_ratio)
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>
402
void
BaseRenderWindow<T>::OnMove
()
403
{
404
this->targetDirty =
true
;
405
}
406
}
407
}
408
}
409
410
#endif