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_CTexturedObject_H 00029 #define opengl_CTexturedObject_H 00030 00031 #include <mrpt/opengl/CRenderizableDisplayList.h> 00032 #include <mrpt/utils/CImage.h> 00033 #include <mrpt/math/geometry.h> 00034 00035 namespace mrpt 00036 { 00037 namespace opengl 00038 { 00039 class OPENGL_IMPEXP CTexturedObject; 00040 00041 // This must be added to any CSerializable derived class: 00042 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CTexturedObject, CRenderizableDisplayList, OPENGL_IMPEXP ) 00043 00044 /** A base class for all OpenGL objects with loadable textures. 00045 * \sa opengl::COpenGLScene, opengl::CTexturedPlane, opengl::CSetOfTexturedTriangles 00046 */ 00047 class OPENGL_IMPEXP CTexturedObject : public CRenderizableDisplayList 00048 { 00049 DEFINE_VIRTUAL_SERIALIZABLE( CTexturedObject ) 00050 00051 protected: 00052 mutable unsigned int m_glTextureName; 00053 mutable bool m_texture_is_loaded; 00054 mutable mrpt::utils::CImage m_textureImage; 00055 mutable mrpt::utils::CImage m_textureImageAlpha; 00056 mutable bool m_enableTransparency; //!< Of the texture using "m_textureImageAlpha" 00057 mutable int r_width,r_height; //!< Size of the texture image, rounded up to next power of 2 00058 mutable int m_fill_x_left,m_fill_y_top,m_fill_x_right,m_fill_y_bottom; //!< The size of the fill in pixels in the textured image, w.r.t the image passed by the user. 00059 00060 00061 CTexturedObject(); 00062 virtual ~CTexturedObject(); 00063 void unloadTexture(); 00064 00065 virtual void render_pre() const; 00066 virtual void render_post() const; 00067 00068 virtual void render_texturedobj() const = 0; //!< Must be implemented by derived classes 00069 00070 void writeToStreamTexturedObject(mrpt::utils::CStream &out) const; 00071 void readFromStreamTexturedObject(mrpt::utils::CStream &in); 00072 00073 public: 00074 /** Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M, they will be internally filled to its dimensions to be powers of two) 00075 * \note Images are copied, the original ones can be deleted. 00076 */ 00077 void assignImage( 00078 const mrpt::utils::CImage& img, 00079 const mrpt::utils::CImage& imgAlpha ); 00080 00081 /** Assigns a texture image, and disable transparency. 00082 * \note Images are copied, the original ones can be deleted. */ 00083 void assignImage(const mrpt::utils::CImage& img ); 00084 00085 /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. */ 00086 void assignImage_fast( 00087 mrpt::utils::CImage& img, 00088 mrpt::utils::CImage& imgAlpha ); 00089 00090 /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. */ 00091 void assignImage_fast(mrpt::utils::CImage& img ); 00092 00093 /** VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that will later destruct the object in order to the OpenGL texture memory to be correctly deleted. 00094 * Calling this method more than once has no effects. If you use one thread, this method will be automatically called when rendering, so there is no need to explicitly call it. 00095 */ 00096 void loadTextureInOpenGL() const; 00097 00098 virtual void render_dl() const; 00099 00100 }; 00101 00102 } // end namespace 00103 00104 } // End of namespace 00105 00106 00107 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011 |