# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

texture.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_TEXTURE_H
00027 #define NL_TEXTURE_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/stream.h"
00032 #include "nel/misc/rect.h"
00033 #include "nel/misc/bitmap.h"
00034 #include <string>
00035 #include <list>
00036 #include <map>
00037 
00038 
00039 namespace NL3D 
00040 {
00041 
00042 
00043 using NLMISC::CBitmap;
00044 
00045 
00046 class   IDriver;
00047 
00048 
00049 //****************************************************************************
00050 
00051 // List typedef.
00052 class   ITextureDrvInfos;
00053 class   CTextureDrvShare;
00054 class TTexDrvInfoPtrMap : public std::map< std::string, ITextureDrvInfos*> {};
00055 typedef std::list<CTextureDrvShare*>            TTexDrvSharePtrList;
00056 typedef TTexDrvInfoPtrMap::iterator                     ItTexDrvInfoPtrMap;
00057 typedef TTexDrvSharePtrList::iterator           ItTexDrvSharePtrList;
00058 
00059 
00060 // Class for interaction of textures with Driver.
00061 // ITextureDrvInfos represent the real data of the texture, stored into the driver (eg: just a GLint for opengl).
00062 class ITextureDrvInfos : public NLMISC::CRefCount
00063 {
00064 private:
00065         IDriver                                 *_Driver;
00066         ItTexDrvInfoPtrMap              _DriverIterator;
00067 
00068 public:
00069         ITextureDrvInfos(IDriver *drv, ItTexDrvInfoPtrMap it) {_Driver= drv; _DriverIterator= it;}
00070         ITextureDrvInfos(class IDriver& driver);
00071         virtual ~ITextureDrvInfos(void);
00072 };
00073 
00074 // Many ITexture may point to the same ITextureDrvInfos, through CTextureDrvShare.
00075 class CTextureDrvShare : public NLMISC::CRefCount
00076 {
00077 private:
00078         IDriver                                 *_Driver;
00079         ItTexDrvSharePtrList    _DriverIterator;
00080 
00081 public:
00082         NLMISC::CSmartPtr<ITextureDrvInfos>             DrvTexture;
00083 
00084 public:
00085         CTextureDrvShare(IDriver *drv, ItTexDrvSharePtrList it) {_Driver= drv; _DriverIterator= it;}
00086         ~CTextureDrvShare();
00087 };
00088 
00089 
00090 //****************************************************************************
00100 /* *** IMPORTANT ********************
00101  * *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL
00102  * **********************************
00103  */
00104 class ITexture : public CBitmap, public NLMISC::CRefCount, public NLMISC::IStreamable
00105 {
00106 public:
00107         // Those enums MUST be the same than in UTexture!!
00108 
00109         enum    TWrapMode
00110         {
00111                 Repeat= 0,
00112                 Clamp,
00113 
00114                 WrapModeCount
00115         };
00116 
00117         enum    TUploadFormat
00118         {
00119                 Auto= 0,
00120                 RGBA8888,
00121                 RGBA4444,
00122                 RGBA5551,
00123                 RGB888,
00124                 RGB565,
00125                 DXTC1,
00126                 DXTC1Alpha,
00127                 DXTC3,
00128                 DXTC5,
00129                 Luminance,
00130                 Alpha,
00131                 AlphaLuminance,
00132                 DsDt,
00133                 UploadFormatCount
00134         };
00135 
00136 
00140         enum    TMagFilter
00141         {
00142                 Nearest=0,
00143                 Linear,
00144 
00145                 MagFilterCount
00146         };
00147 
00151         enum    TMinFilter
00152         {
00153                 NearestMipMapOff=0,
00154                 NearestMipMapNearest,
00155                 NearestMipMapLinear,
00156                 LinearMipMapOff,
00157                 LinearMipMapNearest,
00158                 LinearMipMapLinear,
00159 
00160                 MinFilterCount
00161         };
00162 
00163 
00164 public:
00165 
00167         // @{
00169         ITexture();
00171         ITexture(const ITexture &tex) {operator=(tex);}
00173         virtual ~ITexture();
00175         ITexture &operator=(const ITexture &tex);
00176         // @}
00177 
00178 
00180 
00193         // @{
00194         void                    setWrapS(TWrapMode mode) {_WrapS= mode;}
00195         void                    setWrapT(TWrapMode mode) {_WrapT= mode;}
00196         TWrapMode               getWrapS() const {return _WrapS;}
00197         TWrapMode               getWrapT() const {return _WrapT;}
00203         void                    setUploadFormat(TUploadFormat pf);
00204         TUploadFormat   getUploadFormat() const {return _UploadFormat;}
00205         virtual         void setFilterMode(TMagFilter magf, TMinFilter minf);
00206         TMagFilter              getMagFilter() const {return _MagFilter;}
00207         TMinFilter              getMinFilter() const {return _MinFilter;}
00208         bool                    mipMapOff() const {return _MinFilter==NearestMipMapOff || _MinFilter==LinearMipMapOff;}
00209         bool                    mipMapOn() const {return !mipMapOff();}
00210         // @}
00211 
00212 
00219         void    touch() 
00220         { 
00221                 _ListInvalidRect.clear (); 
00222                 _Touched=true; 
00223                 _GoodGenerate= false;
00224         }
00225 
00234         void    touchRect(const NLMISC::CRect& rect) 
00235         { 
00236                 // The texture must not support sharing....
00237                 nlassert(!supportSharing());
00238                 // Don't invalidate the rectangle if the full texture is already invalidated.
00239                 if (!isAllInvalidated ())
00240                 {
00241                         // Add the region to invalidate list
00242                         _ListInvalidRect.push_back (rect); 
00243                         // Touch flag
00244                         _Touched=true; 
00245                 }
00246 
00247                 _GoodGenerate= false;
00248         }
00249 
00250         
00259         bool getReleasable() const { return _Releasable; }
00260 
00261 
00270         void setReleasable(bool r) { _Releasable = r; }
00271 
00295         void generate()
00296         {
00297                 if(!_GoodGenerate)
00298                 {
00299                         doGenerate();
00300                         _GoodGenerate=true;
00301                 }
00302         }
00303 
00308         void validateGenerateFlag() {_GoodGenerate=true;}
00309 
00313         virtual void release() { reset(); _GoodGenerate= false; }
00314 
00318         virtual bool                    supportSharing() const {return false;}
00319 
00324         virtual std::string             getShareName() const {return std::string();}
00325 
00329         bool    setupedIntoDriver() const 
00330         {
00331                 return TextureDrvShare!=NULL;
00332         }
00333 
00335         void    releaseDriverSetup();
00336 
00338         virtual bool allowDegradation() const { return false; }
00339 
00341         virtual void    serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00342 
00346         virtual void selectTexture(uint index) {}
00347 
00349         virtual bool isSelectable() const { return false; }
00350 
00354         virtual ITexture *buildNonSelectableVersion(uint index) { return this; }
00355 
00356 
00357 
00358         
00360         // @{
00362                 virtual bool isTextureCube() const { return false; }    
00363         // @}
00364 
00365 //****************************
00366 // Private part.
00367 protected:
00368         // Derived texture should set it to true when they are updated.
00369         bool            _Touched;
00370 
00371 
00382         virtual void doGenerate() = 0;
00383 
00384 
00385 private:
00386         bool                    _GoodGenerate;
00387         bool                    _Releasable;
00388         TUploadFormat   _UploadFormat;
00389         TWrapMode               _WrapS;
00390         TWrapMode               _WrapT;
00391         TMinFilter              _MinFilter;
00392         TMagFilter              _MagFilter;
00393 
00394 public:
00395         // Private Part!!!. For Driver Only.
00396         //==================================
00397 
00398         NLMISC::CRefPtr<CTextureDrvShare>       TextureDrvShare;
00404         std::list<NLMISC::CRect>        _ListInvalidRect;
00405 
00406 
00410         bool                                    isAllInvalidated () const
00411         {
00412                 return  _Touched&&(_ListInvalidRect.begin()==_ListInvalidRect.end());
00413         }
00414 
00420         bool    touched (void)
00421         {
00422                 return _Touched;
00423         }
00424 
00425         /*
00426          * Clear the touched flag and the invalid rectangle list
00427          *
00428          * \see isAllInvalidated(), generate(), touch(), touched(), touchRect(), _ListInvalidRect
00429          */
00430         void    clearTouched(void) 
00431         { 
00432                 _Touched=false; 
00433                 _ListInvalidRect.clear();
00434         }
00435 
00436 
00437 
00438 };
00439 
00440 
00441 
00442 } // NL3D
00443 
00444 
00445 #endif // NL_TEXTURE_H
00446 
00447 /* End of texture.h */