diff options
Diffstat (limited to 'docs/doxygen/nel/driver__opengl__texture_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/driver__opengl__texture_8cpp-source.html | 1222 |
1 files changed, 1222 insertions, 0 deletions
diff --git a/docs/doxygen/nel/driver__opengl__texture_8cpp-source.html b/docs/doxygen/nel/driver__opengl__texture_8cpp-source.html new file mode 100644 index 00000000..6d07f55b --- /dev/null +++ b/docs/doxygen/nel/driver__opengl__texture_8cpp-source.html @@ -0,0 +1,1222 @@ +<!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>driver_opengl_texture.cpp</h1><a href="driver__opengl__texture_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00011 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font> +00012 <font class="comment"> *</font> +00013 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00014 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00015 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00016 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00017 <font class="comment"> * any later version.</font> +00018 <font class="comment"></font> +00019 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00020 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00021 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00022 <font class="comment"> * General Public License for more details.</font> +00023 <font class="comment"></font> +00024 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00025 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00026 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00027 <font class="comment"> * MA 02111-1307, USA.</font> +00028 <font class="comment"> */</font> +00029 +00030 <font class="preprocessor">#include "<a class="code" href="stdopengl_8h.html">stdopengl.h</a>"</font> +00031 +00032 <font class="preprocessor">#include "<a class="code" href="texture__cube_8h.html">3d/texture_cube.h</a>"</font> +00033 <font class="preprocessor">#include "<a class="code" href="rect_8h.html">nel/misc/rect.h</a>"</font> +00034 <font class="preprocessor">#include "<a class="code" href="file_8h.html">nel/misc/file.h</a>"</font> <font class="comment">// temp</font> +00035 +00036 +00037 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00038 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00039 +00040 +00041 <font class="keyword">namespace </font>NL3D +00042 { +00043 +00044 +00045 <font class="comment">// ***************************************************************************</font> +<a name="l00046"></a><a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#a0">00046</a> CTextureDrvInfosGL::CTextureDrvInfosGL(IDriver *drv, <a class="code" href="namespaceNL3D.html#a246">ItTexDrvInfoPtrMap</a> it, CDriverGL *drvGl) : ITextureDrvInfos(drv, it) +00047 { +00048 <font class="comment">// The id is auto created here.</font> +00049 glGenTextures(1,&<a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m0">ID</a>); +00050 +00051 <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m1">Compressed</a>= <font class="keyword">false</font>; +00052 <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m2">TextureMemory</a>= 0; +00053 +00054 <font class="comment">// Nb: at Driver dtor, all tex infos are deleted, so _Driver is always valid.</font> +00055 <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m3">_Driver</a>= drvGl; +00056 } +00057 <font class="comment">// ***************************************************************************</font> +<a name="l00058"></a><a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#a1">00058</a> CTextureDrvInfosGL::~CTextureDrvInfosGL() +00059 { +00060 <font class="comment">// The id is auto deleted here.</font> +00061 glDeleteTextures(1,&<a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m0">ID</a>); +00062 +00063 <font class="comment">// release profiling texture mem.</font> +00064 <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m3">_Driver</a>->_AllocatedTextureMemory-= <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m2">TextureMemory</a>; +00065 +00066 <font class="comment">// release in TextureUsed.</font> +00067 <a class="code" href="classNL3D_1_1CTextureDrvInfosGL.html#m3">_Driver</a>->_TextureUsed.erase (<font class="keyword">this</font>); +00068 } +00069 +00070 +00071 +00072 <font class="comment">// ***************************************************************************</font> +00073 <font class="comment">// Get the glText mirror of an existing setuped texture.</font> +00074 <font class="keyword">static</font> <font class="keyword">inline</font> CTextureDrvInfosGL* <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a>(ITexture& tex) +00075 { +00076 CTextureDrvInfosGL* gltex; +00077 gltex= (CTextureDrvInfosGL*)(ITextureDrvInfos*)(tex.TextureDrvShare->DrvTexture); +00078 <font class="keywordflow">return</font> gltex; +00079 } +00080 +00081 +00082 <font class="comment">// ***************************************************************************</font> +00083 <font class="comment">// Translation of TexFmt mode.</font> +<a name="l00084"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c12">00084</a> GLint CDriverGL::getGlTextureFormat(ITexture& tex, <font class="keywordtype">bool</font> &compressed) +00085 { +00086 ITexture::TUploadFormat texfmt= tex.getUploadFormat(); +00087 +00088 <font class="comment">// If auto, retrieve the pixel format of the bitmap.</font> +00089 <font class="keywordflow">if</font>(texfmt== ITexture::Auto) +00090 { +00091 <font class="keywordflow">switch</font>(tex.getPixelFormat()) +00092 { +00093 <font class="keywordflow">case</font> CBitmap::RGBA: +00094 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#o27">_ForceDXTCCompression</a> && tex.allowDegradation() ) +00095 texfmt= ITexture::DXTC5; +00096 <font class="keywordflow">else</font> +00097 texfmt= ITexture::RGBA8888; +00098 <font class="keywordflow">break</font>; +00099 <font class="keywordflow">case</font> CBitmap::DXTC1: texfmt= ITexture::DXTC1; <font class="keywordflow">break</font>; +00100 <font class="keywordflow">case</font> CBitmap::DXTC1Alpha: texfmt= ITexture::DXTC1Alpha; <font class="keywordflow">break</font>; +00101 <font class="keywordflow">case</font> CBitmap::DXTC3: texfmt= ITexture::DXTC3; <font class="keywordflow">break</font>; +00102 <font class="keywordflow">case</font> CBitmap::DXTC5: texfmt= ITexture::DXTC5; <font class="keywordflow">break</font>; +00103 <font class="keywordflow">case</font> CBitmap::Luminance: texfmt= ITexture::Luminance; <font class="keywordflow">break</font>; +00104 <font class="keywordflow">case</font> CBitmap::Alpha: texfmt= ITexture::Alpha; <font class="keywordflow">break</font>; +00105 <font class="keywordflow">case</font> CBitmap::AlphaLuminance: texfmt= ITexture::AlphaLuminance; <font class="keywordflow">break</font>; +00106 <font class="keywordflow">case</font> CBitmap::DsDt: texfmt= ITexture::DsDt; <font class="keywordflow">break</font>; +00107 <font class="keywordflow">default</font>: texfmt= ITexture::RGBA8888; <font class="keywordflow">break</font>; +00108 } +00109 } +00110 +00111 +00112 <font class="comment">// Get gl tex format, try S3TC compressed ones.</font> +00113 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.EXTTextureCompressionS3TC) +00114 { +00115 compressed= <font class="keyword">true</font>; +00116 <font class="comment">// Try Compressed ones.</font> +00117 <font class="keywordflow">switch</font>(texfmt) +00118 { +00119 <font class="keywordflow">case</font> ITexture::DXTC1: <font class="keywordflow">return</font> GL_COMPRESSED_RGB_S3TC_DXT1_EXT; +00120 <font class="keywordflow">case</font> ITexture::DXTC1Alpha: <font class="keywordflow">return</font> GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; +00121 <font class="keywordflow">case</font> ITexture::DXTC3: <font class="keywordflow">return</font> GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; +00122 <font class="keywordflow">case</font> ITexture::DXTC5: <font class="keywordflow">return</font> GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; +00123 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>; +00124 } +00125 } +00126 +00127 +00128 <font class="comment">// Get standard gl tex format.</font> +00129 compressed= <font class="keyword">false</font>; +00130 <font class="keywordflow">switch</font>(texfmt) +00131 { +00132 <font class="keywordflow">case</font> ITexture::RGBA8888: <font class="keywordflow">return</font> GL_RGBA8; +00133 <font class="keywordflow">case</font> ITexture::RGBA4444: <font class="keywordflow">return</font> GL_RGBA4; +00134 <font class="keywordflow">case</font> ITexture::RGBA5551: <font class="keywordflow">return</font> GL_RGB5_A1; +00135 <font class="keywordflow">case</font> ITexture::RGB888: <font class="keywordflow">return</font> GL_RGB8; +00136 <font class="keywordflow">case</font> ITexture::RGB565: <font class="keywordflow">return</font> GL_RGB5; +00137 <font class="keywordflow">case</font> ITexture::Luminance: <font class="keywordflow">return</font> GL_LUMINANCE8; +00138 <font class="keywordflow">case</font> ITexture::Alpha: <font class="keywordflow">return</font> GL_ALPHA8; +00139 <font class="keywordflow">case</font> ITexture::AlphaLuminance: <font class="keywordflow">return</font> GL_LUMINANCE8_ALPHA8; +00140 <font class="keywordflow">case</font> ITexture::DsDt: +00141 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.NVTextureShader) <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a180">GL_DSDT_NV</a>; +00142 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.ATIEnvMapBumpMap) <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a351">GL_DU8DV8_ATI</a>; +00143 <font class="keywordflow">else</font> +00144 { +00145 <a class="code" href="debug_8h.html#a6">nlassert</a>(0); +00146 <font class="keywordflow">return</font> 0; +00147 } +00148 <font class="keywordflow">break</font>; +00149 <font class="keywordflow">default</font>: <font class="keywordflow">return</font> GL_RGBA8; +00150 } +00151 } +00152 +00153 +00154 <font class="comment">// ***************************************************************************</font> +00155 <font class="keyword">static</font> GLint <a class="code" href="namespaceNL3D.html#a348">getGlSrcTextureFormat</a>(ITexture &tex, GLint glfmt) +00156 { +00157 <font class="comment">// Is destination format is alpha or lumiance ?</font> +00158 <font class="keywordflow">if</font> ((glfmt==GL_ALPHA8)||(glfmt==GL_LUMINANCE8_ALPHA8)||(glfmt==GL_LUMINANCE8)) +00159 { +00160 <font class="keywordflow">switch</font>(tex.getPixelFormat()) +00161 { +00162 <font class="keywordflow">case</font> CBitmap::Alpha: <font class="keywordflow">return</font> GL_ALPHA; +00163 <font class="keywordflow">case</font> CBitmap::AlphaLuminance: <font class="keywordflow">return</font> GL_LUMINANCE_ALPHA; +00164 <font class="keywordflow">case</font> CBitmap::Luminance: <font class="keywordflow">return</font> GL_LUMINANCE; +00165 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>; +00166 } +00167 } +00168 +00169 <font class="keywordflow">if</font> (glfmt == <a class="code" href="driver__opengl__extension__def_8h.html#a180">GL_DSDT_NV</a>) +00170 { +00171 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a180">GL_DSDT_NV</a>; +00172 } +00173 +00174 <font class="keywordflow">if</font> (glfmt == <a class="code" href="driver__opengl__extension__def_8h.html#a351">GL_DU8DV8_ATI</a>) +00175 { +00176 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a350">GL_DUDV_ATI</a>; +00177 } +00178 +00179 <font class="comment">// Else, not a Src format for upload, or RGBA.</font> +00180 <font class="keywordflow">return</font> GL_RGBA; +00181 } +00182 +00183 <font class="comment">// ***************************************************************************</font> +00184 <font class="keyword">static</font> GLenum <a class="code" href="namespaceNL3D.html#a349">getGlSrcTextureComponentType</a>(GLint texSrcFormat) +00185 { +00186 <font class="keywordflow">switch</font> (texSrcFormat) +00187 { +00188 <font class="keywordflow">case</font> <a class="code" href="driver__opengl__extension__def_8h.html#a180">GL_DSDT_NV</a>: +00189 <font class="keywordflow">case</font> <a class="code" href="driver__opengl__extension__def_8h.html#a351">GL_DU8DV8_ATI</a>: +00190 <font class="keywordflow">return</font> GL_BYTE; <font class="comment">// these are signed format </font> +00191 <font class="keywordflow">break</font>; +00192 <font class="keywordflow">default</font>: +00193 <font class="keywordflow">return</font> GL_UNSIGNED_BYTE; +00194 <font class="keywordflow">break</font>; +00195 +00196 } +00197 } +00198 +00199 <font class="comment">// ***************************************************************************</font> +<a name="l00200"></a><a class="code" href="classNL3D_1_1CDriverGL.html#z412_0">00200</a> uint CDriverGL::computeMipMapMemoryUsage(uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, uint h, GLint glfmt)<font class="keyword"> const</font> +00201 <font class="keyword"></font>{ +00202 <font class="keywordflow">switch</font>(glfmt) +00203 { +00204 <font class="keywordflow">case</font> GL_RGBA8: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 4; +00205 <font class="comment">// Well this is ugly, but simple :). GeForce 888 is stored as 32 bits.</font> +00206 <font class="keywordflow">case</font> GL_RGB8: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 4; +00207 <font class="keywordflow">case</font> GL_RGBA4: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 2; +00208 <font class="keywordflow">case</font> GL_RGB5_A1: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 2; +00209 <font class="keywordflow">case</font> GL_RGB5: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 2; +00210 <font class="keywordflow">case</font> GL_LUMINANCE8: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 1; +00211 <font class="keywordflow">case</font> GL_ALPHA8: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 1; +00212 <font class="keywordflow">case</font> GL_LUMINANCE8_ALPHA8: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 2; +00213 <font class="keywordflow">case</font> GL_COMPRESSED_RGB_S3TC_DXT1_EXT: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h /2; +00214 <font class="keywordflow">case</font> GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h /2; +00215 <font class="keywordflow">case</font> GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 1; +00216 <font class="keywordflow">case</font> GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 1; +00217 <font class="keywordflow">case</font> <a class="code" href="driver__opengl__extension__def_8h.html#a351">GL_DU8DV8_ATI</a>: +00218 <font class="keywordflow">case</font> <a class="code" href="driver__opengl__extension__def_8h.html#a180">GL_DSDT_NV</a>: <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 2; +00219 }; +00220 +00221 <font class="comment">// One format has not been coded.</font> +00222 <a class="code" href="debug_8h.html#a12">nlstop</a>; +00223 +00225 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h* 4; +00226 } +00227 +00228 +00229 <font class="comment">// ***************************************************************************</font> +00230 <font class="comment">// Translation of Wrap mode.</font> +00231 <font class="keyword">static</font> <font class="keyword">inline</font> GLenum <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(ITexture::TWrapMode mode, <font class="keyword">const</font> CGlExtensions &extensions) +00232 { +00233 <font class="keywordflow">if</font>(mode== ITexture::Repeat) +00234 <font class="keywordflow">return</font> GL_REPEAT; +00235 <font class="keywordflow">else</font> +00236 { +00237 <font class="keywordflow">if</font>(extensions.Version1_2) +00238 <font class="keywordflow">return</font> GL_CLAMP_TO_EDGE; +00239 <font class="keywordflow">else</font> +00240 <font class="keywordflow">return</font> GL_CLAMP; +00241 } +00242 } +00243 +00244 +00245 <font class="comment">// ***************************************************************************</font> +00246 <font class="keyword">static</font> <font class="keyword">inline</font> GLenum <a class="code" href="namespaceNL3D.html#a351">translateMagFilterToGl</a>(ITexture::TMagFilter mode) +00247 { +00248 <font class="keywordflow">switch</font>(mode) +00249 { +00250 <font class="keywordflow">case</font> ITexture::Linear: <font class="keywordflow">return</font> GL_LINEAR; +00251 <font class="keywordflow">case</font> ITexture::Nearest: <font class="keywordflow">return</font> GL_NEAREST; +00252 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>; +00253 } +00254 +00255 <a class="code" href="debug_8h.html#a12">nlstop</a>; +00256 <font class="keywordflow">return</font> GL_LINEAR; +00257 } +00258 +00259 +00260 <font class="comment">// ***************************************************************************</font> +00261 <font class="keyword">static</font> <font class="keyword">inline</font> GLenum <a class="code" href="namespaceNL3D.html#a352">translateMinFilterToGl</a>(ITexture::TMinFilter mode) +00262 { +00263 <font class="keywordflow">switch</font>(mode) +00264 { +00265 <font class="keywordflow">case</font> ITexture::NearestMipMapOff: <font class="keywordflow">return</font> GL_NEAREST; +00266 <font class="keywordflow">case</font> ITexture::NearestMipMapNearest: <font class="keywordflow">return</font> GL_NEAREST_MIPMAP_NEAREST; +00267 <font class="keywordflow">case</font> ITexture::NearestMipMapLinear: <font class="keywordflow">return</font> GL_NEAREST_MIPMAP_LINEAR; +00268 <font class="keywordflow">case</font> ITexture::LinearMipMapOff: <font class="keywordflow">return</font> GL_LINEAR; +00269 <font class="keywordflow">case</font> ITexture::LinearMipMapNearest: <font class="keywordflow">return</font> GL_LINEAR_MIPMAP_NEAREST; +00270 <font class="keywordflow">case</font> ITexture::LinearMipMapLinear: <font class="keywordflow">return</font> GL_LINEAR_MIPMAP_LINEAR; +00271 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>; +00272 } +00273 +00274 <a class="code" href="debug_8h.html#a12">nlstop</a>; +00275 <font class="keywordflow">return</font> GL_LINEAR; +00276 } +00277 +00278 +00279 <font class="comment">// ***************************************************************************</font> +00280 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="namespaceNL3D.html#a353">sameDXTCFormat</a>(ITexture &tex, GLint glfmt) +00281 { +00282 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGB_S3TC_DXT1_EXT && tex.PixelFormat==CBitmap::DXTC1) +00283 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00284 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && tex.PixelFormat==CBitmap::DXTC1Alpha) +00285 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00286 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT3_EXT && tex.PixelFormat==CBitmap::DXTC3) +00287 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00288 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT5_EXT && tex.PixelFormat==CBitmap::DXTC5) +00289 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00290 +00291 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00292 } +00293 +00294 +00295 <font class="comment">// ***************************************************************************</font> +00296 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="namespaceNL3D.html#a354">isDXTCFormat</a>(GLint glfmt) +00297 { +00298 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGB_S3TC_DXT1_EXT) +00299 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00300 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) +00301 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00302 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) +00303 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00304 <font class="keywordflow">if</font>(glfmt==GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) +00305 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00306 +00307 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00308 } +00309 +00310 +00311 <font class="comment">// ***************************************************************************</font> +<a name="l00312"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a18">00312</a> <font class="keywordtype">bool</font> CDriverGL::setupTexture (ITexture& tex) +00313 { +00314 <font class="keywordtype">bool</font> nTmp; +00315 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CDriverGL.html#a19">setupTextureEx</a> (tex, <font class="keyword">true</font>, nTmp); +00316 } +00317 +00318 <font class="comment">// ***************************************************************************</font> +<a name="l00319"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a19">00319</a> <font class="keywordtype">bool</font> CDriverGL::setupTextureEx (ITexture& tex, <font class="keywordtype">bool</font> bUpload, <font class="keywordtype">bool</font> &bAllUploaded, <font class="keywordtype">bool</font> bMustRecreateSharedTexture) +00320 { +00321 bAllUploaded = <font class="keyword">false</font>; +00322 +00323 <font class="keywordflow">if</font>(tex.isTextureCube() && (!<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.ARBTextureCubeMap)) +00324 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00325 +00326 <font class="comment">// 0. Create/Retrieve the driver texture.</font> +00327 <font class="comment">//=======================================</font> +00328 <font class="keywordtype">bool</font> mustCreate = <font class="keyword">false</font>; +00329 <font class="keywordflow">if</font> ( !tex.TextureDrvShare ) +00330 { +00331 <font class="comment">// insert into driver list. (so it is deleted when driver is deleted).</font> +00332 <a class="code" href="namespaceNL3D.html#a247">ItTexDrvSharePtrList</a> it= <a class="code" href="classNL3D_1_1IDriver.html#n1">_TexDrvShares</a>.insert(<a class="code" href="classNL3D_1_1IDriver.html#n1">_TexDrvShares</a>.end()); +00333 <font class="comment">// create and set iterator, for future deletion.</font> +00334 *it= tex.TextureDrvShare= <font class="keyword">new</font> <a class="code" href="classNL3D_1_1IDriver.html#l1">CTextureDrvShare</a>(<font class="keyword">this</font>, it); +00335 +00336 <font class="comment">// Must (re)-create the texture.</font> +00337 mustCreate = <font class="keyword">true</font>; +00338 } +00339 +00340 <font class="keywordflow">if</font> ( (!tex.touched()) && (!mustCreate) ) +00341 <font class="keywordflow">return</font> <font class="keyword">true</font>; <font class="comment">// Do not do anything</font> +00342 +00343 +00344 <font class="comment">// 1. If modified, may (re)load texture part or all of the texture.</font> +00345 <font class="comment">//=================================================================</font> +00346 +00347 +00348 <font class="keywordtype">bool</font> mustLoadAll= <font class="keyword">false</font>; +00349 <font class="keywordtype">bool</font> mustLoadPart= <font class="keyword">false</font>; +00350 +00351 +00352 <font class="comment">// To avoid any delete/new ptr problem, disable all texturing.</font> +00353 <font class="comment">/* If an old texture is deleted, _CurrentTexture[*] and _CurrentTextureInfoGL[*] are invalid. </font> +00354 <font class="comment"> But this is grave only if a new texture is created, with the same pointer (bad luck). </font> +00355 <font class="comment"> Since an newly allocated texture always pass here before use, we are sure to avoid any problems.</font> +00356 <font class="comment"> */</font> +00357 <font class="keywordflow">for</font>(sint stage=0 ; stage<<a class="code" href="classNL3D_1_1CDriverGL.html#c28">inlGetNumTextStages</a>() ; stage++) +00358 { +00359 <a class="code" href="classNL3D_1_1CDriverGL.html#c2">activateTexture</a>(stage, NULL); +00360 } +00361 +00362 +00363 <font class="comment">// A. Share mgt.</font> +00364 <font class="comment">//==============</font> +00365 <font class="keywordflow">if</font>(tex.supportSharing()) +00366 { +00367 <font class="comment">// Try to get the shared texture.</font> +00368 +00369 <font class="comment">// Create the shared Name.</font> +00370 std::string name; +00371 <a class="code" href="classNL3D_1_1IDriver.html#d0">getTextureShareName</a> (tex, name); +00372 +00373 <font class="comment">// insert or get the texture.</font> +00374 { +00375 CSynchronized<TTexDrvInfoPtrMap>::CAccessor access(&<a class="code" href="classNL3D_1_1IDriver.html#n0">_SyncTexDrvInfos</a>); +00376 TTexDrvInfoPtrMap &rTexDrvInfos = access.value(); +00377 +00378 <a class="code" href="namespaceNL3D.html#a246">ItTexDrvInfoPtrMap</a> itTex; +00379 itTex= rTexDrvInfos.find(name); +00380 +00381 <font class="comment">// texture not found?</font> +00382 <font class="keywordflow">if</font>( itTex==rTexDrvInfos.end() ) +00383 { +00384 <font class="comment">// insert into driver map. (so it is deleted when driver is deleted).</font> +00385 itTex= (rTexDrvInfos.insert(make_pair(name, (<a class="code" href="classNL3D_1_1IDriver.html#l2">ITextureDrvInfos</a>*)NULL))).first; +00386 <font class="comment">// create and set iterator, for future deletion.</font> +00387 itTex->second= tex.TextureDrvShare->DrvTexture= <font class="keyword">new</font> <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a>(<font class="keyword">this</font>, itTex, <font class="keyword">this</font>); +00388 +00389 <font class="comment">// need to load ALL this texture.</font> +00390 mustLoadAll= <font class="keyword">true</font>; +00391 } +00392 <font class="keywordflow">else</font> +00393 { +00394 tex.TextureDrvShare->DrvTexture= itTex->second; +00395 +00396 <font class="keywordflow">if</font>(bMustRecreateSharedTexture) +00397 <font class="comment">// reload this shared texture (user request)</font> +00398 mustLoadAll= <font class="keyword">true</font>; +00399 <font class="keywordflow">else</font> +00400 <font class="comment">// Do not need to reload this texture, even if the format/mipmap has changed, since we found this </font> +00401 <font class="comment">// couple in the map.</font> +00402 mustLoadAll= <font class="keyword">false</font>; +00403 } +00404 } +00405 <font class="comment">// Do not test if part of texture may need to be computed, because Rect invalidation is incompatible </font> +00406 <font class="comment">// with texture sharing.</font> +00407 } +00408 <font class="keywordflow">else</font> +00409 { +00410 <font class="comment">// If texture not already created.</font> +00411 <font class="keywordflow">if</font>(!tex.TextureDrvShare->DrvTexture) +00412 { +00413 <font class="comment">// Must create it. Create auto a GL id (in constructor).</font> +00414 <font class="comment">// Do not insert into the map. This un-shared texture will be deleted at deletion of the texture.</font> +00415 <font class="comment">// Inform ITextureDrvInfos by passing NULL _Driver.</font> +00416 tex.TextureDrvShare->DrvTexture= <font class="keyword">new</font> <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a>(NULL, <a class="code" href="namespaceNL3D.html#a246">ItTexDrvInfoPtrMap</a>(), <font class="keyword">this</font>); +00417 +00418 <font class="comment">// need to load ALL this texture.</font> +00419 mustLoadAll= <font class="keyword">true</font>; +00420 } +00421 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(tex.isAllInvalidated()) +00422 mustLoadAll= <font class="keyword">true</font>; +00423 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(tex.touched()) +00424 mustLoadPart= <font class="keyword">true</font>; +00425 } +00426 +00427 <font class="comment">// B. Setup texture.</font> +00428 <font class="comment">//==================</font> +00429 <font class="keywordflow">if</font>(mustLoadAll || mustLoadPart) +00430 { +00431 <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a>* gltext; +00432 gltext= <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a>(tex); +00433 +00434 <font class="comment">// system of "backup the previous binded texture" seems to not work with some drivers....</font> +00435 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.activeTextureARB(0); +00436 <font class="keywordflow">if</font>(tex.isTextureCube()) +00437 { +00438 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::TextureCubeMap); +00439 <font class="comment">// Bind this texture, for reload...</font> +00440 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, gltext->ID); +00441 } +00442 <font class="keywordflow">else</font> +00443 { +00444 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::Texture2D); +00445 <font class="comment">// Bind this texture, for reload...</font> +00446 glBindTexture(GL_TEXTURE_2D, gltext->ID); +00447 } +00448 +00449 +00450 glPixelStorei(GL_UNPACK_ALIGNMENT,1); +00451 +00452 <font class="comment">// a. Load All the texture case.</font> +00453 <font class="comment">//==============================</font> +00454 <font class="keywordflow">if</font> (mustLoadAll) +00455 { +00456 <font class="comment">// profiling. sub old textre memory usage, and reset.</font> +00457 <a class="code" href="classNL3D_1_1CDriverGL.html#z412_3">_AllocatedTextureMemory</a>-= gltext->TextureMemory; +00458 gltext->TextureMemory= 0; +00459 +00460 +00461 <font class="keywordflow">if</font>(tex.isTextureCube()) +00462 { +00463 <font class="keyword">static</font> GLenum face_map[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, +00464 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, +00465 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, +00466 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, +00467 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, +00468 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB }; +00469 CTextureCube *pTC = NLMISC::safe_cast<CTextureCube *>(&tex); +00470 <font class="comment">// Regenerate all the texture.</font> +00471 tex.generate(); +00472 <font class="keywordflow">for</font>(uint nText = 0; nText < 6; ++nText) +00473 <font class="keywordflow">if</font>(pTC->getTexture((CTextureCube::TFace)nText) != NULL) +00474 { +00475 ITexture *pTInTC = pTC->getTexture((CTextureCube::TFace)nText); +00476 <font class="comment">// Get the correct texture format from texture...</font> +00477 GLint glfmt= <a class="code" href="classNL3D_1_1CDriverGL.html#c12">getGlTextureFormat</a>(*pTInTC, gltext->Compressed); +00478 GLint glSrcFmt= <a class="code" href="namespaceNL3D.html#a348">getGlSrcTextureFormat</a>(*pTInTC, glfmt); +00479 GLenum glSrcType= <a class="code" href="namespaceNL3D.html#a349">getGlSrcTextureComponentType</a>(glSrcFmt); +00480 +00481 sint nMipMaps; +00482 <font class="keywordflow">if</font>(glSrcFmt==GL_RGBA && pTInTC->getPixelFormat()!=CBitmap::RGBA ) +00483 pTInTC->convertToType(CBitmap::RGBA); +00484 <font class="keywordflow">if</font>(tex.mipMapOn()) +00485 { +00486 pTInTC->buildMipMaps(); +00487 nMipMaps= pTInTC->getMipMapCount(); +00488 } +00489 <font class="keywordflow">else</font> +00490 nMipMaps= 1; +00491 +00492 <font class="comment">// Fill mipmaps.</font> +00493 <font class="keywordflow">for</font>(sint i=0;i<nMipMaps;i++) +00494 { +00495 <font class="keywordtype">void</font> *ptr= &(*pTInTC->getPixels(i).begin()); +00496 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= pTInTC->getWidth(i); +00497 uint h= pTInTC->getHeight(i); +00498 <font class="keywordflow">if</font> (bUpload) +00499 { +00500 glTexImage2D (face_map[nText], i, glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, 0, glSrcFmt, glSrcType, ptr); +00501 bAllUploaded = <font class="keyword">true</font>; +00502 } +00503 <font class="keywordflow">else</font> +00504 { +00505 glTexImage2D (face_map[nText], i, glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, 0, glSrcFmt, glSrcType, NULL); +00506 } +00507 <font class="comment">// profiling: count TextureMemory usage.</font> +00508 gltext->TextureMemory+= <a class="code" href="classNL3D_1_1CDriverGL.html#z412_0">computeMipMapMemoryUsage</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, glfmt); +00509 } +00510 } +00511 } +00512 <font class="keywordflow">else</font> +00513 { +00514 <font class="comment">// Regenerate all the texture.</font> +00515 tex.generate(); +00516 +00517 <font class="keywordflow">if</font>(tex.getSize()>0) +00518 { +00519 <font class="comment">// Get the correct texture format from texture...</font> +00520 GLint glfmt= <a class="code" href="classNL3D_1_1CDriverGL.html#c12">getGlTextureFormat</a>(tex, gltext->Compressed); +00521 GLint glSrcFmt= <a class="code" href="namespaceNL3D.html#a348">getGlSrcTextureFormat</a>(tex, glfmt); +00522 GLenum glSrcType= <a class="code" href="namespaceNL3D.html#a349">getGlSrcTextureComponentType</a>(glSrcFmt); +00523 +00524 <font class="comment">// DXTC: if same format, and same mipmapOn/Off, use glTexCompressedImage*.</font> +00525 <font class="comment">// We cannot build the mipmaps if they are not here.</font> +00526 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.EXTTextureCompressionS3TC && <a class="code" href="namespaceNL3D.html#a353">sameDXTCFormat</a>(tex, glfmt) && +00527 (tex.mipMapOff() || tex.getMipMapCount()>1) ) +00528 { +00529 sint nMipMaps; +00530 <font class="keywordflow">if</font>(tex.mipMapOn()) +00531 nMipMaps= tex.getMipMapCount(); +00532 <font class="keywordflow">else</font> +00533 nMipMaps= 1; +00534 +00535 <font class="comment">// Degradation in Size allowed only if DXTC texture are provided with mipmaps.</font> +00536 <font class="comment">// Because use them to resize !!!</font> +00537 uint decalMipMapResize= 0; +00538 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>>0 && tex.allowDegradation() && nMipMaps>1) +00539 { +00540 decalMipMapResize= <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>, (uint)(nMipMaps-1)); +00541 } +00542 +00543 <font class="comment">// Fill mipmaps.</font> +00544 <font class="keywordflow">for</font>(sint i=decalMipMapResize;i<nMipMaps;i++) +00545 { +00546 <font class="keywordtype">void</font> *ptr= &(*tex.getPixels(i).begin()); +00547 sint size= tex.getPixels(i).size(); +00548 <font class="keywordflow">if</font> (bUpload) +00549 { +00550 <a class="code" href="driver__opengl__extension_8h.html#a35">nglCompressedTexImage2DARB</a> (GL_TEXTURE_2D, i-decalMipMapResize, glfmt, +00551 tex.getWidth(i),tex.getHeight(i), 0, size, ptr); +00552 bAllUploaded = <font class="keyword">true</font>; +00553 } +00554 <font class="keywordflow">else</font> +00555 { +00556 <font class="comment">//nglCompressedTexImage2DARB (GL_TEXTURE_2D, i-decalMipMapResize, glfmt, </font> +00557 <font class="comment">// tex.getWidth(i),tex.getHeight(i), 0, size, NULL);</font> +00558 glTexImage2D (GL_TEXTURE_2D, i-decalMipMapResize, glfmt, tex.getWidth(i), tex.getHeight(i), +00559 0, glSrcFmt, glSrcType, NULL); +00560 } +00561 +00562 <font class="comment">// profiling: count TextureMemory usage.</font> +00563 gltext->TextureMemory+= tex.getPixels(i).size(); +00564 } +00565 } +00566 <font class="keywordflow">else</font> +00567 { +00568 sint nMipMaps; +00569 <font class="keywordflow">if</font>(glSrcFmt==GL_RGBA && tex.getPixelFormat()!=CBitmap::RGBA ) +00570 { +00571 bUpload = <font class="keyword">true</font>; <font class="comment">// Force all upload</font> +00572 tex.convertToType(CBitmap::RGBA); +00573 } +00574 +00575 <font class="comment">// Degradation in Size.</font> +00576 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>>0 && tex.allowDegradation()) +00577 { +00578 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= tex.getWidth(0) >> <a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>; +00579 uint h= tex.getHeight(0) >> <a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>; +00580 <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= max(1U, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00581 h= max(1U, h); +00582 tex.resample(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h); +00583 } +00584 +00585 <font class="keywordflow">if</font>(tex.mipMapOn()) +00586 { +00587 tex.buildMipMaps(); +00588 nMipMaps= tex.getMipMapCount(); +00589 } +00590 <font class="keywordflow">else</font> +00591 nMipMaps= 1; +00592 +00593 <font class="comment">// Fill mipmaps.</font> +00594 <font class="keywordflow">for</font>(sint i=0;i<nMipMaps;i++) +00595 { +00596 <font class="keywordtype">void</font> *ptr= &(*tex.getPixels(i).begin()); +00597 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= tex.getWidth(i); +00598 uint h= tex.getHeight(i); +00599 +00600 <font class="keywordflow">if</font> (bUpload) +00601 { +00602 glTexImage2D (GL_TEXTURE_2D, i, glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, 0,glSrcFmt, glSrcType, ptr); +00603 bAllUploaded = <font class="keyword">true</font>; +00604 } +00605 <font class="keywordflow">else</font> +00606 { +00607 glTexImage2D (GL_TEXTURE_2D, i, glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, 0,glSrcFmt, glSrcType, NULL); +00608 } +00609 <font class="comment">// profiling: count TextureMemory usage.</font> +00610 gltext->TextureMemory += <a class="code" href="classNL3D_1_1CDriverGL.html#z412_0">computeMipMapMemoryUsage</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, glfmt); +00611 } +00612 } +00613 } +00614 } +00615 <font class="comment">//printf("%d,%d,%d\n", tex.getMipMapCount(), tex.getWidth(0), tex.getHeight(0));</font> +00616 +00617 +00618 <font class="comment">// profiling. add new TextureMemory usage.</font> +00619 <a class="code" href="classNL3D_1_1CDriverGL.html#z412_3">_AllocatedTextureMemory</a>+= gltext->TextureMemory; +00620 } +00621 <font class="comment">// b. Load part of the texture case.</font> +00622 <font class="comment">//==================================</font> +00623 <font class="comment">// \todo yoyo: TODO_DXTC</font> +00624 <font class="comment">// Replace parts of a compressed image. Maybe don't work with the actual system of invalidateRect()...</font> +00625 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (mustLoadPart && !gltext->Compressed) +00626 { +00627 <font class="comment">// Regenerate wanted part of the texture.</font> +00628 tex.generate(); +00629 +00630 <font class="keywordflow">if</font>(tex.getSize()>0) +00631 { +00632 <font class="comment">// Get the correct texture format from texture...</font> +00633 <font class="comment">//===============================================</font> +00634 <font class="keywordtype">bool</font> dummy; +00635 GLint glfmt= <a class="code" href="classNL3D_1_1CDriverGL.html#c12">getGlTextureFormat</a>(tex, dummy); +00636 GLint glSrcFmt= <a class="code" href="namespaceNL3D.html#a348">getGlSrcTextureFormat</a>(tex, glfmt); +00637 GLenum glSrcType= <a class="code" href="namespaceNL3D.html#a349">getGlSrcTextureComponentType</a>(glSrcFmt); +00638 +00639 sint nMipMaps; +00640 <font class="keywordflow">if</font>(glSrcFmt==GL_RGBA && tex.getPixelFormat()!=CBitmap::RGBA ) +00641 tex.convertToType(CBitmap::RGBA); +00642 <font class="keywordflow">if</font>(tex.mipMapOn()) +00643 { +00644 <font class="keywordtype">bool</font> hadMipMap= tex.getMipMapCount()>1; +00645 tex.buildMipMaps(); +00646 nMipMaps= tex.getMipMapCount(); +00647 <font class="comment">// If the texture had no mipmap before, release them.</font> +00648 <font class="keywordflow">if</font>(!hadMipMap) +00649 { +00650 tex.releaseMipMaps(); +00651 } +00652 } +00653 <font class="keywordflow">else</font> +00654 nMipMaps= 1; +00655 +00656 <font class="comment">// For all rect, update the texture/mipmap.</font> +00657 <font class="comment">//===============================================</font> +00658 list<NLMISC::CRect>::iterator itRect; +00659 <font class="keywordflow">for</font>(itRect=tex._ListInvalidRect.begin(); itRect!=tex._ListInvalidRect.end(); itRect++) +00660 { +00661 CRect &rect= *itRect; +00662 sint x0= rect.X; +00663 sint y0= rect.Y; +00664 sint x1= rect.X+rect.Width; +00665 sint y1= rect.Y+rect.Height; +00666 +00667 <font class="comment">// Fill mipmaps.</font> +00668 <font class="keywordflow">for</font>(sint i=0;i<nMipMaps;i++) +00669 { +00670 <font class="keywordtype">void</font> *ptr= &(*tex.getPixels(i).begin()); +00671 sint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= tex.getWidth(i); +00672 sint h= tex.getHeight(i); +00673 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(x0, 0, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00674 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(y0, 0, h); +00675 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(x1, x0, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00676 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(y1, y0, h); +00677 +00678 glPixelStorei(GL_UNPACK_ROW_LENGTH, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00679 glPixelStorei(GL_UNPACK_SKIP_ROWS, y0); +00680 glPixelStorei(GL_UNPACK_SKIP_PIXELS, x0); +00681 <font class="keywordflow">if</font> (bUpload) +00682 glTexSubImage2D (GL_TEXTURE_2D, i, x0, y0, x1-x0, y1-y0, glSrcFmt,glSrcType, ptr); +00683 <font class="keywordflow">else</font> +00684 glTexSubImage2D (GL_TEXTURE_2D, i, x0, y0, x1-x0, y1-y0, glSrcFmt,glSrcType, NULL); +00685 +00686 <font class="comment">// Next mipmap!!</font> +00687 <font class="comment">// floor .</font> +00688 x0= x0/2; +00689 y0= y0/2; +00690 <font class="comment">// ceil.</font> +00691 x1= (x1+1)/2; +00692 y1= (y1+1)/2; +00693 } +00694 } +00695 +00696 <font class="comment">// Reset the transfer mode...</font> +00697 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); +00698 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); +00699 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); +00700 } +00701 } +00702 +00703 +00704 <font class="comment">// Release, if wanted.</font> +00705 <font class="keywordflow">if</font>(tex.getReleasable()) +00706 tex.release(); +00707 +00708 <font class="comment">// Basic parameters.</font> +00709 <font class="comment">//==================</font> +00710 gltext->WrapS= tex.getWrapS(); +00711 gltext->WrapT= tex.getWrapT(); +00712 gltext->MagFilter= tex.getMagFilter(); +00713 gltext->MinFilter= tex.getMinFilter(); +00714 <font class="keywordflow">if</font>(tex.isTextureCube()) +00715 { +00716 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_S, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(ITexture::Clamp, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00717 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_T, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(ITexture::Clamp, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00718 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_R, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(ITexture::Clamp, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00719 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MAG_FILTER, <a class="code" href="namespaceNL3D.html#a351">translateMagFilterToGl</a>(gltext->MagFilter)); +00720 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MIN_FILTER, <a class="code" href="namespaceNL3D.html#a352">translateMinFilterToGl</a>(gltext->MinFilter)); +00721 } +00722 <font class="keywordflow">else</font> +00723 { +00724 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(gltext->WrapS, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00725 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(gltext->WrapT, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00726 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, <a class="code" href="namespaceNL3D.html#a351">translateMagFilterToGl</a>(gltext->MagFilter)); +00727 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, <a class="code" href="namespaceNL3D.html#a352">translateMinFilterToGl</a>(gltext->MinFilter)); +00728 } +00729 +00730 +00731 +00732 <font class="comment">// Disable texture 0</font> +00733 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_4">_CurrentTexture</a>[0]= NULL; +00734 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[0]= NULL; +00735 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::TextureDisabled); +00736 } +00737 +00738 +00739 <font class="comment">// The texture is correctly setuped.</font> +00740 tex.clearTouched(); +00741 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00742 } +00743 +00744 +00745 <font class="comment">// ***************************************************************************</font> +<a name="l00746"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a20">00746</a> <font class="keywordtype">bool</font> CDriverGL::uploadTexture (ITexture& tex, CRect& rect, uint8 nNumMipMap) +00747 { +00748 <font class="keywordflow">if</font> (tex.TextureDrvShare == NULL) +00749 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// Texture not created</font> +00750 <font class="keywordflow">if</font> (tex.TextureDrvShare->DrvTexture == NULL) +00751 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// Texture not created</font> +00752 <font class="keywordflow">if</font> (tex.isTextureCube()) +00753 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00754 +00755 <a class="code" href="debug_8h.html#a6">nlassert</a>(nNumMipMap<(uint8)tex.getMipMapCount()); +00756 +00757 <font class="comment">// validate rect.</font> +00758 sint x0 = rect.X; +00759 sint y0 = rect.Y; +00760 sint x1 = rect.X+rect.Width; +00761 sint y1 = rect.Y+rect.Height; +00762 sint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> = tex.getWidth (nNumMipMap); +00763 sint h = tex.getHeight (nNumMipMap); +00764 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (x0, 0, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00765 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (y0, 0, h); +00766 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (x1, x0, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00767 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (y1, y0, h); +00768 +00769 <font class="comment">// bind the texture to upload </font> +00770 <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a>* gltext; +00771 gltext = <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a> (tex); +00772 +00773 <font class="comment">// system of "backup the previous binded texture" seems to not work with some drivers....</font> +00774 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.activeTextureARB (0); +00775 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode (CDriverGLStates::Texture2D); +00776 <font class="comment">// Bind this texture, for reload...</font> +00777 glBindTexture (GL_TEXTURE_2D, gltext->ID); +00778 +00779 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); +00780 +00781 <font class="keywordtype">bool</font> dummy; +00782 GLint glfmt = <a class="code" href="classNL3D_1_1CDriverGL.html#c12">getGlTextureFormat</a> (tex, dummy); +00783 GLint glSrcFmt = <a class="code" href="namespaceNL3D.html#a348">getGlSrcTextureFormat</a> (tex, glfmt); +00784 GLenum glSrcType= <a class="code" href="namespaceNL3D.html#a349">getGlSrcTextureComponentType</a>(glSrcFmt); +00785 <font class="comment">// If DXTC format</font> +00786 <font class="comment">//if (isDXTCFormat(glfmt))</font> +00787 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.EXTTextureCompressionS3TC && <a class="code" href="namespaceNL3D.html#a353">sameDXTCFormat</a>(tex, glfmt) && +00788 (tex.mipMapOff() || tex.getMipMapCount()>1) ) +00789 { +00790 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.EXTTextureCompressionS3TC && <a class="code" href="namespaceNL3D.html#a353">sameDXTCFormat</a>(tex, glfmt) && +00791 (tex.mipMapOff() || tex.getMipMapCount()>1) ); +00792 +00793 sint nUploadMipMaps; +00794 <font class="keywordflow">if</font> (tex.mipMapOn()) +00795 nUploadMipMaps = tex.getMipMapCount(); +00796 <font class="keywordflow">else</font> +00797 nUploadMipMaps = 1; +00798 +00799 uint decalMipMapResize = 0; +00800 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>>0 && tex.allowDegradation() && nUploadMipMaps>1) +00801 { +00802 decalMipMapResize = <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>, (uint)(nUploadMipMaps-1)); +00803 } +00804 +00805 <font class="comment">// Compute src compressed size and location</font> +00806 sint <a class="code" href="driver__opengl__extension__def_8h.html#a393">imageSize</a> = (x1-x0)*(y1-y0); +00807 <font class="keywordtype">void</font> *ptr = &(*tex.getPixels(nNumMipMap).begin()); +00808 +00809 <font class="comment">// If DXTC1 or DXTC1A, then 4 bits/texel else 8 bits/texel</font> +00810 <font class="keywordflow">if</font> (glfmt == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || glfmt == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) +00811 { +00812 <a class="code" href="driver__opengl__extension__def_8h.html#a393">imageSize</a> /= 2; +00813 ptr = (uint8*)ptr + y0*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>/2 + x0/2; +00814 } +00815 <font class="keywordflow">else</font> +00816 { +00817 ptr = (uint8*)ptr + y0*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> + x0; +00818 } +00819 +00820 <font class="comment">// Upload</font> +00821 +00822 <font class="keywordflow">if</font> (decalMipMapResize > nNumMipMap) +00823 { +00824 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_4">_CurrentTexture</a>[0]= NULL; +00825 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[0]= NULL; +00826 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode (CDriverGLStates::TextureDisabled); +00827 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00828 } +00829 +00830 +00831 <a class="code" href="debug_8h.html#a6">nlassert</a> (((x0&3) == 0) && ((y0&3) == 0)); +00832 <font class="keywordflow">if</font> ((<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>>=4) && (h>=4)) +00833 { +00834 <a class="code" href="driver__opengl__extension_8h.html#a38">nglCompressedTexSubImage2DARB</a> ( GL_TEXTURE_2D, nNumMipMap-decalMipMapResize, +00835 x0, y0, (x1-x0), (y1-y0), glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a393">imageSize</a>, ptr ); +00836 } +00837 <font class="keywordflow">else</font> +00838 { +00839 <font class="comment">// The CompressedTexSubImage2DARB function do not functionnate properly if width or height</font> +00840 <font class="comment">// of the mipmap is less than 4 pixel so we use the other form. (its not really time critical</font> +00841 <font class="comment">// to upload 16 bytes so we can do it twice if texture is cut)</font> +00842 <a class="code" href="driver__opengl__extension__def_8h.html#a393">imageSize</a> = tex.getPixels(nNumMipMap).size(); +00843 <a class="code" href="driver__opengl__extension_8h.html#a35">nglCompressedTexImage2DARB</a> (GL_TEXTURE_2D, nNumMipMap-decalMipMapResize, +00844 glfmt, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, h, 0, <a class="code" href="driver__opengl__extension__def_8h.html#a393">imageSize</a>, ptr); +00845 } +00846 } +00847 <font class="keywordflow">else</font> +00848 { +00849 <font class="comment">// glSrcFmt and ITexture format must be identical</font> +00850 <a class="code" href="debug_8h.html#a6">nlassert</a> (glSrcFmt!=GL_RGBA || tex.getPixelFormat()==CBitmap::RGBA); +00851 +00852 <font class="keywordtype">void</font> *ptr= &(*tex.getPixels(nNumMipMap).begin()); +00853 glPixelStorei (GL_UNPACK_ROW_LENGTH, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00854 glPixelStorei (GL_UNPACK_SKIP_ROWS, y0); +00855 glPixelStorei (GL_UNPACK_SKIP_PIXELS, x0); +00856 glTexSubImage2D (GL_TEXTURE_2D, nNumMipMap, x0, y0, x1-x0, y1-y0, glSrcFmt,glSrcType, ptr); +00857 +00858 <font class="comment">// Reset the transfer mode...</font> +00859 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); +00860 glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); +00861 glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); +00862 } +00863 +00864 <font class="comment">// Disable texture 0</font> +00865 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_4">_CurrentTexture</a>[0]= NULL; +00866 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[0]= NULL; +00867 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode (CDriverGLStates::TextureDisabled); +00868 +00869 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00870 } +00871 +00872 <font class="comment">// ***************************************************************************</font> +<a name="l00873"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a21">00873</a> <font class="keywordtype">bool</font> CDriverGL::uploadTextureCube (ITexture& tex, CRect& rect, uint8 nNumMipMap, uint8 nNumFace) +00874 { +00875 <font class="keywordflow">if</font> (tex.TextureDrvShare == NULL) +00876 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// Texture not created</font> +00877 <font class="keywordflow">if</font> (!tex.isTextureCube()) +00878 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00879 +00880 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00881 } +00882 +00883 <font class="comment">// ***************************************************************************</font> +<a name="l00884"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c2">00884</a> <font class="keywordtype">bool</font> CDriverGL::activateTexture(uint stage, ITexture *tex) +00885 { +00886 <font class="keywordflow">if</font> (this-><a class="code" href="classNL3D_1_1CDriverGL.html#z405_4">_CurrentTexture</a>[stage]!=tex) +00887 { +00888 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.activeTextureARB(stage); +00889 <font class="keywordflow">if</font>(tex) +00890 { +00891 <font class="comment">// get the drv info. should be not NULL.</font> +00892 <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a>* gltext; +00893 gltext= <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a>(*tex); +00894 +00895 <font class="comment">// Profile, log the use of this texture</font> +00896 <font class="comment">//=========================================</font> +00897 <font class="keywordflow">if</font> (_SumTextureMemoryUsed) +00898 { +00899 <font class="comment">// Insert the pointer of this texture</font> +00900 <a class="code" href="classNL3D_1_1CDriverGL.html#z412_7">_TextureUsed</a>.insert (gltext); +00901 } +00902 +00903 +00904 <font class="keywordflow">if</font>(tex->isTextureCube()) +00905 { +00906 <font class="comment">// setup texture mode, after activeTextureARB()</font> +00907 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::TextureCubeMap); +00908 +00909 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.ARBTextureCubeMap) +00910 { +00911 <font class="comment">// Activate texturing...</font> +00912 <font class="comment">//======================</font> +00913 +00914 <font class="comment">// If the shared texture is the same than before, no op.</font> +00915 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[stage] != gltext) +00916 { +00917 <font class="comment">// Cache setup.</font> +00918 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[stage]= gltext; +00919 +00920 <font class="comment">// setup this texture</font> +00921 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, gltext->ID); +00922 +00923 +00924 <font class="comment">// Change parameters of texture, if necessary.</font> +00925 <font class="comment">//============================================</font> +00926 <font class="keywordflow">if</font>(gltext->MagFilter!= tex->getMagFilter()) +00927 { +00928 gltext->MagFilter= tex->getMagFilter(); +00929 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MAG_FILTER, <a class="code" href="namespaceNL3D.html#a351">translateMagFilterToGl</a>(gltext->MagFilter)); +00930 } +00931 <font class="keywordflow">if</font>(gltext->MinFilter!= tex->getMinFilter()) +00932 { +00933 gltext->MinFilter= tex->getMinFilter(); +00934 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_MIN_FILTER, <a class="code" href="namespaceNL3D.html#a352">translateMinFilterToGl</a>(gltext->MinFilter)); +00935 } +00936 } +00937 } +00938 } +00939 <font class="keywordflow">else</font> +00940 { +00941 <font class="comment">// setup texture mode, after activeTextureARB()</font> +00942 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::Texture2D); +00943 +00944 <font class="comment">// Activate texture...</font> +00945 <font class="comment">//======================</font> +00946 +00947 <font class="comment">// If the shared texture is the same than before, no op.</font> +00948 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[stage] != gltext) +00949 { +00950 <font class="comment">// Cache setup.</font> +00951 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[stage]= gltext; +00952 +00953 <font class="comment">// setup this texture</font> +00954 glBindTexture(GL_TEXTURE_2D, gltext->ID); +00955 +00956 +00957 <font class="comment">// Change parameters of texture, if necessary.</font> +00958 <font class="comment">//============================================</font> +00959 <font class="keywordflow">if</font>(gltext->WrapS!= tex->getWrapS()) +00960 { +00961 gltext->WrapS= tex->getWrapS(); +00962 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(gltext->WrapS, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00963 } +00964 <font class="keywordflow">if</font>(gltext->WrapT!= tex->getWrapT()) +00965 { +00966 gltext->WrapT= tex->getWrapT(); +00967 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, <a class="code" href="namespaceNL3D.html#a350">translateWrapToGl</a>(gltext->WrapT, <a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>)); +00968 } +00969 <font class="keywordflow">if</font>(gltext->MagFilter!= tex->getMagFilter()) +00970 { +00971 gltext->MagFilter= tex->getMagFilter(); +00972 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, <a class="code" href="namespaceNL3D.html#a351">translateMagFilterToGl</a>(gltext->MagFilter)); +00973 } +00974 <font class="keywordflow">if</font>(gltext->MinFilter!= tex->getMinFilter()) +00975 { +00976 gltext->MinFilter= tex->getMinFilter(); +00977 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, <a class="code" href="namespaceNL3D.html#a352">translateMinFilterToGl</a>(gltext->MinFilter)); +00978 } +00979 } +00980 } +00981 } +00982 <font class="keywordflow">else</font> +00983 { +00984 <font class="comment">// Force no texturing for this stage.</font> +00985 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_5">_CurrentTextureInfoGL</a>[stage]= NULL; +00986 <font class="comment">// setup texture mode, after activeTextureARB()</font> +00987 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.setTextureMode(CDriverGLStates::TextureDisabled); +00988 } +00989 +00990 this-><a class="code" href="classNL3D_1_1CDriverGL.html#z405_4">_CurrentTexture</a>[stage]= tex; +00991 } +00992 +00993 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00994 } +00995 +00996 <font class="comment">// ***************************************************************************</font> +<a name="l00997"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c5">00997</a> <font class="keywordtype">void</font> CDriverGL::forceActivateTexEnvMode(uint stage, <font class="keyword">const</font> CMaterial::CTexEnv &env) +00998 { +00999 <font class="comment">// This maps the CMaterial::TTexOperator</font> +01000 <font class="keyword">static</font> <font class="keyword">const</font> GLenum operatorLUT[9]= { GL_REPLACE, GL_MODULATE, GL_ADD, GL_ADD_SIGNED_EXT, +01001 GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, <a class="code" href="driver__opengl__extension__def_8h.html#a352">GL_BUMP_ENVMAP_ATI</a> }; +01002 +01003 <font class="comment">// This maps the CMaterial::TTexSource</font> +01004 <font class="keyword">static</font> <font class="keyword">const</font> GLenum sourceLUT[4]= { GL_TEXTURE, GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT }; +01005 +01006 <font class="comment">// This maps the CMaterial::TTexOperand</font> +01007 <font class="keyword">static</font> <font class="keyword">const</font> GLenum operandLUT[4]= { GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }; +01008 +01009 <font class="comment">// This maps the CMaterial::TTexOperator, used for openGL Arg2 setup.</font> +01010 <font class="keyword">static</font> <font class="keyword">const</font> GLenum interpolateSrcLUT[8]= { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, +01011 GL_TEXTURE, GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT }; +01012 +01013 +01014 +01015 <font class="comment">// cache mgt.</font> +01016 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_6">_CurrentTexEnv</a>[stage].EnvPacked= env.EnvPacked; +01017 <font class="comment">// Disable Special tex env f().</font> +01018 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_7">_CurrentTexEnvSpecial</a>[stage]= <a class="code" href="classNL3D_1_1CDriverGL.html#z405_0u0">TexEnvSpecialDisabled</a>; +01019 +01020 +01021 <font class="comment">// Setup the gl env mode.</font> +01022 <a class="code" href="classNL3D_1_1CDriverGL.html#z405_11">_DriverGLStates</a>.activeTextureARB(stage); +01023 <font class="comment">// "Normal drivers", setup EnvCombine.</font> +01024 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z403_0">_Extensions</a>.EXTTextureEnvCombine) +01025 { +01026 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); +01027 +01028 +01029 <font class="comment">// RGB.</font> +01030 <font class="comment">//=====</font> +01031 <font class="comment">// Operator.</font> +01032 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, operatorLUT[env.Env.OpRGB] ); +01033 <font class="comment">// Arg0.</font> +01034 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, sourceLUT[env.Env.SrcArg0RGB] ); +01035 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, operandLUT[env.Env.OpArg0RGB]); +01036 <font class="comment">// Arg1.</font> +01037 <font class="keywordflow">if</font>(env.Env.OpRGB > CMaterial::Replace) +01038 { +01039 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, sourceLUT[env.Env.SrcArg1RGB] ); +01040 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, operandLUT[env.Env.OpArg1RGB]); +01041 <font class="comment">// Arg2.</font> +01042 <font class="keywordflow">if</font>(env.Env.OpRGB >= CMaterial::InterpolateTexture ) +01043 { +01044 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, interpolateSrcLUT[env.Env.OpRGB] ); +01045 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA); +01046 } +01047 } +01048 +01049 +01050 <font class="comment">// Alpha.</font> +01051 <font class="comment">//=====</font> +01052 <font class="comment">// Operator.</font> +01053 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, operatorLUT[env.Env.OpAlpha] ); +01054 <font class="comment">// Arg0.</font> +01055 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, sourceLUT[env.Env.SrcArg0Alpha] ); +01056 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, operandLUT[env.Env.OpArg0Alpha]); +01057 <font class="comment">// Arg1.</font> +01058 <font class="keywordflow">if</font>(env.Env.OpAlpha > CMaterial::Replace) +01059 { +01060 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, sourceLUT[env.Env.SrcArg1Alpha] ); +01061 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, operandLUT[env.Env.OpArg1Alpha]); +01062 <font class="comment">// Arg2.</font> +01063 <font class="keywordflow">if</font>(env.Env.OpAlpha >= CMaterial::InterpolateTexture ) +01064 { +01065 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, interpolateSrcLUT[env.Env.OpAlpha] ); +01066 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA); +01067 } +01068 } +01069 } +01070 <font class="comment">// Very Bad drivers.</font> +01071 <font class="keywordflow">else</font> +01072 { +01073 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +01074 } +01075 +01076 } +01077 +01078 +01079 <font class="comment">// ***************************************************************************</font> +<a name="l01080"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c6">01080</a> <font class="keywordtype">void</font> CDriverGL::activateTexEnvColor(uint stage, <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> col) +01081 { +01082 <font class="keywordflow">if</font> (col != <a class="code" href="classNL3D_1_1CDriverGL.html#z405_6">_CurrentTexEnv</a>[stage].ConstantColor) +01083 { +01084 <a class="code" href="classNL3D_1_1CDriverGL.html#c7">forceActivateTexEnvColor</a>(stage, col); +01085 } +01086 } +01087 +01088 +01089 <font class="comment">// ***************************************************************************</font> +<a name="l01090"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c3">01090</a> <font class="keywordtype">void</font> CDriverGL::activateTexEnvMode(uint stage, <font class="keyword">const</font> CMaterial::CTexEnv &env) +01091 { +01092 <font class="comment">// If a special Texture environnement is setuped, or if not the same normal texture environnement,</font> +01093 <font class="comment">// must setup a new normal Texture environnement.</font> +01094 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CDriverGL.html#z405_7">_CurrentTexEnvSpecial</a>[stage] != <a class="code" href="classNL3D_1_1CDriverGL.html#z405_0u0">TexEnvSpecialDisabled</a> || <a class="code" href="classNL3D_1_1CDriverGL.html#z405_6">_CurrentTexEnv</a>[stage].EnvPacked!= env.EnvPacked) +01095 { +01096 <a class="code" href="classNL3D_1_1CDriverGL.html#c5">forceActivateTexEnvMode</a>(stage, env); +01097 } +01098 } +01099 +01100 +01101 <font class="comment">// ***************************************************************************</font> +<a name="l01102"></a><a class="code" href="classNL3D_1_1CDriverGL.html#c4">01102</a> <font class="keywordtype">void</font> CDriverGL::activateTexEnvColor(uint stage, <font class="keyword">const</font> CMaterial::CTexEnv &env) +01103 { +01104 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CDriverGL.html#z405_6">_CurrentTexEnv</a>[stage].ConstantColor!= env.ConstantColor) +01105 { +01106 <a class="code" href="classNL3D_1_1CDriverGL.html#c7">forceActivateTexEnvColor</a>(stage, env); +01107 } +01108 } +01109 +01110 +01111 <font class="comment">// ***************************************************************************</font> +<a name="l01112"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a22">01112</a> <font class="keywordtype">void</font> CDriverGL::forceDXTCCompression(<font class="keywordtype">bool</font> dxtcComp) +01113 { +01114 <a class="code" href="classNL3D_1_1CDriverGL.html#o27">_ForceDXTCCompression</a>= dxtcComp; +01115 } +01116 +01117 <font class="comment">// ***************************************************************************</font> +<a name="l01118"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a23">01118</a> <font class="keywordtype">void</font> CDriverGL::forceTextureResize(uint divisor) +01119 { +01120 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(divisor, 1U, 256U); +01121 +01122 <font class="comment">// 16 -> 4.</font> +01123 <a class="code" href="classNL3D_1_1CDriverGL.html#o28">_ForceTextureResizePower</a>= <a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a>(divisor); +01124 } +01125 +01126 +01127 <font class="comment">// ***************************************************************************</font> +<a name="l01128"></a><a class="code" href="classNL3D_1_1CDriverGL.html#a87">01128</a> <font class="keywordtype">void</font> CDriverGL::swapTextureHandle(ITexture &tex0, ITexture &tex1) +01129 { +01130 <font class="comment">// ensure creation of both texture</font> +01131 <a class="code" href="classNL3D_1_1CDriverGL.html#a18">setupTexture</a>(tex0); +01132 <a class="code" href="classNL3D_1_1CDriverGL.html#a18">setupTexture</a>(tex1); +01133 +01134 <font class="comment">// avoid any problem, disable all textures</font> +01135 <font class="keywordflow">for</font>(sint stage=0; stage<<a class="code" href="classNL3D_1_1CDriverGL.html#c28">inlGetNumTextStages</a>() ; stage++) +01136 { +01137 <a class="code" href="classNL3D_1_1CDriverGL.html#c2">activateTexture</a>(stage, NULL); +01138 } +01139 +01140 <font class="comment">// get the handle.</font> +01141 <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a> *t0= <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a>(tex0); +01142 <a class="code" href="classNL3D_1_1CDriverGL.html#l0">CTextureDrvInfosGL</a> *t1= <a class="code" href="namespaceNL3D.html#a347">getTextureGl</a>(tex1); +01143 +01144 <font class="comment">/* Swap contents. Can't swap directly the pointers cause would have to change all CTextureDrvShare which point on</font> +01145 <font class="comment"> Can't do swap(*t0, *t1), because must keep the correct _DriverIterator</font> +01146 <font class="comment"> */</font> +01147 swap(t0->ID, t1->ID); +01148 swap(t0->Compressed, t1->Compressed); +01149 swap(t0->TextureMemory, t1->TextureMemory); +01150 swap(t0->WrapS, t1->WrapS); +01151 swap(t0->WrapT, t1->WrapT); +01152 swap(t0->MagFilter, t1->MagFilter); +01153 swap(t0->MinFilter, t1->MinFilter); +01154 +01155 } +01156 +01157 +01158 } <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> |