<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hapblue&#039;s blog</title>
	<atom:link href="http://www.hapblue.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.hapblue.com</link>
	<description></description>
	<lastBuildDate>Wed, 25 May 2011 17:09:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>自制的地精成本收益分析网站-goblin</title>
		<link>http://www.hapblue.com/?p=416</link>
		<comments>http://www.hapblue.com/?p=416#comments</comments>
		<pubDate>Wed, 25 May 2011 15:58:17 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[goblin]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wow]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=416</guid>
		<description><![CDATA[前些时间玩WOW在AH倒腾锻造的一些商品时候偶然产生了做这么一个网站的想法。主要功能是指定一些低级原材料的成本价格然后计算出制造的最终产品的成本价，再根据指定的售价得到收益。经过一个礼拜的设计到实现，目前的完成结果如上图。网站地址是： goblin : http://goblin.hapblue.com/ 界面糙了些，功能上只能说凑合，非常不实用，添加新的物品的流程还是太繁琐。在计算产品成本时是基于: 将低级原材料的成本提交到服务器上。 根据制造品的配方计算出产品的成本，再由提交的价格计算收益并保存在服务器上。 从服务器调取更新后的成本，价格、收益并显示在页面上。 感觉访问服务器有些过于频繁了，一些计算应该可以独立于本地上进行，但这样又需要将大量的配方和原材料成本数据保存到本地上，相比较而言好像也不够理想，而且实现上比前者复杂。 下面是添加一个新产品并进行关注的流程： 添加物品(insert item)：需要将产品以及所有相关的材料都添加进物品数据库中，否则无法添加相应配方并进行成本计算。 需要输入所要添加物品的名称以及在计算成本时每单位的数量（如矿石一组是20个）。 添加配方(insert recipe)：只有产品和原材料全部都在物品数据库中存在时才可添加该配方。 添加关注物品(favorite)：为避免显示过多用户不关心的物品数据，只有该用户关注的物品才显示在成本收益计算页面中。（虽然现在还没有加入用户管理功能= =。) 也可以在items页面下进行添加关注的操作。输入要关注物品的名称即可。 指定成本价格(valuate)： 这一步操作没有什么要说的，输入对应的成本和价格，结果就如首页图所示。 已知和未知的BUG很多，还有许多有待完善和补充的地方，待以后有时间再慢慢修改。算起来这还是第一次做网站，可能也算不上是网站，充其量就是一些PHP和HTML的混搭，全当学习练手之用，游戏之余的另外消遣。]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb3.png" width="596" height="517" /></p>
<p>前些时间玩WOW在AH倒腾锻造的一些商品时候偶然产生了做这么一个网站的想法。主要功能是指定一些低级原材料的成本价格然后计算出制造的最终产品的成本价，再根据指定的售价得到收益。经过一个礼拜的设计到实现，目前的完成结果如上图。网站地址是： <a title="goblin" href="http://goblin.hapblue.com/" target="_blank">goblin</a> : <a href="http://goblin.hapblue.com/" target="_blank">http://goblin.hapblue.com/</a></p>
</p>
<p><span id="more-416"></span>
</p>
<p>界面糙了些，功能上只能说凑合，非常不实用，添加新的物品的流程还是太繁琐。在计算产品成本时是基于:</p>
<ol>
<li>将低级原材料的成本提交到服务器上。 </li>
<li>根据制造品的配方计算出产品的成本，再由提交的价格计算收益并保存在服务器上。 </li>
<li>从服务器调取更新后的成本，价格、收益并显示在页面上。 </li>
</ol>
<p>感觉访问服务器有些过于频繁了，一些计算应该可以独立于本地上进行，但这样又需要将大量的配方和原材料成本数据保存到本地上，相比较而言好像也不够理想，而且实现上比前者复杂。</p>
<p>下面是添加一个新产品并进行关注的流程：</p>
<ol>
<li>添加物品(insert item)：需要将产品以及所有相关的材料都添加进物品数据库中，否则无法添加相应配方并进行成本计算。 需要输入所要添加物品的名称以及在计算成本时每单位的数量（如矿石一组是20个）。      <br /><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb7.png" width="322" height="99" /></li>
<li>
<p>添加配方(insert recipe)：只有产品和原材料全部都在物品数据库中存在时才可添加该配方。<img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb5.png" width="428" height="298" /> </p>
</li>
<li>
<p>添加关注物品(favorite)：为避免显示过多用户不关心的物品数据，只有该用户关注的物品才显示在成本收益计算页面中。（虽然现在还没有加入用户管理功能= =。) 也可以在items页面下进行添加关注的操作。输入要关注物品的名称即可。</p>
<p>     <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb6.png" width="285" height="70" /> </li>
<li>指定成本价格(valuate)： 这一步操作没有什么要说的，输入对应的成本和价格，结果就如首页图所示。</li>
</ol>
<p>已知和未知的BUG很多，还有许多有待完善和补充的地方，待以后有时间再慢慢修改。算起来这还是第一次做网站，可能也算不上是网站，充其量就是一些PHP和HTML的混搭，全当学习练手之用，游戏之余的另外消遣。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=416</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes &#8211; Nurbs</title>
		<link>http://www.hapblue.com/?p=409</link>
		<comments>http://www.hapblue.com/?p=409#comments</comments>
		<pubDate>Wed, 25 May 2011 15:20:52 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[Nurbs]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=409</guid>
		<description><![CDATA[The original text is HERE. The NURBS Model The NURBS (Non Uniform Rational B-Spline) model proposes the definition of a curve as a piecewise rational polynomial function of the parameter u. See [1] for a complete description of this model. NURBS Curve Definition A NURBS curve is defined by control points Pi, i=0..n, which influence is weighted by rational [...]]]></description>
			<content:encoded><![CDATA[<p>The original text is <a title="Nurbs" href="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/Nurbs.htm" target="_blank">HERE</a>.</p>
<h3>The NURBS Model</h3>
<p>The NURBS (Non Uniform Rational B-Spline) model proposes the definition of a curve as a piecewise rational polynomial function of the <strong>parameter</strong> <em>u</em>. See <a href="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/Nurbs.htm#References">[1]</a> for a complete description of this model.</p>
<p><span id="more-409"></span></p>
<h4>NURBS Curve Definition</h4>
<p>A NURBS curve is defined by <strong>control points</strong> <em>Pi, i=0..n</em>, which influence is weighted by <strong>rational polynomial functions</strong> <em>Ri, i=0..n</em> (dependent on the parameter) and <strong>weights</strong> <em>wi, i=0..n</em> (independent on the parameter). The rational polynomial functions <em>Ri</em> are defined by the means of a <strong>basis</strong>, called B-Spline basis, set of piecewise polynomial functions <em>Nik, i=0..n</em>, of same <strong>degree</strong> <em>k</em>. The degree of the NURBS curve is the degree of the polynomial functions.</p>
<p><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/NurbsEquations1.gif" alt="NurbsEquations1.gif (2585 bytes)" width="479" height="119" /></p>
<p>The definition of the basis <em>Nik</em> is uniquely determined by a <strong>knot vector</strong>. The pieces of the basis polynomial functions are called <strong>arcs</strong>. They represent an interval for the parameter values to calculate a segment of shape.</p>
<p>The control points are not, in general, points of the NURBS curve. By convention however, the first and last control points are the begin and end point of the curve respectively, except for the periodic NURBS curves. These control points can be seen as an attracting zone for the curve, which influence is weighted as seen previously.</p>
<h4>Knot Vector</h4>
<p>The knot vector is the way to state the definition of the basis. In particular, it manages the continuity between the different arcs of the basis functions, and, hence, the curves that use it. The knot vector is a set of non decreasing parameter values <em>(t_0,..,t_m)</em>, called <strong>knot values</strong> or <strong>knots</strong>. The B-Spline basis is recursively defined as follows, with <em>i=0,..,n</em>:</p>
<p><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/NurbsEquations2.gif" alt="NurbsEquations2.gif (2205 bytes)" width="479" height="119" /></p>
<p>with the following conventions:</p>
<p><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/NurbsEquations6.gif" alt="NurbsEquations6.gif (1919 bytes)" width="479" height="119" /></p>
<p>The relation between the number of knots (<em>m+1</em>), the degree (<em>k</em>) of <em>Nik</em> and the number of control points (<em>n+1</em>) is given as follows:</p>
<p><span style="color: #ff0000;"><em>m = (n+1) + k</em></span></p>
<p>Knot values are non-decreasing, so a knot vector can have knots with the same value. In this case, the knot is called <strong>multiple</strong>, and its multiplicity is the number of repetitions of the same value. <span style="color: #ff0000;">There are as many arcs as knots of different values plus one. </span>If the increment is always 1, the knot vector is called <strong>uniform</strong>.</p>
<p>The multiplicity is a way to specify the <strong>continuity order</strong> between the arcs. Hence, there is a relation between the multiplicity and this continuity order:</p>
<ol>
<li>For an internal knot value (neither the first, nor the last), the continuity order is the degree minus the multiplicity. As a consequence, the multiplicity of a knots cannot be strictly greater then the degree.</li>
<li><span style="color: #ff0000;">By convention, for a non periodic basis (open curve), each extreme knot value has a multiplicity equal to the degree plus one.</span></li>
<li>For a periodic basis (they are used to model closed curves), the first point applies for all knots. Moreover, the first and last multiplicities are the same.</li>
</ol>
<p>The following table summarizes these relations:</p>
<table>
<tbody>
<tr>
<td></td>
<td>Multiplicity (<tt>m</tt>)</td>
<td>Continuity order</td>
</tr>
<tr>
<td>internal knot values</td>
<td><tt>1 &lt;= m &lt;= degree</tt></td>
<td><tt>Degree-m</tt></td>
</tr>
<tr>
<td>extreme knot values for a non periodic basis</td>
<td><span style="color: #ff0000;"><tt>degree+1 </tt>(by convention)</span></td>
<td><tt>(-1)</tt></td>
</tr>
<tr>
<td>same first and last multiplicities for a periodic basis</td>
<td><tt>1 &lt;= m &lt;= degree</tt></td>
<td><tt>Degree-m</tt></td>
</tr>
</tbody>
</table>
<table width="100%">
<tbody>
<tr>
<td valign="top">Example 1</td>
<td>Knot vector of one arc of degree 3: 0 0 0 0 1 1 1 1<br />
In this case, there are 4 control points</td>
</tr>
</tbody>
</table>
<table border="0" width="100%">
<caption><a name="Fig 1"></a>Fig. 1: Illustration of Example 1</caption>
<tbody>
<tr>
<td><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/Nurbs2.gif" alt="Nurbs2.gif (4065 bytes)" width="479" height="359" /></td>
</tr>
<tr>
<td>The green curve has four control points (CP1 to CP4).If you move CP3 to CP3&#8242;, the curve is attracted by this new points.</p>
<p>Notice two important properties of this kind of NURBS, called Bezier arc:</p>
<ul>
<li>The curve is inside the convex hull of the control points</li>
<li>The curve is tangent to the segment joigning the first and second control points at the beginning of the curve, and to the segment joining the last and next to last control points at its end.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<table width="100%">
<tbody>
<tr>
<td valign="top">Example 2</td>
<td>Non uniform knot vector, 3 arcs of degree 3, C2 continuity: 0 0 0 0 2 8 9 9 9 9<br />
In this case, there are 6 control points</td>
</tr>
</tbody>
</table>
<table border="0" width="100%">
<caption><a name="Fig. 2"></a>Fig. 2: Illustration of Example 2</caption>
<tbody>
<tr>
<td><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/Nurbs1.gif" alt="Nurbs1.gif (4942 bytes)" width="479" height="359" /></td>
</tr>
<tr>
<td>The green curve is an example of non uniform polynomial B-Spline curve, having the knot vector of the example 2. The weight of each control point is 1.If you assign (1,1,10,20,5,1) to the control points, it gives the red curve. This curve is attracted by the control points CP3 and CP4, that are more weighted than the others.</p>
<p>These curves have three arcs: CP1-K1, K1-K2, K2-CP2.</td>
</tr>
</tbody>
</table>
<p>According to the definition, it is possible to create NURBS curves that are only C0 or C1 continuous. Despite of this fact, remember that the CGM geometric operators suppose that the geometry is at least C2 continuous.</p>
<h4>Bernstein Basis and Bézier Points</h4>
<p>NURBS, NUPS, UPBS have a common feature: the continuity between arcs is managed, with more or less flexibility, by the model with the knot vector. The arcs definitions are linked together. Now, the Bernstein-Bézier model defines a basis for one arc. To define a curve with several arcs, you have to connect arcs, each arc being independent on its neighbors. Hence, the continuity is not managed by the model, you have to put constraints between the different arcs to insure it.</p>
<p>The parametric equation of an arc of degree <em>k</em> and the functions of the basis are as follows:</p>
<p><img src="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/images/NurbsEquations5.gif" alt="NurbsEquations5.gif " width="479" height="119" /></p>
<p>The control points <em>Pi</em> are called Bézier points.</p>
<p>The transformation of a NURBS curve into a Bernstein-Bézier curve amounts to increase the multiplicity of the knots until having a C0 continuity. Conversely, the transformation of a Bernstein-Bézier curve into a NURBS curve amounts to build a knot vector for which the knots have a multiplicity equal to the degree.</p>
<p><a href="http://www.maruf.ca/files/caadoc/CAAGobTechArticles/Nurbs.htm#Fig 1">Fig. 1</a> displays examples of Bézier arcs.</p>
<p>&nbsp;</p>
<p><span style="font-size: 12px; line-height: normal;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=409</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Marching的一种GLSL实现</title>
		<link>http://www.hapblue.com/?p=408</link>
		<comments>http://www.hapblue.com/?p=408#comments</comments>
		<pubDate>Mon, 16 May 2011 13:18:45 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[GLSL]]></category>
		<category><![CDATA[openGL]]></category>
		<category><![CDATA[shader]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=408</guid>
		<description><![CDATA[用三维纹理表示体数据的密度场，使用GLSL语言实现光线经过介质衰减、散射然后进入视野的光照模拟。 Vertex shader file fragment shader file 这里有关于GLSL的介绍：传送门]]></description>
			<content:encoded><![CDATA[<p>用三维纹理表示体数据的密度场，使用GLSL语言实现光线经过介质衰减、散射然后进入视野的光照模拟。</p>
<ul>
<li>Vertex shader file </li>
</ul>
<p> <script src="http://pastebin.com/embed_js.php?i=2ieLpzHV"></script>
<ul>
<li>fragment shader file </li>
</ul>
<p> <script src="http://pastebin.com/embed_js.php?i=Tc63ccc0"></script>
<p>这里有关于GLSL的介绍：<a title="An Intro of GLSL" href="http://www.hapblue.com/?p=332" target="_blank">传送门</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=408</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>地城手册预览-PTR4.2 新福利</title>
		<link>http://www.hapblue.com/?p=407</link>
		<comments>http://www.hapblue.com/?p=407#comments</comments>
		<pubDate>Mon, 16 May 2011 02:58:36 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[动漫&游戏]]></category>
		<category><![CDATA[wow]]></category>
		<category><![CDATA[游戏]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=407</guid>
		<description><![CDATA[在最新的4.2测试服中已经加入了地城手册，虽然还没有最终完成，但从中我们已经或多或少可以知道地城手册可以提供的各种信息，而且这也将成为以后游戏中必不可少的一项基本工具。 地城手册已经列出了现有的和在4.2中将加入的新副本火源之界。 &#160; 可以在地城手册中查看每个BOSS的掉落列表（看来atlasloot即将被取代了= =） 当然最重要的是可以查看BOSS的详细技能说明（向以前一次一次尝试来获取技能数据的先行者致敬） 顺便一提，在技能列表的右边会有具有辅助提示作用的一些小标记，用于对应职业特别注意，例如盾牌，加号，剑这些图示。上图中的骷髅有说是需要大家注意的杀招，或者是只有在heroic模式中才会出现的技能。当然我更倾向于后者，想象如果整个一个阶段都是骷髅杀招的话……]]></description>
			<content:encoded><![CDATA[<p>在最新的4.2测试服中已经加入了地城手册，虽然还没有最终完成，但从中我们已经或多或少可以知道地城手册可以提供的各种信息，而且这也将成为以后游戏中必不可少的一项基本工具。</p>
<p>地城手册已经列出了现有的和在4.2中将加入的新副本火源之界。</p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_1.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="encounterjournal_1" border="0" alt="encounterjournal_1" src="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_1_thumb.jpg" width="644" height="420" /></a>&#160;</p>
<p>可以在地城手册中查看每个BOSS的掉落列表（看来atlasloot即将被取代了= =）</p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_2.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="encounterjournal_2" border="0" alt="encounterjournal_2" src="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_2_thumb.jpg" width="644" height="417" /></a> </p>
<p>当然最重要的是可以查看BOSS的详细技能说明（向以前一次一次尝试来获取技能数据的先行者致敬）</p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_3.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="encounterjournal_3" border="0" alt="encounterjournal_3" src="http://www.hapblue.com/wp-content/uploads/2011/05/encounterjournal_3_thumb.jpg" width="644" height="416" /></a> </p>
<p>顺便一提，在技能列表的右边会有具有辅助提示作用的一些小标记，用于对应职业特别注意，例如盾牌，加号，剑这些图示。上图中的骷髅有说是需要大家注意的杀招，或者是只有在heroic模式中才会出现的技能。当然我更倾向于后者，想象如果整个一个阶段都是骷髅杀招的话……</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=407</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>台服战网绑定，英雄榜与美服同步</title>
		<link>http://www.hapblue.com/?p=396</link>
		<comments>http://www.hapblue.com/?p=396#comments</comments>
		<pubDate>Fri, 13 May 2011 08:52:52 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[动漫&游戏]]></category>
		<category><![CDATA[wow]]></category>
		<category><![CDATA[游戏]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=396</guid>
		<description><![CDATA[今天上午台服魔兽世界的战网绑定正式开启，随之而来的是旧版英雄榜升级，界面与功能已与美服同步。 但是3D角色浏览功能还未正常。在新的英雄榜中可以清晰的浏览装备，宝石，附魔，重铸以及天赋雕纹。]]></description>
			<content:encoded><![CDATA[<p>今天上午台服魔兽世界的战网绑定正式开启，随之而来的是旧版英雄榜升级，界面与功能已与美服同步。</p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/character1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="character" border="0" alt="character" src="http://www.hapblue.com/wp-content/uploads/2011/05/character_thumb1.png" width="500" height="333" /></a> </p>
<p>但是3D角色浏览功能还未正常。在新的英雄榜中可以清晰的浏览装备，宝石，附魔，重铸以及天赋雕纹。</p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb.png" width="202" height="236" /></a> <a href="http://www.hapblue.com/wp-content/uploads/2011/05/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb1.png" width="223" height="244" /></a></p>
<p><a href="http://www.hapblue.com/wp-content/uploads/2011/05/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.hapblue.com/wp-content/uploads/2011/05/image_thumb2.png" width="244" height="89" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=396</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Intro of GLSL</title>
		<link>http://www.hapblue.com/?p=332</link>
		<comments>http://www.hapblue.com/?p=332#comments</comments>
		<pubDate>Tue, 20 Jul 2010 08:51:58 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[GLSL]]></category>
		<category><![CDATA[openGL]]></category>
		<category><![CDATA[shader]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=332</guid>
		<description><![CDATA[The original paper is here. GLSL – An Introduction By: Florian Rudolf What Is GLSL? GLSL (GLslang) is a short term for the official OpenGL Shading Language. GLSL is a C/C++ similar high level programming language for several parts of the graphic card. With GLSL you can code (right up to) short programs, called shaders, [...]]]></description>
			<content:encoded><![CDATA[<p>The original paper is <a href="http://nehe.gamedev.net/data/articles/article.asp?article=21" target="_blank">here</a>.</p>
<p><span><span style="font-size: x-small;"><span style="text-decoration: underline;">GLSL – An Introduction</span></span></span></p>
<p><span> <span style="font-size: xx-small;">By: Florian Rudolf</span></span></p>
<p><span style="font-size: xx-small;"><span style="text-decoration: underline;"><strong>What Is GLSL?</strong></span><strong> </strong></span></p>
<p>GLSL (GLslang) is a short term for the official OpenGL Shading Language.  GLSL is a C/C++ similar high level programming language for several parts of the graphic  card. With GLSL you can code (right up to) short programs, called shaders, which are  executed on the GPU.</p>
<p><span><span style="font-size: xx-small;"><span><span id="more-332"></span></span></span></span></p>
<p><span><strong><span style="text-decoration: underline;">Why Shaders?</span></strong></span></p>
<p>Until DirectX 8 hardware (GeForce 2 and lower, Radoen 7000 and lower)  the graphic pipeline could only be configured, but not be programmed. For example there is  the OpenGL lighting model with ambient, diffuse, specular and emissive lighting. This model  is mainly used but there are many other models for lighting. In fixed-function OpenGL only  this lighting model could be used, no other. With Shaders you are able to write your own  lighting model. But that’s only one feature of shaders. There are thousands of other really  nice possibilities: Shadows, Environment Mapping, Per-Pixel Lighting, Bump Mapping, Parallax  Bump Mapping, HDR, and much more!</p>
<p><strong><span style="text-decoration: underline;">Why GLSL?</span></strong></p>
<p>Shaders are available in OpenGL till 2002 through ARB_vertex_program and  ARB_fragment_program extension. But with those extensions you are only able to use assembly  shaders. Because of the growing complexity of lighting and shading models assembly shaders  are hard to use. GLSL is a high-level shading language, which means that you can write your  shader in C/C++ style. This makes shader development much easier!</p>
<p><strong><span style="text-decoration: underline;">What Is The Difference Between Fixed Function Pipeline And GLSL?</span></strong></p>
<p>There are two types of shaders in GLSL: vertex shaders and fragment  shaders.</p>
<p><strong><span style="text-decoration: underline;">Vertex Shader</span></strong></p>
<p>A vertex shader operates on every vertex. So if you call glVertex* (or  glDrawArrays, …) the vertex shader is executed for each vertex. If you use a vertex shader  you have nearly full control over what is happening with each vertex. But if you use a vertex  shader ALL Per-Vertex operations of the fixed function OpenGL pipeline are replaced  (see Figure 1):</p>
<ul>Vertex Transformation</p>
<p>Normal Transformation, Normalization and Rescaling</p>
<p>Lighting</p>
<p>Texture Coordinate Generation and Transformation</p>
<p>…</ul>
<p>For a full overview what a vertex shader replaces and what it does not  replace please see reference [1], page 41. So if you want to use a vertex shader you HAVE  to do all these things above on your own (of course, only if you need it <img src='http://www.hapblue.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong><span style="text-decoration: underline;">Fragment Shader</span></strong></p>
<p>A fragment shader operates on every fragment which is produced by  rasterization. With fragment shader you have nearly full control over what is happening with  each fragment. But just like a vertex shader, a fragment shader replaces ALL Per-Fragment  operations of the fixed function OpenGL pipeline (see Figure 1):</p>
<ul>Texture access and application (Texture environments)</p>
<p>Fog</p>
<p>…</ul>
<p>For a full overview what a fragment shader replaces and what it does not  replace please see reference [1], page 43. Using a fragment shader is just like using a  vertex shader, because you HAVE to do all these things above on your own (of course, only if  you need it).</p>
<p><img src="http://nehe.gamedev.net/data/articles/extras/article21/image1.jpg" border="1" alt="" /><br />
Figure 1, OpenGL 1.5 fixed function pipeline [1]</p>
<p><strong><span style="text-decoration: underline;">What Does GLSL Look Like?</span></strong></p>
<p>As mentioned above there are 2 types of shaders, a vertex shader and a  fragment shader. Each shader type has other inputs and outputs.</p>
<p><strong><span style="text-decoration: underline;">Data Types In GLSL</span></strong></p>
<p>There are four main types: float, int, bool and sampler. For the first  three types, vector types are available:</p>
<pre>vec2, vec3, vec4			2D, 3D and 4D floating point vector

ivec2, ivec3, ivec4			2D, 3D and 4D integer vector

bvec2, bvec3, bvec4			2D, 3D and 4D boolean vectors</pre>
<p>For floats here are also matrix types:mat2, mat3, mat4			2&#215;2, 3&#215;3, 4&#215;4 floating point matrix</p>
<p>Samplers are types representing textures. They are used for texture  sampling. Sampler types have to be uniform. They are not allowed to be declared as a non-uniform  type. Here are the different sampler types:</p>
<pre>sampler1D, sampler2D, sampler3D		1D, 2D and 3D texture

samplerCube				Cube Map texture

sampler1Dshadow, sampler2Dshadow	1D and 2D depth-component texture</pre>
<p><strong><span style="text-decoration: underline;">About Attributes, Uniforms And Varyings</span></strong></p>
<p>There are three types of inputs and outputs in a shader: uniforms,  attributes and varyings.</p>
<p>Uniforms are values which do not change during a rendering, for example  the light position or the light color.  Uniforms are available in vertex and fragment  shaders. Uniforms are read-only.</p>
<p>Attributes are only available in vertex shader and they are input values  which change every vertex, for example the vertex position or normals. Attributes are  read-only.</p>
<p>Varyings are used for passing data from a vertex shader to a fragment  shader. Varyings are (perspective correct) interpolated across the primitive. Varyings are  read-only in fragment shader but are read- and writeable in vertex shader (but be careful,  reading a varying type before writing to it will return an undefined value). If you want to use  varyings you have to declare the same varying in your vertex shader and in your fragment  shader.</p>
<p>All uniform, attribute and varying types HAVE to be global. You are not  allowed to specify a uniform/attribute/varying type in a function or a void.</p>
<p><strong><span style="text-decoration: underline;">Built-In Types</span></strong></p>
<p>GLSL has some built-in attributes in a vertex shader:</p>
<pre>gl_Vertex				4D vector representing the vertex position

gl_Normal				3D vector representing the vertex normal

gl_Color				4D vector representing the vertex color

gl_MultiTexCoordX			4D vector representing the texture coordinate of texture unit X</pre>
<p>There are some other built-in attributes, see reference [2], page 41 for  a full list.</p>
<p>GLSL also has some built-in uniforms:</p>
<pre>gl_ModelViewMatrix			4x4 Matrix representing the model-view matrix.

gl_ModelViewProjectionMatrix		4x4 Matrix representing the model-view-projection matrix.

gl_NormalMatrix				3x3 Matrix representing the inverse transpose model-view matrix.

					This matrix is used for normal transformation.</pre>
<p>There are some other built-in uniforms, like lighting states. See  reference [2], page 42 for a full list.</p>
<p><strong><span style="text-decoration: underline;">GLSL Built-In Varyings:</span></strong></p>
<pre>gl_FrontColor				4D vector representing the primitives front color

gl_BackColor				4D vector representing the primitives back color

gl_TexCoord[X]				4D vector representing the Xth texture coordinate</pre>
<p>There are some other built-in varyings. See reference [2], page 44 for a  full list.</p>
<p>And last but not least there are some built-in types which are used for  shader output:</p>
<pre>gl_Position				4D vector representing the final processed vertex position. Only 

					available in vertex shader.

gl_FragColor				4D vector representing the final color which is written in the frame 

					buffer. Only available in fragment shader.

gl_FragDepth				float representing the depth which is written in the depth buffer.

					Only available in fragment shader.</pre>
<p>The importance of built-in types is that they are mapped to the OpenGL  states. For example if you call glLightfv(GL_LIGHT0, GL_POSITION, my_light_position) this value  is available as a uniform using gl_LightSource[0].position in a vertex and/or fragment  shader.</p>
<p><strong><span style="text-decoration: underline;">Generic Types</span></strong></p>
<p>You are also able to specify your own attributes, uniforms and varyings.  For example if you want to pass a 3D tangent vector for each vertex from your  application to the vertex shader you can specify a “Tangent” attribute:attribute vec3 Tangent;</p>
<p>See <a href="http://nehe.gamedev.net/data/articles/article.asp?article=21" target="_blank">full text</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=332</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>一种自动的 Singleton 工具</title>
		<link>http://www.hapblue.com/?p=327</link>
		<comments>http://www.hapblue.com/?p=327#comments</comments>
		<pubDate>Mon, 12 Jul 2010 08:19:51 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=327</guid>
		<description><![CDATA[本文摘自《游戏编程精粹 1 》，提出了一种方便且安全的方法，提供到C++类 singleton 的访问，同时保留当其实例化和销毁时的完全控制。 singleton 是一种对象，它在一个系统中的任何时候只有一个实例。在游戏中，singleton 的一些常见例子是纹理贴图，文件或用户界面的管理程序。它们每一个都是一个子系统，通常假定从游戏开始时可用，一直持续到游戏关闭。 一种通用的解决方法是使用模板来自动定义 singleton 指针，并完成指针设置、查询和清除的工作。它还可以检查（通过 assert() )确保没有将 singleton 实例化多次。最重要的一点是，我们可以免费获得所有这些功能，只需要从以下这个简单的类派生就可以： #include &#60;cassert&#62; &#160; template &#60;typename T&#62; class Singleton &#123; static T* ms_Singleton; &#160; public: Singleton&#40;void&#41; &#123; assert&#40;!ms_Singleton&#41;; int offset = &#40;int&#41;&#40;T*&#41;1 - &#40;int&#41;&#40;Singleton&#60;t&#62;*&#41;&#40;T*&#41;1; ms_Singleton = &#40;T*&#41;&#40;&#40;int&#41;this + offset&#41;; &#125; ~Singleton&#40;void&#41; &#123; assert&#40;ms_Singleton&#41;; ms_Singleton = 0; &#125; static T&#38; GetSingleton&#40;void&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>本文摘自《游戏编程精粹 1 》，提出了一种方便且安全的方法，提供到C++类 singleton 的访问，同时保留当其实例化和销毁时的完全控制。</p>
<p> <span id="more-327"></span>
<p>singleton 是一种对象，它在一个系统中的任何时候只有一个实例。在游戏中，singleton 的一些常见例子是纹理贴图，文件或用户界面的管理程序。它们每一个都是一个子系统，通常假定从游戏开始时可用，一直持续到游戏关闭。</p>
<p>一种通用的解决方法是使用模板来自动定义 singleton 指针，并完成指针设置、查询和清除的工作。它还可以检查（通过 assert() )确保没有将 singleton 实例化多次。最重要的一点是，我们可以免费获得所有这些功能，只需要从以下这个简单的类派生就可以：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;cassert&gt;</span>
&nbsp;
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> Singleton
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">static</span> T<span style="color: #000040;">*</span> ms_Singleton<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	Singleton<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>ms_Singleton<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">int</span> offset <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>T<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>Singleton<span style="color: #000080;">&lt;</span>t<span style="color: #000080;">&gt;</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>T<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
		ms_Singleton <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>T<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">this</span> <span style="color: #000040;">+</span> offset<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	~Singleton<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span>ms_Singleton<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		ms_Singleton <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">static</span> T<span style="color: #000040;">&amp;</span> GetSingleton<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span>ms_Singleton<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>ms_Singleton<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">static</span> T<span style="color: #000040;">*</span> GetSingletonPtr<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>ms_Singleton<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span> T<span style="color: #000040;">*</span> Singleton<span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">ms_Singleton</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span></pre></div></div>

<p>将任何类转换成 singleton ，只需要按以下3个简单步骤来做：</p>
<ol>
<li>从Singleton&lt;MyClass&gt; 公开派生你的类 MyClass。 </li>
<li>确保使用前在系统中创建了 MyClass 的实例。如果实例化并不重要，可以通过将它设为全局或局部静态，让编译程序来做；也可以通过一个属主类，用 new 和 delete 来自己做。不论实例在何时如何创建，它将被追踪，并通过公共接口为系统其他部分用作 singleton。 </li>
<li>在系统的任何地方调用 MyClass::GetSingleton() 来使用对象。也可以 #define g_MyClass 为 MyClass::GetSingleton() ，并将其作为全局对象来对待，以方便书写。 </li>
</ol>
<p>以下是使用该类的例子：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//sample code</span>
<span style="color: #0000ff;">class</span> TextureMgr <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> Singleton<span style="color: #000080;">&lt;</span>TextureMgr<span style="color: #000080;">&gt;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	Texture<span style="color: #000040;">*</span>  GetTexture<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">// ...</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #339900;">#define g_TextureMgr TextureMgr::GetSingleton()</span>
&nbsp;
<span style="color: #0000ff;">void</span> Func<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Texture<span style="color: #000040;">*</span> stone1 <span style="color: #000080;">=</span> TextureMgr<span style="color: #008080;">::</span><span style="color: #007788;">GetSingleton</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">GetTexture</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;stone1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Texture<span style="color: #000040;">*</span> wood6 <span style="color: #000080;">=</span> g_TextureMgr.<span style="color: #007788;">GetTexture</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;wood6&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">// ...</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>这个 Singleton 类的惟一目的是在它的派生 (MyClass) 类型的任何实例创建和销毁时自动注册和注销它们。所有重要的工作在 Singleton 的构造函数中完成，在此它计算出派生实例的相对位置，并将结果存储到 singleton 指针 (ms_Singleton) 。注意，派生类可能不仅仅从 Singleton 派生，在这种情况下 MyClass 的 “this” 不同。这种解决方法假设一个不存在的对象在内存的 0&#215;1 位置上，将此对象强制转换为两种类型，并得到其偏移量的差值。这个差值可以有效的作为 Singleton&lt;MyClass&gt; 和它派生类型 MyClass 的距离，可用于计算 singleton 指针。</p>
<p><font face="Viner Hand ITC">Reference</font></p>
<p>Meyers, Scott, More Effective C++, Addison-Wesley Publishing Co., 1995</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=327</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About BITMAPINFO</title>
		<link>http://www.hapblue.com/?p=322</link>
		<comments>http://www.hapblue.com/?p=322#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:12:55 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[GDI]]></category>
		<category><![CDATA[vc++]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=322</guid>
		<description><![CDATA[在用GDI函数 SetDIBitsToDevice 显示DIB位图时，需要一个类型为 BITMAPINFO * 的参数 lpbmi。这个参数一般需要自己赋值。 int SetDIBitsToDevice&#40; __in HDC hdc, __in int XDest, __in int YDest, __in DWORD dwWidth, __in DWORD dwHeight, __in int XSrc, __in int YSrc, __in UINT uStartScan, __in UINT cScanLines, __in const VOID *lpvBits, __in const BITMAPINFO *lpbmi, __in UINT fuColorUse &#41;; BITMAPINFO结构体的定义如下： typedef struct tagBITMAPINFO &#123; BITMAPINFOHEADER bmiHeader; [...]]]></description>
			<content:encoded><![CDATA[<p><span id="more-322"></span>
<p>在用GDI函数 SetDIBitsToDevice 显示DIB位图时，需要一个类型为 BITMAPINFO * 的参数 lpbmi。这个参数一般需要自己赋值。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> SetDIBitsToDevice<span style="color: #008000;">&#40;</span>
  __in  HDC hdc,
  __in  <span style="color: #0000ff;">int</span> XDest,
  __in  <span style="color: #0000ff;">int</span> YDest,
  __in  DWORD dwWidth,
  __in  DWORD dwHeight,
  __in  <span style="color: #0000ff;">int</span> XSrc,
  __in  <span style="color: #0000ff;">int</span> YSrc,
  __in  UINT uStartScan,
  __in  UINT cScanLines,
  __in  <span style="color: #0000ff;">const</span> VOID <span style="color: #000040;">*</span>lpvBits,
  __in  <span style="color: #0000ff;">const</span> BITMAPINFO <span style="color: #000040;">*</span>lpbmi,
  __in  UINT fuColorUse
<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>BITMAPINFO结构体的定义如下：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span> tagBITMAPINFO <span style="color: #008000;">&#123;</span>
  BITMAPINFOHEADER bmiHeader<span style="color: #008080;">;</span>
  RGBQUAD          bmiColors<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> BITMAPINFO, <span style="color: #000040;">*</span>PBITMAPINFO<span style="color: #008080;">;</span></pre></div></div>

<p>其中 BITMAPINFOHEADER 的结构定义如下：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span> tagBITMAPINFOHEADER <span style="color: #008000;">&#123;</span>
DWORD biSize<span style="color: #008080;">;</span> 
LONG biWidth<span style="color: #008080;">;</span> 
LONG biHeight<span style="color: #008080;">;</span> 
WORD biPlanes<span style="color: #008080;">;</span> 
WORD biBitCount<span style="color: #008080;">;</span>
DWORD biCompression<span style="color: #008080;">;</span> 
DWORD biSizeImage<span style="color: #008080;">;</span> 
LONG biXPelsPerMeter<span style="color: #008080;">;</span>
LONG biYPelsPerMeter<span style="color: #008080;">;</span>
DWORD biClrUsed<span style="color: #008080;">;</span>
DWORD biClrImportant<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> BITMAPINFOHEADER, <span style="color: #000040;">*</span>PBITMAPINFOHEADER<span style="color: #008080;">;</span></pre></div></div>

<p>bmiColors[1] 是一个只有一个项的数组，其结构 RGBQUAD 定义如下：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span> tagRGBQUAD <span style="color: #008000;">&#123;</span>
    BYTE    rgbBlue<span style="color: #008080;">;</span>
    BYTE    rgbGreen<span style="color: #008080;">;</span>
    BYTE    rgbRed<span style="color: #008080;">;</span>
    BYTE    rgbReserved<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> RGBQUAD</pre></div></div>

<p>bmiColors[1] 的这个设计是为了照顾bmp文件，bmp文件主要有4部分组成：</p>
<ol>
<li>BITMAPFILEHEADER bmp头文件 </li>
<li>BITMAPINFOHEADER bmp文件信息头 </li>
<li>RGBQUAD&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bmp文件调色板 </li>
<li>BITMAP&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bmp文件数据 </li>
</ol>
<p>而对于不同BPP (bits per pixel) 的 bitmap 来说，palette （调色板）的大小是不一样的。对于8位灰度图像而言，palette 有256 个RGBQUAD 。因为 palette 是连续存储的，在BITMAPINFO 里只存放palette的第一项。</p>
<p>下面代码为一个8位灰度图像的BITMAPINFO 赋值：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">BITMAPINFOHEADER bmih<span style="color: #008080;">;</span>
<span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>bmih, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>BITMAPINFOHEADER<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
bmih.<span style="color: #007788;">biSize</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>BITMAPINFOHEADER<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
bmih.<span style="color: #007788;">biWidth</span> <span style="color: #000080;">=</span> width<span style="color: #008080;">;</span>
bmih.<span style="color: #007788;">biHeight</span> <span style="color: #000080;">=</span> <span style="color: #000040;">-</span>height<span style="color: #008080;">;</span>     <span style="color: #666666;">//biHeight should be negative</span>
bmih.<span style="color: #007788;">biPlanes</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>           <span style="color: #666666;">//biPlanes must be 1</span>
bmih.<span style="color: #007788;">biBitCount</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">8</span><span style="color: #008080;">;</span>         <span style="color: #666666;">//bpp</span>
bmih.<span style="color: #007788;">biCompression</span> <span style="color: #000080;">=</span> BI_RGB<span style="color: #008080;">;</span> <span style="color: #666666;">//no compression</span>
&nbsp;
RGBQUAD colorTable<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">256</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
DWORD color <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">256</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i, color <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #208080;">0x010101</span><span style="color: #008000;">&#41;</span>
	<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>DWORD <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>colorTable<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> color<span style="color: #008080;">;</span>
&nbsp;
BITMAPINFO <span style="color: #000040;">*</span> pbmi<span style="color: #008080;">;</span>
pbmi <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>BITMAPINFO <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">malloc</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>BITMAPINFOHEADER<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>RGBQUAD<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">256</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
pbmi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>bmiHeader <span style="color: #000080;">=</span> bmih<span style="color: #008080;">;</span>
<span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>pbmi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>bmiColors, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>colorTable, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>RGBQUAD<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">256</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=322</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Winsock tip 2</title>
		<link>http://www.hapblue.com/?p=316</link>
		<comments>http://www.hapblue.com/?p=316#comments</comments>
		<pubDate>Sat, 26 Jun 2010 15:05:31 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[winsock]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=316</guid>
		<description><![CDATA[最近用到了winsock 的事件等待模型，小结一下。事件驱动模型与消息驱动模型相比，省去了消息中必不可少的窗口。通过建立Event，与socket 绑定，选择关心的事件，然后调用WSAWaitForMultipleEvents，当有相关事件触发或等待超时，线程继续前进。 The WSAWaitForMultipleEvents function returns when one or all of the specified event objects are in the signaled state, when the time-out interval expires, or when an I/O completion routine has executed. DWORD WSAWaitForMultipleEvents&#40; __in DWORD cEvents, __in const WSAEVENT *lphEvents, __in BOOL fWaitAll, __in DWORD dwTimeout, __in BOOL fAlertable &#41;; WSAWaitForMultipleEvents 基本使用模式如下。 [...]]]></description>
			<content:encoded><![CDATA[<p>最近用到了winsock 的事件等待模型，小结一下。事件驱动模型与消息驱动模型相比，省去了消息中必不可少的窗口。通过建立Event，与socket 绑定，选择关心的事件，然后调用WSAWaitForMultipleEvents，当有相关事件触发或等待超时，线程继续前进。</p>
<p><span id="more-316"></span></p>
<p>The <strong>WSAWaitForMultipleEvents</strong> function returns when one or all of the specified event objects are in the signaled state, when the time-out interval expires, or when an I/O completion routine has executed.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">DWORD WSAWaitForMultipleEvents<span style="color: #008000;">&#40;</span>
  __in  DWORD cEvents,
  __in  <span style="color: #0000ff;">const</span> WSAEVENT <span style="color: #000040;">*</span>lphEvents,
  __in  BOOL fWaitAll,
  __in  DWORD dwTimeout,
  __in  BOOL fAlertable
<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>WSAWaitForMultipleEvents 基本使用模式如下。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> ret <span style="color: #000080;">=</span> WSAWaitForMultipleEvents<span style="color: #008000;">&#40;</span>EventTotal, EventArray, FALSE, WSA_INFINITE, FALSE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> index <span style="color: #000080;">=</span> ret <span style="color: #000040;">-</span> WSA_WAIT_EVENT_0<span style="color: #008080;">;</span>
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span> index <span style="color: #000080;">&lt;</span> EventTotal<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>index<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    ret <span style="color: #000080;">=</span> WSAWaitForMultipleEvents<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span>, EventArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, TRUE, <span style="color: #0000dd;">1000</span>, FALSE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>ret <span style="color: #000080;">==</span> WSA_WAIT_TIMEOUT<span style="color: #008000;">&#41;</span> <span style="color: #000040;">||</span> <span style="color: #008000;">&#40;</span>ret <span style="color: #000080;">==</span> WSA_WAIT_FAILED<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//do something ...</span>
    <span style="color: #666666;">//if it is a socket event</span>
    WSAEnumNetworkEvents<span style="color: #008000;">&#40;</span>socket, EventArray<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span>, <span style="color: #000040;">&amp;</span>NetworkEvents<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>NetworkEvents.<span style="color: #007788;">lNetworkEvents</span> <span style="color: #000040;">&amp;</span> FD_READ<span style="color: #008000;">&#41;</span>
        <span style="color: #666666;">//do something</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>NetworkEvents.<span style="color: #007788;">lNetworkEvents</span> <span style="color: #000040;">&amp;</span> FD_CLOSE<span style="color: #008000;">&#41;</span>
        <span style="color: #666666;">//do something</span>
    <span style="color: #666666;">//if (...)</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>相关结构和函数。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSANETWORKEVENTS    NetworkEvents<span style="color: #008080;">;</span>
WSAOVERLAPPED       AcceptOverlapped<span style="color: #008080;">;</span>
WSABUF              DataBuf<span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">EventArray<span style="color: #008000;">&#91;</span>EventTotal<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> WSACreateEvent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSAEventSelect<span style="color: #008000;">&#40;</span>socket, EventArray<span style="color: #008000;">&#91;</span>EventTotal<span style="color: #008000;">&#93;</span>, FD_READ <span style="color: #000040;">|</span> FD_CLOSE<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSAResetEvent<span style="color: #008000;">&#40;</span>EventArray<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSACloseEvent<span style="color: #008000;">&#40;</span>EventArray<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSARecv<span style="color: #008000;">&#40;</span>socket, <span style="color: #000040;">&amp;</span>RecvDataBuf, <span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>RecvBytes, <span style="color: #000040;">&amp;</span>Flags, <span style="color: #000040;">&amp;</span>AcceptOverlapped, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">WSASend<span style="color: #008000;">&#40;</span>socket, <span style="color: #000040;">&amp;</span>SendDataBuf, <span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>SendBytes, Flags, <span style="color: #000040;">&amp;</span>AcceptOverlapped, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">HANDLE event<span style="color: #008080;">;</span>
event <span style="color: #000080;">=</span> CreateEvent<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, TRUE, FALSE, <span style="color: #008000;">&#40;</span>LPCTSTR<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;event name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
SetEvent<span style="color: #008000;">&#40;</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
ResetEvent<span style="color: #008000;">&#40;</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
CloseHandle<span style="color: #008000;">&#40;</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<h6>Requirements</h6>
<p>Header: Winsock2.h</p>
<p>Library: Ws2_32.lib</p>
<p>DLL: Ws2_32.dll</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=316</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CUDA Tip 2 &#8211; CUDA 存储器</title>
		<link>http://www.hapblue.com/?p=309</link>
		<comments>http://www.hapblue.com/?p=309#comments</comments>
		<pubDate>Sat, 12 Jun 2010 06:48:10 +0000</pubDate>
		<dc:creator>hap</dc:creator>
				<category><![CDATA[笔记]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[CUDA]]></category>
		<category><![CDATA[存储器]]></category>

		<guid isPermaLink="false">http://www.hapblue.com/?p=309</guid>
		<description><![CDATA[寄存器 局部存储器 共享存储器 全局存储器 主机端内存 主机端页锁定内存 常数存储器 纹理存储器 存储器 位置 拥有缓存 访问权限 变量生存周期 register GPU 片内 N/A device 可读/写 与thread相同 local memory 板载显存 无 device 可读/写 与thread相同 shared memory GPU 片内 N/A device 可读/写 与block相同 constant memory 板载显存 有 device 可读，host可读/写 可在程序中保持 texture memory 板载显存 有 device 可读，host可读/写 可在程序中保持 global memory 板载显存 无 device 可读/写，host可读/写 [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>寄存器</li>
<li>局部存储器</li>
<li>共享存储器</li>
<li>全局存储器</li>
<li>主机端内存</li>
<li>主机端页锁定内存</li>
<li>常数存储器</li>
<li>纹理存储器</li>
</ol>
<p><span id="more-309"></span></p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="120" valign="top">存储器</td>
<td width="120" valign="top">位置</td>
<td width="120" valign="top">拥有缓存</td>
<td width="120" valign="top">访问权限</td>
<td width="120" valign="top">变量生存周期</td>
</tr>
<tr>
<td width="120" valign="top">register</td>
<td width="120" valign="top">GPU 片内</td>
<td width="120" valign="top">N/A</td>
<td width="120" valign="top">device 可读/写</td>
<td width="120" valign="top">与thread相同</td>
</tr>
<tr>
<td width="120" valign="top">local memory</td>
<td width="120" valign="top">板载显存</td>
<td width="120" valign="top">无</td>
<td width="120" valign="top">device 可读/写</td>
<td width="120" valign="top">与thread相同</td>
</tr>
<tr>
<td width="120" valign="top">shared memory</td>
<td width="120" valign="top">GPU 片内</td>
<td width="120" valign="top">N/A</td>
<td width="120" valign="top">device 可读/写</td>
<td width="120" valign="top">与block相同</td>
</tr>
<tr>
<td width="120" valign="top">constant memory</td>
<td width="120" valign="top">板载显存</td>
<td width="120" valign="top">有</td>
<td width="120" valign="top">device 可读，host可读/写</td>
<td width="120" valign="top">可在程序中保持</td>
</tr>
<tr>
<td width="120" valign="top">texture memory</td>
<td width="120" valign="top">板载显存</td>
<td width="120" valign="top">有</td>
<td width="120" valign="top">device 可读，host可读/写</td>
<td width="120" valign="top">可在程序中保持</td>
</tr>
<tr>
<td width="120" valign="top">global memory</td>
<td width="120" valign="top">板载显存</td>
<td width="120" valign="top">无</td>
<td width="120" valign="top">device 可读/写，host可读/写</td>
<td width="120" valign="top">可在程序中保持</td>
</tr>
<tr>
<td width="120" valign="top">host memory</td>
<td width="120" valign="top">host 内存</td>
<td width="120" valign="top">无</td>
<td width="120" valign="top">host 可读/写</td>
<td width="120" valign="top">可在程序中保持</td>
</tr>
<tr>
<td width="120" valign="top">pinned memory</td>
<td width="120" valign="top">host 内存</td>
<td width="120" valign="top">无</td>
<td width="120" valign="top">host 可读/写</td>
<td width="120" valign="top">可在程序中保持</td>
</tr>
</tbody>
</table>
<ul>
<li>共享存储器</li>
</ul>
<p>示例：共享存储器的动态与静态分配与初始化</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span><span style="color: #000040;">**</span> argv<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    testKernel<span style="color: #000080;">&lt;&lt;&lt;</span><span style="color: #0000dd;">1</span>, <span style="color: #0000dd;">10</span>, mem_size<span style="color: #000080;">&gt;&gt;&gt;</span><span style="color: #008000;">&#40;</span>d_idata, d_odata<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    CUT_EXIT<span style="color: #008000;">&#40;</span>argc, argv<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
__global__ <span style="color: #0000ff;">void</span> testKernel<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> g_idata, <span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> g_odata<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">extern</span> __shared__ <span style="color: #0000ff;">float</span> sdata_dynamic<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//extern 声明，大小由主机端程序决定。动态声明</span>
    __shared__ <span style="color: #0000ff;">int</span> sdata_static<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//静态声明数组大小</span>
&nbsp;
    sdata_static<span style="color: #008000;">&#91;</span>tid<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #666666;">//shared memory 不能在定义时初始化</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</div>
<p>将共享存储器中的变量声明为外部数组时，数组的大小将在Kernel 启动时确定，通过其执行参数确定。通过这种方式定义的所有变量都开始于相同的地址，因此数组中的变量的布局必须通过偏移量显式管理。例：如果希望在动态分配的共享存储器内获得与以下代码对应的内容：</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">short</span> array0<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">128</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">float</span> array1<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">64</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> array2<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">256</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span></pre></div></div>

</div>
<p>应该按照下面的方式定义：</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">extern</span> __shared__ <span style="color: #0000ff;">char</span> array<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
__device__ <span style="color: #0000ff;">void</span> func<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">short</span><span style="color: #000040;">*</span> array0 <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">short</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>array<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> array1 <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>array0<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">128</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span><span style="color: #000040;">*</span> array2 <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>array1<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">64</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</div>
<ul>
<li>全局存储器</li>
</ul>
<p>显存中的全局存储器也称为线性内存。线性内存通常使用 cudaMalloc() 函数分配， cudaFree() 函数释放，并由 cudaMemcpy() 进行主机端与设备端的数据传输。通过CUDA API分配的空间未经过初始化，初始化共享存储器需要调用 cudaMemset 函数。</p>
<p>对于二维、三维数组，我们使用 cudaMallocPitch() 和 cudaMalloc3D() 分配线性存储空间。这些函数能够确保分配满足对齐要求。</p>
<p>例：分配一个尺寸为 width * height 的 float 型2D 数组，以及遍历数组元素。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//主机端代码</span>
<span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> devPtr<span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> pitch<span style="color: #008080;">;</span>
cudaMallocPitch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">**</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>devPtr, <span style="color: #000040;">&amp;</span>pitch,
		width <span style="color: #000040;">*</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
myKernel<span style="color: #000080;">&lt;&lt;&lt;</span><span style="color: #0000dd;">100</span>, <span style="color: #0000dd;">512</span><span style="color: #000080;">&gt;&gt;&gt;</span><span style="color: #008000;">&#40;</span>devPtr, pitch<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #666666;">//设备端代码</span>
__global__ <span style="color: #0000ff;">void</span> myKernel<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> devPtr, <span style="color: #0000ff;">int</span> pitch<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> r <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> r <span style="color: #000080;">&lt;</span> height<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>r<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> row <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>devPtr <span style="color: #000040;">+</span> r <span style="color: #000040;">*</span> pitch<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> c <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> c <span style="color: #000080;">&lt;</span> width<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>c<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> element <span style="color: #000080;">=</span> row<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>例：分配一个 width * height * depth 的 float 型3D 数组，以及遍历数组元素。</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//主机端代码</span>
cudaPitchedPtr devPitchedPtr<span style="color: #008080;">;</span>
cudaExtent extent <span style="color: #000080;">=</span> make_cudaExtent<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">64</span>, <span style="color: #0000dd;">64</span>, <span style="color: #0000dd;">64</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cudaMalloc3D<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>devPitchedPtr, extent<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
myKernel<span style="color: #000080;">&lt;&lt;&lt;</span><span style="color: #0000dd;">100</span>, <span style="color: #0000dd;">512</span><span style="color: #000080;">&gt;&gt;&gt;</span><span style="color: #008000;">&#40;</span>devPitchedPtr, extent<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//设备端代码</span>
__global__ <span style="color: #0000ff;">void</span> myKernel<span style="color: #008000;">&#40;</span>cudaPitchedPtr devPitchedPtr, cudaExtent extent<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> devPtr <span style="color: #000080;">=</span> devPitchedPtr.<span style="color: #007788;">ptr</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">size_t</span> pitch <span style="color: #000080;">=</span> devPitchedPtr.<span style="color: #007788;">pitch</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">size_t</span> slicePitch <span style="color: #000080;">=</span> pitch <span style="color: #000040;">*</span> extent.<span style="color: #007788;">height</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> z <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> z <span style="color: #000080;">&lt;</span> extent.<span style="color: #007788;">depth</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>z<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> slice <span style="color: #000080;">=</span> devPtr <span style="color: #000040;">+</span> z <span style="color: #000040;">*</span> slicePitch<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> y <span style="color: #000080;">&lt;</span> extent.<span style="color: #007788;">height</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>y<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> row <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>slice <span style="color: #000040;">+</span> y <span style="color: #000040;">*</span> pitch<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> x <span style="color: #000080;">&lt;</span> extent.<span style="color: #007788;">width</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>x<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
				<span style="color: #0000ff;">float</span> element <span style="color: #000080;">=</span> row<span style="color: #008000;">&#91;</span>x<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</div>
<p>例：二维数组和CUDA数组间的数据拷贝。</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">cudaMemcpy2DToArray<span style="color: #008000;">&#40;</span>cuArray, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, devPtr, pitch,
		    width <span style="color: #000040;">*</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>, height,
		    cudaMemcpyDeviceToDevice<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

</div>
<ul>
<li>主机端页锁定内存</li>
</ul>
<p>通过 cudaHostAlloc() 和 cudaFreeHost() 来分配和释放 pinned memory。</p>
<ul>
<li>常数存储器</li>
</ul>
<p>定义常数存储器时，需要将其定义在所有函数之外，作用范围为整个文件，并且对主机端和设备端函数都可见。下面两段代码说明了两种常数存储器的使用方法。</p>
<p>第一种方法是直接在定义时直接初始化常熟存储器，然后再Kernel里面直接使用就可以了。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">__constant__ <span style="color: #0000ff;">int</span> t_HelloCUDA<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">11</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">1</span>, <span style="color: #0000dd;">2</span>, <span style="color: #0000dd;">3</span>, <span style="color: #0000dd;">4</span>, <span style="color: #0000dd;">5</span>, <span style="color: #0000dd;">6</span>, <span style="color: #0000dd;">7</span>, <span style="color: #0000dd;">8</span>, <span style="color: #0000dd;">9</span>, <span style="color: #0000dd;">10</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
__constant__ <span style="color: #0000ff;">int</span> num <span style="color: #000080;">=</span> <span style="color: #0000dd;">11</span><span style="color: #008080;">;</span></pre></div></div>

<p>第二种方法是定义一个costant 数组，然后使用函数进行赋值。</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">__constant__ <span style="color: #0000ff;">char</span> p_HelloCUDA<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">11</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
CUDA_SAFE_CALL<span style="color: #008000;">&#40;</span>cudaMemcpyToSymbol<span style="color: #008000;">&#40;</span>p_HelloCUDA, helloCUDA, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">11</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<ul>
<li>纹理存储器</li>
</ul>
<p>在Kernel 中访问纹理存储器的操作称为纹理拾取（texture fetching）。纹理拾取使用的坐标与数据在显存中的位置可以不同，我们通过纹理参照系（texture reference）约定二者的映射方式。将显存中的数据与纹理参照系关联的操作，称为将数据与纹理绑定（texture binding）。显存中可以绑定到纹理的数据有两种，分别是普通的线性存储器（Linear Memory）和 CUDA 数组（CUDA Array）。</p>
<p>纹理存储器的使用</p>
<ol>
<li>声明CUDA数组，分配空间</li>
<li>声明纹理参照系</li>
<li>设置运行时纹理参照系属性</li>
<li>纹理绑定</li>
<li>纹理拾取</li>
</ol>
<p>例：简单的纹理使用。</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/*
声明纹理参照系
texture&lt;Type, Dim, ReadMode&gt; texRef;
*/</span>
<span style="color: #666666;">//2D float texture</span>
texture<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">float</span>, <span style="color: #0000dd;">2</span>, cudaReadModeElementType<span style="color: #000080;">&gt;</span> texRef<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//设备端代码，一个简单的转换kernel</span>
__global__ <span style="color: #0000ff;">void</span> transformKernel<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> output, <span style="color: #0000ff;">int</span> width, <span style="color: #0000ff;">int</span> height, <span style="color: #0000ff;">float</span> theta<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">//计算归一化的纹理坐标</span>
	<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> blockIdx.<span style="color: #007788;">x</span> <span style="color: #000040;">*</span> blockDim.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span> threadIdx.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> y <span style="color: #000080;">=</span> blockIdx.<span style="color: #007788;">y</span> <span style="color: #000040;">*</span> blockDim.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span> threadIdx.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span> u <span style="color: #000080;">=</span> x <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>width<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span> v <span style="color: #000080;">=</span> y <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>height<span style="color: #008080;">;</span>
	<span style="color: #666666;">//坐标转换</span>
	u <span style="color: #000040;">-</span><span style="color: #000080;">=</span> <span style="color:#800080;">0.5f</span><span style="color: #008080;">;</span>
	v <span style="color: #000040;">-</span><span style="color: #000080;">=</span> <span style="color:#800080;">0.5f</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span> tu <span style="color: #000080;">=</span> u <span style="color: #000040;">*</span> cosf<span style="color: #008000;">&#40;</span>theta<span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> v <span style="color: #000040;">*</span> sinf<span style="color: #008000;">&#40;</span>theta<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color:#800080;">0.5f</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span> tv <span style="color: #000080;">=</span> v <span style="color: #000040;">*</span> cosf<span style="color: #008000;">&#40;</span>theta<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> u <span style="color: #000040;">*</span> sinf<span style="color: #008000;">&#40;</span>theta<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color:#800080;">0.5f</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//读纹理并向全局存储器写会</span>
	output<span style="color: #008000;">&#91;</span>y <span style="color: #000040;">*</span> width <span style="color: #000040;">+</span> x<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> tex2D<span style="color: #008000;">&#40;</span>tex, tu, tv<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #666666;">//主机端代码</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">//在先存上为CUDA array 分配空间</span>
	cudaChannelFormatDesc channelDesc <span style="color: #000080;">=</span> cudaCreatChannelDesc<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">32</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, cudaChannelFormatKindFloat<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	cudaArray<span style="color: #000040;">*</span> cuArray<span style="color: #008080;">;</span>
	cudaMallocArray<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>cuArray, <span style="color: #000040;">&amp;</span>channelDesc, width, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//内存中h_data地址处的数据向显存进行拷贝</span>
	cudaMemcpyToArray<span style="color: #008000;">&#40;</span>cuArray, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, h_data, size, cudaMemcpyHostToDevice<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//设置纹理参数</span>
	texRef.<span style="color: #007788;">addressMode</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> cudaAddressModeWrap<span style="color: #008080;">;</span>
	texRef.<span style="color: #007788;">addressMode</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> cudaAddressModeWrap<span style="color: #008080;">;</span>
	texRef.<span style="color: #007788;">filterMode</span> <span style="color: #000080;">=</span> cudaFilterModeLinear<span style="color: #008080;">;</span>
	texRef.<span style="color: #007788;">normalized</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//数组绑定到纹理</span>
	cudaBindTextureToArray<span style="color: #008000;">&#40;</span>texRef, cuArray, <span style="color: #000040;">&amp;</span>channelDesc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//问转换结果分配显存空间</span>
	<span style="color: #0000ff;">float</span><span style="color: #000040;">*</span> output<span style="color: #008080;">;</span>
	cudaMalloc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">**</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>output, width <span style="color: #000040;">*</span> height <span style="color: #000040;">*</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//启动 kernel</span>
	dim3 dimBlock<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">16</span>, <span style="color: #0000dd;">16</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	dim3 dimGrid<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>width <span style="color: #000040;">+</span> dimBlock.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> dimBlock.<span style="color: #007788;">x</span>, <span style="color: #008000;">&#40;</span>height <span style="color: #000040;">+</span> dimBlock.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> dimBlock.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	transformKernel<span style="color: #000080;">&lt;&lt;&lt;</span>dimGrid, dimBlock<span style="color: #000080;">&gt;&gt;&gt;</span><span style="color: #008000;">&#40;</span>output, width, height, angle<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">//释放显存空间</span>
	cudaFreeArray<span style="color: #008000;">&#40;</span>cuArray<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	cudaFree<span style="color: #008000;">&#40;</span>output<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.hapblue.com/?feed=rss2&#038;p=309</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

