1<HTML> 2<BODY> 3<p>The Renderscript rendering and computational APIs offer a low-level, high performance means of 4carrying out mathematical calculations and 3D graphics rendering. An example of Renderscript in 5applications include the 3D carousel view that is present in Android 3.0 applications such as the 6Books and YouTube applications. This API is intended for developers who are comfortable working with 7native code and want to maximize their performance critical applications.</p> 8 9<p>Renderscript adopts a control and slave architecture where the low-level native code is controlled by the 10higher level Android system that runs in the virtual machine (VM). The VM code handles resource 11allocation and lifecycle management of the Renderscript enabled application and calls the Renderscript 12code through high level entry points. The Android build tools generate these entry points through reflection on 13the native Renderscript code, which you write in C (C99 standard). The Renderscript code 14does the intensive computation and returns the result back to the Android VM.</p> 15 16<p>You can find the Renderscript native 17APIs in the <code><sdk_root>/platforms/android-3.0/renderscript</code> directory. 18The Android system APIs are broken into a few main groups:</p> 19 20<h4>Core</h4> 21<p>These classes are used internally by the system for memory allocation. They are used by the classes that 22are generated by the build tools:</p> 23<ul> 24 <li>Allocation</li> 25 <li>Element</li> 26 <li>Type</li> 27 <li>Script</li> 28</ul> 29 30 31<h4>Data Types</h4> 32<p>These data types are used by the classes that are generated 33by the build tools. They are the reflected counterparts of the native data types that 34are defined by the native Renderscript APIs and used by your Renderscript code. The 35classes include:</p> 36<ul> 37 <li>Byte2, Byte3, and Byte4</li> 38 <li>Float2, Float3, Float4</li> 39 <li>Int2, Int3, Int4</li> 40 <li>Long2, Long3, Long4</li> 41 <li>Matrix2f, Matrix3f, Matrix4f</li> 42 <li>Short2, Short3, Short4</li> 43</ul> 44 45<p>For example, if you declared the following struct in your .rs Renderscript file:</p> 46 47<pre>struct Hello { float3 position; rs_matrix4x4 transform; }</pre> 48 49<p>The build tools generate a class through reflection that looks like the following:</p> 50<pre> 51class Hello { 52 static public class Item { 53 Float4 position; 54 Matrix4f transform; 55 } 56Element createElement(RenderScript rs) { 57 Element.Builder eb = new Element.Builder(rs); 58 eb.add(Element.F32_3(rs), "position"); 59 eb.add(Element.MATRIX_4X4(rs), "transform"); 60 return eb.create(); 61 } 62} 63</pre> 64 65<h4>Graphics</h4> 66<p>These classes are specific to graphics Renderscripts and support a typical rendering 67pipeline.</p> 68<ul> 69<li>Mesh</li> 70<li>ProgramFragment</li> 71<li>ProgramRaster</li> 72<li>ProgramStore</li> 73<li>ProgramVertex</li> 74<li>RSSurfaceView</li> 75<li>Sampler</li> 76</ul> 77 78</p> 79<p> 80For information on how to create an application that uses Renderscript, and also the 81see <a href="../../../guide/topics/graphics/renderscript.html">3D with 82Renderscript</a> dev guide. 83</p> 84</BODY> 85</HTML> 86