Main MRPT website > C++ reference
MRPT logo
CRenderizableDisplayList.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_CRenderizableDisplayList_H
29 #define opengl_CRenderizableDisplayList_H
30 
32 
33 namespace mrpt
34 {
35  namespace opengl
36  {
37  #define INVALID_DISPLAY_LIST_ID static_cast<unsigned int>(-1)
38 
39  // This must be added to any CSerializable derived class:
41 
42  /** A renderizable object suitable for rendering with OpenGL's display lists.
43  * The idea is to use the derived classes' ::render() method to save all the primitives
44  * into one display list, then in subsequent rendering events, just execute the list.
45  * This method is normally faster since it avoids the bottleneck between CPU-GPU. On the
46  * other hand, it demands more memory on the graphic card.
47  *
48  * Instructions for implementing derived classes:
49  * - Each time the object is modified is some way that modifies its appearance, you must call notifyChange()
50  * - Implement the rendering method: render_dl(), calling to OpenGL primitives as usual. They'll be saved in a display list transparently.
51  *
52  * \sa mrpt::opengl::CRenderizable
53  * \ingroup mrpt_opengl_grp
54  */
56  {
58 
59  private:
60  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).
61  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...).
62 
63  protected:
64  /** @name Methods accesible or implemented by derived classes
65  @{ */
66 
67  /** Must be called to notify that the object has changed (so, the display list must be updated) */
68  EIGEN_STRONG_INLINE void notifyChange() const { m_dl_recreate=true;}
69 
70  /** Derived classes must implement this method to the render the object. */
71  virtual void render_dl() const = 0;
72 
73  /** Optional: If the object has some state in which creating a display list is NOT preferred over direct rendering,
74  * implement this method and return "true" in those cases. */
75  virtual bool should_skip_display_list_cache() const { return false; }
76 
77  inline void readFromStreamRender(mrpt::utils::CStream &in)
78  {
80  notifyChange();
81  }
82 
83  /** @} */
84 
85  public:
87  virtual ~CRenderizableDisplayList();
88 
89  /** Interface for the stlplus smart pointer class. */
90  inline CRenderizableDisplayList * clone() const
91  {
92  return static_cast<CRenderizableDisplayList*>( this->duplicate() );
93  }
94 
95  /** Render the object, regenerating the display list if needed, otherwise just calling it. */
96  virtual void render() const;
97 
98 
99  /** @name Changes the appearance of the object to render (methods from CRenderizable that need to be redefined)
100  @{ */
101 
102  virtual CRenderizable& setColorR_u8(const uint8_t r) {m_color.R=r; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
103  virtual CRenderizable& setColorG_u8(const uint8_t g) {m_color.G=g; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
104  virtual CRenderizable& setColorB_u8(const uint8_t b) {m_color.B=b; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
105  virtual CRenderizable& setColorA_u8(const uint8_t a) {m_color.A=a; notifyChange(); return *this;} //!<Color components in the range [0,255] \return a ref to this
106  virtual CRenderizable& setColor_u8( const mrpt::utils::TColor &c) { CRenderizable::setColor_u8(c); notifyChange(); return *this; } //!< Changes the default object color \return a ref to this
107 
108  /** @} */
109 
110  };
111 
112  } // end namespace
113 
114 } // End of namespace
115 
116 
117 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013