Example codes of RenderScript

Introduction

Example code and documents about RenderScript.

Documents

API Specification * rs_graphics * rs_core * rs_math * rs_time

Examples

  • Gravity
  • PageCurl
  • Carousel

Examples of Other sites

  • CarouselView – CarouselView(3D) example code like Google Music

DOWNLOAD SOURCE

Introduction

Carousel is a example of carousel view like Youtube application on Android tablet.

Demo Video

Introduction

API specification of rs_graphics.rsh

Details

Binding Program | Function | Description | |:————-|:—————-| | rsgBindProgramFragment(rs_program_fragment pf); | Bind the program fragment. | | rsgBindProgramStore(rs_program_store ps); | Bind the program store. | | rsgBindProgramVertex(rs_program_vertex pv); | Bind the program vertex. | | rsgBindProgramRaster(rs_program_raster pr); | Bind the program raster. | | rsgBindSampler(rs_program_fragment, uint slot, rs_sampler); | Bind the program sampler. | | rsgBindTexture(rs_program_fragment, uint slot, rs_allocation); | Bind the texture data. |

Load Matrix

Function Description rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 ); Load vertex matrix as projection matrix. rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 ); Load vertex matrix as model matrix. rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 ); Load vertex matrix as texure matrix. rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 ); Get the Projection vertex matrix.

Set constant color

Function Description rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a); Set the constant color for a fixed function emulation program.

Get surface size

Function Description rsgGetWidth(void); Get the width of the current rendering surface. rsgGetHeight(void); Get the height of the current rendering surface.

Sync memory buffer

Function Description rsgAllocationSyncAll(rs_allocation alloc); Sync the contents of an allocation from its SCRIPT memory space to its HW memory spaces.

Drawing/Graphics

Function Description rsgDrawRect(float x1, float y1, float x2, float y2, float z); Low performance utility function for drawing a simple rectangle.
Not intended for drawing large quantities of geometry. rsgDrawQuad(float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3,
float x4, float y4, float z4); Low performance utility function for drawing a simple quad.
Not intended for drawing large quantities of geometry. rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h); Low performance function for drawing rectangles in screenspace.
This function uses the default passthough ProgramVertex.
Any bound ProgramVertex is ignored.
This function has considerable overhead and should not be used for drawing in shipping applications. rsgDrawMesh(rs_mesh ism);
rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len); Draw a mesh of geometry using the current context state.
The whole mesh is rendered. rsgClearColor(float r, float g, float b, float a); Clears the rendering surface to the specified color. rsgClearDepth(float value); Clears the depth suface to the specified value.

Drawing/Text

Function Description rsgDrawText(const char *, int x, int y);
rsgDrawText(rs_allocation, int x, int y); Draw text string. rsgBindFont(rs_font); Set the text font. rsgFontColor(float r, float g, float b, float a); Set the text color. rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom); Returns the bounding box of the text relative to (0, 0).
Any of left, right, top, bottom could be NULL

Misc Function Description rsgMeshComputeBoundingBox(rs_mesh mesh, float minX, float minY, float minZ,
float 
maxX, float maxY, float maxZ);
rsgMeshComputeBoundingBox(rs_mesh mesh, float3 bBoxMin, float3 bBoxMax) {
float x1, y1, z1, x2, y2, z2;
rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
bBoxMin->x = x1;
bBoxMin->y = y1;
bBoxMin->z = z1;
bBoxMax->x = x2;
bBoxMax->y = y2;
bBoxMax->z = z2;
}