| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| |
| <title>/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh Source File</title> |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| |
| |
| |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div! --> |
| |
| |
| <!-- Generated by Doxygen 1.7.5.1 --> |
| <div id="navrow1" class="tabs"> |
| <ul class="tablist"> |
| <li><a href="index.html"><span>Overview</span></a></li> |
| <li class="current"><a href="globals.html"><span>Globals</span></a></li> |
| <li><a href="annotated.html"><span>Structs</span></a></li> |
| </ul> |
| </div> |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh</div> </div> |
| </div> |
| <div class="contents"> |
| <a href="rs__math_8rsh.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> |
| <a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2011 The Android Open Source Project</span> |
| <a name="l00003"></a>00003 <span class="comment"> *</span> |
| <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> |
| <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> |
| <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> |
| <a name="l00007"></a>00007 <span class="comment"> *</span> |
| <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> |
| <a name="l00009"></a>00009 <span class="comment"> *</span> |
| <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> |
| <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> |
| <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> |
| <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> |
| <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> |
| <a name="l00015"></a>00015 <span class="comment"> */</span> |
| <a name="l00016"></a>00016 |
| <a name="l00024"></a>00024 <span class="preprocessor">#ifndef __RS_MATH_RSH__</span> |
| <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define __RS_MATH_RSH__</span> |
| <a name="l00026"></a>00026 <span class="preprocessor"></span> |
| <a name="l00027"></a>00027 |
| <a name="l00031"></a>00031 <span class="keyword">extern</span> <span class="keywordtype">int</span> __attribute__((overloadable)) |
| <a name="l00032"></a>00032 <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">int</span> max_value); |
| <a name="l00036"></a>00036 extern <span class="keywordtype">int</span> __attribute__((overloadable)) |
| <a name="l00037"></a>00037 <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">int</span> min_value, <span class="keywordtype">int</span> max_value); |
| <a name="l00041"></a>00041 extern <span class="keywordtype">float</span> __attribute__((overloadable)) |
| <a name="l00042"></a>00042 <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">float</span> max_value); |
| <a name="l00046"></a>00046 extern <span class="keywordtype">float</span> __attribute__((overloadable)) |
| <a name="l00047"></a>00047 <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">float</span> min_value, <span class="keywordtype">float</span> max_value); |
| <a name="l00048"></a>00048 |
| <a name="l00052"></a>00052 extern <span class="keywordtype">float</span> __attribute__((overloadable)) |
| <a name="l00053"></a>00053 <a class="code" href="rs__math_8rsh.html#ac4f127e78da0849321c7f6db14f9e989">rsFrac</a>(<span class="keywordtype">float</span>); |
| <a name="l00054"></a>00054 |
| <a name="l00055"></a>00055 |
| <a name="l00057"></a>00057 <span class="comment">// int ops</span> |
| <a name="l00059"></a>00059 <span class="comment"></span> |
| <a name="l00067"></a>00067 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> amount, <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> low, <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> high); |
| <a name="l00068"></a>00068 |
| <a name="l00072"></a>00072 _RS_RUNTIME <span class="keywordtype">int</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">int</span> amount, <span class="keywordtype">int</span> low, <span class="keywordtype">int</span> high); |
| <a name="l00076"></a>00076 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> amount, <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> low, <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> high); |
| <a name="l00080"></a>00080 _RS_RUNTIME <span class="keywordtype">short</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">short</span> amount, <span class="keywordtype">short</span> low, <span class="keywordtype">short</span> high); |
| <a name="l00084"></a>00084 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> amount, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> low, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> high); |
| <a name="l00088"></a>00088 _RS_RUNTIME <span class="keywordtype">char</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">char</span> amount, <span class="keywordtype">char</span> low, <span class="keywordtype">char</span> high); |
| <a name="l00089"></a>00089 |
| <a name="l00090"></a>00090 |
| <a name="l00101"></a>00101 __inline__ static <span class="keywordtype">void</span> __attribute__((overloadable, always_inline)) |
| <a name="l00102"></a><a class="code" href="rs__math_8rsh.html#a191f9c687c56322c18b7d71491602122">00102</a> <a class="code" href="rs__math_8rsh.html#a191f9c687c56322c18b7d71491602122">rsExtractFrustumPlanes</a>(const <a class="code" href="structrs__matrix4x4.html" title="4x4 float matrix">rs_matrix4x4</a> *viewProj, |
| <a name="l00103"></a>00103 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *left, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *right, |
| <a name="l00104"></a>00104 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *top, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *bottom, |
| <a name="l00105"></a>00105 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *near, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *far) { |
| <a name="l00106"></a>00106 <span class="comment">// x y z w = a b c d in the plane equation</span> |
| <a name="l00107"></a>00107 left->x = viewProj->m[3] + viewProj->m[0]; |
| <a name="l00108"></a>00108 left->y = viewProj->m[7] + viewProj->m[4]; |
| <a name="l00109"></a>00109 left->z = viewProj->m[11] + viewProj->m[8]; |
| <a name="l00110"></a>00110 left->w = viewProj->m[15] + viewProj->m[12]; |
| <a name="l00111"></a>00111 |
| <a name="l00112"></a>00112 right->x = viewProj->m[3] - viewProj->m[0]; |
| <a name="l00113"></a>00113 right->y = viewProj->m[7] - viewProj->m[4]; |
| <a name="l00114"></a>00114 right->z = viewProj->m[11] - viewProj->m[8]; |
| <a name="l00115"></a>00115 right->w = viewProj->m[15] - viewProj->m[12]; |
| <a name="l00116"></a>00116 |
| <a name="l00117"></a>00117 top->x = viewProj->m[3] - viewProj->m[1]; |
| <a name="l00118"></a>00118 top->y = viewProj->m[7] - viewProj->m[5]; |
| <a name="l00119"></a>00119 top->z = viewProj->m[11] - viewProj->m[9]; |
| <a name="l00120"></a>00120 top->w = viewProj->m[15] - viewProj->m[13]; |
| <a name="l00121"></a>00121 |
| <a name="l00122"></a>00122 bottom->x = viewProj->m[3] + viewProj->m[1]; |
| <a name="l00123"></a>00123 bottom->y = viewProj->m[7] + viewProj->m[5]; |
| <a name="l00124"></a>00124 bottom->z = viewProj->m[11] + viewProj->m[9]; |
| <a name="l00125"></a>00125 bottom->w = viewProj->m[15] + viewProj->m[13]; |
| <a name="l00126"></a>00126 |
| <a name="l00127"></a>00127 near->x = viewProj->m[3] + viewProj->m[2]; |
| <a name="l00128"></a>00128 near->y = viewProj->m[7] + viewProj->m[6]; |
| <a name="l00129"></a>00129 near->z = viewProj->m[11] + viewProj->m[10]; |
| <a name="l00130"></a>00130 near->w = viewProj->m[15] + viewProj->m[14]; |
| <a name="l00131"></a>00131 |
| <a name="l00132"></a>00132 far->x = viewProj->m[3] - viewProj->m[2]; |
| <a name="l00133"></a>00133 far->y = viewProj->m[7] - viewProj->m[6]; |
| <a name="l00134"></a>00134 far->z = viewProj->m[11] - viewProj->m[10]; |
| <a name="l00135"></a>00135 far->w = viewProj->m[15] - viewProj->m[14]; |
| <a name="l00136"></a>00136 |
| <a name="l00137"></a>00137 <span class="keywordtype">float</span> len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(left->xyz); |
| <a name="l00138"></a>00138 *left /= len; |
| <a name="l00139"></a>00139 len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(right->xyz); |
| <a name="l00140"></a>00140 *right /= len; |
| <a name="l00141"></a>00141 len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(top->xyz); |
| <a name="l00142"></a>00142 *top /= len; |
| <a name="l00143"></a>00143 len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(bottom->xyz); |
| <a name="l00144"></a>00144 *bottom /= len; |
| <a name="l00145"></a>00145 len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(near->xyz); |
| <a name="l00146"></a>00146 *near /= len; |
| <a name="l00147"></a>00147 len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(far->xyz); |
| <a name="l00148"></a>00148 *far /= len; |
| <a name="l00149"></a>00149 } |
| <a name="l00150"></a>00150 |
| <a name="l00161"></a>00161 __inline__ <span class="keyword">static</span> <span class="keywordtype">bool</span> __attribute__((overloadable, always_inline)) |
| <a name="l00162"></a><a class="code" href="rs__math_8rsh.html#a7bbeaf44838e08e68d5cf3e3d7b0818c">00162</a> <a class="code" href="rs__math_8rsh.html#a7bbeaf44838e08e68d5cf3e3d7b0818c">rsIsSphereInFrustum</a>(<a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *sphere, |
| <a name="l00163"></a>00163 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *left, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *right, |
| <a name="l00164"></a>00164 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *top, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *bottom, |
| <a name="l00165"></a>00165 <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *near, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *far) { |
| <a name="l00166"></a>00166 |
| <a name="l00167"></a>00167 <span class="keywordtype">float</span> distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(left->xyz, sphere->xyz) + left->w; |
| <a name="l00168"></a>00168 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00169"></a>00169 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00170"></a>00170 } |
| <a name="l00171"></a>00171 distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(right->xyz, sphere->xyz) + right->w; |
| <a name="l00172"></a>00172 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00173"></a>00173 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00174"></a>00174 } |
| <a name="l00175"></a>00175 distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(top->xyz, sphere->xyz) + top->w; |
| <a name="l00176"></a>00176 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00177"></a>00177 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00178"></a>00178 } |
| <a name="l00179"></a>00179 distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(bottom->xyz, sphere->xyz) + bottom->w; |
| <a name="l00180"></a>00180 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00181"></a>00181 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00182"></a>00182 } |
| <a name="l00183"></a>00183 distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(near->xyz, sphere->xyz) + near->w; |
| <a name="l00184"></a>00184 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00185"></a>00185 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00186"></a>00186 } |
| <a name="l00187"></a>00187 distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(far->xyz, sphere->xyz) + far->w; |
| <a name="l00188"></a>00188 <span class="keywordflow">if</span> (distToCenter < -sphere->w) { |
| <a name="l00189"></a>00189 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
| <a name="l00190"></a>00190 } |
| <a name="l00191"></a>00191 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
| <a name="l00192"></a>00192 } |
| <a name="l00193"></a>00193 |
| <a name="l00194"></a>00194 |
| <a name="l00205"></a>00205 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<span class="keywordtype">float</span> r, <span class="keywordtype">float</span> g, <span class="keywordtype">float</span> b); |
| <a name="l00206"></a>00206 |
| <a name="l00217"></a>00217 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<span class="keywordtype">float</span> r, <span class="keywordtype">float</span> g, <span class="keywordtype">float</span> b, <span class="keywordtype">float</span> a); |
| <a name="l00218"></a>00218 |
| <a name="l00227"></a>00227 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<a class="code" href="rs__types_8rsh.html#a0046fa0f208d0899adbcf1f8b5aafadd">float3</a> color); |
| <a name="l00228"></a>00228 |
| <a name="l00236"></a>00236 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> color); |
| <a name="l00237"></a>00237 |
| <a name="l00245"></a>00245 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> <a class="code" href="rs__math_8rsh.html#a48bb0c2e7b1f2b62b2a8970c7d709eca">rsUnpackColor8888</a>(<a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> c); |
| <a name="l00246"></a>00246 |
| <a name="l00247"></a>00247 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) rsYuvToRGBA_uchar4(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> y, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> u, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> v); |
| <a name="l00248"></a>00248 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> __attribute__((overloadable)) rsYuvToRGBA_float4(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> y, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> u, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> v); |
| <a name="l00249"></a>00249 |
| <a name="l00250"></a>00250 |
| <a name="l00251"></a>00251 <span class="preprocessor">#endif</span> |
| </pre></div></div> |
| </div> |
| |
| </body> |
| </html> |