Main MRPT website > C++ reference for MRPT 1.9.9
CRenderizableDisplayList.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef opengl_CRenderizableDisplayList_H
10 #define opengl_CRenderizableDisplayList_H
11 
13 
14 namespace mrpt
15 {
16 namespace opengl
17 {
18 #define INVALID_DISPLAY_LIST_ID static_cast<unsigned int>(-1)
19 
20 /** A renderizable object suitable for rendering with OpenGL's display lists.
21  * The idea is to use the derived classes' ::render() method to save all the
22  *primitives
23  * into one display list, then in subsequent rendering events, just execute
24  *the list.
25  * This method is normally faster since it avoids the bottleneck between
26  *CPU-GPU. On the
27  * other hand, it demands more memory on the graphic card.
28  *
29  * Instructions for implementing derived classes:
30  * - Each time the object is modified is some way that modifies its
31  *appearance, you must call notifyChange()
32  * - Implement the rendering method: render_dl(), calling to OpenGL
33  *primitives
34  *as usual. They'll be saved in a display list transparently.
35  *
36  * \sa mrpt::opengl::CRenderizable
37  * \ingroup mrpt_opengl_grp
38  */
40 {
42 
43  private:
44  /** Display list ID, for derived classes that want to use it (it's
45  * automatically deleted and freed on destruction of this base class). */
46  mutable unsigned int m_dl;
47  /** If using display lists, this is true when the list must be updated (the
48  * object changes, it's the first rendering, etc...). */
49  mutable bool m_dl_recreate;
50 
51  protected:
52  /** @name Methods accesible or implemented by derived classes
53  @{ */
54 
55  /** Must be called to notify that the object has changed (so, the display
56  * list must be updated) */
57  EIGEN_STRONG_INLINE void notifyChange() const { m_dl_recreate = true; }
58  /** Derived classes must implement this method to the render the object. */
59  virtual void render_dl() const = 0;
60 
61  /** Optional: If the object has some state in which creating a display list
62  * is NOT preferred over direct rendering,
63  * implement this method and return "true" in those cases. */
64  virtual bool should_skip_display_list_cache() const { return false; }
66  {
68  notifyChange();
69  }
70 
71  /** @} */
72 
73  public:
75  virtual ~CRenderizableDisplayList();
76 
77  /** Render the object, regenerating the display list if needed, otherwise
78  * just calling it. */
79  void render() const override;
80 
81  /** @name Changes the appearance of the object to render (methods from
82  CRenderizable that need to be redefined)
83  @{ */
84  /**Color components in the range [0,255] \return a ref to this */
86  {
87  m_color.R = r;
88  notifyChange();
89  return *this;
90  }
91  /**Color components in the range [0,255] \return a ref to this */
93  {
94  m_color.G = g;
95  notifyChange();
96  return *this;
97  }
98  /**Color components in the range [0,255] \return a ref to this */
100  {
101  m_color.B = b;
102  notifyChange();
103  return *this;
104  }
105  /**Color components in the range [0,255] \return a ref to this */
107  {
108  m_color.A = a;
109  notifyChange();
110  return *this;
111  }
112  /** Changes the default object color \return a ref to this */
114  {
116  notifyChange();
117  return *this;
118  }
119  /**Color components in the range [0,255] \return a ref to this */
121  uint8_t R, uint8_t G, uint8_t B, uint8_t A = 255)
122  {
124  notifyChange();
125  return *this;
126  }
127  /** @} */
128 };
129 
130 } // namespace opengl
131 
132 } // namespace mrpt
133 
134 #endif
bool m_dl_recreate
If using display lists, this is true when the list must be updated (the object changes, it&#39;s the first rendering, etc...).
CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
CRenderizable & setColor_u8(uint8_t R, uint8_t G, uint8_t B, uint8_t A=255)
Color components in the range [0,255].
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Changes the default object color.
const double G
void render() const override
Render the object, regenerating the display list if needed, otherwise just calling it...
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
virtual bool should_skip_display_list_cache() const
Optional: If the object has some state in which creating a display list is NOT preferred over direct ...
uint8_t B
Definition: TColor.h:48
uint8_t G
Definition: TColor.h:48
CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
unsigned int m_dl
Display list ID, for derived classes that want to use it (it&#39;s automatically deleted and freed on des...
virtual void render_dl() const =0
Derived classes must implement this method to the render the object.
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
unsigned char uint8_t
Definition: rptypes.h:41
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
virtual CRenderizable & setColor_u8(const mrpt::img::TColor &c)
const GLubyte * c
Definition: glext.h:6313
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
uint8_t R
Definition: TColor.h:48
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
const float R
GLuint in
Definition: glext.h:7274
void readFromStreamRender(mrpt::serialization::CArchive &in)
CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
A RGB color - 8bit.
Definition: TColor.h:22
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void readFromStreamRender(mrpt::serialization::CArchive &in)
uint8_t A
Definition: TColor.h:48



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019