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
14namespace 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:
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:
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
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
#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...
A renderizable object suitable for rendering with OpenGL's display lists.
unsigned int m_dl
Display list ID, for derived classes that want to use it (it's automatically deleted and freed on des...
CRenderizable & setColorG_u8(const uint8_t g) MRPT_OVERRIDE
Color components in the range [0,255].
CRenderizableDisplayList * clone() const
Interface for the stlplus smart pointer class.
void render() const MRPT_OVERRIDE
Render the object, regenerating the display list if needed, otherwise just calling it.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
CRenderizable & setColor_u8(const mrpt::utils::TColor &c) MRPT_OVERRIDE
Changes the default object color.
CRenderizable & setColorB_u8(const uint8_t b) MRPT_OVERRIDE
Color components in the range [0,255].
CRenderizable & setColorA_u8(const uint8_t a) MRPT_OVERRIDE
Color components in the range [0,255].
virtual void render_dl() const =0
Derived classes must implement this method to the render the object.
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 ...
bool m_dl_recreate
If using display lists, this is true when the list must be updated (the object changes,...
void readFromStreamRender(mrpt::utils::CStream &in)
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:45
void readFromStreamRender(utils::CStream &in)
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:39
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned char uint8_t
Definition: pstdint.h:143
A RGB color - 8bit.
Definition: TColor.h:26



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Tue Jan 17 22:40:29 UTC 2023