Ignition Rendering

API Reference

0.1.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 IGNITION_RENDERING_BASE_BASERENDERTARGET_HH_
18 #define IGNITION_RENDERING_BASE_BASERENDERTARGET_HH_
19 
20 #include <string>
21 
25 
26 namespace ignition
27 {
28  namespace rendering
29  {
30  template <class T>
31  class IGNITION_RENDERING_VISIBLE BaseRenderTarget :
32  public virtual RenderTarget,
33  public virtual T
34  {
35  public: BaseRenderTarget();
36 
37  public: virtual ~BaseRenderTarget();
38 
39  public: virtual void PreRender();
40 
41  public: virtual unsigned int Width() const;
42 
43  public: virtual void SetWidth(const unsigned int _width);
44 
45  public: virtual unsigned int Height() const;
46 
47  public: virtual void SetHeight(const unsigned int _height);
48 
49  public: virtual PixelFormat Format() const;
50 
51  public: virtual void SetFormat(PixelFormat _format);
52 
53  // Documentation inherited
54  public: virtual math::Color BackgroundColor() const;
55 
56  protected: virtual void Rebuild();
57 
58  protected: virtual void RebuildImpl() = 0;
59 
60  protected: PixelFormat format = PF_UNKNOWN;
61 
62  protected: bool targetDirty = true;
63 
64  protected: unsigned int width = 0u;
65 
66  protected: unsigned int height = 0u;
67  };
68 
69  template <class T>
70  class IGNITION_RENDERING_VISIBLE BaseRenderTexture :
71  public virtual RenderTexture,
72  public virtual T
73  {
74  public: BaseRenderTexture();
75 
76  public: virtual ~BaseRenderTexture();
77  };
78 
79  template <class T>
80  class IGNITION_RENDERING_VISIBLE BaseRenderWindow :
81  public virtual RenderWindow,
82  public virtual T
83  {
84  public: BaseRenderWindow();
85 
86  public: virtual ~BaseRenderWindow();
87 
88  public: virtual std::string Handle() const;
89 
90  public: virtual void SetHandle(const std::string &_handle);
91 
92  public: virtual double DevicePixelRatio() const;
93 
94  public: virtual void SetDevicePixelRatio(const double _ratio);
95 
96  public: virtual void OnResize(const unsigned int _width,
97  const unsigned int _height);
98 
99  public: virtual void OnMove();
100 
101  protected: std::string handle;
102 
103  protected: double ratio = 1.0;
104  };
105 
107  // BaseRenderTarget
109  template <class T>
111  {
112  }
113 
115  template <class T>
117  {
118  }
119 
121  template <class T>
123  {
124  T::PreRender();
125  this->Rebuild();
126  }
127 
129  template <class T>
131  {
132  if (this->targetDirty)
133  {
134  this->RebuildImpl();
135  this->targetDirty = false;
136  }
137  }
138 
140  template <class T>
141  unsigned int BaseRenderTarget<T>::Width() const
142  {
143  return this->width;
144  }
145 
147  template <class T>
148  void BaseRenderTarget<T>::SetWidth(const unsigned int _width)
149  {
150  this->width = _width;
151  this->targetDirty = true;
152  }
153 
155  template <class T>
156  unsigned int BaseRenderTarget<T>::Height() const
157  {
158  return this->height;
159  }
160 
162  template <class T>
163  void BaseRenderTarget<T>::SetHeight(const unsigned int _height)
164  {
165  this->height = _height;
166  this->targetDirty = true;
167  }
168 
170  template <class T>
172  {
173  return this->format;
174  }
175 
177  template <class T>
179  {
180  this->format = PixelUtil::Sanitize(_format);
181  this->targetDirty = true;
182  }
183 
185  template <class T>
187  {
188  return this->Scene()->BackgroundColor();
189  }
190 
191 
193  // BaseRenderTexture
195  template <class T>
197  {
198  }
199 
201  template <class T>
203  {
204  }
205 
207  // BaseRenderWindow
209  template <class T>
211  {
212  }
213 
215  template <class T>
217  {
218  }
219 
221  template <class T>
223  {
224  return this->handle;
225  }
226 
228  template <class T>
230  {
231  this->handle = _handle;
232  this->targetDirty = true;
233  }
234 
236  template <class T>
238  {
239  return this->ratio;
240  }
241 
243  template <class T>
245  {
246  this->ratio = _ratio;
247  this->targetDirty = true;
248  }
249 
251  template <class T>
252  void BaseRenderWindow<T>::OnResize(const unsigned int _width,
253  const unsigned int _height)
254  {
255  this->width = _width;
256  this->height = _height;
257  this->targetDirty = true;
258  }
259 
261  template <class T>
263  {
264  this->targetDirty = true;
265  }
266  }
267 }
268 #endif
virtual ~BaseRenderTarget()
Definition: BaseRenderTarget.hh:116
TextureUnitState::TextureAddressingMode u
Definition: BaseRenderTarget.hh:70
virtual math::Color BackgroundColor() const =0
Get the scene background color.
virtual ~BaseRenderWindow()
Definition: BaseRenderTarget.hh:216
Definition: BaseRenderTarget.hh:31
virtual void PreRender()
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseRenderTarget.hh:122
STL class.
Represents a render-target to which cameras can render images.
Definition: RenderTarget.hh:34
virtual void SetDevicePixelRatio(const double _ratio)
Set the device to pixel ratio.
Definition: BaseRenderTarget.hh:244
virtual void SetHandle(const std::string &_handle)
Set the window handle to attach the render window to.
Definition: BaseRenderTarget.hh:229
virtual void Rebuild()
Definition: BaseRenderTarget.hh:130
Definition: BaseRenderTarget.hh:80
virtual math::Color BackgroundColor() const
Get the background color of the render target. This should be the same as the scene background color...
Definition: BaseRenderTarget.hh:186
virtual double DevicePixelRatio() const
Get the device to pixel ratio.
Definition: BaseRenderTarget.hh:237
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:44
PixelFormat
Definition: PixelFormat.hh:29
virtual std::string Handle() const
Get the window handle that the render window is attached to.
Definition: BaseRenderTarget.hh:222
virtual unsigned int Height() const
Get render target height in pixels.
Definition: BaseRenderTarget.hh:156
Represents a off-screen render-texture to which cameras can render images.
Definition: RenderTarget.hh:82
std::string handle
Definition: BaseRenderTarget.hh:101
virtual void SetHeight(const unsigned int _height)
Set the render target height in pixels.
Definition: BaseRenderTarget.hh:163
virtual unsigned int Width() const
Get render target width in pixels.
Definition: BaseRenderTarget.hh:141
Represents a on-screen render-window to which cameras can render images.
Definition: RenderTarget.hh:93
virtual void SetFormat(PixelFormat _format)
Set the render target image format.
Definition: BaseRenderTarget.hh:178
virtual PixelFormat Format() const
Set the render target image format.
Definition: BaseRenderTarget.hh:171
< Unknown or errant type
Definition: PixelFormat.hh:32
static PixelFormat Sanitize(PixelFormat _format)
Sanitize given format. If the given value is invalid, PF_UNKNOWN will be returned, otherwise input will be returned unchanged.
BaseRenderTarget()
Definition: BaseRenderTarget.hh:110
virtual ~BaseRenderTexture()
Definition: BaseRenderTarget.hh:202
Definition: ArrowVisual.hh:22
BaseRenderTexture()
Definition: BaseRenderTarget.hh:196
virtual void OnMove()
Alert the window of a window move event.
Definition: BaseRenderTarget.hh:262
virtual void SetWidth(const unsigned int _width)
Set the render target width in pixels.
Definition: BaseRenderTarget.hh:148
BaseRenderWindow()
Definition: BaseRenderTarget.hh:210
virtual void OnResize(const unsigned int _width, const unsigned int _height)
Alert the window of a window resize event.
Definition: BaseRenderTarget.hh:252