diff options
Diffstat (limited to 'docs/doxygen/nel/async__texture__manager_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/async__texture__manager_8cpp-source.html | 865 |
1 files changed, 865 insertions, 0 deletions
diff --git a/docs/doxygen/nel/async__texture__manager_8cpp-source.html b/docs/doxygen/nel/async__texture__manager_8cpp-source.html new file mode 100644 index 00000000..1f04a66c --- /dev/null +++ b/docs/doxygen/nel/async__texture__manager_8cpp-source.html @@ -0,0 +1,865 @@ +<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<HTML> +<HEAD> + <TITLE>nevrax.org : docs</TITLE> + <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css"> + <link href="doxygen.css" rel="stylesheet" type="text/css"> +</HEAD> +<BODY MARGINHEIGHT="0" MARGINWIDTH="0"> + +<!-- uplinks --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD> + </TR> +</TABLE> + +<!-- banner Nevrax --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%> + <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR> +</TABLE> + +<!-- main table --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + + <!------ Begin Box ------> + <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black> + <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF> + <TABLE cellspacing=0 cellpadding=1 border=0> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr> + </TABLE> + </TD></TR></TABLE></TD></TR></TABLE> + <!------ End Box ------> + + </TD> + <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + +<!-- title --> +<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td> +<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A> +</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT=""> +</td></tr></table> + + +<!-- block --> +<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD> + <TD><B>Documentation</B></TD> + <TD ALIGN=RIGHT> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center> +<hr><h1>async_texture_manager.cpp</h1><a href="async__texture__manager_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000-2002 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font> +00027 +00028 <font class="preprocessor">#include "<a class="code" href="async__texture__manager_8h.html">3d/async_texture_manager.h</a>"</font> +00029 <font class="preprocessor">#include "<a class="code" href="async__file__manager__3d_8h.html">3d/async_file_manager_3d.h</a>"</font> +00030 <font class="preprocessor">#include "<a class="code" href="mesh__base__instance_8h.html">3d/mesh_base_instance.h</a>"</font> +00031 <font class="preprocessor">#include "<a class="code" href="driver_8h.html">3d/driver.h</a>"</font> +00032 +00033 +00034 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00035 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00036 +00037 <font class="keyword">namespace </font>NL3D +00038 { +00039 +00040 <font class="comment">// ***************************************************************************</font> +<a name="l00041"></a><a class="code" href="async__texture__manager_8cpp.html#a0">00041</a> <font class="preprocessor">#define NL3D_ATM_MIN_DISTANCE 1.0f</font> +00042 <font class="preprocessor"></font> +00043 <font class="comment">// ***************************************************************************</font> +<a name="l00044"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#a0">00044</a> CAsyncTextureManager::CTextureEntry::CTextureEntry() +00045 { +00046 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#n0">IsTextureEntry</a>= <font class="keyword">true</font>; +00047 +00048 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m1">Loaded</a>= <font class="keyword">false</font>; +00049 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m2">UpLoaded</a>= <font class="keyword">false</font>; +00050 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m3">CanHaveLOD</a>= <font class="keyword">false</font>; +00051 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m4">BuildFromHLSManager</a>= <font class="keyword">false</font>; +00052 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m5">HLSManagerTextId</a>= -1; +00053 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m6">BaseSize</a>= 0; +00054 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m9">TotalTextureSizeAsked</a>= 0; +00055 } +00056 +00057 +00058 <font class="comment">// ***************************************************************************</font> +<a name="l00059"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#a1">00059</a> <font class="keywordtype">void</font> CAsyncTextureManager::CTextureEntry::createCoarseBitmap() +00060 { +00061 <font class="comment">// the texture must exist.</font> +00062 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>); +00063 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>->getSize()>0); +00064 +00065 <font class="comment">// copy the bitmap.</font> +00066 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>= *<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>; +00067 <font class="comment">// remove all mipmaps, and convert to DXTC1 (if possible, ie if was DXTC5 or DXTC3 as example)</font> +00068 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>.<a class="code" href="classNLMISC_1_1CBitmap.html#a12">releaseMipMaps</a>(); +00069 <font class="comment">// TODODO: consersion to DXTC1</font> +00070 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>.<a class="code" href="classNLMISC_1_1CBitmap.html#a4">convertToType</a>(CBitmap::DXTC1); +00071 } +00072 +00073 +00074 <font class="comment">// ***************************************************************************</font> +<a name="l00075"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#a0">00075</a> CAsyncTextureManager::CTextureLod::CTextureLod() +00076 { +00077 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#n0">IsTextureEntry</a>= <font class="keyword">false</font>; +00078 +00079 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m0">TextureEntry</a>= NULL; +00080 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m1">Weight</a>= 0; +00081 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m2">Level</a>= 0; +00082 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m3">Loaded</a>= <font class="keyword">false</font>; +00083 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m4">UpLoaded</a>= <font class="keyword">false</font>; +00084 <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m5">ExtraSize</a>= 0; +00085 } +00086 +00087 +00088 <font class="comment">// ***************************************************************************</font> +<a name="l00089"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a1">00089</a> CAsyncTextureManager::~CAsyncTextureManager() +00090 { +00091 <font class="comment">// For all remaining textures, delete them.</font> +00092 <font class="keywordflow">for</font>(uint i=0;i<<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++) +00093 { +00094 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]) +00095 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">deleteTexture</a>(i); +00096 } +00097 +00098 <font class="comment">// there must be no waitting textures, nor map, nor current upload texture</font> +00099 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.empty() && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.empty() && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==NULL +00100 && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>==NULL); +00101 } +00102 +00103 <font class="comment">// ***************************************************************************</font> +<a name="l00104"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a0">00104</a> CAsyncTextureManager::CAsyncTextureManager() +00105 { +00106 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>= 3; +00107 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>= 1; +00108 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>= 65536; +00109 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>= 20*1024; +00110 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL; +00111 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>= 10*1024*1024; +00112 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>= 0; +00113 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o6">_LastTextureSizeGot</a>= 0; +00114 +00115 <font class="comment">// Do not share this texture, to force uploading of the lods.</font> +00116 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL; +00117 } +00118 +00119 +00120 <font class="comment">// ***************************************************************************</font> +<a name="l00121"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a2">00121</a> <font class="keywordtype">void</font> CAsyncTextureManager::setupLod(uint baseLevel, uint maxLevel) +00122 { +00123 <a class="code" href="debug_8h.html#a6">nlassert</a>(baseLevel>=maxLevel); +00124 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>= baseLevel; +00125 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>= maxLevel; +00126 } +00127 +00128 +00129 <font class="comment">// ***************************************************************************</font> +<a name="l00130"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a3">00130</a> <font class="keywordtype">void</font> CAsyncTextureManager::setupMaxUploadPerFrame(uint maxup) +00131 { +00132 <font class="keywordflow">if</font>(maxup>0) +00133 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>= maxup; +00134 } +00135 +00136 <font class="comment">// ***************************************************************************</font> +<a name="l00137"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a4">00137</a> <font class="keywordtype">void</font> CAsyncTextureManager::setupMaxHLSColoringPerFrame(uint maxCol) +00138 { +00139 <font class="keywordflow">if</font>(maxCol>0) +00140 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>= maxCol; +00141 } +00142 +00143 <font class="comment">// ***************************************************************************</font> +<a name="l00144"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a5">00144</a> <font class="keywordtype">void</font> CAsyncTextureManager::setupMaxTotalTextureSize(uint maxText) +00145 { +00146 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>= maxText; +00147 } +00148 +00149 +00150 <font class="comment">// ***************************************************************************</font> +00151 uint CAsyncTextureManager::addTextureRef(<font class="keyword">const</font> string &textNameNotLwr, CMeshBaseInstance *instance) +00152 { +00153 uint ret; +00154 +00155 <font class="comment">// strlwr name</font> +00156 string textName= textNameNotLwr; +00157 strlwr(textName); +00158 +00159 <font class="comment">// find the texture in map</font> +00160 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#u1">ItTextureEntryMap</a> it; +00161 it= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.find(textName); +00162 +00163 <font class="comment">// not found, create.</font> +00164 <font class="keywordflow">if</font>(it==<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.end()) +00165 { +00166 <font class="comment">// search a free id.</font> +00167 uint i= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size(); +00168 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.empty()) +00169 { +00170 i= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.back(); +00171 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.pop_back(); +00172 } +00173 <font class="comment">// resize if needed.</font> +00174 <font class="keywordflow">if</font>(i>=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size()) +00175 { +00176 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.push_back(NULL); +00177 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.reserve(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.capacity()); +00178 } +00179 +00180 <font class="comment">// alloc new.</font> +00181 CTextureEntry *text= <font class="keyword">new</font> CTextureEntry(); +00182 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]= text; +00183 text->Texture= <font class="keyword">new</font> CTextureFile; +00184 <font class="comment">// Do not allow degradation.</font> +00185 text->Texture->setAllowDegradation(<font class="keyword">false</font>); +00186 +00187 <font class="comment">// add to map.</font> +00188 it= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.insert(make_pair(textName, i)).first; +00189 <font class="comment">// bkup the it for deletion</font> +00190 text->ItMap= it; +00191 +00192 <font class="comment">// Start Color or Async loading.</font> +00193 text->Texture->setFileName(textName); +00194 <font class="comment">// First try with the HLSManager</font> +00195 sint colorTextId= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#m0">HLSManager</a>.findTexture(textName); +00196 <font class="comment">// If found</font> +00197 <font class="keywordflow">if</font>(colorTextId!=-1) +00198 { +00199 <font class="comment">// Mark the texture as Loaded, and ready to colorize (done in update()).</font> +00200 text->Loaded= <font class="keyword">true</font>; +00201 text->BuildFromHLSManager= <font class="keyword">true</font>; +00202 text->HLSManagerTextId= colorTextId; +00203 } +00204 <font class="comment">// else must async load it.</font> +00205 <font class="keywordflow">else</font> +00206 { +00207 <font class="comment">// start to load a small DDS version if possible</font> +00208 text->Texture->setMipMapSkipAtLoad(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>); +00209 <font class="comment">// load it async.</font> +00210 CAsyncFileManager3D::getInstance().loadTexture(text->Texture, &text->Loaded); +00211 } +00212 <font class="comment">// Add to a list so we can check each frame if it has ended.</font> +00213 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.push_back(i); +00214 } +00215 +00216 <font class="comment">// get the id of the text entry.</font> +00217 ret= it->second; +00218 +00219 <font class="comment">// add this instance to the list of ones which use this texture.</font> +00220 CTextureEntry *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[ret]; +00221 text->Instances.push_back(instance); +00222 +00223 <font class="comment">// if the texture is not yet ready, must increment the instance refCount.</font> +00224 <font class="keywordflow">if</font>(!text->UpLoaded) +00225 instance->_AsyncTextureToLoadRefCount++; +00226 +00227 <font class="keywordflow">return</font> ret; +00228 } +00229 +00230 +00231 <font class="comment">// ***************************************************************************</font> +<a name="l00232"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">00232</a> <font class="keywordtype">void</font> CAsyncTextureManager::deleteTexture(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>) +00233 { +00234 CTextureEntry *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]; +00235 +00236 +00237 <font class="comment">// **** Stop AsyncLoading/UpLoading of main texture.</font> +00238 +00239 <font class="comment">// stop async loading if not ended</font> +00240 <font class="keywordflow">if</font>(!text->Loaded) +00241 { +00242 CAsyncFileManager3D::getInstance().cancelLoadTexture(text->Texture); +00243 } +00244 +00245 <font class="comment">// remove map entry</font> +00246 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.erase(text->ItMap); +00247 +00248 <font class="comment">// remove in list of waiting textures</font> +00249 vector<uint>::iterator itWait= find(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.begin(),<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end(), <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>); +00250 <font class="keywordflow">if</font>(itWait!=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end()) +00251 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.erase(itWait); +00252 +00253 <font class="comment">// If it was the currently uploaded one, abort</font> +00254 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==text) +00255 { +00256 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL; +00257 } +00258 +00259 <font class="comment">// If not uploaded.</font> +00260 <font class="keywordflow">if</font>(!text->UpLoaded) +00261 { +00262 <font class="comment">// For all its remainding instances, dec refcount</font> +00263 <font class="keywordflow">for</font>(uint i=0;i<text->Instances.size();i++) +00264 { +00265 text->Instances[i]->_AsyncTextureToLoadRefCount--; +00266 } +00267 } +00268 +00269 <font class="comment">// remove from bench</font> +00270 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>-= text->TotalTextureSizeAsked; +00271 +00272 +00273 <font class="comment">// **** Stop AsyncLoading/UpLoading of HDLod 's texture.</font> +00274 +00275 <font class="comment">// Check if must stop TextureLod loading/uploading.</font> +00276 CTextureLod *textLod= &text->HDLod; +00277 <font class="keywordflow">if</font>(textLod==<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>) +00278 { +00279 <font class="comment">// stop the async loading if not ended.</font> +00280 <font class="keywordflow">if</font>(!textLod->Loaded) +00281 { +00282 CAsyncFileManager3D::getInstance().cancelLoadTexture(textLod->Texture); +00283 } +00284 <font class="comment">// stop uploading if was me</font> +00285 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==textLod) +00286 { +00287 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL; +00288 } +00289 <font class="comment">// stop loading me.</font> +00290 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL; +00291 } +00292 +00293 <font class="comment">// At last delete texture entry.</font> +00294 <font class="keyword">delete</font> text; +00295 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]= NULL; +00296 <font class="comment">// add a new free id.</font> +00297 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.push_back(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>); +00298 } +00299 +00300 +00301 <font class="comment">// ***************************************************************************</font> +<a name="l00302"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a7">00302</a> <font class="keywordtype">void</font> CAsyncTextureManager::releaseTexture(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, CMeshBaseInstance *instance) +00303 { +00304 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a><<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size()); +00305 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]); +00306 +00307 <font class="comment">// find an instance in this texture an remove it.</font> +00308 CTextureEntry *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]; +00309 uint instSize= text->Instances.size(); +00310 <font class="keywordflow">for</font>(uint i=0;i<instSize;i++) +00311 { +00312 <font class="keywordflow">if</font>(text->Instances[i]== instance) +00313 { +00314 <font class="comment">// Must first release the refCount if the texture is not uploaded</font> +00315 <font class="keywordflow">if</font>(!text->UpLoaded) +00316 text->Instances[i]->_AsyncTextureToLoadRefCount--; +00317 <font class="comment">// remove it by swapping with last texture</font> +00318 text->Instances[i]= text->Instances[instSize-1]; +00319 text->Instances.pop_back(); +00320 <font class="comment">// must stop: remove only the first occurence of instance.</font> +00321 <font class="keywordflow">break</font>; +00322 } +00323 } +00324 +00325 <font class="comment">// if no more instance occurence, the texture is no more used => release it.</font> +00326 <font class="keywordflow">if</font>(text->Instances.empty()) +00327 { +00328 <font class="comment">// do all the good stuff</font> +00329 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">deleteTexture</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>); +00330 } +00331 } +00332 +00333 <font class="comment">// ***************************************************************************</font> +<a name="l00334"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a8">00334</a> <font class="keywordtype">bool</font> CAsyncTextureManager::isTextureUpLoaded(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>)<font class="keyword"> const</font> +00335 <font class="keyword"></font>{ +00336 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a><<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size()); +00337 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]); +00338 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]->UpLoaded; +00339 } +00340 +00341 +00342 <font class="comment">// ***************************************************************************</font> +<a name="l00343"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a9">00343</a> <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CBitmap.html">NLMISC::CBitmap</a> *CAsyncTextureManager::getCoarseBitmap(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>)<font class="keyword"> const</font> +00344 <font class="keyword"></font>{ +00345 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>>=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size()) +00346 <font class="keywordflow">return</font> NULL; +00347 CTextureEntry *textEntry= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]; +00348 <font class="keywordflow">if</font>(!textEntry) +00349 <font class="keywordflow">return</font> NULL; +00350 +00351 <font class="comment">// if the textEntry not uploaded, return NULL</font> +00352 <font class="keywordflow">if</font>(!textEntry->UpLoaded) +00353 <font class="keywordflow">return</font> NULL; +00354 +00355 <font class="comment">// ok return the CoarseBitmap</font> +00356 <font class="keywordflow">return</font> &textEntry->CoarseBitmap; +00357 } +00358 +00359 +00360 <font class="comment">// ***************************************************************************</font> +<a name="l00361"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a10">00361</a> <font class="keywordtype">void</font> CAsyncTextureManager::update(IDriver *pDriver) +00362 { +00363 uint nTotalUploaded = 0; +00364 uint nTotalColored = 0; +00365 +00366 <font class="comment">// if no texture to upload, get the next one</font> +00367 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==NULL) +00368 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">getNextTextureToUpLoad</a>(nTotalColored, pDriver); +00369 +00370 <font class="comment">// while some texture to upload</font> +00371 <font class="keywordflow">while</font>(_CurrentUploadTexture) +00372 { +00373 ITexture *pText= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>-><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>; +00374 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c2">uploadTexturePart</a>(pText, pDriver, nTotalUploaded)) +00375 { +00376 <font class="comment">// Stuff for TextureEntry</font> +00377 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>-><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#a0">isTextureEntry</a>()) +00378 { +00379 uint i; +00380 CTextureEntry *textEntry= static_cast<CTextureEntry*>(_CurrentUploadTexture); +00381 <font class="comment">// If we are here, the texture is finally entirely uploaded. Compile it!</font> +00382 textEntry->UpLoaded= <font class="keyword">true</font>; +00383 <font class="comment">// Can Have lod if texture is DXTC and have mipMaps! Also disalbe if system disable it</font> +00384 textEntry->CanHaveLOD= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">validDXTCMipMap</a>(pText) && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>; +00385 <font class="comment">// compute the size it takes in VRAM</font> +00386 uint baseMipMapSize= pText->getSize(0)*CBitmap::bitPerPixels[pText->getPixelFormat()]/8; +00387 <font class="comment">// full size with mipmap</font> +00388 textEntry->BaseSize= (uint)(baseMipMapSize*1.33f); +00389 <font class="comment">// UpLoaded !! => signal all instances.</font> +00390 <font class="keywordflow">for</font>(i=0;i<textEntry->Instances.size();i++) +00391 { +00392 textEntry->Instances[i]->_AsyncTextureToLoadRefCount--; +00393 } +00394 +00395 <font class="comment">// Create the coarse bitmap with the text (NB: still in memory here)</font> +00396 textEntry->createCoarseBitmap(); +00397 +00398 <font class="comment">// If CanHaveLOD, create now the lods entries.</font> +00399 <font class="keywordflow">if</font>(textEntry->CanHaveLOD) +00400 { +00401 <font class="comment">/* Allow only the MaxLod to be loaded async</font> +00402 <font class="comment"> This is supposed to be faster since a fseek is much longer than a texture Read.</font> +00403 <font class="comment"> Then it is more intelligent to read only One texture (the High Def), than to try to</font> +00404 <font class="comment"> read intermediate ones (512, 256, 128) because this made 3 more fseek.</font> +00405 <font class="comment"> */</font> +00406 <font class="comment">// create only the MaxLod possible entry</font> +00407 CTextureLod &textLod= textEntry->HDLod; +00408 <font class="comment">// fill textLod</font> +00409 textLod.TextureEntry= textEntry; +00410 textLod.Level= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>; +00411 <font class="comment">// extra size of the lod only (important for LoadBalacing in updateTextureLodSystem())</font> +00412 textLod.ExtraSize= textEntry->BaseSize*(1<<(2*(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>-<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>))) - textEntry->BaseSize; +00413 <font class="comment">// not yet loaded/upLoaded</font> +00414 textLod.Loaded= <font class="keyword">false</font>; +00415 textLod.UpLoaded= <font class="keyword">false</font>; +00416 } +00417 +00418 <font class="comment">// compute texture size for bench</font> +00419 textEntry->TotalTextureSizeAsked= textEntry->BaseSize + textEntry->HDLod.ExtraSize; +00420 +00421 <font class="comment">// Add texture size to global texture size</font> +00422 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>+= textEntry->TotalTextureSizeAsked; +00423 } +00424 <font class="comment">// else, stuff for textureLod.</font> +00425 <font class="keywordflow">else</font> +00426 { +00427 CTextureLod *textLod= static_cast<CTextureLod*>(_CurrentUploadTexture); +00428 <font class="comment">// Swap the uploaded Driver Handle with the Main texture.</font> +00429 pDriver->swapTextureHandle(*textLod->Texture, *textLod->TextureEntry->Texture); +00430 <font class="comment">// Flag the Lod.</font> +00431 textLod->UpLoaded= <font class="keyword">true</font>; +00432 <font class="comment">// Ok, ended to completly load this textureLod.</font> +00433 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL; +00434 } +00435 +00436 <font class="comment">// finally uploaded in VRAM, can release the RAM texture memory</font> +00437 pText->release(); +00438 +00439 <font class="comment">// if not break because can't upload all parts, get next texture to upload</font> +00440 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL; +00441 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">getNextTextureToUpLoad</a>(nTotalColored, pDriver); +00442 } +00443 <font class="keywordflow">else</font> +00444 <font class="comment">// Fail to upload all, abort.</font> +00445 <font class="keywordflow">return</font>; +00446 } +00447 } +00448 +00449 +00450 <font class="comment">// ***************************************************************************</font> +<a name="l00451"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c2">00451</a> <font class="keywordtype">bool</font> CAsyncTextureManager::uploadTexturePart(ITexture *pText, IDriver *pDriver, uint &nTotalUploaded) +00452 { +00453 uint nMipMap; +00454 nMipMap = pText->getMipMapCount(); +00455 +00456 +00457 <font class="comment">// If this is the start of uploading, setup the texture in driver.</font> +00458 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>==0 && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>==0) +00459 { +00460 <font class="comment">// If the texture is not a valid DXTC with mipmap</font> +00461 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">validDXTCMipMap</a>(pText)) +00462 { +00463 <font class="comment">/* For now, prefer do nothing, because this may be an error (texture not found)</font> +00464 <font class="comment"> and the texture may not be used at all, so don't take VRAM for nothing.</font> +00465 <font class="comment"> => if the texture is used, it will be loaded synchronously by the caller later in the process</font> +00466 <font class="comment"> => frame freeze.</font> +00467 <font class="comment"> */</font> +00468 <font class="comment">/*</font> +00469 <font class="comment"> // upload All now.</font> +00470 <font class="comment"> // MipMap generation and compression may be done here => Maybe Big Freeze.</font> +00471 <font class="comment"> // approximate*2 instead of *1.33 for mipmaps.</font> +00472 <font class="comment"> uint nWeight = pText->getSize (0) * 2;</font> +00473 <font class="comment"> nWeight= (nWeight*CBitmap::bitPerPixels[pText->getPixelFormat()])/8;</font> +00474 <font class="comment"> nTotalUploaded+= nWeight;</font> +00475 <font class="comment"> pDriver->setupTexture(*pText);</font> +00476 <font class="comment"> return true;*/</font> +00477 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00478 } +00479 <font class="keywordflow">else</font> +00480 { +00481 <font class="comment">// Create the texture only and do not upload anything</font> +00482 <font class="keywordtype">bool</font> isRel = pText->getReleasable (); +00483 pText->setReleasable (<font class="keyword">false</font>); +00484 <font class="keywordtype">bool</font> isAllUploaded = <font class="keyword">false</font>; +00485 <font class="comment">/* Even if the shared texture is still referenced and so still exist in driver, we MUST recreate with good size</font> +00486 <font class="comment"> the texture. This is important for Texture Memory Load Balancing</font> +00487 <font class="comment"> (this may means that is used elsewhere than in the CAsyncTextureManager)</font> +00488 <font class="comment"> Hence: bMustRecreateSharedTexture==true</font> +00489 <font class="comment"> */</font> +00490 pDriver->setupTextureEx (*pText, <font class="keyword">false</font>, isAllUploaded, <font class="keyword">true</font>); +00491 pText->setReleasable (isRel); +00492 <font class="comment">// if the texture is already uploaded, abort partial uploading.</font> +00493 <font class="keywordflow">if</font> (isAllUploaded) +00494 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00495 } +00496 } +00497 +00498 +00499 <font class="comment">// try to upload all mipmap</font> +00500 <font class="keywordflow">for</font>(; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a><nMipMap; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>++) +00501 { +00502 CRect zeRect; +00503 uint nMM= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>; +00504 +00505 <font class="comment">// What is left to upload ?</font> +00506 uint nWeight = pText->getSize (nMM) - <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>*pText->getWidth(nMM); +00507 nWeight= (nWeight*CBitmap::bitPerPixels[pText->getPixelFormat()])/8; +00508 +00509 <font class="keywordflow">if</font> ((nTotalUploaded + nWeight) > <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>) +00510 { +00511 <font class="comment">// We cannot upload the whole mipmap -> we have to cut it</font> +00512 uint nSizeToUpload = <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a> - nTotalUploaded ; +00513 uint nLineWeight = (pText->getWidth(nMM)*CBitmap::bitPerPixels[pText->getPixelFormat()])/8; +00514 uint nNbLineToUpload = nSizeToUpload / nLineWeight; +00515 <font class="comment">// Upload 4 line by 4 line, and upload at leat one 4*line.</font> +00516 nNbLineToUpload = nNbLineToUpload / 4; +00517 nNbLineToUpload= max(nNbLineToUpload, 1U); +00518 nNbLineToUpload *= 4; +00519 <font class="comment">// comput rect to upload</font> +00520 uint32 nNewLine = <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> + nNbLineToUpload; +00521 nNewLine= <a class="code" href="bit__set_8cpp.html#a0">min</a>(nNewLine, pText->getHeight(nMM)); +00522 zeRect.set (0, <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>, pText->getWidth(nMM), nNewLine); +00523 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> = nNewLine; +00524 <font class="comment">// if fill all the mipmap, must go to next</font> +00525 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> == pText->getHeight(nMM)) +00526 { +00527 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> = 0; +00528 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>++; +00529 } +00530 } +00531 <font class="keywordflow">else</font> +00532 { +00533 <font class="comment">// We can upload the whole mipmap (or the whole rest of the mipmap)</font> +00534 zeRect.set (0, <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>, pText->getWidth(nMM), pText->getHeight(nMM)); +00535 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>= 0; +00536 } +00537 +00538 <font class="comment">// upload the texture </font> +00539 pDriver->uploadTexture (*pText, zeRect, (uint8)nMM); +00540 +00541 nTotalUploaded += nWeight; +00542 <font class="comment">// If outpass max allocated upload, abort.</font> +00543 <font class="keywordflow">if</font> (nTotalUploaded > <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>) +00544 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00545 } +00546 +00547 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00548 } +00549 +00550 +00551 <font class="comment">// ***************************************************************************</font> +<a name="l00552"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">00552</a> <font class="keywordtype">void</font> CAsyncTextureManager::getNextTextureToUpLoad(uint &nTotalColored, IDriver *pDriver) +00553 { +00554 <font class="comment">// Reset texture uploading</font> +00555 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL; +00556 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>= 0; +00557 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>= 0; +00558 +00559 <font class="comment">// Search in WaitingTextures if one has ended async loading</font> +00560 vector<uint>::iterator it; +00561 <font class="keywordflow">for</font>(it=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.begin();it!=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end();it++) +00562 { +00563 CTextureEntry *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[*it]; +00564 <font class="comment">// If Async loading done.</font> +00565 <font class="keywordflow">if</font>(text->Loaded) +00566 { +00567 <font class="comment">// Is it a "texture to color" with HLSManager? yes=> color it now.</font> +00568 <font class="keywordflow">if</font>(text->BuildFromHLSManager) +00569 { +00570 <font class="comment">// If not beyond the max coloring texture</font> +00571 <font class="keywordflow">if</font>(nTotalColored<<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>) +00572 { +00573 <font class="comment">// Build the texture directly in the TextureFile.</font> +00574 <a class="code" href="debug_8h.html#a9">nlverify</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#m0">HLSManager</a>.buildTexture(text->HLSManagerTextId, *text->Texture)); +00575 <font class="comment">// Must validate the textureFile generation. NB: little weird since this is not really a textureFile.</font> +00576 <font class="comment">// But it is the easier way to do it.</font> +00577 text->Texture->validateGenerateFlag(); +00578 <font class="comment">// compute the texture size (approx). NB: DXTC5 means 1 pixel==1 byte.</font> +00579 uint size= (uint)(text->Texture->getSize(0)*1.33); +00580 <font class="comment">// Add it to the num of colorised texture done in current update().</font> +00581 nTotalColored+= size; +00582 } +00583 <font class="comment">// Else must quit and don't update any more texture this frame (_CurrentUploadTexture==NULL)</font> +00584 <font class="keywordflow">else</font> +00585 <font class="keywordflow">return</font>; +00586 } +00587 +00588 <font class="comment">// upload this one</font> +00589 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= text; +00590 <font class="comment">// remove it from list of waiting textures</font> +00591 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.erase(it); +00592 <font class="comment">// found => end.</font> +00593 <font class="keywordflow">return</font>; +00594 } +00595 } +00596 +00597 <font class="comment">// If here, and if no more waiting textures, update the Lod system.</font> +00598 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.empty()) +00599 { +00600 <font class="comment">// if end to load the current lod.</font> +00601 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a> && <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>-><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m3">Loaded</a>) +00602 { +00603 <font class="comment">// upload this one</font> +00604 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>; +00605 <font class="keywordflow">return</font>; +00606 } +00607 +00608 <font class="comment">// if no Lod texture currently loading, try to load/unload one</font> +00609 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a> == NULL) +00610 { +00611 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c3">updateTextureLodSystem</a>(pDriver); +00612 } +00613 } +00614 } +00615 +00616 +00617 <font class="comment">// ***************************************************************************</font> +<a name="l00618"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">00618</a> <font class="keywordtype">bool</font> CAsyncTextureManager::validDXTCMipMap(ITexture *pText) +00619 { +00620 <font class="keywordflow">return</font> pText->getMipMapCount()>1 && ( +00621 pText->getPixelFormat() == CBitmap::DXTC1 || +00622 pText->getPixelFormat() == CBitmap::DXTC1Alpha || +00623 pText->getPixelFormat() == CBitmap::DXTC3 || +00624 pText->getPixelFormat() == CBitmap::DXTC5 ); +00625 } +00626 +00627 +00628 <font class="comment">// ***************************************************************************</font> +<a name="l00629"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c3">00629</a> <font class="keywordtype">void</font> CAsyncTextureManager::updateTextureLodSystem(IDriver *pDriver) +00630 { +00631 sint i; +00632 +00633 <font class="comment">// the array to sort</font> +00634 <font class="keyword">static</font> vector<CTextureLod*> lodArray; +00635 lodArray.clear(); +00636 uint reserveSize= 0; +00637 +00638 <font class="comment">// for each texture entry compute min distance of use</font> +00639 <font class="comment">//=============</font> +00640 uint currentBaseSize= 0; +00641 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++) +00642 { +00643 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]) +00644 <font class="keywordflow">continue</font>; +00645 CTextureEntry &text= *<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]; +00646 <font class="comment">// do it only for Lodable textures</font> +00647 <font class="keywordflow">if</font>(text.CanHaveLOD) +00648 { +00649 text.MinDistance= FLT_MAX; +00650 <font class="comment">// for all instances.</font> +00651 <font class="keywordflow">for</font>(uint j=0;j<text.Instances.size();j++) +00652 { +00653 <font class="keywordtype">float</font> instDist= text.Instances[j]->getAsyncTextureDistance(); +00654 text.MinDistance= <a class="code" href="bit__set_8cpp.html#a0">min</a>(text.MinDistance, instDist); +00655 } +00656 +00657 <font class="comment">// avoid /0</font> +00658 text.MinDistance= max(<a class="code" href="async__texture__manager_8cpp.html#a0">NL3D_ATM_MIN_DISTANCE</a>, text.MinDistance); +00659 +00660 <font class="comment">// how many textLods to add</font> +00661 reserveSize++; +00662 +00663 <font class="comment">// the minimum mem size the system take with base lod.</font> +00664 currentBaseSize+= text.BaseSize; +00665 } +00666 } +00667 <font class="comment">// reserve space</font> +00668 lodArray.reserve(reserveSize); +00669 +00670 +00671 <font class="comment">// for each texture lod compute weight, and append</font> +00672 <font class="comment">//=============</font> +00673 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++) +00674 { +00675 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]) +00676 <font class="keywordflow">continue</font>; +00677 CTextureEntry &text= *<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]; +00678 <font class="comment">// do it only for Lodable textures</font> +00679 <font class="keywordflow">if</font>(text.CanHaveLOD) +00680 { +00681 <font class="comment">// This Weight is actually a screen Pixel Ratio! (divide by distance)</font> +00682 CTextureLod *textLod= &text.HDLod; +00683 textLod->Weight= (1<<textLod->Level) / text.MinDistance; +00684 <font class="comment">// add to array</font> +00685 lodArray.push_back(textLod); +00686 } +00687 } +00688 +00689 +00690 <font class="comment">// sort</font> +00691 <font class="comment">//=============</font> +00692 CPredTextLod pred; +00693 sort(lodArray.begin(), lodArray.end(), pred); +00694 +00695 +00696 <font class="comment">// Compute lod to load/unload</font> +00697 <font class="comment">//=============</font> +00698 <font class="comment">// Compute Pivot, ie what lods have to be loaded, and what lods do not</font> +00699 uint pivot= 0; +00700 uint currentWantedSize= currentBaseSize; +00701 uint currentLoadedSize= currentBaseSize; +00702 <font class="keywordflow">for</font>(i=lodArray.size()-1;i>=0;i--) +00703 { +00704 uint lodSize= lodArray[i]->ExtraSize; +00705 currentWantedSize+= lodSize; +00706 <font class="keywordflow">if</font>(lodArray[i]->UpLoaded) +00707 currentLoadedSize+= lodSize; +00708 <font class="comment">// if > max allowed, stop the pivot here. NB: the pivot is included in the "must load them" part.</font> +00709 <font class="keywordflow">if</font>(currentWantedSize > <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>) +00710 { +00711 pivot= i; +00712 <font class="keywordflow">break</font>; +00713 } +00714 } +00715 <font class="comment">// continue to count currentLoadedSize</font> +00716 <font class="keywordflow">for</font>(;i>=0;i--) +00717 { +00718 <font class="keywordflow">if</font>(lodArray[i]->UpLoaded) +00719 currentLoadedSize+= lodArray[i]->ExtraSize; +00720 } +00721 <font class="comment">// save bench.</font> +00722 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o6">_LastTextureSizeGot</a>= currentLoadedSize; +00723 +00724 +00725 <font class="comment">// if the loadedSize is inferior to the wanted size, we can load a new LOD</font> +00726 CTextureLod *textLod= NULL; +00727 <font class="keywordtype">bool</font> unload; +00728 <font class="keywordflow">if</font>(currentLoadedSize<currentWantedSize) +00729 { +00730 unload= <font class="keyword">false</font>; +00731 <font class="comment">// search from end of the list to pivot (included), the first LOD (ie the most important) to load.</font> +00732 <font class="keywordflow">for</font>(i=lodArray.size()-1;i>=(sint)pivot;i--) +00733 { +00734 <font class="keywordflow">if</font>(!lodArray[i]->UpLoaded) +00735 { +00736 textLod= lodArray[i]; +00737 <font class="keywordflow">break</font>; +00738 } +00739 } +00740 <font class="comment">// One must have been found, since currentLoadedSize<currentWantedSize</font> +00741 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod); +00742 } +00743 <font class="keywordflow">else</font> +00744 { +00745 unload= <font class="keyword">true</font>; +00746 <font class="comment">// search from start to pivot (exclued), the first LOD (ie the less important) to unload.</font> +00747 <font class="keywordflow">for</font>(i=0;i<(sint)pivot;i++) +00748 { +00749 <font class="keywordflow">if</font>(lodArray[i]->UpLoaded) +00750 { +00751 textLod= lodArray[i]; +00752 <font class="keywordflow">break</font>; +00753 } +00754 } +00755 <font class="comment">// it is possible that not found here. It means that All is Ok!!</font> +00756 <font class="keywordflow">if</font>(textLod==NULL) +00757 <font class="comment">// no-op.</font> +00758 <font class="keywordflow">return</font>; +00759 } +00760 +00761 +00762 <font class="comment">// load/unload</font> +00763 <font class="comment">//=============</font> +00764 <font class="keywordflow">if</font>(!unload) +00765 { +00766 <font class="comment">// create a new TextureFile, with no sharing system.</font> +00767 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod->Texture==NULL); +00768 textLod->Texture= <font class="keyword">new</font> CTextureFile; +00769 <font class="comment">// Do not allow degradation.</font> +00770 textLod->Texture->setAllowDegradation(<font class="keyword">false</font>); +00771 textLod->Texture->enableSharing(<font class="keyword">false</font>); +00772 textLod->Texture->setFileName(textLod->TextureEntry->Texture->getFileName()); +00773 textLod->Texture->setMipMapSkipAtLoad(textLod->Level); +00774 <font class="comment">// setup async loading</font> +00775 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= textLod; +00776 <font class="comment">// load it async.</font> +00777 CAsyncFileManager3D::getInstance().loadTexture(textLod->Texture, &textLod->Loaded); +00778 } +00779 <font class="keywordflow">else</font> +00780 { +00781 <font class="comment">// Swap now the lod.</font> +00782 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod->Texture!=NULL); +00783 <font class="comment">// Swap the uploaded Driver Handle with the Main texture (ot get the Ugly one)</font> +00784 pDriver->swapTextureHandle(*textLod->Texture, *textLod->TextureEntry->Texture); +00785 <font class="comment">// Flag the Lod.</font> +00786 textLod->UpLoaded= <font class="keyword">false</font>; +00787 textLod->Loaded= <font class="keyword">false</font>; +00788 <font class="comment">// Release completly the texture in driver. (SmartPtr delete)</font> +00789 textLod->Texture= NULL; +00790 } +00791 +00792 } +00793 +00794 +00795 +00796 } <font class="comment">// NL3D</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |