Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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  // This must be added to any CSerializable derived class:
21  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CRenderizableDisplayList, CRenderizable, OPENGL_IMPEXP )
22 
23  /** A renderizable object suitable for rendering with OpenGL's display lists.
24  * The idea is to use the derived classes' ::render() method to save all the primitives
25  * into one display list, then in subsequent rendering events, just execute the list.
26  * This method is normally faster since it avoids the bottleneck between 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 appearance, you must call notifyChange()
31  * - Implement the rendering method: render_dl(), calling to OpenGL primitives 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  mutable unsigned int m_dl; //!< Display list ID, for derived classes that want to use it (it's automatically deleted and freed on destruction of this base class).
42  mutable bool m_dl_recreate; //!< If using display lists, this is true when the list must be updated (the object changes, it's the first rendering, etc...).
43 
44  protected:
45  /** @name Methods accesible or implemented by derived classes
46  @{ */
47 
48  /** Must be called to notify that the object has changed (so, the display list must be updated) */
49  EIGEN_STRONG_INLINE void notifyChange() const { m_dl_recreate=true;}
50 
51  /** Derived classes must implement this method to the render the object. */
52  virtual void render_dl() const = 0;
53 
54  /** Optional: If the object has some state in which creating a display list is NOT preferred over direct rendering,
55  * implement this method and return "true" in those cases. */
56  virtual bool should_skip_display_list_cache() const { return false; }
57 
59  {
61  notifyChange();
62  }
63 
64  /** @} */
65 
66  public:
68  virtual ~CRenderizableDisplayList();
69 
70  /** Interface for the stlplus smart pointer class. */
72  {
73  return static_cast<CRenderizableDisplayList*>( this->duplicate() );
74  }
75 
76  /** Render the object, regenerating the display list if needed, otherwise just calling it. */
77  void render() const MRPT_OVERRIDE;
78 
79 
80  /** @name Changes the appearance of the object to render (methods from CRenderizable that need to be redefined)
81  @{ */
82  CRenderizable& setColorR_u8(const uint8_t r) MRPT_OVERRIDE {m_color.R=r; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
83  CRenderizable& setColorG_u8(const uint8_t g) MRPT_OVERRIDE {m_color.G=g; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
84  CRenderizable& setColorB_u8(const uint8_t b) MRPT_OVERRIDE {m_color.B=b; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
85  CRenderizable& setColorA_u8(const uint8_t a) MRPT_OVERRIDE {m_color.A=a; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
86  CRenderizable& setColor_u8( const mrpt::utils::TColor &c) MRPT_OVERRIDE { CRenderizable::setColor_u8(c); notifyChange(); return *this; } //!< Changes the default object color \return a ref to this
87 
88  /** @} */
89 
90  };
91  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CRenderizableDisplayList, CRenderizable, OPENGL_IMPEXP )
92 
93  } // end namespace
94 
95 } // End of namespace
96 
97 
98 #endif
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:44
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:36
mrpt::opengl::CRenderizable::readFromStreamRender
void readFromStreamRender(utils::CStream &in)
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:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:16
mrpt::opengl::CRenderizableDisplayList::readFromStreamRender
void readFromStreamRender(mrpt::utils::CStream &in)
Definition: CRenderizableDisplayList.h:58
mrpt::opengl::CRenderizableDisplayList::clone
CRenderizableDisplayList * clone() const
Interface for the stlplus smart pointer class.
Definition: CRenderizableDisplayList.h:71
mrpt::utils::CStream
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CSerializable.h:174
CRenderizable.h
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:56
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:42
DEFINE_VIRTUAL_SERIALIZABLE
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
Definition: CSerializable.h:192
DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
Definition: CSerializable.h:170
mrpt::utils::TColor
A RGB color - 8bit.
Definition: TColor.h:25
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:41
mrpt::opengl::CRenderizable::setColor_u8
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c)
MRPT_OVERRIDE
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Sat Jan 18 22:37:07 UTC 2020