Home | History | Annotate | Download | only in renderscript
      1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      2 <html xmlns="http://www.w3.org/1999/xhtml">
      3 <head>
      4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
      5 
      6 <title>/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh Source File</title>
      7 <link href="tabs.css" rel="stylesheet" type="text/css"/>
      8 <link href="doxygen.css" rel="stylesheet" type="text/css" />
      9 
     10 
     11 
     12 </head>
     13 <body>
     14 <div id="top"><!-- do not remove this div! -->
     15 
     16 
     17 <!-- Generated by Doxygen 1.7.5.1 -->
     18   <div id="navrow1" class="tabs">
     19     <ul class="tablist">
     20       <li><a href="index.html"><span>Overview</span></a></li>
     21       <li class="current"><a href="globals.html"><span>Globals</span></a></li>
     22       <li><a href="annotated.html"><span>Structs</span></a></li>
     23     </ul>
     24   </div>
     25 <div class="header">
     26   <div class="headertitle">
     27 <div class="title">/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh</div>  </div>
     28 </div>
     29 <div class="contents">
     30 <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>
     31 <a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2011 The Android Open Source Project</span>
     32 <a name="l00003"></a>00003 <span class="comment"> *</span>
     33 <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
     34 <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span>
     35 <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span>
     36 <a name="l00007"></a>00007 <span class="comment"> *</span>
     37 <a name="l00008"></a>00008 <span class="comment"> *      http://www.apache.org/licenses/LICENSE-2.0</span>
     38 <a name="l00009"></a>00009 <span class="comment"> *</span>
     39 <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span>
     40 <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
     41 <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
     42 <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span>
     43 <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span>
     44 <a name="l00015"></a>00015 <span class="comment"> */</span>
     45 <a name="l00016"></a>00016 
     46 <a name="l00024"></a>00024 <span class="preprocessor">#ifndef __RS_MATH_RSH__</span>
     47 <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define __RS_MATH_RSH__</span>
     48 <a name="l00026"></a>00026 <span class="preprocessor"></span>
     49 <a name="l00027"></a>00027 
     50 <a name="l00031"></a>00031 <span class="keyword">extern</span> <span class="keywordtype">int</span> __attribute__((overloadable))
     51 <a name="l00032"></a>00032     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">int</span> max_value);
     52 <a name="l00036"></a>00036 extern <span class="keywordtype">int</span> __attribute__((overloadable))
     53 <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);
     54 <a name="l00041"></a>00041 extern <span class="keywordtype">float</span> __attribute__((overloadable))
     55 <a name="l00042"></a>00042     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">float</span> max_value);
     56 <a name="l00046"></a>00046 extern <span class="keywordtype">float</span> __attribute__((overloadable))
     57 <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);
     58 <a name="l00048"></a>00048 
     59 <a name="l00052"></a>00052 extern <span class="keywordtype">float</span> __attribute__((overloadable))
     60 <a name="l00053"></a>00053     <a class="code" href="rs__math_8rsh.html#ac4f127e78da0849321c7f6db14f9e989">rsFrac</a>(<span class="keywordtype">float</span>);
     61 <a name="l00054"></a>00054 
     62 <a name="l00055"></a>00055 
     63 <a name="l00057"></a>00057 <span class="comment">// int ops</span>
     64 <a name="l00059"></a>00059 <span class="comment"></span>
     65 <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);
     66 <a name="l00068"></a>00068 
     67 <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);
     68 <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);
     69 <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);
     70 <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);
     71 <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);
     72 <a name="l00089"></a>00089 
     73 <a name="l00090"></a>00090 
     74 <a name="l00101"></a>00101 __inline__ static <span class="keywordtype">void</span> __attribute__((overloadable, always_inline))
     75 <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,
     76 <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,
     77 <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,
     78 <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) {
     79 <a name="l00106"></a>00106     <span class="comment">// x y z w = a b c d in the plane equation</span>
     80 <a name="l00107"></a>00107     left-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[0];
     81 <a name="l00108"></a>00108     left-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[4];
     82 <a name="l00109"></a>00109     left-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[8];
     83 <a name="l00110"></a>00110     left-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[12];
     84 <a name="l00111"></a>00111 
     85 <a name="l00112"></a>00112     right-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[0];
     86 <a name="l00113"></a>00113     right-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[4];
     87 <a name="l00114"></a>00114     right-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[8];
     88 <a name="l00115"></a>00115     right-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[12];
     89 <a name="l00116"></a>00116 
     90 <a name="l00117"></a>00117     top-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[1];
     91 <a name="l00118"></a>00118     top-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[5];
     92 <a name="l00119"></a>00119     top-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[9];
     93 <a name="l00120"></a>00120     top-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[13];
     94 <a name="l00121"></a>00121 
     95 <a name="l00122"></a>00122     bottom-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[1];
     96 <a name="l00123"></a>00123     bottom-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[5];
     97 <a name="l00124"></a>00124     bottom-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[9];
     98 <a name="l00125"></a>00125     bottom-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[13];
     99 <a name="l00126"></a>00126 
    100 <a name="l00127"></a>00127     near-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[2];
    101 <a name="l00128"></a>00128     near-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[6];
    102 <a name="l00129"></a>00129     near-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[10];
    103 <a name="l00130"></a>00130     near-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[14];
    104 <a name="l00131"></a>00131 
    105 <a name="l00132"></a>00132     far-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[2];
    106 <a name="l00133"></a>00133     far-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[6];
    107 <a name="l00134"></a>00134     far-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[10];
    108 <a name="l00135"></a>00135     far-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[14];
    109 <a name="l00136"></a>00136 
    110 <a name="l00137"></a>00137     <span class="keywordtype">float</span> len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(left-&gt;xyz);
    111 <a name="l00138"></a>00138     *left /= len;
    112 <a name="l00139"></a>00139     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(right-&gt;xyz);
    113 <a name="l00140"></a>00140     *right /= len;
    114 <a name="l00141"></a>00141     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(top-&gt;xyz);
    115 <a name="l00142"></a>00142     *top /= len;
    116 <a name="l00143"></a>00143     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(bottom-&gt;xyz);
    117 <a name="l00144"></a>00144     *bottom /= len;
    118 <a name="l00145"></a>00145     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(near-&gt;xyz);
    119 <a name="l00146"></a>00146     *near /= len;
    120 <a name="l00147"></a>00147     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(far-&gt;xyz);
    121 <a name="l00148"></a>00148     *far /= len;
    122 <a name="l00149"></a>00149 }
    123 <a name="l00150"></a>00150 
    124 <a name="l00161"></a>00161 __inline__ <span class="keyword">static</span> <span class="keywordtype">bool</span> __attribute__((overloadable, always_inline))
    125 <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,
    126 <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,
    127 <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,
    128 <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) {
    129 <a name="l00166"></a>00166 
    130 <a name="l00167"></a>00167     <span class="keywordtype">float</span> distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(left-&gt;xyz, sphere-&gt;xyz) + left-&gt;w;
    131 <a name="l00168"></a>00168     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    132 <a name="l00169"></a>00169         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    133 <a name="l00170"></a>00170     }
    134 <a name="l00171"></a>00171     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(right-&gt;xyz, sphere-&gt;xyz) + right-&gt;w;
    135 <a name="l00172"></a>00172     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    136 <a name="l00173"></a>00173         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    137 <a name="l00174"></a>00174     }
    138 <a name="l00175"></a>00175     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(top-&gt;xyz, sphere-&gt;xyz) + top-&gt;w;
    139 <a name="l00176"></a>00176     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    140 <a name="l00177"></a>00177         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    141 <a name="l00178"></a>00178     }
    142 <a name="l00179"></a>00179     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(bottom-&gt;xyz, sphere-&gt;xyz) + bottom-&gt;w;
    143 <a name="l00180"></a>00180     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    144 <a name="l00181"></a>00181         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    145 <a name="l00182"></a>00182     }
    146 <a name="l00183"></a>00183     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(near-&gt;xyz, sphere-&gt;xyz) + near-&gt;w;
    147 <a name="l00184"></a>00184     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    148 <a name="l00185"></a>00185         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    149 <a name="l00186"></a>00186     }
    150 <a name="l00187"></a>00187     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(far-&gt;xyz, sphere-&gt;xyz) + far-&gt;w;
    151 <a name="l00188"></a>00188     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
    152 <a name="l00189"></a>00189         <span class="keywordflow">return</span> <span class="keyword">false</span>;
    153 <a name="l00190"></a>00190     }
    154 <a name="l00191"></a>00191     <span class="keywordflow">return</span> <span class="keyword">true</span>;
    155 <a name="l00192"></a>00192 }
    156 <a name="l00193"></a>00193 
    157 <a name="l00194"></a>00194 
    158 <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);
    159 <a name="l00206"></a>00206 
    160 <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);
    161 <a name="l00218"></a>00218 
    162 <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);
    163 <a name="l00228"></a>00228 
    164 <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);
    165 <a name="l00237"></a>00237 
    166 <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);
    167 <a name="l00246"></a>00246 
    168 <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);
    169 <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);
    170 <a name="l00249"></a>00249 
    171 <a name="l00250"></a>00250 
    172 <a name="l00251"></a>00251 <span class="preprocessor">#endif</span>
    173 </pre></div></div>
    174 </div>
    175 
    176 </body>
    177 </html>
    178