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
G
const double G
Definition: vision_stereo_rectify/test.cpp:31
mrpt::opengl::CRenderizable::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizable.cpp:164
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
mrpt::opengl::CRenderizableDisplayList::render
void render() const override
Render the object, regenerating the display list if needed, otherwise just calling it.
Definition: CRenderizableDisplayList.cpp:80
c
const GLubyte * c
Definition: glext.h:6313
mrpt::opengl::CRenderizableDisplayList::CRenderizableDisplayList
CRenderizableDisplayList()
Definition: CRenderizableDisplayList.cpp:59
mrpt::opengl::CRenderizableDisplayList::setColor_u8
CRenderizable & setColor_u8(uint8_t R, uint8_t G, uint8_t B, uint8_t A=255)
Color components in the range [0,255].
Definition: CRenderizableDisplayList.h:120
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:48
mrpt::opengl::CRenderizableDisplayList::~CRenderizableDisplayList
virtual ~CRenderizableDisplayList()
Definition: CRenderizableDisplayList.cpp:65
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::CRenderizableDisplayList::setColorA_u8
CRenderizable & setColorA_u8(const uint8_t a) override
Color components in the range [0,255].
Definition: CRenderizableDisplayList.h:106
g
GLubyte g
Definition: glext.h:6279
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::opengl::CRenderizableDisplayList::render_dl
virtual void render_dl() const =0
Derived classes must implement this method to the render the object.
R
const float R
Definition: CKinematicChain.cpp:138
mrpt::opengl::CRenderizableDisplayList::setColorR_u8
CRenderizable & setColorR_u8(const uint8_t r) override
Color components in the range [0,255].
Definition: CRenderizableDisplayList.h:85
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:48
mrpt::opengl::CRenderizable::m_color
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
CRenderizable.h
mrpt::opengl::CRenderizableDisplayList::setColorB_u8
CRenderizable & setColorB_u8(const uint8_t b) override
Color components in the range [0,255].
Definition: CRenderizableDisplayList.h:99
mrpt::opengl::CRenderizableDisplayList::should_skip_display_list_cache
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 ...
Definition: CRenderizableDisplayList.h:64
mrpt::opengl::CRenderizableDisplayList::m_dl_recreate
bool m_dl_recreate
If using display lists, this is true when the list must be updated (the object changes,...
Definition: CRenderizableDisplayList.h:49
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:48
DEFINE_VIRTUAL_SERIALIZABLE
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
Definition: CSerializable.h:119
mrpt::img::TColor::G
uint8_t G
Definition: TColor.h:48
mrpt::opengl::CRenderizableDisplayList::setColorG_u8
CRenderizable & setColorG_u8(const uint8_t g) override
Color components in the range [0,255].
Definition: CRenderizableDisplayList.h:92
mrpt::opengl::CRenderizableDisplayList::m_dl
unsigned int m_dl
Display list ID, for derived classes that want to use it (it's automatically deleted and freed on des...
Definition: CRenderizableDisplayList.h:46
in
GLuint in
Definition: glext.h:7274
mrpt::opengl::CRenderizable::setColor_u8
virtual CRenderizable & setColor_u8(const mrpt::img::TColor &c)
Definition: CRenderizable.cpp:356
mrpt::opengl::CRenderizableDisplayList::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizableDisplayList.h:65
mrpt::opengl::CRenderizableDisplayList::setColor_u8
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Changes the default object color.
Definition: CRenderizableDisplayList.h:113
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST