Peter_vdL

Introduction to Renderscript

by Peter_vdL Motorola 02-27-2011 06:08 PM - edited 03-13-2011 07:30 PM

Many, if not most, of the new features of Honeycomb (Android 3.0, API level 11) relate to UI changes to accommodate the android:xlargeScreen of a tablet.   But there's one very interesting new feature, that has little to do with screen size, and everything to do with graphics performance.  Step into the spotlight, Renderscript!

[The second installment, Renderscript Part II, can be found here]

 

A Description of Renderscript

There isn't a wealth of information on Renderscript yet.  There's an Android developer blogpost "Introducing Renderscript" here, and some notes in the Graphics section of the developer docs here.   And there are five sample Renderscript programs accompanying the Honeycomb SDK.  We'll walk through one of these programs soon enough, but let's start by outlining Google's description of Renderscript. The blog linked above says that Renderscript is

  1. a new high performance 3D graphics API
  2. currently used in live wallpaper and in the Android Youtube and Book apps, and 
  3. now being made public with Honeycomb
Google's developer, R. Jason Sams, goes on to explain that Renderscript provides
  • a rendering API for a set of 3D features that are easily hardware-accelerated
  • a computing API that is geared to operations that GPUs implement
  • a C-based scripting language for programmers to specify the computing and rendering operations.

Computing and rendering are the two big critical parts of graphic operations.  "Computing" is calculating the trajectories of all the points that make up your moving object, to fix where they have moved to.  "Rendering" is painting those points and the texture surfaces draped over them, onto the screen.  Sams is explaining that Renderscript is a scripting language offering a thin API, that covers the computing and rendering operations most commonly done in hardware.  The more familiar you are with low level graphics hardware primitives, the easier you will find it to get started with Renderscript.

 

All About Performance

Google is saying clearly here that Renderscript is meant for programmers who want the maximum graphics performance, and are willing to "program down to the silicon" to achieve it.   Well, maybe not all the way down to the nand and nor gates, but certainly it's for programmers who are willing learn a new language, Renderscript, to get faster graphics performance.

Since Renderscript is geared to real hardware, you won't see Renderscript code running in the emulator.  If you want try developing some Renderscript for yourself, you will have to use a device that runs Honeycomb.  At the time of writing (Februrary 2011) the only device on the market running Honeycomb is the Motorola XOOM.  So that's another reason for you to ask your manager to get you a XOOM - staying current with the latest graphics performance technology.

Walk through the Code
Maybe it's time for that code walk-through.  We'll do this in two parts.   The first part will be importing, compiling, and running the sample code from the Honeycomb SDK. The second part (in a second blog post) will be a review of the source files, and an explanation of what a Renderscript app is composed of.

If you look at the samples/android-11 folder of your Android SDK, you'll see the 30-odd sample programs provided for Honeycomb.  You can easily import any of these into MOTODEV Studio by selecting File > New > Android Project for Studio.   Here's what the dialog looks like in MOTODEV Studio (it's similar in Eclipse). 
screen.png

Now you can provide a project name (for sanity and simplicity, use the same name as the sample), click API level 11, and click the radio button labeled "Create project from existing source".  Browse to the sample program that you want, and click Finish.  Studio or Eclipse will smoothly import the source files from the SDK samples, and make an Eclipse project out of them.

Build and Run
After you've brought the sample code into MOTODEV Studio or Eclipse, the default settings cause new projects to build automatically.  Then highlight the project, connect a XOOM tablet via USB cable, and "Run as Android Application" as usual.  For the Renderscript Fountain sample code, this screen snapshot shows the results.  Wherever you touch the screen, a ball (fountain) of droplets appears, and cascades down to the bottom.  The screen snapshot is so large because the XOOM has a WXGA 1280 x 800 display.  All that room on the screen!

rsFount2.png

(The "raster-y squares" icon at the top left of the screen, and the word "Fountain" is a new Honeycomb feature, highlighting which app is running, or what the app is doing). 

There's an even simpler Renderscript app, that paints "Hello world" wherever you touch the screen.  Read the next installment (coming in a few days) for an analysis of the source files that make up a Renderscript app.  In the meantime, I hope to meet you at the San Francisco XOOM meetup on Tuesday March 1, 6:30-9pm.

Cheers,

 

Peter van der Linden

Android Technology Evangelist

Comments
by JHandal7(anon) on 02-28-2011 10:07 AM

 

Hi Peter,

 

Great tutorial,about the fountain is someway to tested in the emulator?

 

I've a opengles 1.1 3D game running Froyo ,it's a plane fying between obstacles.

 

I need some advivce about rewriting it using Renderscript,.

 

THX

 

 

 

 

 

by Peter_vdL Motorola on 02-28-2011 02:46 PM

Hi JH,

 

Thanks for your feedback.

 

Alas, I don't see any way to run renderscript code on the emulator.   It's the same situation as with sensors, such as the accelerometer and the magnetometer.   You cannot emulate the use and operation of those sensors, by running code in the emulator, because they require the participation of actual hardware to work.

 

So right now, it's the XOOM or nothing, if you want to try Renderscript.   On the plus side - by engaging now, you will be right at the forefront of an emerging new high performance graphics technology!

 

   Peter

Post a Comment
Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
reCAPTCHA challenge image
Type the characters you see in the picture above.Type the words you hear.
About MOTODEV Blog
The MOTODEV blog keeps you updated on mobile app development news from MOTODEV and the Android developer community.

Subscribe to our RSS feed Subscribe via RSS

Follow Us:
Fan MOTODEV on Facebook Join the MOTODEV LinkedIn Group MOTODEV on YouTube

motodev profile

motodev Very interesting info about using StackMob & force.com tools 2 migrate legacy systems to cloud & mobile. moto.ly/l2cloud 7 days ago · reply · retweet · favorite

motodev profile

motodev At #AppsForChange today in SF helping non-profits build & market apps. are u a non-profit w/ a great mobile app? share with us a link. 6 days ago · reply · retweet · favorite

motodev profile

motodev for those that missed our Google+ Hangout on cloud & mobile you can watch it on the MOTODEV blog @ ow.ly/cRqod #l2cloud 6 days ago · reply · retweet · favorite

Our Blog & Comment Policy
Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Motorola. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Motorola or any other party.

Remember, when you comment, please stay on topic and avoid spam, profanity, and anything else that violates our user guidelines. All comments require approval by Motorola and can be rejected for any reason.

For customer support issues with your Motorola phone go to the Motorola customer support website.