Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

texture.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                       texture.h  -  Texture abstraction
00003                              -------------------
00004     begin                : Tue Oct 30 2001
00005     copyright            : (C) 2001 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, texture.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2001
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NETEXTURE_H
00028 #define __NETEXTURE_H
00029 
00030 
00031 
00038 #ifndef __NEED_VECTOR_STRING
00039 #  define __NEED_VECTOR_STRING
00040 #endif
00041 
00042 #include "base.h"
00043 #include "pointer.h"
00044 #include "filetype.h"
00045 #include "pool.h"
00046 #include "hashstring.h"
00047 #include "module.h"
00048 #include "logstream.h"
00049 
00050 #include <string>
00051 
00052 
00053 namespace NeoEngine
00054 {
00055 
00056 
00057 // External classes
00058 class RenderDevice;
00059 class FileManager;
00060 
00061 // Forward declarations
00062 class ImageData;
00063 class Texture;
00064 
00065 
00066 PoolExport( Texture );
00067 
00068 typedef Pool< Texture > TexturePool;
00069 
00070 
00071 
00080 class NEOENGINE_API Texture : public RefCounter
00081 {
00082     public:
00083 
00087         enum TEXTUREDEF
00088         {
00089           INVALIDID                                   = -1,
00090           FILEVERSION                                 =  1
00091         };
00092 
00096         enum TEXTUREINTERNALFORMAT
00097         {
00098           INTERNALFORMAT_RGB888                       = 0,
00099           INTERNALFORMAT_RGBA8888                     = 1,
00100           INTERNALFORMAT_RGBx8888                     = 2,
00101           INTERNALFORMAT_RGBA4444                     = 3,
00102           INTERNALFORMAT_RGBx4444                     = 4,
00103           INTERNALFORMAT_RGBA5551                     = 5,
00104           INTERNALFORMAT_RGBx5551                     = 6,
00105           INTERNALFORMAT_RGB565                       = 7,
00106           INTERNALFORMAT_ALPHA8                       = 8,
00107           INTERNALFORMAT_GRAY8                        = 9,
00108           INTERNALFORMAT_GRAYALPHA88                  = 10
00109         };
00110 
00114         enum TEXTUREFORMAT
00115         {
00117           DEFAULT                                     = -1,
00118           RGB                                         = 0,
00119           RGBA                                        = 1,
00120           ALPHA                                       = 2,
00121           GRAY                                        = 3,
00122           GRAYALPHA                                   = 4
00123         };
00124 
00128         enum TEXTURETYPE
00129         {
00131           TEX2D                                       = 0,
00132 
00134           CUBEMAP                                     = 1
00135         };
00136 
00140         enum TEXTURELOADFLAG
00141         {
00143           NOFLAGS                                     = 0,
00144 
00146           NOMIPMAPS                                   = 1
00147         };
00148 
00152         enum TEXTURECUBEMAPFACE
00153         {
00155           CUBEFACE_RIGHT                              = 0,
00156 
00158           CUBEFACE_LEFT                               = 1,
00159 
00161           CUBEFACE_UP                                 = 2,
00162 
00164           CUBEFACE_DOWN                               = 3,
00165 
00167           CUBEFACE_BACK                               = 4,
00168 
00170           CUBEFACE_FRONT                              = 5
00171         };
00172 
00176         enum TEXTUREFILTERMODE
00177         {
00179           NEAREST                                     = 1,
00180 
00182           LINEAR                                      = 2,
00183 
00185           ANISO                                       = 3,
00186 
00188           NOFILTERING                                 = ( NEAREST | ( NEAREST << 8 ) | ( NEAREST << 16 ) ),
00189 
00191           BILINEAR                                    = ( LINEAR  | ( LINEAR  << 8 ) | ( NEAREST << 16 ) ),
00192 
00194           TRILINEAR                                   = ( LINEAR  | ( LINEAR  << 8 ) | ( LINEAR  << 16 ) ),
00195 
00197           ANISOTROPIC                                 = ( ANISO | ( ANISO << 8 ) | ( ANISO << 16 ) )
00198         };
00199 
00200 
00201     protected:
00202 
00204         HashString                                    m_strName;
00205 
00207         int                                           m_iID;
00208 
00210         int                                           m_iWidth, m_iHeight;
00211 
00213         float                                         m_fWidth, m_fHeight;
00214 
00216         float                                         m_fRatio;
00217 
00219         TEXTURETYPE                                   m_eType;
00220 
00222         TEXTUREFORMAT                                 m_eFormat;
00223 
00225         int                                           m_iInternalFormat;
00226 
00228         TexturePool                                  *m_pkPool;
00229 
00231         unsigned int                                  m_uiFiltering;
00232 
00234         unsigned int                                  m_uiMaxAnisotropy;
00235 
00236     public:
00237 
00241                                                       Texture( const std::string &rstrName, TexturePool *pkTexturePool );
00242 
00246         virtual                                      ~Texture();
00247 
00251         inline int                                    GetID() const { return m_iID; }
00252 
00256         inline TEXTURETYPE                            GetType() const { return m_eType; }
00257 
00262         inline bool                                   IsValid() const { return( m_iID != INVALIDID ); }
00263 
00268         inline bool                                   HasAlpha() const { return( ( m_eFormat == RGBA ) || ( m_eFormat == ALPHA ) ); }
00269 
00273         inline float                                  GetWidth() const { return( IsValid() ? m_fWidth : 0.0f ); }
00274 
00278         inline float                                  GetHeight() const { return( IsValid() ? m_fHeight : 0.0f ); }
00279 
00283         void                                          SetName( const std::string &rstrName );
00284 
00288         inline const HashString                      &GetName() const { return m_strName; }
00289 
00293         inline TEXTUREFORMAT                          GetFormat() const { return m_eFormat; }
00294 
00298         inline unsigned int                           GetFiltering() const { return m_uiFiltering; }
00299 
00303         inline unsigned int                           GetMaxAnisotropy() const { return m_uiMaxAnisotropy; }
00304 
00314         virtual bool                                  UploadImage( ImageData *pkImageData, TEXTURETYPE eType = TEX2D, TEXTUREFORMAT eFormat = DEFAULT, unsigned int uiFlags = 0, unsigned int uiFiltering = 0, unsigned int uiMaxAnisotropy = 1 ) = 0;
00315 
00321         bool                                          GenerateNormalizationCubeMap( int iSize = 256 );
00322 
00329         static inline unsigned int                    BuildFilter( TEXTUREFILTERMODE eMinFilter, TEXTUREFILTERMODE eMagFilter, TEXTUREFILTERMODE eMipFilter ) { return( eMinFilter | ( eMagFilter << 8 ) | ( eMipFilter << 16 ) ); }
00330 
00335         inline void                                   SetMaxAnisotropy( unsigned int uiMaxAnisotropy ) { m_uiMaxAnisotropy = uiMaxAnisotropy; }
00336 
00342         inline bool                                   operator < ( const Texture &rkTexture ) const { return( m_iID < rkTexture.GetID() ); }
00343 
00349         inline bool                                   operator == ( const Texture &rkTexture ) const { return( ( m_eType == rkTexture.GetType() ) && ( m_eFormat == rkTexture.GetFormat() ) && ( m_strName == rkTexture.GetName() ) ); }
00350 };
00351 
00352 
00353 //Make a smart pointer typedef
00354 SmartPointer(Texture);
00355 
00356 
00357 #ifdef WIN32
00358 #  ifndef __HAVE_VECTOR_NETEXTURE
00359      UDTVectorEXPIMP( class Texture* );
00360 #    define __HAVE_VECTOR_NETEXTURE
00361 #  endif
00362 #endif
00363 
00364 
00369 class NEOENGINE_API ImageData
00370 {
00371     public:
00372 
00374         int                                           m_iWidth;
00375 
00377         int                                           m_iHeight;
00378 
00380         Texture::TEXTUREFORMAT                        m_eFormat;
00381 
00383         int                                           m_iChannels;
00384 
00386         int                                           m_iBPP;
00387 
00389         unsigned char                                *m_pucData;
00390 
00392         class ImageCodec                             *m_pkCodec;
00393 
00395         int                                           m_iMipMaps;
00396         
00398         ImageData                                    *m_pkMipMaps;
00399         
00400         
00404                                                       ImageData() : m_iWidth(0), m_iHeight(0), m_eFormat( Texture::RGB ), m_pucData(0), m_pkCodec(0), m_iMipMaps(0), m_pkMipMaps(0) {}
00405 
00409         virtual                                      ~ImageData();
00410 
00414         virtual void                                  CreateMipMaps();
00415 
00426         static bool                                   ScaleImage( int iComp, int iInWidth, int iInHeight, const unsigned char *pInData, int iOutWidth, int iOutHeight, unsigned char *pOutData );
00427 };
00428 
00429 
00434 class NEOENGINE_API ImageCodec : public FiletypeIdentifier
00435 {
00436     friend class TextureLoader;
00437 
00438     protected:
00439 
00441         ModulePtr                                     m_pkModule;
00442 
00443     
00444     public:
00445         
00450                                                       ImageCodec( const std::string &rstrFiletypeName, const std::vector<std::string> &rvstrExtensions );
00451 
00454         virtual                                      ~ImageCodec();
00455 
00461         virtual ImageData                            *LoadImage( File *pkFile ) = 0;
00462 
00467         virtual void                                  FreeImage( ImageData *pkImageData ) = 0;
00468 };
00469 
00470 
00471 
00472 
00473 #ifdef WIN32
00474 #  ifndef __HAVE_VECTOR_NEIMAGECODEC
00475      UDTVectorEXPIMP( class ImageCodec* );
00476 #    define __HAVE_VECTOR_NEIMAGECODEC
00477 #  endif
00478 #endif
00479 
00480 
00487 class NEOENGINE_API TextureLoader
00488 {
00489     protected:
00490 
00492         std::vector< ImageCodec* >                    m_vpkCodecs;
00493 
00495         FileManager                                  *m_pkFileManager;
00496 
00497 
00498     public:
00499 
00503                                                       TextureLoader( FileManager *pkFileManager = 0 );
00504 
00507         virtual                                      ~TextureLoader();
00508 
00514         bool                                          LoadCodec( const std::string &rstrName );
00515         
00521         ImageData                                    *LoadImageData( File *pkFile );
00522 
00528         ImageData                                    *LoadImageData( const std::string &rstrFilename );
00529         
00534         void                                          FreeImageData( ImageData *pkImageData );
00535 };
00536 
00537 
00538 };
00539 
00540 
00541 #endif // __NETEXTURE_H
00542 

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5