aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/patchdlm__context_8cpp-source.html
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
committerneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
commit0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch)
tree2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/patchdlm__context_8cpp-source.html
downloadnevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz
nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip
Initial commit
Diffstat (limited to 'docs/doxygen/nel/patchdlm__context_8cpp-source.html')
-rw-r--r--docs/doxygen/nel/patchdlm__context_8cpp-source.html1328
1 files changed, 1328 insertions, 0 deletions
diff --git a/docs/doxygen/nel/patchdlm__context_8cpp-source.html b/docs/doxygen/nel/patchdlm__context_8cpp-source.html
new file mode 100644
index 00000000..abd02197
--- /dev/null
+++ b/docs/doxygen/nel/patchdlm__context_8cpp-source.html
@@ -0,0 +1,1328 @@
+<!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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</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>
+&nbsp;
+
+<!-- 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>&nbsp;</td>
+</tr></table>
+<!-- Generated by Doxygen 1.2.14 -->
+<center>
+<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <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> &nbsp; </center>
+<hr><h1>patchdlm_context.cpp</h1><a href="patchdlm__context_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="patchdlm__context_8h.html">3d/patchdlm_context.h</a>"</font>
+00029 <font class="preprocessor">#include "<a class="code" href="patch_8h.html">3d/patch.h</a>"</font>
+00030 <font class="preprocessor">#include "<a class="code" href="bezier__patch_8h.html">3d/bezier_patch.h</a>"</font>
+00031 <font class="preprocessor">#include "<a class="code" href="point__light_8h.html">3d/point_light.h</a>"</font>
+00032 <font class="preprocessor">#include "<a class="code" href="texture__dlm_8h.html">3d/texture_dlm.h</a>"</font>
+00033 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
+00034 <font class="preprocessor">#include "<a class="code" href="tile__far__bank_8h.html">3d/tile_far_bank.h</a>"</font>
+00035 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font>
+00036 <font class="preprocessor">#include "<a class="code" href="system__info_8h.html">nel/misc/system_info.h</a>"</font>
+00037 <font class="preprocessor">#include "<a class="code" href="fast__mem_8h.html">nel/misc/fast_mem.h</a>"</font>
+00038
+00039
+00040 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
+00041 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
+00042
+00043 <font class="keyword">namespace </font>NL3D
+00044 {
+00045
+00046 <font class="comment">// ***************************************************************************</font>
+00047 <font class="comment">// ***************************************************************************</font>
+00048 <font class="comment">// ***************************************************************************</font>
+00049
+00050
+00051 <font class="comment">// ***************************************************************************</font>
+<a name="l00052"></a><a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#a0">00052</a> <font class="keywordtype">void</font> CPatchDLMPointLight::compile(<font class="keyword">const</font> CPointLight &amp;pl, <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> landDiffMat, <font class="keywordtype">float</font> maxAttEnd)
+00053 {
+00054 <a class="code" href="debug_8h.html#a6">nlassert</a>(maxAttEnd&gt;0);
+00055
+00056 <font class="comment">// copy color</font>
+00057 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m0">R</a>= (float) (( pl.getDiffuse().R*(landDiffMat.<a class="code" href="classNLMISC_1_1CRGBA.html#m0">R</a>+1) ) &gt;&gt;8);
+00058 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m1">G</a>= (float) (( pl.getDiffuse().G*(landDiffMat.<a class="code" href="classNLMISC_1_1CRGBA.html#m1">G</a>+1) ) &gt;&gt;8);
+00059 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m2">B</a>= (float) (( pl.getDiffuse().B*(landDiffMat.<a class="code" href="classNLMISC_1_1CRGBA.html#m2">B</a>+1) ) &gt;&gt;8);
+00060 <font class="comment">// Copy Spot/Pos/Dir.</font>
+00061 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m3">IsSpot</a>= pl.getType() == CPointLight::SpotLight;
+00062 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m4">Pos</a>= pl.getPosition();
+00063 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m5">Dir</a>= pl.getSpotDirection();
+00064
+00065 <font class="comment">// compute spot params</font>
+00066 <font class="keywordflow">if</font>(IsSpot)
+00067 {
+00068 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m6">CosMax</a>= cosf(pl.getSpotAngleBegin());
+00069 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>= cosf(pl.getSpotAngleEnd());
+00070 }
+00071 <font class="keywordflow">else</font>
+00072 {
+00073 <font class="comment">// with tesse Values, we have always (cosSpot-CosMin) * OOCosDelta &gt; 1.0f</font>
+00074 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m6">CosMax</a>= -1;
+00075 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>= -2;
+00076 }
+00077 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m8">OOCosDelta</a>= 1.f / (<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m6">CosMax</a>-<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>);
+00078
+00079 <font class="comment">// compute att params</font>
+00080 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>= pl.getAttenuationEnd();
+00081 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m10">AttMin</a>= pl.getAttenuationBegin();
+00082 <font class="comment">// infinite pointLight?</font>
+00083 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>==0)
+00084 {
+00085 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>= maxAttEnd;
+00086 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m10">AttMin</a>= maxAttEnd*0.99f;
+00087 }
+00088 <font class="comment">// To big pointLigt?</font>
+00089 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>&gt;maxAttEnd)
+00090 {
+00091 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>= maxAttEnd;
+00092 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m10">AttMin</a>= <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m10">AttMin</a>, maxAttEnd*0.99f);
+00093 }
+00094 <font class="comment">// compile distance</font>
+00095 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m11">OOAttDelta</a>= 1.f / (<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m10">AttMin</a>-<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>);
+00096
+00097
+00098 <font class="comment">// Compute bounding sphere.</font>
+00099 <font class="comment">// If not a spot or if angleMin&gt;Pi/2</font>
+00100 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m3">IsSpot</a> || <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>&lt;0)
+00101 {
+00102 <font class="comment">// Take sphere of pointlight sphere</font>
+00103 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>= <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m4">Pos</a>;
+00104 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m1">Radius</a>= <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>;
+00105 <font class="comment">// The bbox englobe the sphere.</font>
+00106 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m13">BBox</a>.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_0">setCenter</a>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m4">Pos</a>);
+00107 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m13">BBox</a>.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_1">setHalfSize</a>(CVector(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>, <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>, <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>));
+00108 }
+00109 <font class="keywordflow">else</font>
+00110 {
+00111 <font class="comment">// Compute BSphere.</font>
+00112 <font class="comment">//==============</font>
+00113
+00114 <font class="comment">// compute sinus of AngleMin</font>
+00115 <font class="keywordtype">float</font> sinMin= sqrtf(1-<a class="code" href="namespaceNLMISC.html#a214">sqr</a>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>));
+00116
+00117 <font class="comment">// Test 2 centers: Center of radius along Dir: Pos+Dir*AttMax/2, and intersection of end cone with line (Pos,Dir)</font>
+00118 <font class="comment">// Don't know why but I think they are sufficiently good :)</font>
+00119 <font class="comment">// See below for computing of those centers.</font>
+00120
+00121 <font class="comment">/* compute radius of each sphere by taking max of 3 distances: distance to spotLight center, distance</font>
+00122 <font class="comment"> to spotLight forward extremity, and distance to spotLight circle interstion Cone/Sphere. (named DCCS)</font>
+00123 <font class="comment"> NB: Do the compute with radius=1 at first, then multiply later.</font>
+00124 <font class="comment"> */</font>
+00125 <font class="keywordtype">float</font> radius1= 0.5f; <font class="comment">// =max(0.5, 0.5); max distance to spot center and extremity center :)</font>
+00126 <font class="comment">// for distance DCCS, this is the hypothenuse of (cosMin-0.5) + sinMin.</font>
+00127 <font class="keywordtype">float</font> dccs= sqrtf( <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>-0.5f) + <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(sinMin));
+00128 <font class="comment">// take the bigger.</font>
+00129 radius1= max(radius1, dccs );
+00130
+00131 <font class="comment">// Same reasoning for center2.</font>
+00132 <font class="keywordtype">float</font> radius2= max(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>, 1-<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>); <font class="comment">// max distance to spot center and extremity center :)</font>
+00133 <font class="comment">// for distance DCCS, it is simply sinMin!!</font>
+00134 dccs= sinMin;
+00135 <font class="comment">// take the bigger.</font>
+00136 radius2= max(radius2, dccs );
+00137
+00138
+00139 <font class="comment">// Then take the center which gives the smaller sphere</font>
+00140 <font class="keywordflow">if</font>(radius1&lt;radius2)
+00141 {
+00142 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>= <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m4">Pos</a> + (<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m5">Dir</a>*0.5f*<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>);
+00143 <font class="comment">// radius1 E [0,1], must take real size.</font>
+00144 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m1">Radius</a>= radius1 * <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>;
+00145 }
+00146 <font class="keywordflow">else</font>
+00147 {
+00148 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>= <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m4">Pos</a> + (<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m5">Dir</a>*<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m7">CosMin</a>*<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>);
+00149 <font class="comment">// radius2 E [0,1], must take real size.</font>
+00150 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m1">Radius</a>= radius2 * <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m9">AttMax</a>;
+00151 }
+00152
+00153
+00154 <font class="comment">// Compute BBox.</font>
+00155 <font class="comment">//==============</font>
+00156
+00157 <font class="comment">// just take bbox of the sphere, even if not optimal.</font>
+00158 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m13">BBox</a>.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_0">setCenter</a>(<a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>);
+00159 <font class="keywordtype">float</font> rad= <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m12">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m1">Radius</a>;
+00160 <a class="code" href="classNL3D_1_1CPatchDLMPointLight.html#m13">BBox</a>.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_1">setHalfSize</a>( CVector(rad, rad, rad) );
+00161 }
+00162 }
+00163
+00164
+00165 <font class="comment">// ***************************************************************************</font>
+00166 <font class="comment">// ***************************************************************************</font>
+00167 <font class="comment">// ***************************************************************************</font>
+00168
+00169
+00170 <font class="comment">// ***************************************************************************</font>
+<a name="l00171"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a0">00171</a> CPatchDLMContext::CPatchDLMContext()
+00172 {
+00173 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>= NULL;
+00174 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>= NULL;
+00175 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o2">_DLMContextList</a>= NULL;
+00176 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m12">OldPointLightCount</a>= 0;
+00177 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m13">CurPointLightCount</a>= 0;
+00178 <font class="comment">// By default there is crash in textures</font>
+00179 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a>= <font class="keyword">false</font>;
+00180 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o7">_IsDstTextureFullBlack</a>= <font class="keyword">false</font>;
+00181 }
+00182
+00183
+00184 <font class="comment">// ***************************************************************************</font>
+<a name="l00185"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a1">00185</a> CPatchDLMContext::~CPatchDLMContext()
+00186 {
+00187 <font class="comment">// release the lightmap in the texture</font>
+00188 <font class="keywordflow">if</font>(_DLMTexture)
+00189 {
+00190 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;releaseLightMap(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>);
+00191 }
+00192 <font class="comment">// exit</font>
+00193 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>= NULL;
+00194 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>= NULL;
+00195
+00196 <font class="comment">// remove it from list.</font>
+00197 <font class="keywordflow">if</font>(_DLMContextList)
+00198 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o2">_DLMContextList</a>-&gt;remove(<font class="keyword">this</font>);
+00199 }
+00200
+00201
+00202 <font class="comment">// ***************************************************************************</font>
+00203 <font class="preprocessor">#ifdef NL_DLM_TILE_RES</font>
+00204 <font class="preprocessor"></font><font class="comment">// if tileRes defined, still start to clip at tessBlockLevel.</font>
+00205 <font class="preprocessor">#define NL_DLM_CLIP_FACTOR 2</font>
+00206 <font class="preprocessor"></font><font class="preprocessor">#else</font>
+00207 <font class="preprocessor"></font><font class="comment">// start to clip at tessBlockLevel (same as dlm map precision)</font>
+<a name="l00208"></a><a class="code" href="patchdlm__context_8cpp.html#a0">00208</a> <font class="preprocessor">#define NL_DLM_CLIP_FACTOR 1</font>
+00209 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
+00210 <font class="preprocessor"></font>
+<a name="l00211"></a><a class="code" href="patchdlm__context_8cpp.html#a1">00211</a> <font class="preprocessor">#define NL_DLM_CLIP_NUM_LEVEL 3</font>
+00212 <font class="preprocessor"></font>
+00213 <font class="comment">// ***************************************************************************</font>
+<a name="l00214"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a2">00214</a> <font class="keywordtype">bool</font> CPatchDLMContext::generate(CPatch *patch, CTextureDLM *textureDLM, CPatchDLMContextList *ctxList)
+00215 {
+00216 <a class="code" href="debug_8h.html#a6">nlassert</a>(patch);
+00217 <a class="code" href="debug_8h.html#a6">nlassert</a>(textureDLM);
+00218 <a class="code" href="debug_8h.html#a6">nlassert</a>(ctxList);
+00219
+00220 <font class="comment">// keep info on patch/landscape.</font>
+00221 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>= patch;
+00222 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>= textureDLM;
+00223 <font class="comment">// append to the list.</font>
+00224 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o2">_DLMContextList</a>= ctxList;
+00225 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o2">_DLMContextList</a>-&gt;append(<font class="keyword">this</font>);
+00226
+00227 <font class="comment">// Get Texture Size info; </font>
+00228 <font class="preprocessor">#ifdef NL_DLM_TILE_RES</font>
+00229 <font class="preprocessor"></font> <font class="comment">// get coord at cornes of tiles</font>
+00230 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>= (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS())+1;
+00231 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>= (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderT())+1;
+00232 <font class="preprocessor">#else</font>
+00233 <font class="preprocessor"></font> <font class="comment">// get coord at cornes of tessBlocks</font>
+00234 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>= (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS()/2)+1;
+00235 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>= (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderT()/2)+1;
+00236 <font class="preprocessor">#endif</font>
+00237 <font class="preprocessor"></font>
+00238 <font class="comment">// Allocate space in texture</font>
+00239 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;createLightMap(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>))
+00240 {
+00241 <font class="comment">// Mark as not allocated.</font>
+00242 <font class="comment">// NB: the context still work with NULL _DLMTexture, but do nothing (excpetionnal case)</font>
+00243 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>= NULL;
+00244 }
+00245
+00246 <font class="comment">// If the lightmap is correclty allocated in the global texture, compute UVBias.</font>
+00247 <font class="keywordflow">if</font>(_DLMTexture)
+00248 {
+00249 <font class="comment">// Compute patch UV matrix from pixels. Must map to center of pixels.</font>
+00250 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m4">DLMUScale</a>= (float)(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>-1) / (float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;getWidth();
+00251 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m5">DLMVScale</a>= (float)(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>-1) / (float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;getHeight();
+00252 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m6">DLMUBias</a>= ((float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>+0.5f) / (float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;getWidth();
+00253 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m7">DLMVBias</a>= ((float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>+0.5f) / (float)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;getHeight();
+00254 }
+00255 <font class="keywordflow">else</font>
+00256 {
+00257 <font class="comment">// Build UVBias such that the UVs point to Black</font>
+00258 <font class="comment">// NB: TextureDLM ensure that point (MaxX,MaxY) of texture is black.</font>
+00259 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m4">DLMUScale</a>= 0;
+00260 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m5">DLMVScale</a>= 0;
+00261 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m6">DLMUBias</a>= 1;
+00262 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m7">DLMVBias</a>= 1;
+00263 }
+00264
+00265 <font class="comment">// TestYoyo: to see lightmap usage in the big texture</font>
+00266 <font class="comment">/*DLMUScale= _Patch-&gt;getOrderS();</font>
+00267 <font class="comment"> DLMVScale= _Patch-&gt;getOrderT();</font>
+00268 <font class="comment"> DLMUBias= 0;</font>
+00269 <font class="comment"> DLMVBias= 0;*/</font>
+00270
+00271
+00272 <font class="comment">// Bound 8bits UV for Vegetable. This is to ensure vegetable Dlm UVs won't peek in neighbor lightmaps.</font>
+00273 sint tmpU, tmpV;
+00274 <font class="comment">// Bound U minimum</font>
+00275 tmpU= (sint)ceil ( (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m6">DLMUBias</a>) * 255 );
+00276 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tmpU, 0, 255);
+00277 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m8">MinU8</a>= tmpU;
+00278 <font class="comment">// Bound U maximum</font>
+00279 tmpU= (sint)floor( (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m6">DLMUBias</a>+<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m4">DLMUScale</a>) * 255 );
+00280 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tmpU, (sint)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m8">MinU8</a>, 255);
+00281 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m9">MaxU8</a>= tmpU;
+00282 <font class="comment">// Bound V minimum</font>
+00283 tmpV= (sint)ceil ( (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m7">DLMVBias</a>) * 255 );
+00284 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tmpV, 0, 255);
+00285 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m10">MinV8</a>= tmpV;
+00286 <font class="comment">// Bound V maximum</font>
+00287 tmpV= (sint)floor( (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m7">DLMVBias</a>+<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m5">DLMVScale</a>) * 255 );
+00288 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tmpV, (sint)<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m10">MinV8</a>, 255);
+00289 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m11">MaxV8</a>= tmpV;
+00290
+00291
+00292 <font class="comment">// Allocate RAM Lightmap</font>
+00293 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z301_1">resize</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+00294
+00295 <font class="comment">// generate Vertices: pos and normals</font>
+00296 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z301_1">resize</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+00297 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
+00298 <font class="keywordtype">float</font> ds= 1.0f / (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>-1);
+00299 <font class="keywordtype">float</font> dt= 1.0f / (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>-1);
+00300 <font class="comment">// eval all the patch.</font>
+00301 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= 0;
+00302 uint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
+00303 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=dt)
+00304 {
+00305 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>= 0;
+00306 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+=ds)
+00307 {
+00308 CVertex &amp;vert= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
+00309 <font class="comment">// NB: use the bezier patch, and don't take Noise into account, for speed reason.</font>
+00310 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;unpackIntoCache();
+00311 <font class="comment">// Eval pos.</font>
+00312 vert.Pos= bpatch-&gt;eval(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
+00313 <font class="comment">// Eval Normal.</font>
+00314 vert.Normal= bpatch-&gt;evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
+00315 }
+00316 }
+00317
+00318 <font class="comment">// Build bounding Spheres QuadTree</font>
+00319 <font class="comment">//============</font>
+00320
+00321 <font class="comment">// Size of the cluster array (at level 0)</font>
+00322 uint bsx, bsy;
+00323 <font class="preprocessor">#ifdef NL_DLM_TILE_RES</font>
+00324 <font class="preprocessor"></font> <font class="comment">// level 0 is at tile level.</font>
+00325 bsx= max(1, (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS())/<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a> );
+00326 bsy= max(1, (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderT())/<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a> );
+00327 <font class="preprocessor">#else</font>
+00328 <font class="preprocessor"></font> <font class="comment">// level 0 is at tessBlock level.</font>
+00329 bsx= max(1, (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS()/2)/<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a> );
+00330 bsy= max(1, (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderT()/2)/<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a> );
+00331 <font class="preprocessor">#endif</font>
+00332 <font class="preprocessor"></font>
+00333 <font class="comment">// resize bboxes for level 0.</font>
+00334 <font class="keyword">static</font> vector&lt;CAABBox&gt; tmpBBoxes[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00335 tmpBBoxes[0].resize(bsx * bsy);
+00336
+00337 <font class="comment">// Extend all leaves clusters BBoxes with patch coordinates</font>
+00338 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;bsy;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00339 {
+00340 <font class="comment">// For Y, compute how many patch Positions used to extend bbox.</font>
+00341 uint beginY= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>;
+00342 uint endY= <a class="code" href="bit__set_8cpp.html#a0">min</a>( (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>+1, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+00343 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;bsx;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
+00344 {
+00345 <font class="comment">// For X, compute how many patch Positions used to extend bbox.</font>
+00346 uint beginX= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>;
+00347 uint endX= <a class="code" href="bit__set_8cpp.html#a0">min</a>((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>+1, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>);
+00348 <font class="comment">// Build a bbox.</font>
+00349 CAABBox bbox;
+00350 bbox.setCenter(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>[beginY*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a> + beginX].Pos);
+00351 <font class="keywordflow">for</font>(uint yi= beginY; yi&lt;endY; yi++)
+00352 {
+00353 <font class="keywordflow">for</font>(uint xi= beginX; xi&lt;endX; xi++)
+00354 {
+00355 bbox.extend(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>[yi*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a> + xi].Pos);
+00356 }
+00357 }
+00358 <font class="comment">// Set the BBox info.</font>
+00359 tmpBBoxes[0][<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*bsx + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= bbox;
+00360 }
+00361 }
+00362
+00363 <font class="comment">// build parent BSpheres for quadTree hierarchy</font>
+00364 uint curLevel= 0;
+00365 uint nextLevel= 1;
+00366 uint nextBsx= max(1U, bsx/2);
+00367 uint nextBsy= max(1U, bsy/2);
+00368 <font class="comment">// the number of cluster Sons, and descendants this cluster level owns.</font>
+00369 uint tmpClusterNumToSkip[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00370 <font class="comment">// width for this cluster level.</font>
+00371 uint tmpClusterWidth[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00372 <font class="comment">// Number of sons per line/column</font>
+00373 uint tmpClusterWSon[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00374 uint tmpClusterHSon[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00375 <font class="comment">// Fill level 0 info</font>
+00376 tmpClusterNumToSkip[0]= 0;
+00377 tmpClusterWidth[0]= bsx;
+00378 tmpClusterWSon[0]= 0;
+00379 tmpClusterHSon[0]= 0;
+00380 uint finalClusterSize= bsx * bsy;
+00381
+00382 <font class="comment">// If the next level has 1x1 cases, it is not usefull (since same sphere as entire Patch)</font>
+00383 <font class="keywordflow">while</font>(nextBsx * nextBsy &gt; 1 &amp;&amp; nextLevel&lt;<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a> )
+00384 {
+00385 finalClusterSize+= nextBsx * nextBsy;
+00386
+00387 uint wSon= (bsx/nextBsx);
+00388 uint hSon= (bsy/nextBsy);
+00389 <font class="comment">// compute cluster level info.</font>
+00390 tmpClusterWidth[nextLevel]= nextBsx;
+00391 tmpClusterWSon[nextLevel]= wSon;
+00392 tmpClusterHSon[nextLevel]= hSon;
+00393 <font class="comment">// NB: level 0 has 0 sons to skip, hence level1 must skip (1+0)*4= 4 (wSon==hSon==2)</font>
+00394 <font class="comment">// level2 must skip (1+4)*4= 20 (wSon==hSon==2)</font>
+00395 tmpClusterNumToSkip[nextLevel]= (1+tmpClusterNumToSkip[curLevel]) * wSon * hSon;
+00396
+00397 <font class="comment">// alloc bboxes.</font>
+00398 tmpBBoxes[nextLevel].resize(nextBsx * nextBsy);
+00399
+00400 <font class="comment">// For all cluster of upper level, build bb, as union of finers clusters</font>
+00401 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;nextBsy;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00402 {
+00403 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;nextBsx;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
+00404 {
+00405 <font class="comment">// compute coordinate in curLevel tmpBBoxes to look</font>
+00406 uint x2= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*wSon;
+00407 uint y2= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*hSon;
+00408 <font class="comment">// Build a bbox for 4 (or 2) children clusters</font>
+00409 <font class="keywordflow">if</font>(wSon&gt;1 &amp;&amp; hSon&gt;1)
+00410 {
+00411 CAABBox bbox1;
+00412 CAABBox bbox2;
+00413 bbox1= CAABBox::computeAABBoxUnion(
+00414 tmpBBoxes[curLevel][y2*bsx + x2], tmpBBoxes[curLevel][y2*bsx + x2+1]);
+00415 bbox2= CAABBox::computeAABBoxUnion(
+00416 tmpBBoxes[curLevel][(y2+1)*bsx + x2], tmpBBoxes[curLevel][(y2+1)*bsx + x2+1]);
+00417 <font class="comment">// final father bbox.</font>
+00418 tmpBBoxes[nextLevel][<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*nextBsx + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= CAABBox::computeAABBoxUnion(bbox1, bbox2);
+00419 }
+00420 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(wSon==1)
+00421 {
+00422 CAABBox bbox1;
+00423 bbox1= CAABBox::computeAABBoxUnion(
+00424 tmpBBoxes[curLevel][y2*bsx + x2], tmpBBoxes[curLevel][(y2+1)*bsx + x2]);
+00425 <font class="comment">// final father bbox.</font>
+00426 tmpBBoxes[nextLevel][<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*nextBsx + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= bbox1;
+00427 }
+00428 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(hSon==1)
+00429 {
+00430 CAABBox bbox1;
+00431 bbox1= CAABBox::computeAABBoxUnion(
+00432 tmpBBoxes[curLevel][y2*bsx + x2], tmpBBoxes[curLevel][y2*bsx + x2+1]);
+00433 <font class="comment">// final father bbox.</font>
+00434 tmpBBoxes[nextLevel][<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*nextBsx + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= bbox1;
+00435 }
+00436 <font class="keywordflow">else</font>
+00437 <font class="comment">// impossible...</font>
+00438 <a class="code" href="debug_8h.html#a12">nlstop</a>;
+00439 }
+00440 }
+00441
+00442 <font class="comment">// upper level.</font>
+00443 bsx= nextBsx;
+00444 bsy= nextBsy;
+00445 nextBsx= max(1U, nextBsx/2);
+00446 nextBsy= max(1U, nextBsy/2);
+00447 curLevel++;
+00448 nextLevel++;
+00449 }
+00450
+00451
+00452 <font class="comment">// Resize clusters with size according to all levels</font>
+00453 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z301_1">resize</a>(finalClusterSize);
+00454 uint iDstCluster= 0;
+00455
+00456 <font class="comment">// Fill cluster hierarchy, in _Clusters.</font>
+00457 uint numLevels= nextLevel;
+00458 <font class="comment">// NB: the principle is recursive, but it is "iterated", with a stack-like: tmpClusterX and tmpClusterY;</font>
+00459 uint tmpClusterX[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00460 uint tmpClusterY[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00461 uint tmpClusterXMin[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00462 uint tmpClusterYMin[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00463 uint tmpClusterXMax[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00464 uint tmpClusterYMax[<a class="code" href="patchdlm__context_8cpp.html#a1">NL_DLM_CLIP_NUM_LEVEL</a>];
+00465 <font class="comment">// we start at curLevel (the highest Level), and we must fill all the squares of this level</font>
+00466 tmpClusterX[curLevel]= 0;
+00467 tmpClusterY[curLevel]= 0;
+00468 tmpClusterXMin[curLevel]= 0;
+00469 tmpClusterYMin[curLevel]= 0;
+00470 tmpClusterXMax[curLevel]= bsx;
+00471 tmpClusterYMax[curLevel]= bsy;
+00472 <font class="comment">// while the "root" level is not pop</font>
+00473 <font class="keywordflow">while</font>(curLevel &lt; numLevels)
+00474 {
+00475 <font class="comment">// If we ended with this level (all lines done).</font>
+00476 <font class="keywordflow">if</font>(tmpClusterY[curLevel] &gt;= tmpClusterYMax[curLevel])
+00477 {
+00478 <font class="comment">// Ok, finished with this level, pop up.</font>
+00479 curLevel++;
+00480 <font class="comment">// skip.</font>
+00481 <font class="keywordflow">continue</font>;
+00482 }
+00483
+00484 <a class="code" href="debug_8h.html#a6">nlassert</a>(iDstCluster&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>());
+00485
+00486 <font class="comment">// get the bbox from current position.</font>
+00487 CAABBox bbox= tmpBBoxes[curLevel][ tmpClusterY[curLevel] * tmpClusterWidth[curLevel] + tmpClusterX[curLevel] ];
+00488 <font class="comment">// Fill _Clusters for this square.</font>
+00489 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].BSphere.Center= bbox.getCenter();
+00490 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].BSphere.Radius= bbox.getRadius();
+00491 <font class="comment">// If leaf level, fill special info</font>
+00492 <font class="keywordflow">if</font>(curLevel == 0)
+00493 {
+00494 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].NSkips= 0;
+00495 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].X= tmpClusterX[0];
+00496 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].Y= tmpClusterY[0];
+00497 }
+00498 <font class="comment">// else, set total number of sons to skips if "invisible"</font>
+00499 <font class="keywordflow">else</font>
+00500 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[iDstCluster].NSkips= tmpClusterNumToSkip[curLevel];
+00501
+00502 <font class="comment">// next dst cluster</font>
+00503 iDstCluster ++;
+00504
+00505
+00506 <font class="comment">// If not Leaf level, recurs. First pass, use curLevel params (tmpClusterX...)</font>
+00507 <font class="keywordflow">if</font>(curLevel &gt; 0)
+00508 {
+00509 <font class="comment">// compute info for next level.</font>
+00510 tmpClusterXMin[curLevel-1]= tmpClusterX[curLevel] * tmpClusterWSon[curLevel];
+00511 tmpClusterYMin[curLevel-1]= tmpClusterY[curLevel] * tmpClusterHSon[curLevel];
+00512 tmpClusterXMax[curLevel-1]= (tmpClusterX[curLevel]+1) * tmpClusterWSon[curLevel];
+00513 tmpClusterYMax[curLevel-1]= (tmpClusterY[curLevel]+1) * tmpClusterHSon[curLevel];
+00514 <font class="comment">// begin iteration of child level</font>
+00515 tmpClusterX[curLevel-1]= tmpClusterXMin[curLevel-1];
+00516 tmpClusterY[curLevel-1]= tmpClusterYMin[curLevel-1];
+00517 }
+00518
+00519
+00520 <font class="comment">// next square for this level</font>
+00521 tmpClusterX[curLevel]++;
+00522 <font class="comment">// if ended for X.</font>
+00523 <font class="keywordflow">if</font>(tmpClusterX[curLevel] &gt;= tmpClusterXMax[curLevel])
+00524 {
+00525 <font class="comment">// reset X.</font>
+00526 tmpClusterX[curLevel]= tmpClusterXMin[curLevel];
+00527 <font class="comment">// next line.</font>
+00528 tmpClusterY[curLevel]++;
+00529 }
+00530
+00531
+00532 <font class="comment">// If not Leaf level, recurs. Second pass, after tmpClusterX and tmpClusterY of curLevel are changed</font>
+00533 <font class="keywordflow">if</font>(curLevel &gt; 0)
+00534 {
+00535 <font class="comment">// descend in hierarchy. (recurs)</font>
+00536 curLevel--;
+00537 }
+00538
+00539 }
+00540
+00541 <font class="comment">// All dst clusters must have been filled</font>
+00542 <a class="code" href="debug_8h.html#a6">nlassert</a>(iDstCluster == <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>());
+00543
+00544
+00545 <font class="comment">// PreProcess Patch TileColors.</font>
+00546 <font class="comment">//============</font>
+00547 <font class="comment">// Verify that a CTileColor is nothing more than a 565 color.</font>
+00548 <a class="code" href="debug_8h.html#a6">nlassert</a>(<font class="keyword">sizeof</font>(CTileColor)==<font class="keyword">sizeof</font>(uint16));
+00549 <font class="preprocessor">#ifndef NL_DLM_TILE_RES</font>
+00550 <font class="preprocessor"></font>
+00551 <font class="comment">// retrieve patch tileColor pointer.</font>
+00552 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors.size()&gt;0);
+00553 CTileColor *tileColor= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors[0];
+00554
+00555 <font class="comment">// skip 1 tiles colors per column and per row</font>
+00556 uint wTileColor= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS()+1;
+00557 CTileColor *tcOrigin= tileColor;
+00558 <font class="comment">// alloc _LowResTileColors at same resolution than lightmap</font>
+00559 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o8">_LowResTileColors</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z301_1">resize</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+00560 uint16 *dstLRtc= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o8">_LowResTileColors</a>[0];
+00561
+00562 <font class="comment">// For all lines of dst.</font>
+00563 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00564 {
+00565 <font class="comment">// tileColor start of line.</font>
+00566 tileColor= tcOrigin + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*2* wTileColor;
+00567 sint npix= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;
+00568 <font class="comment">// for all pixels at corner of tessBlock.</font>
+00569 <font class="keywordflow">for</font>(;npix&gt;0; npix--, tileColor+=2, dstLRtc++)
+00570 {
+00571 *dstLRtc= tileColor-&gt;Color565;
+00572 }
+00573
+00574 }
+00575 <font class="preprocessor">#endif</font>
+00576 <font class="preprocessor"></font>
+00577
+00578 <font class="comment">// compute the TextureFar used for Far dynamic lightmaping.</font>
+00579 <font class="comment">//============</font>
+00580 <font class="comment">// NB: simpler to compute it at generate() time, even if not necessarly needed for near</font>
+00581 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#c0">computeTextureFar</a>();
+00582
+00583
+00584 <font class="comment">// fill texture with Black</font>
+00585 <font class="comment">//============</font>
+00586 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#a3">clearLighting</a>();
+00587
+00588 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00589 }
+00590
+00591 <font class="comment">// ***************************************************************************</font>
+<a name="l00592"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a3">00592</a> <font class="keywordtype">void</font> CPatchDLMContext::clearLighting()
+00593 {
+00594 <font class="comment">// If the srcTexture is not already black.</font>
+00595 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a>)
+00596 {
+00597 <font class="comment">// Reset Lightmap with black.</font>
+00598 uint count= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>();
+00599 <font class="keywordflow">if</font>(count&gt;0)
+00600 {
+00601 memset(&amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0], 0, count * <font class="keyword">sizeof</font>(CRGBA));
+00602 }
+00603
+00604 <font class="comment">// Now the src lightmap is fully black</font>
+00605 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a>= <font class="keyword">true</font>;
+00606 }
+00607 }
+00608
+00609
+00610 <font class="comment">// ***************************************************************************</font>
+00611
+00612 <font class="comment">// TestYoyo: I thought this code was better, but actually, this is not the case</font>
+00613 <font class="comment">/*</font>
+00614 <font class="comment">static float NL3D_Val1= 1.f;</font>
+00615 <font class="comment">inline void __stdcall fastClamp01(float &amp;x)</font>
+00616 <font class="comment">{</font>
+00617 <font class="comment"> __asm</font>
+00618 <font class="comment"> {</font>
+00619 <font class="comment"> mov esi, x</font>
+00620 <font class="comment"> mov eax, [esi]</font>
+00621 <font class="comment"></font>
+00622 <font class="comment"> // clamp to 0.</font>
+00623 <font class="comment"> cmp eax, 0x80000001 // set carry if sign bit is set.</font>
+00624 <font class="comment"> sbb ecx, ecx // if attDist is negative, ecx==0 , else 0xFFFFFFFF.</font>
+00625 <font class="comment"> and eax, ecx // if attDist is negative, eax=0, else unchanged</font>
+00626 <font class="comment"></font>
+00627 <font class="comment"> // clamp eax to 1 (NB: now we are sure eax&gt;=0).</font>
+00628 <font class="comment"> cmp eax, NL3D_Val1 // set carry if &lt; Val1.</font>
+00629 <font class="comment"> sbb ecx, ecx // if &lt; Val1, ecx==0xFFFFFFFF, else 0.</font>
+00630 <font class="comment"> and eax, ecx // if &lt; Val1, ecx= eax, else ecx=0</font>
+00631 <font class="comment"> not ecx</font>
+00632 <font class="comment"> and ecx, NL3D_Val1 // if &gt; Val1, ecx== Val1, else ecx= 0.</font>
+00633 <font class="comment"> add eax, ecx // finally, eax= val clamped to 1.</font>
+00634 <font class="comment"></font>
+00635 <font class="comment"> // store.</font>
+00636 <font class="comment"> mov [esi], eax</font>
+00637 <font class="comment"> }</font>
+00638 <font class="comment">}*/</font>
+00639
+00640 <font class="comment">// faster to do a simple clamp ???</font>
+00641 <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(<font class="keywordtype">float</font> &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
+00642 {
+00643 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, 0.f, 1.f);
+00644 }
+00645
+00646
+00647 <font class="comment">// ***************************************************************************</font>
+<a name="l00648"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a4">00648</a> <font class="keywordtype">void</font> CPatchDLMContext::addPointLightInfluence(<font class="keyword">const</font> CPatchDLMPointLight &amp;pl)
+00649 {
+00650 uint nverts= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>();
+00651 <a class="code" href="debug_8h.html#a6">nlassert</a>(nverts==<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>());
+00652
+00653 <font class="keywordflow">if</font>(nverts==0)
+00654 <font class="keywordflow">return</font>;
+00655 CVertex *vert= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>[0];
+00656
+00657
+00658 <font class="comment">// precise clip: parse the quadTree of sphere</font>
+00659 <font class="comment">//================</font>
+00660 uint i, <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
+00661 uint startX, startY, endX, endY;
+00662 startX= 0xFFFFFFFF;
+00663 startY= 0xFFFFFFFF;
+00664 endX= 0;
+00665 endY= 0;
+00666 <font class="keywordflow">for</font>(i=0;i&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>();)
+00667 {
+00668 <font class="comment">// If the sphere intersect pl, </font>
+00669 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].BSphere.intersect(pl.BSphere) )
+00670 {
+00671 <font class="comment">// if this cluster is a leaf, extend start/end</font>
+00672 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].NSkips==0)
+00673 {
+00674 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].X;
+00675 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].Y;
+00676 startX= <a class="code" href="bit__set_8cpp.html#a0">min</a>(startX, <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
+00677 startY= <a class="code" href="bit__set_8cpp.html#a0">min</a>(startY, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
+00678 endX= max(endX, <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1);
+00679 endY= max(endY, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1);
+00680 }
+00681 <font class="comment">// go to next cluster (a brother, a parent or a son)</font>
+00682 i++;
+00683 }
+00684 <font class="keywordflow">else</font>
+00685 {
+00686 <font class="comment">// if this cluster is a leaf, just go to next cluster (a parent or a brother)</font>
+00687 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].NSkips==0)
+00688 i++;
+00689 <font class="comment">// else, go to next brother or parent (NSkips say how to go)</font>
+00690 <font class="keywordflow">else</font>
+00691 i+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>[i].NSkips;
+00692 }
+00693 }
+00694 <font class="comment">// if never intersect, just quit.</font>
+00695 <font class="keywordflow">if</font>(startX==0xFFFFFFFF)
+00696 <font class="keywordflow">return</font>;
+00697
+00698 <font class="comment">// get vertices in array to process.</font>
+00699 startX*=<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>;
+00700 startY*=<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>;
+00701 endX= <a class="code" href="bit__set_8cpp.html#a0">min</a>(endX*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>+1, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>);
+00702 endY= <a class="code" href="bit__set_8cpp.html#a0">min</a>(endY*<a class="code" href="patchdlm__context_8cpp.html#a0">NL_DLM_CLIP_FACTOR</a>+1, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+00703
+00704 <font class="comment">// TestYoyo only.</font>
+00705 <font class="comment">/*extern uint YOYO_LandDLCount;</font>
+00706 <font class="comment"> YOYO_LandDLCount+= (endX - startX) * (endY - startY);*/</font>
+00707
+00708 <font class="comment">// process all vertices</font>
+00709 <font class="comment">//================</font>
+00710 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>,g,b;
+00711 CRGBA *dst= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0];
+00712 CVertex *originVert= vert;
+00713 CRGBA *originDst= dst;
+00714
+00715 <font class="comment">// TestYoyo: finally, precache does not seems to impact final result.</font>
+00716 <font class="comment">// precache loading, for better cache use. NB: precache the entire line, ignoring clip result.</font>
+00717 <font class="comment">// Precache only if interesting.</font>
+00718 <font class="comment">/*if( (endX - startX)*4&gt;=Width &amp;&amp; (endY-startY)&gt;=2)</font>
+00719 <font class="comment"> {</font>
+00720 <font class="comment"> vert= originVert + startY*Width;</font>
+00721 <font class="comment"> dst= originDst + startY*Width;</font>
+00722 <font class="comment"> uint nPixelLine= (endY-startY)*Width;</font>
+00723 <font class="comment"> CFastMem::precacheBest(vert, nPixelLine * sizeof(CVertex));</font>
+00724 <font class="comment"> CFastMem::precacheBest(dst, nPixelLine * sizeof(CRGBA));</font>
+00725 <font class="comment"> }*/</font>
+00726
+00727 <font class="comment">// Start 24 precision, for faster compute.</font>
+00728 <a class="code" href="namespaceNL3D.html#a364">OptFastFloorBegin24</a>();
+00729
+00730 <font class="comment">// If the pointLight is a spot, compute is more complex/slower</font>
+00731 <font class="keywordflow">if</font>(pl.IsSpot)
+00732 {
+00733 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=startY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;endY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00734 {
+00735 nverts= endX - startX;
+00736
+00737 vert= originVert + startX + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;
+00738 dst= originDst + startX + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;
+00739 <font class="keywordflow">for</font>(;nverts&gt;0; nverts--, vert++, dst++)
+00740 {
+00741 CVector dirToP= vert-&gt;Pos - pl.Pos;
+00742 <font class="keywordtype">float</font> dist= dirToP.norm();
+00743 dirToP/= dist;
+00744
+00745 <font class="comment">// compute cos for pl. attenuation</font>
+00746 <font class="keywordtype">float</font> cosSpot= dirToP * pl.Dir;
+00747 <font class="keywordtype">float</font> attSpot= (cosSpot-pl.CosMin) * pl.OOCosDelta;
+00748 <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(attSpot);
+00749
+00750 <font class="comment">// distance attenuation</font>
+00751 <font class="keywordtype">float</font> attDist= (dist-pl.AttMax) * pl.OOAttDelta;
+00752 <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(attDist);
+00753
+00754 <font class="comment">// compute diffuse lighting</font>
+00755 <font class="keywordtype">float</font> diff= -(vert-&gt;Normal * dirToP);
+00756 <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(diff);
+00757
+00758 <font class="comment">// compute colors.</font>
+00759 diff*= attSpot * attDist;
+00760 <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>= pl.R*diff;
+00761 g= pl.G*diff;
+00762 b= pl.B*diff;
+00763
+00764 CRGBA col;
+00765 col.R= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>);
+00766 col.G= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(g);
+00767 col.B= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(b);
+00768
+00769 <font class="comment">// add to map.</font>
+00770 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
+00771 <font class="preprocessor"></font> <font class="comment">// Fast AddClamp.</font>
+00772 __asm
+00773 {
+00774 mov esi, dst
+00775
+00776 mov al, [esi]dst.R
+00777 add al, col.R
+00778 sbb cl, cl
+00779 or al, cl
+00780 mov [esi]dst.R, al
+00781
+00782 mov al, [esi]dst.G
+00783 add al, col.G
+00784 sbb cl, cl
+00785 or al, cl
+00786 mov [esi]dst.G, al
+00787
+00788 mov al, [esi]dst.B
+00789 add al, col.B
+00790 sbb cl, cl
+00791 or al, cl
+00792 mov [esi]dst.B, al
+00793 }
+00794 <font class="preprocessor">#else</font>
+00795 <font class="preprocessor"></font> <font class="comment">// add and clamp to map.</font>
+00796 dst-&gt;addRGBOnly(*dst, col);
+00797 <font class="preprocessor">#endif</font>
+00798 <font class="preprocessor"></font> }
+00799 }
+00800 }
+00801 <font class="comment">// else, pointLight with no Spot cone attenuation</font>
+00802 <font class="keywordflow">else</font>
+00803 {
+00804 <font class="comment">// TestYoyo</font>
+00805 <font class="comment">/*extern void YOYO_startDLMItCount();</font>
+00806 <font class="comment"> YOYO_startDLMItCount();*/</font>
+00807
+00808 <font class="comment">// Compute lightmap pixels of interest </font>
+00809 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=startY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;endY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00810 {
+00811 nverts= endX - startX;
+00812
+00813 vert= originVert + startX + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;
+00814 dst= originDst + startX + <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;
+00815 <font class="keywordflow">for</font>(;nverts&gt;0; nverts--, vert++, dst++)
+00816 {
+00817 CVector dirToP= vert-&gt;Pos - pl.Pos;
+00818 <font class="keywordtype">float</font> dist= dirToP.norm();
+00819 <font class="keywordtype">float</font> OODist= 1.0f / dist;
+00820 dirToP*= OODist;
+00821
+00822 <font class="comment">// distance attenuation</font>
+00823 <font class="keywordtype">float</font> attDist= (dist-pl.AttMax) * pl.OOAttDelta;
+00824 <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(attDist);
+00825
+00826 <font class="comment">// compute diffuse lighting</font>
+00827 <font class="keywordtype">float</font> diff= -(vert-&gt;Normal * dirToP);
+00828 <a class="code" href="namespaceNL3D.html#a397">fastClamp01</a>(diff);
+00829
+00830 <font class="comment">// compute colors.</font>
+00831 diff*= attDist;
+00832 <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>= pl.R*diff;
+00833 g= pl.G*diff;
+00834 b= pl.B*diff;
+00835
+00836 CRGBA col;
+00837 col.R= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>);
+00838 col.G= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(g);
+00839 col.B= (uint8)<a class="code" href="namespaceNL3D.html#a366">OptFastFloor24</a>(b);
+00840
+00841 <font class="comment">// add to map.</font>
+00842 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
+00843 <font class="preprocessor"></font> <font class="comment">// Fast AddClamp.</font>
+00844 __asm
+00845 {
+00846 mov esi, dst
+00847
+00848 mov al, [esi]dst.R
+00849 add al, col.R
+00850 sbb cl, cl
+00851 or al, cl
+00852 mov [esi]dst.R, al
+00853
+00854 mov al, [esi]dst.G
+00855 add al, col.G
+00856 sbb cl, cl
+00857 or al, cl
+00858 mov [esi]dst.G, al
+00859
+00860 mov al, [esi]dst.B
+00861 add al, col.B
+00862 sbb cl, cl
+00863 or al, cl
+00864 mov [esi]dst.B, al
+00865 }
+00866 <font class="preprocessor">#else</font>
+00867 <font class="preprocessor"></font> <font class="comment">// add and clamp to map.</font>
+00868 dst-&gt;addRGBOnly(*dst, col);
+00869 <font class="preprocessor">#endif</font>
+00870 <font class="preprocessor"></font> }
+00871 }
+00872
+00873 <font class="comment">// TestYoyo</font>
+00874 <font class="comment">/*extern void YOYO_endDLMItCount();</font>
+00875 <font class="comment"> YOYO_endDLMItCount();*/</font>
+00876 }
+00877
+00878 <font class="comment">// Stop 24 bit precision</font>
+00879 <a class="code" href="namespaceNL3D.html#a365">OptFastFloorEnd24</a>();
+00880
+00881 <font class="comment">// Src texture is modified, hence it can't be black.</font>
+00882 <font class="comment">//==============</font>
+00883 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a>= <font class="keyword">false</font>;
+00884 }
+00885
+00886
+00887 <font class="comment">// ***************************************************************************</font>
+<a name="l00888"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a5">00888</a> <font class="keywordtype">void</font> CPatchDLMContext::compileLighting(TCompileType compType, CRGBA modulateCte)
+00889 {
+00890 <font class="comment">// If srcTexture is full black, and if dst texture is already full black too, don't need to update dst texture</font>
+00891 <font class="keywordflow">if</font>(! (<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a> &amp;&amp; <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o7">_IsDstTextureFullBlack</a>) )
+00892 {
+00893 <font class="comment">// if lightMap allocated</font>
+00894 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>()&gt;0 &amp;&amp; <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>)
+00895 {
+00896 <font class="comment">// If the srcTexture is full black (ie no pointLight influence touch it), </font>
+00897 <font class="keywordflow">if</font>(_IsSrcTextureFullBlack)
+00898 {
+00899 <font class="comment">// reset the texture to full black.</font>
+00900 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;fillRect(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, 0);
+00901 }
+00902 <font class="comment">// else the srcTexture is not full black (ie some pointLight influence touch it), </font>
+00903 <font class="keywordflow">else</font>
+00904 {
+00905 <font class="comment">// if must modulate with tileColor</font>
+00906 <font class="keywordflow">if</font>(compType == <a class="code" href="classNL3D_1_1CPatchDLMContext.html#s4s0">ModulateTileColor</a>)
+00907 {
+00908 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors.size()&gt;=0);
+00909 <font class="preprocessor"> #ifdef NL_DLM_TILE_RES</font>
+00910 <font class="preprocessor"></font> <font class="comment">// retrieve userColor pointer.</font>
+00911 uint16 *tileColor= (uint16*)(&amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors[0]);
+00912 <font class="preprocessor"> #else</font>
+00913 <font class="preprocessor"></font> uint16 *tileColor= (uint16*)(&amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o8">_LowResTileColors</a>[0]);
+00914 <font class="preprocessor"> #endif</font>
+00915 <font class="preprocessor"></font>
+00916 <font class="comment">// modulate and fill dest.</font>
+00917 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;modulateAndfillRect565(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0], tileColor);
+00918 }
+00919 <font class="comment">// else if must modulate with textureFar</font>
+00920 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(compType == <a class="code" href="classNL3D_1_1CPatchDLMContext.html#s4s1">ModulateTextureFar</a>)
+00921 {
+00922 <font class="comment">// modulate and fill dest.</font>
+00923 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;modulateAndfillRect8888(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0], &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o9">_TextureFar</a>[0]);
+00924 }
+00925 <font class="comment">// else if must modulate with constante</font>
+00926 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(compType == <a class="code" href="classNL3D_1_1CPatchDLMContext.html#s4s2">ModulateConstant</a>)
+00927 {
+00928 <font class="comment">// modulate and fill dest.</font>
+00929 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;modulateConstantAndfillRect(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0], modulateCte);
+00930 }
+00931 <font class="comment">// else, no Modulate.</font>
+00932 <font class="keywordflow">else</font>
+00933 {
+00934 <font class="comment">// just copy lightmap to texture</font>
+00935 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o1">_DLMTexture</a>-&gt;copyRect(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m0">TextPosX</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m1">TextPosY</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>, <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>, &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>[0]);
+00936 }
+00937 }
+00938 }
+00939
+00940
+00941 <font class="comment">// copy full black state</font>
+00942 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o7">_IsDstTextureFullBlack</a>= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o6">_IsSrcTextureFullBlack</a>;
+00943 }
+00944 }
+00945
+00946
+00947 <font class="comment">// ***************************************************************************</font>
+<a name="l00948"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#a7">00948</a> uint CPatchDLMContext::getMemorySize()<font class="keyword"> const</font>
+00949 <font class="keyword"></font>{
+00950 uint size= <font class="keyword">sizeof</font>(CPatchDLMContext);
+00951 size+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o3">_Vertices</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>() * <font class="keyword">sizeof</font>(CVertex);
+00952 size+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o4">_LightMap</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>() * <font class="keyword">sizeof</font>(CRGBA);
+00953 size+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o5">_Clusters</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>() * <font class="keyword">sizeof</font>(CCluster);
+00954 size+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o9">_TextureFar</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>() * <font class="keyword">sizeof</font>(CRGBA);
+00955 <font class="preprocessor">#ifndef NL_DLM_TILE_RES</font>
+00956 <font class="preprocessor"></font> size+= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o8">_LowResTileColors</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z302_0">size</a>() * <font class="keyword">sizeof</font>(uint16);
+00957 <font class="preprocessor">#endif</font>
+00958 <font class="preprocessor"></font>
+00959 <font class="keywordflow">return</font> size;
+00960 }
+00961
+00962
+00963 <font class="comment">// ***************************************************************************</font>
+<a name="l00964"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#c0">00964</a> <font class="keywordtype">void</font> CPatchDLMContext::computeTextureFar()
+00965 {
+00966 <font class="comment">// First compute Far at order1 Level (ie 2x2 pixels per tiles).</font>
+00967 <font class="comment">//==================</font>
+00968 <font class="keyword">static</font> vector&lt;CRGBA&gt; tileFars;
+00969 <font class="comment">// Get the FarBank from landscape.</font>
+00970 CTileFarBank &amp;farBank= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getLandscape()-&gt;TileFarBank;
+00971 <font class="comment">// size of the texture.</font>
+00972 uint os= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderS();
+00973 uint ot= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;getOrderT();
+00974 <font class="comment">// resize tmp texture. keep a border of 1 pixel around this texture (for average with border)</font>
+00975 uint tfWidth= os*2+2;
+00976 uint tfHeight= ot*2+2;
+00977 uint tfSize= tfWidth * tfHeight;
+00978 tileFars.resize(tfSize);
+00979 CRGBA *dst= &amp;tileFars[0];
+00980
+00981 <font class="comment">// default: fill dst with black (for possible non-existing tiles).</font>
+00982 memset(dst, 0, tfSize*<font class="keyword">sizeof</font>(CRGBA));
+00983
+00984 <font class="comment">// For all tiles.</font>
+00985 uint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
+00986 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;ot; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+00987 {
+00988 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;os;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
+00989 {
+00990 <font class="comment">// get the tile from patch.</font>
+00991 CTileElement &amp;tileElm= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;Tiles[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*os + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
+00992
+00993 <font class="comment">// For all layers</font>
+00994 <font class="keywordflow">for</font>(uint <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>=0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>&lt;3;<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>++)
+00995 {
+00996 uint16 tileId= tileElm.Tile[0];
+00997 <font class="keywordflow">if</font> (tileId!=<a class="code" href="tile__element_8h.html#a12">NL_TILE_ELM_LAYER_EMPTY</a>)
+00998 {
+00999 <font class="comment">// Get the read only pointer on the far tile</font>
+01000 <font class="keyword">const</font> CTileFarBank::CTileFar* pTile= farBank.getTile (tileId);
+01001 <font class="comment">// if exist.</font>
+01002 <font class="keywordflow">if</font>(pTile &amp;&amp; pTile-&gt;isFill (CTileFarBank::diffuse))
+01003 {
+01004 <font class="comment">// get tile element information.</font>
+01005 sint nRot= tileElm.getTileOrient(<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>);
+01006 <font class="keywordtype">bool</font> is256x256;
+01007 uint8 uvOff;
+01008 tileElm.getTile256Info(is256x256, uvOff);
+01009
+01010 <font class="comment">// compute src pixel</font>
+01011 <font class="keyword">const</font> CRGBA *srcPixel= pTile-&gt;getPixels(CTileFarBank::diffuse, CTileFarBank::order1);
+01012 <font class="comment">// compute src info, for this tile rot and 256x256 context.</font>
+01013 sint srcDeltaX;
+01014 sint srcDeltaY;
+01015 srcPixel= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#f0">computeTileFarSrcDeltas</a>(nRot, is256x256, uvOff, srcPixel, srcDeltaX, srcDeltaY);
+01016
+01017 <font class="comment">// compute dst coordinate. start writing at pixel (1,1)</font>
+01018 CRGBA *dstPixel= dst + (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*2+1)*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*2+1;
+01019
+01020 <font class="keywordflow">if</font>(<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>==0)
+01021 {
+01022 <font class="comment">// copy the tile content to the texture.</font>
+01023 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#f1">copyTileToTexture</a>(srcPixel, srcDeltaX, srcDeltaY, dstPixel, tfWidth);
+01024 }
+01025 <font class="keywordflow">else</font>
+01026 {
+01027 <font class="comment">// blend the tile content to the texture.</font>
+01028 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#f2">blendTileToTexture</a>(srcPixel, srcDeltaX, srcDeltaY, dstPixel, tfWidth);
+01029 }
+01030 }
+01031 <font class="keywordflow">else</font>
+01032 <font class="comment">// go to next tile.</font>
+01033 <font class="keywordflow">break</font>;
+01034 }
+01035 <font class="keywordflow">else</font>
+01036 <font class="comment">// go to next tile.</font>
+01037 <font class="keywordflow">break</font>;
+01038 }
+01039 }
+01040 }
+01041
+01042 <font class="comment">/* copy borders pixels from border of current patch</font>
+01043 <font class="comment"> NB: this is not correct, but visually sufficient.</font>
+01044 <font class="comment"> To look on neighbor would be more complex.</font>
+01045 <font class="comment"> */</font>
+01046
+01047 <font class="comment">// copy lines up and down.</font>
+01048 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= tfHeight-1;
+01049 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=1;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;tfWidth-1;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
+01050 {
+01051 <font class="comment">// copy line 0 from line 1.</font>
+01052 dst[0*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= dst[1*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
+01053 <font class="comment">// copy last line from last line-1.</font>
+01054 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= dst[(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-1)*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
+01055 }
+01056
+01057 <font class="comment">// copy column left and right</font>
+01058 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= tfWidth-1;
+01059 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=1;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;tfHeight-1;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+01060 {
+01061 <font class="comment">// copy column 0 from column 1.</font>
+01062 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + 0]= dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + 1];
+01063 <font class="comment">// copy last column from last column-1.</font>
+01064 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-1];
+01065 }
+01066
+01067 <font class="comment">// copy 4 corners</font>
+01068 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= tfWidth-1;
+01069 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= tfHeight-1;
+01070 <font class="comment">// top-left corner</font>
+01071 dst[0]= dst[1];
+01072 <font class="comment">// top-right corner</font>
+01073 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= dst[<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-1];
+01074 <font class="comment">// bottom-left corner</font>
+01075 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + 0]= dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + 1];
+01076 <font class="comment">// bottom-right corner</font>
+01077 dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= dst[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*tfWidth + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-1];
+01078
+01079
+01080 <font class="comment">// Average to DLM resolution (ie OrderS+1, OrderT+1)</font>
+01081 <font class="comment">//==================</font>
+01082 <font class="comment">// resize _TextureFar.</font>
+01083 <a class="code" href="classNL3D_1_1CPatchDLMContext.html#o9">_TextureFar</a>.<a class="code" href="classNLMISC_1_1CObjectVector.html#z301_1">resize</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>);
+01084 CRGBA *<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>= &amp;tileFars[0];
+01085 dst= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o9">_TextureFar</a>[0];
+01086
+01087 <font class="comment">// for all pixels of dst texture.</font>
+01088 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
+01089 {
+01090 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++, dst++)
+01091 {
+01092 <font class="comment">// compute coordinate in tileFars.</font>
+01093 uint x2, y2;
+01094 <font class="preprocessor">#ifdef NL_DLM_TILE_RES</font>
+01095 <font class="preprocessor"></font> x2= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> * 2;
+01096 y2= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> * 2;
+01097 <font class="preprocessor">#else</font>
+01098 <font class="preprocessor"></font> <font class="comment">// easiest method: sample every 2 tiles.</font>
+01099 x2= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> * 4;
+01100 y2= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> * 4;
+01101 <font class="preprocessor">#endif</font>
+01102 <font class="preprocessor"></font>
+01103 <font class="comment">// Average the 4 pixels around this tile corner</font>
+01104 dst-&gt;avg4RGBOnly(<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>[y2*tfWidth + x2],
+01105 <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>[y2*tfWidth + x2+1],
+01106 <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>[(y2+1)*tfWidth + x2],
+01107 <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>[(y2+1)*tfWidth + x2+1]);
+01108 }
+01109 }
+01110
+01111
+01112 <font class="comment">// Modulate result with TileColors.</font>
+01113 <font class="comment">//==================</font>
+01114 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors.size()&gt;=0);
+01115 <font class="preprocessor"> #ifdef NL_DLM_TILE_RES</font>
+01116 <font class="preprocessor"></font> <font class="comment">// retrieve userColor pointer.</font>
+01117 uint16 *tileColor= (uint16*)(&amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o0">_Patch</a>-&gt;TileColors[0]);
+01118 <font class="preprocessor"> #else</font>
+01119 <font class="preprocessor"></font> uint16 *tileColor= (uint16*)(&amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o8">_LowResTileColors</a>[0]);
+01120 <font class="preprocessor"> #endif</font>
+01121 <font class="preprocessor"></font>
+01122 <font class="comment">// For all pixels</font>
+01123 dst= &amp;<a class="code" href="classNL3D_1_1CPatchDLMContext.html#o9">_TextureFar</a>[0];
+01124 <font class="keywordflow">for</font>(sint n= <a class="code" href="classNL3D_1_1CPatchDLMContext.html#m2">Width</a>*<a class="code" href="classNL3D_1_1CPatchDLMContext.html#m3">Height</a>; n&gt;0; n--, dst++, tileColor++)
+01125 {
+01126 uint16 tc= *tileColor;
+01127 <font class="comment">// modulate R.</font>
+01128 dst-&gt;R= ( (tc&gt;&gt;11) * dst-&gt;R)&gt;&gt;5;
+01129 <font class="comment">// modulate G.</font>
+01130 dst-&gt;G= (((tc&gt;&gt;5)&amp;63) * dst-&gt;G)&gt;&gt;6;
+01131 <font class="comment">// modulate B.</font>
+01132 dst-&gt;B= ( (tc&amp;31) * dst-&gt;B)&gt;&gt;5;
+01133 }
+01134
+01135 }
+01136
+01137
+01138
+01139 <font class="comment">// ***************************************************************************</font>
+<a name="l01140"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#f0">01140</a> <font class="keyword">const</font> CRGBA *CPatchDLMContext::computeTileFarSrcDeltas(sint nRot, <font class="keywordtype">bool</font> is256x256, uint8 uvOff, <font class="keyword">const</font> CRGBA *srcPixel, sint &amp;srcDeltaX, sint &amp;srcDeltaY)
+01141 {
+01142 <font class="comment">// NB: code copied from CTextureFar::rebuildRectangle()</font>
+01143
+01144 <font class="comment">// The tileSize at order1 is 2.</font>
+01145 uint tileSize= 2;
+01146
+01147 <font class="comment">// Source size</font>
+01148 sint sourceSize;
+01149
+01150 <font class="comment">// Source offset (for 256)</font>
+01151 uint sourceOffset=0;
+01152
+01153 <font class="comment">// 256 ?</font>
+01154 <font class="keywordflow">if</font> (is256x256)
+01155 {
+01156 <font class="comment">// On the left ?</font>
+01157 <font class="keywordflow">if</font> (uvOff&amp;0x02)
+01158 sourceOffset+=tileSize;
+01159
+01160 <font class="comment">// On the bottom ?</font>
+01161 <font class="keywordflow">if</font> ((uvOff==1)||(uvOff==2))
+01162 sourceOffset+=2*tileSize*tileSize;
+01163
+01164 <font class="comment">// Yes, 256</font>
+01165 sourceSize=tileSize&lt;&lt;1;
+01166 }
+01167 <font class="keywordflow">else</font>
+01168 {
+01169 <font class="comment">// No, 128</font>
+01170 sourceSize=tileSize;
+01171 }
+01172
+01173 <font class="comment">// Compute offset and deltas</font>
+01174 <font class="keywordflow">switch</font> (nRot)
+01175 {
+01176 <font class="keywordflow">case</font> 0:
+01177 <font class="comment">// Source pointers</font>
+01178 srcPixel= srcPixel+sourceOffset;
+01179
+01180 <font class="comment">// Source delta</font>
+01181 srcDeltaX=1;
+01182 srcDeltaY=sourceSize;
+01183 <font class="keywordflow">break</font>;
+01184 <font class="keywordflow">case</font> 1:
+01185 {
+01186 <font class="comment">// Source pointers</font>
+01187 uint newOffset=sourceOffset+(tileSize-1);
+01188 srcPixel=srcPixel+newOffset;
+01189
+01190 <font class="comment">// Source delta</font>
+01191 srcDeltaX=sourceSize;
+01192 srcDeltaY=-1;
+01193 }
+01194 <font class="keywordflow">break</font>;
+01195 <font class="keywordflow">case</font> 2:
+01196 {
+01197 <font class="comment">// Destination pointer</font>
+01198 uint newOffset=sourceOffset+(tileSize-1)*sourceSize+tileSize-1;
+01199 srcPixel=srcPixel+newOffset;
+01200
+01201 <font class="comment">// Source delta</font>
+01202 srcDeltaX=-1;
+01203 srcDeltaY=-sourceSize;
+01204 }
+01205 <font class="keywordflow">break</font>;
+01206 <font class="keywordflow">case</font> 3:
+01207 {
+01208 <font class="comment">// Destination pointer</font>
+01209 uint newOffset=sourceOffset+(tileSize-1)*sourceSize;
+01210 srcPixel=srcPixel+newOffset;
+01211
+01212 <font class="comment">// Source delta</font>
+01213 srcDeltaX=-sourceSize;
+01214 srcDeltaY=1;
+01215 }
+01216 <font class="keywordflow">break</font>;
+01217 }
+01218
+01219 <font class="keywordflow">return</font> srcPixel;
+01220 }
+01221
+01222
+01223 <font class="comment">// ***************************************************************************</font>
+<a name="l01224"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#f1">01224</a> <font class="keywordtype">void</font> CPatchDLMContext::copyTileToTexture(<font class="keyword">const</font> CRGBA *srcPixel, sint srcDeltaX, sint srcDeltaY, CRGBA *dstPixel, uint dstStride)
+01225 {
+01226 <font class="comment">// copy the 2x2 tile to the texture.</font>
+01227
+01228 <font class="comment">// first line.</font>
+01229 dstPixel[0]= srcPixel[0];
+01230 dstPixel[1]= srcPixel[srcDeltaX];
+01231 <font class="comment">// second line.</font>
+01232 dstPixel[0+dstStride]= srcPixel[srcDeltaY];
+01233 dstPixel[1+dstStride]= srcPixel[srcDeltaY+srcDeltaX];
+01234 }
+01235
+01236 <font class="comment">// ***************************************************************************</font>
+<a name="l01237"></a><a class="code" href="classNL3D_1_1CPatchDLMContext.html#f2">01237</a> <font class="keywordtype">void</font> CPatchDLMContext::blendTileToTexture(<font class="keyword">const</font> CRGBA *srcPixel, sint srcDeltaX, sint srcDeltaY, CRGBA *dstPixel, uint dstStride)
+01238 {
+01239 <font class="comment">// blend the 2x2 tile with the texture.</font>
+01240 CRGBA *dst;
+01241 CRGBA <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>;
+01242
+01243 <font class="comment">// first line.</font>
+01244 dst= &amp;dstPixel[0]; <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>= srcPixel[0];
+01245 dst-&gt;blendFromuiRGBOnly(*dst, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>.A);
+01246
+01247 dst= &amp;dstPixel[1]; <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>= srcPixel[srcDeltaX];
+01248 dst-&gt;blendFromuiRGBOnly(*dst, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>.A);
+01249
+01250 <font class="comment">// second line.</font>
+01251 dst= &amp;dstPixel[0+dstStride]; <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>= srcPixel[srcDeltaY];
+01252 dst-&gt;blendFromuiRGBOnly(*dst, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>.A);
+01253
+01254 dst= &amp;dstPixel[1+dstStride]; <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>= srcPixel[srcDeltaY+srcDeltaX];
+01255 dst-&gt;blendFromuiRGBOnly(*dst, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>.A);
+01256 }
+01257
+01258
+01259 } <font class="comment">// NL3D</font>
+</pre></div>
+
+<!-- footer -->
+<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>