Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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  inline CRenderizable& setColor_u8( uint8_t R, uint8_t G, uint8_t B, uint8_t A=255) { CRenderizable::setColor_u8(R,G,B,A); notifyChange(); return *this; } //!<Color components in the range [0,255] \return a ref to this
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
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:5406
GLboolean GLboolean g
Definition: glew.h:5406
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
CRenderizable & setColor_u8(uint8_t R, uint8_t G, uint8_t B, uint8_t A=255)
Color components in the range [0,255].
const GLfloat * c
Definition: glew.h:10088
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:44
CRenderizableDisplayList * clone() const
Interface for the stlplus smart pointer class.
GLuint in
Definition: glew.h:7146
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
unsigned char uint8_t
Definition: rptypes.h:43
A renderizable object suitable for rendering with OpenGL's display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#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...
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 ...
CRenderizable & setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE
Changes the default object color.
CRenderizable & setColorG_u8(const uint8_t g) MRPT_OVERRIDE
Color components in the range [0,255].
void readFromStreamRender(mrpt::utils::CStream &in)
A RGB color - 8bit.
Definition: TColor.h:26
CRenderizable & setColorB_u8(const uint8_t b) MRPT_OVERRIDE
Color components in the range [0,255].
void readFromStreamRender(utils::CStream &in)
const float R
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c)
GLdouble GLdouble GLdouble r
Definition: glew.h:1311
GLdouble GLdouble GLdouble b
Definition: glew.h:5092
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
CRenderizable & setColorA_u8(const uint8_t a) MRPT_OVERRIDE
Color components in the range [0,255].



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018