00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 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/CRenderizable.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, CRenderizable, 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 CRenderizable 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 void render_texture_pre() const; 00066 void render_texture_post() const; 00067 00068 void writeToStreamTexturedObject(mrpt::utils::CStream &out) const; 00069 void readFromStreamTexturedObject(mrpt::utils::CStream &in); 00070 00071 public: 00072 /** 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) 00073 * \note Images are copied, the original ones can be deleted. 00074 */ 00075 void assignImage( 00076 const mrpt::utils::CImage& img, 00077 const mrpt::utils::CImage& imgAlpha ); 00078 00079 /** Assigns a texture image, and disable transparency. 00080 * \note Images are copied, the original ones can be deleted. */ 00081 void assignImage(const mrpt::utils::CImage& img ); 00082 00083 /** 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. */ 00084 void assignImage_fast( 00085 mrpt::utils::CImage& img, 00086 mrpt::utils::CImage& imgAlpha ); 00087 00088 /** 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. */ 00089 void assignImage_fast(mrpt::utils::CImage& img ); 00090 00091 /** 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. 00092 * 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. 00093 */ 00094 void loadTextureInOpenGL() const; 00095 00096 }; 00097 00098 } // end namespace 00099 00100 } // End of namespace 00101 00102 00103 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
