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