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::opengl
15 {
16 #define INVALID_DISPLAY_LIST_ID static_cast<unsigned int>(-1)
17 
18 /** A renderizable object suitable for rendering with OpenGL's display lists.
19  * The idea is to use the derived classes' ::render() method to save all the
20  *primitives
21  * into one display list, then in subsequent rendering events, just execute
22  *the list.
23  * This method is normally faster since it avoids the bottleneck between
24  *CPU-GPU. On the
25  * other hand, it demands more memory on the graphic card.
26  *
27  * Instructions for implementing derived classes:
28  * - Each time the object is modified is some way that modifies its
29  *appearance, you must call notifyChange()
30  * - Implement the rendering method: render_dl(), calling to OpenGL
31  *primitives
32  *as usual. They'll be saved in a display list transparently.
33  *
34  * \sa mrpt::opengl::CRenderizable
35  * \ingroup mrpt_opengl_grp
36  */
38 {
40 
41  private:
42  /** Display list ID, for derived classes that want to use it (it's
43  * automatically deleted and freed on destruction of this base class). */
44  mutable unsigned int m_dl;
45  /** If using display lists, this is true when the list must be updated (the
46  * object changes, it's the first rendering, etc...). */
47  mutable bool m_dl_recreate;
48 
49  protected:
50  /** @name Methods accesible or implemented by derived classes
51  @{ */
52 
53  /** Must be called to notify that the object has changed (so, the display
54  * list must be updated) */
55  EIGEN_STRONG_INLINE void notifyChange() const { m_dl_recreate = true; }
56  /** Derived classes must implement this method to the render the object. */
57  virtual void render_dl() const = 0;
58 
59  /** Optional: If the object has some state in which creating a display list
60  * is NOT preferred over direct rendering,
61  * implement this method and return "true" in those cases. */
62  virtual bool should_skip_display_list_cache() const { return false; }
64  {
66  notifyChange();
67  }
68 
69  /** @} */
70 
71  public:
73  virtual ~CRenderizableDisplayList();
74 
75  /** Render the object, regenerating the display list if needed, otherwise
76  * just calling it. */
77  void render() const override;
78 
79  /** @name Changes the appearance of the object to render (methods from
80  CRenderizable that need to be redefined)
81  @{ */
82  /**Color components in the range [0,255] \return a ref to this */
84  {
85  m_color.R = r;
86  notifyChange();
87  return *this;
88  }
89  /**Color components in the range [0,255] \return a ref to this */
91  {
92  m_color.G = g;
93  notifyChange();
94  return *this;
95  }
96  /**Color components in the range [0,255] \return a ref to this */
98  {
99  m_color.B = b;
100  notifyChange();
101  return *this;
102  }
103  /**Color components in the range [0,255] \return a ref to this */
105  {
106  m_color.A = a;
107  notifyChange();
108  return *this;
109  }
110  /** Changes the default object color \return a ref to this */
112  {
114  notifyChange();
115  return *this;
116  }
117  /**Color components in the range [0,255] \return a ref to this */
119  uint8_t R, uint8_t G, uint8_t B, uint8_t A = 255)
120  {
122  notifyChange();
123  return *this;
124  }
125  /** @} */
126 };
127 
128 }
129 #endif
130 
131 
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:41
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:46
uint8_t G
Definition: TColor.h:46
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:46
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:52
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
const float R
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
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:20
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void readFromStreamRender(mrpt::serialization::CArchive &in)
uint8_t A
Definition: TColor.h:46



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020