Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxGLTexture.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_gfx_gfxGLTexture_h
00020 #define freecloth_gfx_gfxGLTexture_h
00021 
00022 #ifndef freecloth_gfx_package_h
00023 #include <freecloth/gfx/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_resmgt_rcShdPtr_h
00027 #include <freecloth/resmgt/rcShdPtr.h>
00028 #endif
00029 
00030 #ifndef freecloth_resmgt_rcBase_h
00031 #include <freecloth/resmgt/rcBase.h>
00032 #endif
00033 
00034 ////////////////////////////////////////////////////////////////////////////////
00035 // FORWARD DECLARATIONS
00036 
00037 class GfxImage;
00038 
00039 FREECLOTH_NAMESPACE_START
00040     class GePoint;
00041 FREECLOTH_NAMESPACE_END
00042 
00043 ////////////////////////////////////////////////////////////////////////////////
00044 /*!
00045  * \class GfxGLTexture freecloth/gfx/gfxGLTexture.h
00046  * \brief Wrapper around an image and handle allocation of graphics RAM.
00047  *
00048  * Image is padded to a power-of-2 size, as required by OpenGL.
00049  */
00050 class GfxGLTexture : public RCBase
00051 {
00052 
00053 public:
00054     //----- types and enumerations -----
00055     typedef RCShdPtr<GfxImage> ImagePtr;
00056 
00057     //----- member functions -----
00058 
00059     GfxGLTexture(
00060         const ImagePtr& image,
00061         Int32 format
00062     );
00063     virtual ~GfxGLTexture();
00064     UInt32  getTextureId() const;
00065 
00066     //! Get position of top-right corner of image in texture co-ordinates.
00067     //! If the input image is a large enough power-of-2 size, this will always
00068     //! be (1,1).
00069     //! Otherwise, the image is padded with zeros to a power-of-2 size, and
00070     //! the top-right corner will have a (u,v) position somewhere between
00071     //! (.5,.5) and (1,1)
00072     GePoint getCorner() const;
00073 
00074     void    bind() const;
00075     void    generateMipmaps();
00076 
00077     //! Get width of texture image prior to power-of-2 related padding
00078     UInt32 getOriginalWidth() const;
00079     //! Get height of texture image prior to power-of-2 related padding
00080     UInt32 getOriginalHeight() const;
00081     //! Get aspect ratio prior to power-of-2 related padding
00082     Float getOriginalAspectRatio() const;
00083     //! Get actual image used for texture
00084     const GfxImage& getImage() const;
00085 
00086     //----- static member functions -----
00087 
00088     //! Embeds input image in a larger image whose size is a power of two.
00089     //! Keep in mind that texture co-ordinates need to take into account the
00090     //! new image size.
00091     static RCShdPtr<GfxImage> makePow2( const GfxImage& );
00092 
00093 private:
00094 
00095     //----- member functions -----
00096     //! Disallowed.
00097     GfxGLTexture( const GfxGLTexture& );
00098     //! Disallowed.
00099     GfxGLTexture& operator = ( const GfxGLTexture& );
00100 
00101     //----- data members -----
00102 
00103     ImagePtr    _image;
00104     UInt32      _textureId;
00105     Int32       _format;
00106     UInt32      _originalWidth;
00107     UInt32      _originalHeight;
00108 };
00109 #endif

Generated on Fri May 2 16:51:13 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002