MRPT  1.9.9
CRenderizableDisplayList.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 
13 namespace mrpt::opengl
14 {
15 #define INVALID_DISPLAY_LIST_ID static_cast<unsigned int>(-1)
16 
17 /** A renderizable object suitable for rendering with OpenGL's display lists.
18  * The idea is to use the derived classes' ::render() method to save all the
19  *primitives
20  * into one display list, then in subsequent rendering events, just execute
21  *the list.
22  * This method is normally faster since it avoids the bottleneck between
23  *CPU-GPU. On the
24  * other hand, it demands more memory on the graphic card.
25  *
26  * Instructions for implementing derived classes:
27  * - Each time the object is modified is some way that modifies its
28  *appearance, you must call notifyChange()
29  * - Implement the rendering method: render_dl(), calling to OpenGL
30  *primitives
31  *as usual. They'll be saved in a display list transparently.
32  *
33  * \sa mrpt::opengl::CRenderizable
34  * \ingroup mrpt_opengl_grp
35  */
37 {
39 
40  private:
41  /** Display list ID, for derived classes that want to use it (it's
42  * automatically deleted and freed on destruction of this base class). */
43  mutable unsigned int m_dl;
44  /** If using display lists, this is true when the list must be updated (the
45  * object changes, it's the first rendering, etc...). */
46  mutable bool m_dl_recreate{true};
47 
48  protected:
49  /** @name Methods accesible or implemented by derived classes
50  @{ */
51 
52  /** Must be called to notify that the object has changed (so, the display
53  * list must be updated) */
54  inline void notifyChange() const { m_dl_recreate = true; }
55  /** Derived classes must implement this method to the render the object. */
56  virtual void render_dl() const = 0;
57 
58  /** Optional: If the object has some state in which creating a display list
59  * is NOT preferred over direct rendering,
60  * implement this method and return "true" in those cases. */
61  virtual bool should_skip_display_list_cache() const { return false; }
63  {
65  notifyChange();
66  }
67 
68  /** @} */
69 
70  public:
72  ~CRenderizableDisplayList() override;
73 
74  /** Render the object, regenerating the display list if needed, otherwise
75  * just calling it. */
76  void render() const override;
77 
78  /** @name Changes the appearance of the object to render (methods from
79  CRenderizable that need to be redefined)
80  @{ */
81  /**Color components in the range [0,255] \return a ref to this */
83  {
84  m_color.R = r;
85  notifyChange();
86  return *this;
87  }
88  /**Color components in the range [0,255] \return a ref to this */
90  {
91  m_color.G = g;
92  notifyChange();
93  return *this;
94  }
95  /**Color components in the range [0,255] \return a ref to this */
97  {
98  m_color.B = b;
99  notifyChange();
100  return *this;
101  }
102  /**Color components in the range [0,255] \return a ref to this */
104  {
105  m_color.A = a;
106  notifyChange();
107  return *this;
108  }
109  /** Changes the default object color \return a ref to this */
111  {
113  notifyChange();
114  return *this;
115  }
116  /**Color components in the range [0,255] \return a ref to this */
118  uint8_t R, uint8_t G, uint8_t B, uint8_t A = 255)
119  {
121  notifyChange();
122  return *this;
123  }
124  /** @} */
125 };
126 
127 } // namespace mrpt::opengl
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...).
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
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:40
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:44
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:6406
GLubyte g
Definition: glext.h:6372
GLubyte GLubyte b
Definition: glext.h:6372
uint8_t R
Definition: TColor.h:46
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:51
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
const float R
GLuint in
Definition: glext.h:7391
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:6372
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: ee555d257 Fri Aug 16 10:05:39 2019 +0200 at vie ago 16 10:10:14 CEST 2019