to top
Android APIs
Since: API Level 11
package

android.renderscript

The Renderscript rendering and computational APIs offer a low-level, high performance means of carrying out mathematical calculations and 3D graphics rendering.

For more information, see the Renderscript developer guide.

An example of Renderscript in applications include the 3D carousel view that is present in Android 3.0 applications such as the Books and YouTube applications. This API is intended for developers who are comfortable working with native code and want to maximize their performance critical applications.

Renderscript adopts a control and slave architecture where the low-level native code is controlled by the higher level Android system that runs in the virtual machine (VM). The VM code handles resource allocation and lifecycle management of the Renderscript enabled application and calls the Renderscript code through high level entry points. The Android build tools generate these entry points through reflection on the native Renderscript code, which you write in C (C99 standard). The Renderscript code does the intensive computation and returns the result back to the Android VM.

You can find the Renderscript native APIs in the <sdk_root>/platforms/android-11/renderscript directory. The Android system APIs are broken into a few main groups:

Core

These classes are used internally by the system for memory allocation. They are used by the classes that are generated by the build tools:

  • Allocation
  • Element
  • Type
  • Script

Data Types

These data types are used by the classes that are generated by the build tools. They are the reflected counterparts of the native data types that are defined by the native Renderscript APIs and used by your Renderscript code. The classes include:

  • Byte2, Byte3, and Byte4
  • Float2, Float3, Float4
  • Int2, Int3, Int4
  • Long2, Long3, Long4
  • Matrix2f, Matrix3f, Matrix4f
  • Short2, Short3, Short4

For example, if you declared the following struct in your .rs Renderscript file:

struct Hello { float3 position; rs_matrix4x4 transform; }

The build tools generate a class through reflection that looks like the following:

class Hello {
    static public class Item {
        Float4 position;
        Matrix4f transform;
    }
Element createElement(RenderScript rs) {
        Element.Builder eb = new Element.Builder(rs);
        eb.add(Element.F32_3(rs), "position");
        eb.add(Element.MATRIX_4X4(rs), "transform");
        return eb.create();
    }
}

Graphics

These classes are specific to graphics Renderscripts and support a typical rendering pipeline.

  • Mesh
  • ProgramFragment
  • ProgramRaster
  • ProgramStore
  • ProgramVertex
  • RSSurfaceView
  • Sampler

Classes

Allocation

Memory allocation class for renderscript. 

AllocationAdapter  
BaseObj BaseObj is the base class for interfacing with native renderscript objects. 
Byte2 Class for exposing the native Renderscript byte2 type back to the Android system. 
Byte3 Class for exposing the native Renderscript byte3 type back to the Android system. 
Byte4 Class for exposing the native Renderscript byte4 type back to the Android system. 
Double2 Class for exposing the native Renderscript double2 type back to the Android system. 
Double3 Class for exposing the native Renderscript double3 type back to the Android system. 
Double4 Class for exposing the native Renderscript double4 type back to the Android system. 
Element

The most basic data type. 

Element.Builder Builder class for producing complex elements with matching field and name pairs. 
FieldPacker Utility class for packing arguments and structures from Android system objects to Renderscript objects. 
FileA3D This class is deprecated. in API 16 FileA3D allows users to load Renderscript objects from files or resources stored on disk. It could be used to load items such as 3D geometry data converted to a Renderscript format from content creation tools. Currently only meshes are supported in FileA3D. When successfully loaded, FileA3D will contain a list of index entries for all the objects stored inside it.  
FileA3D.IndexEntry This class is deprecated. in API 16 IndexEntry contains information about one of the Renderscript objects inside the file's index. It could be used to query the object's type and also name and load the object itself if necessary.  
Float2 Class for exposing the native Renderscript float2 type back to the Android system. 
Float3 Class for exposing the native Renderscript float2 type back to the Android system. 
Float4 Class for exposing the native Renderscript float2 type back to the Android system. 
Font This class is deprecated. in API 16

This class gives users a simple way to draw hardware accelerated text. Internally, the glyphs are rendered using the Freetype library and an internal cache of rendered glyph bitmaps is maintained. Each font object represents a combination of a typeface, and point size. You can create multiple font objects to represent styles such as bold or italic text, faces, and different font sizes. During creation, the Android system quieries device's screen DPI to ensure proper sizing across multiple device configurations.

Fonts are rendered using screen-space positions and no state setup beyond binding a font to the Renderscript is required. A note of caution on performance, though the state changes are transparent to the user, they do happen internally, and it is more efficient to render large batches of text in sequence. It is also more efficient to render multiple characters at once instead of one by one to improve draw call batching.

Font color and transparency are not part of the font object and you can freely modify them in the script to suit the user's rendering needs. Font colors work as a state machine. Every new call to draw text uses the last color set in the script.

 
Int2 Class for exposing the native Renderscript int2 type back to the Android system. 
Int3 Class for exposing the native Renderscript int3 type back to the Android system. 
Int4 Class for exposing the native Renderscript int4 type back to the Android system. 
Long2 Class for exposing the native Renderscript long2 type back to the Android system. 
Long3 Class for exposing the native Renderscript long3 type back to the Android system. 
Long4 Class for exposing the native Renderscript long4 type back to the Android system. 
Matrix2f Class for exposing the native Renderscript rs_matrix2x2 type back to the Android system. 
Matrix3f Class for exposing the native Renderscript rs_matrix3x3 type back to the Android system. 
Matrix4f Class for exposing the native Renderscript rs_matrix4x4 type back to the Android system. 
Mesh This class is deprecated. in API 16

This class is a container for geometric data displayed with Renderscript. Internally, a mesh is a collection of allocations that represent vertex data (positions, normals, texture coordinates) and index data such as triangles and lines.

Vertex data could either be interleaved within one allocation that is provided separately, as multiple allocation objects, or done as a combination of both. When a vertex channel name matches an input in the vertex program, Renderscript automatically connects the two together.

Parts of the mesh can be rendered with either explicit index sets or primitive types.

 
Mesh.AllocationBuilder This class is deprecated. in API 16 Mesh builder object. It starts empty and requires the user to add all the vertex and index allocations that comprise the mesh  
Mesh.Builder This class is deprecated. in API 16 Mesh builder object. It starts empty and requires you to add the types necessary to create vertex and index allocations.  
Mesh.TriangleMeshBuilder This class is deprecated. in API 16 Builder that allows creation of a mesh object point by point and triangle by triangle  
Program Program is a base class for all the objects that modify various stages of the graphics pipeline  
Program.BaseProgramBuilder  
ProgramFragment This class is deprecated. in API 16

The Renderscript fragment program, also known as fragment shader is responsible for manipulating pixel data in a user defined way. It's constructed from a GLSL shader string containing the program body, textures inputs, and a Type object that describes the constants used by the program. Similar to the vertex programs, when an allocation with constant input values is bound to the shader, its values are sent to the graphics program automatically.

The values inside the allocation are not explicitly tracked. If they change between two draw calls using the same program object, the runtime needs to be notified of that change by calling rsgAllocationSyncAll so it could send the new values to hardware. Communication between the vertex and fragment programs is handled internally in the GLSL code. For example, if the fragment program is expecting a varying input called varTex0, the GLSL code inside the program vertex must provide it.

 
ProgramFragment.Builder This class is deprecated. in API 16  
ProgramFragmentFixedFunction This class is deprecated. in API 16

ProgramFragmentFixedFunction is a helper class that provides a way to make a simple fragment shader without writing any GLSL code. This class allows for display of constant color, interpolated color from the vertex shader, or combinations of the both blended with results of up to two texture lookups.

 
ProgramFragmentFixedFunction.Builder This class is deprecated. in API 16  
ProgramRaster This class is deprecated. in API 16 Program raster is primarily used to specify whether point sprites are enabled and to control the culling mode. By default, back faces are culled.  
ProgramRaster.Builder This class is deprecated. in API 16  
ProgramStore

ProgramStore contains a set of parameters that control how the graphics hardware handles writes to the framebuffer. 

ProgramStore.Builder Builder class for ProgramStore object. 
ProgramVertex This class is deprecated. in API 16 ProgramVertex, also know as a vertex shader, describes a stage in the graphics pipeline responsible for manipulating geometric data in a user-defined way.  
ProgramVertex.Builder This class is deprecated. in API 16 Builder class for creating ProgramVertex objects. The builder starts empty and the user must minimally provide the GLSL shader code, and the varying inputs. Constant, or uniform parameters to the shader may optionally be provided as well.  
ProgramVertexFixedFunction This class is deprecated. in API 16 ProgramVertexFixedFunction is a helper class that provides a simple way to create a fixed function emulation vertex shader without writing any GLSL code.  
ProgramVertexFixedFunction.Builder This class is deprecated. in API 16  
ProgramVertexFixedFunction.Constants This class is deprecated. in API 16 Helper class to store modelview, projection and texture matrices for ProgramVertexFixedFunction  
RenderScript Renderscript base master class. 
RenderScript.RSErrorHandler Runtime error base class. 
RenderScript.RSMessageHandler Base class application should derive from for handling RS messages coming from their scripts. 
RenderScriptGL This class is deprecated. in API 16 The Graphics derivitive of Renderscript. Extends the basic context to add a root script which is the display window for graphical output. When the system needs to update the display the currently bound root script will be called. This script is expected to issue the rendering commands to repaint the screen.

Developer Guides

For more information about creating an application that uses Renderscript, read the Renderscript developer guide.

 
RenderScriptGL.SurfaceConfig This class is deprecated. in API 16 Class which is used to describe a pixel format for a graphical buffer. This is used to describe the intended format of the display surface. The configuration is described by pairs of minimum and preferred bit depths for each component within the config and additional structural information.  
RSSurfaceView This class is deprecated. in API 16 The Surface View for a graphics renderscript (RenderScriptGL) to draw on.

Developer Guides

For more information about creating an application that uses Renderscript, read the Renderscript developer guide.

 
RSTextureView This class is deprecated. in API 16 The Texture View for a graphics renderscript (RenderScriptGL) to draw on.  
Sampler Sampler object which defines how data is extracted from textures. 
Sampler.Builder Builder for creating non-standard samplers. 
Script  
Script.Builder  
Script.FieldBase  
ScriptC  
Short2 Class for exposing the native Renderscript Short2 type back to the Android system. 
Short3 Class for exposing the native Renderscript short3 type back to the Android system. 
Short4 Class for exposing the native Renderscript short4 type back to the Android system. 
Type

Type is an allocation template. 

Type.Builder Builder class for Type. 

Enums

Allocation.MipmapControl Controls mipmap behavior when using the bitmap creation and update functions. 
Element.DataKind The special interpretation of the data if required. 
Element.DataType DataType represents the basic type information for a basic element. 
FileA3D.EntryType This enum is deprecated. in API 16 Specifies what renderscript object type is contained within the FileA3D IndexEntry  
Font.Style This enum is deprecated. in API 16  
Mesh.Primitive This enum is deprecated. in API 16 Describes the way mesh vertex data is interpreted when rendering  
Program.TextureType TextureType specifies what textures are attached to Program objects  
ProgramFragmentFixedFunction.Builder.EnvMode This enum is deprecated. in API 16 EnvMode describes how textures are combined with the existing color in the fixed function fragment shader  
ProgramFragmentFixedFunction.Builder.Format This enum is deprecated. in API 16 Format describes the pixel format of textures in the fixed function fragment shader and how they are sampled  
ProgramRaster.CullMode This enum is deprecated. in API 16  
ProgramStore.BlendDstFunc Specifies the functions used to combine incoming pixels with those already in the frame buffer. 
ProgramStore.BlendSrcFunc Specifies the functions used to combine incoming pixels with those already in the frame buffer. 
ProgramStore.DepthFunc Specifies the function used to determine whether a fragment will be drawn during the depth testing stage in the rendering pipeline by comparing its value with that already in the depth buffer. 
RenderScript.Priority RenderScript worker threads priority enumeration. 
Sampler.Value  
Type.CubemapFace  

Exceptions

RSDriverException Base class for all exceptions thrown by the Android Renderscript  
RSIllegalArgumentException Base class for all exceptions thrown by the Android Renderscript  
RSInvalidStateException Base class for all exceptions thrown by the Android Renderscript  
RSRuntimeException Base class for all exceptions thrown by the Android Renderscript