00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef opengl_CRenderizableDisplayList_H 00029 #define opengl_CRenderizableDisplayList_H 00030 00031 #include <mrpt/opengl/CRenderizable.h> 00032 00033 namespace mrpt 00034 { 00035 namespace opengl 00036 { 00037 #define INVALID_DISPLAY_LIST_ID static_cast<unsigned int>(-1) 00038 00039 // This must be added to any CSerializable derived class: 00040 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CRenderizableDisplayList, CRenderizable, OPENGL_IMPEXP ) 00041 00042 /** A renderizable object suitable for rendering with OpenGL's display lists. 00043 * The idea is to use the derived classes' ::render() method to save all the primitives 00044 * into one display list, then in subsequent rendering events, just execute the list. 00045 * This method is normally faster since it avoids the bottleneck between CPU-GPU. On the 00046 * other hand, it demands more memory on the graphic card. 00047 * 00048 * Instructions for implementing derived classes: 00049 * - Each time the object is modified is some way that modifies its appearance, you must call notifyChange() 00050 * - Implement the rendering method: render_dl(), calling to OpenGL primitives as usual. They'll be saved in a display list transparently. 00051 * 00052 * \sa mrpt::opengl::CRenderizable 00053 */ 00054 class OPENGL_IMPEXP CRenderizableDisplayList : public mrpt::opengl::CRenderizable 00055 { 00056 DEFINE_VIRTUAL_SERIALIZABLE( CRenderizableDisplayList ) 00057 00058 private: 00059 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). 00060 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...). 00061 00062 protected: 00063 /** @name Methods accesible or implemented by derived classes 00064 @{ */ 00065 00066 /** Must be called to notify that the object has changed (so, the display list must be updated) */ 00067 EIGEN_STRONG_INLINE void notifyChange() const { m_dl_recreate=true;} 00068 00069 /** Derived classes must implement this method to the render the object. */ 00070 virtual void render_dl() const = 0; 00071 00072 /** Optional: If the object has some state in which creating a display list is NOT preferred over direct rendering, 00073 * implement this method and return "true" in those cases. */ 00074 virtual bool should_skip_display_list_cache() const { return false; } 00075 00076 inline void readFromStreamRender(mrpt::utils::CStream &in) 00077 { 00078 CRenderizable::readFromStreamRender(in); 00079 notifyChange(); 00080 } 00081 00082 /** @} */ 00083 00084 public: 00085 CRenderizableDisplayList(); 00086 virtual ~CRenderizableDisplayList(); 00087 00088 /** Interface for the stlplus smart pointer class. */ 00089 inline CRenderizableDisplayList * clone() const 00090 { 00091 return static_cast<CRenderizableDisplayList*>( this->duplicate() ); 00092 } 00093 00094 /** Render the object, regenerating the display list if needed, otherwise just calling it. */ 00095 virtual void render() const; 00096 00097 00098 /** @name Changes the appearance of the object to render (methods from CRenderizable that need to be redefined) 00099 @{ */ 00100 00101 virtual CRenderizable& setColorR(const double r) {m_color_R=r; notifyChange(); return *this;} //!<Color components in the range [0,1] \return a ref to this 00102 virtual CRenderizable& setColorG(const double g) {m_color_G=g; notifyChange(); return *this;} //!<Color components in the range [0,1] \return a ref to this 00103 virtual CRenderizable& setColorB(const double b) {m_color_B=b; notifyChange(); return *this;} //!<Color components in the range [0,1] \return a ref to this 00104 virtual CRenderizable& setColorA(const double a) {m_color_A=a; notifyChange(); return *this;} //!<Color components in the range [0,1] \return a ref to this 00105 virtual CRenderizable& setColor( const mrpt::utils::TColorf &c); //!< Changes the default object color \return a ref to this 00106 virtual CRenderizable& setColor( double R, double G, double B, double A=1); //!< Set the color components of this object (R,G,B,Alpha, in the range 0-1) \return a ref to this 00107 00108 /** @} */ 00109 00110 }; 00111 00112 } // end namespace 00113 00114 } // End of namespace 00115 00116 00117 #endif
Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011 |