00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00061
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
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
00101
00102
00103
00104 class ITexture : public CBitmap, public NLMISC::CRefCount, public NLMISC::IStreamable
00105 {
00106 public:
00107
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
00171
00173
00175
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
00237 nlassert(!supportSharing());
00238
00239 if (!isAllInvalidated ())
00240 {
00241
00242 _ListInvalidRect.push_back (rect);
00243
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
00363
00364
00365
00366
00367 protected:
00368
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
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
00427
00428
00429
00430 void clearTouched(void)
00431 {
00432 _Touched=false;
00433 _ListInvalidRect.clear();
00434 }
00435
00436
00437
00438 };
00439
00440
00441
00442 }
00443
00444
00445 #endif // NL_TEXTURE_H
00446
00447