Home | nevrax.com |
|
async_texture_manager.hGo to the documentation of this file.00001 00007 /* Copyright, 2000-2002 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_ASYNC_TEXTURE_MANAGER_H 00027 #define NL_ASYNC_TEXTURE_MANAGER_H 00028 00029 00030 #include "nel/misc/types_nl.h" 00031 #include "3d/texture_file.h" 00032 #include "3d/hls_texture_manager.h" 00033 #include <vector> 00034 #include "nel/misc/bitmap.h" 00035 00036 00037 namespace NL3D 00038 { 00039 00040 00041 class CMeshBaseInstance; 00042 00043 00044 // *************************************************************************** 00053 class CAsyncTextureManager 00054 { 00055 public: 00057 CHLSTextureManager HLSManager; 00058 00059 public: 00060 00062 CAsyncTextureManager(); 00063 ~CAsyncTextureManager(); 00064 00072 void setupLod(uint baseLevel, uint maxLevel); 00074 void setupMaxUploadPerFrame(uint maxup); 00076 void setupMaxHLSColoringPerFrame(uint maxCol); 00078 void setupMaxTotalTextureSize(uint maxText); 00079 00091 uint addTextureRef(const std::string &textName, CMeshBaseInstance *instance); 00092 00094 void releaseTexture(uint id, CMeshBaseInstance *instance); 00095 00097 bool isTextureUpLoaded(uint id) const; 00098 00103 const NLMISC::CBitmap *getCoarseBitmap(uint id) const; 00104 00105 00109 void update(IDriver *pDriver); 00110 00111 00113 uint getTotalTextureSizeAsked() const {return _TotalTextureSizeAsked;} 00115 uint getLastTextureSizeGot() const {return _LastTextureSizeGot;} 00116 00117 00118 // *************************************************************************** 00119 private: 00120 00121 typedef std::map<std::string, uint> TTextureEntryMap; 00122 typedef TTextureEntryMap::iterator ItTextureEntryMap; 00123 00124 00125 // A base texture uploadable. 00126 class CTextureBase 00127 { 00128 public: 00129 // the texture currently loaded / uploaded. 00130 NLMISC::CSmartPtr<CTextureFile> Texture; 00131 00132 bool isTextureEntry() const {return IsTextureEntry;} 00133 protected: 00134 bool IsTextureEntry; 00135 }; 00136 00137 00138 class CTextureEntry; 00139 00140 00141 // A Lod version of a texture entry. 00142 class CTextureLod : public CTextureBase 00143 { 00144 public: 00145 CTextureLod(); 00146 00147 // A Ptr on the real texture used. 00148 CTextureEntry *TextureEntry; 00149 // Weight of the lod, according to distance and level. 00150 float Weight; 00151 // the level of this Lod. 0 means full original texture resolution. 00152 uint8 Level; 00153 // True if loading has ended 00154 bool Loaded; 00155 // True if TextureEntry has at least this lod in VRAM 00156 bool UpLoaded; 00157 // The size that this lod takes in VRAM (minus TextureEntry->BaseSize) 00158 uint ExtraSize; 00159 }; 00160 00161 00162 class CPredTextLod 00163 { 00164 public: 00165 bool operator()(CTextureLod *lod0, CTextureLod *lod1) 00166 { 00167 return lod0->Weight<lod1->Weight; 00168 } 00169 }; 00170 00171 00172 // A texture entry 00173 class CTextureEntry : public CTextureBase 00174 { 00175 public: 00176 // The it in the map. 00177 ItTextureEntryMap ItMap; 00178 // true if async loading has ended 00179 bool Loaded; 00180 // true if the texture is loaded in the driver (at least the coarsest level). 00181 bool UpLoaded; 00182 // true if first loading ended, and if DXTC with mipmap 00183 bool CanHaveLOD; 00184 // true if this texture must be builded from the HLSManager (at first load) 00185 bool BuildFromHLSManager; 00186 // if BuildFromHLSManager, gives the text id in the manager 00187 sint HLSManagerTextId; 00188 00189 // Base Size of the texture, without HDLod 00190 uint BaseSize; 00191 // list of instances currently using this texture. 00192 std::vector<CMeshBaseInstance*> Instances; 00193 // min distance of all Instances. 00194 float MinDistance; 00195 // with all mipmaps loaded, what place this takes. 00196 uint TotalTextureSizeAsked; 00197 00198 // The High Def Lod. 00199 CTextureLod HDLod; 00200 00201 // The Coarse Bitmap stored in RAM for CLod 00202 NLMISC::CBitmap CoarseBitmap; 00203 00204 public: 00205 CTextureEntry(); 00206 00207 void createCoarseBitmap(); 00208 }; 00209 00210 00211 private: 00212 uint _BaseLodLevel, _MaxLodLevel; 00213 uint _MaxUploadPerFrame; 00214 uint _MaxHLSColoringPerFrame; 00215 uint _MaxTotalTextureSize; 00216 uint _TotalTextureSizeAsked; 00217 uint _LastTextureSizeGot; 00218 00219 // Textures Entries. 00220 std::vector<CTextureEntry*> _TextureEntries; 00221 std::vector<uint> _FreeTextureIds; 00222 TTextureEntryMap _TextureEntryMap; 00223 std::vector<uint> _WaitingTextures; 00224 00225 // Upload of texture piece by piece. 00226 CTextureBase *_CurrentUploadTexture; 00227 uint _CurrentUploadTextureMipMap; 00228 uint _CurrentUploadTextureLine; 00229 00230 // The current HDLod async loaded (NB: loaded / or upLoaded) 00231 CTextureLod *_CurrentTextureLodLoaded; 00232 00233 private: 00234 00235 static bool validDXTCMipMap(ITexture *pText); 00236 00237 // delete the texture and all references in map/array, instance refcount etc... 00238 void deleteTexture(uint id); 00239 00240 // Fill _CurrentUploadTexture with next texture to upload, or set NULL if none 00241 void getNextTextureToUpLoad(uint &nTotalColored, IDriver *pDriver); 00242 bool uploadTexturePart(ITexture *pText, IDriver *pDriver, uint &nTotalUpload); 00243 00244 // update list of texture lods. 00245 void updateTextureLodSystem(IDriver *pDriver); 00246 00247 }; 00248 00249 00250 } // NL3D 00251 00252 00253 #endif // NL_ASYNC_TEXTURE_MANAGER_H 00254 00255 /* End of async_texture_manager.h */ |