This Android OpenGL ES 3.0 Sample was written by Cristiano Ferreira - Software Engineer at Intel Corporation.
By batch-rendering multiple versions of the same mesh, instanced rendering can help developers using OpenGL* ES 3.0 and later dramatically improve performance and resource efficiency. The sample code introduced here demonstrates a simple technique for using this capability.
Instanced rendering allows for the reuse of geometry information, to render multiple instances of the same mesh with a single API call. Developers can use uniforms to apply unique attributes to specific instances, which provides for variation using visual properties such as texture. By reducing overhead—and therefore resource requirements—to render large numbers of elements, instanced rendering offers the potential to improve visual experiences, especially on hardware-constrained mobile devices.
Instancing was first introduced in OpenGL 3.1 as an arb extension (ARB_draw_instanced). This capability has now been added to the mobile space, with its inclusion as a core feature in OpenGL ES 3.0.
Downloading and installing the sample
The code sample is available for download from GitHub. To build and deploy the application to your Android device, choose either of the approaches described below.
Approach 1: Use BUILDANDROID.BAT
1. Navigate to InstancingAndroid\Utilities
2. Run buildandroid.bat
Approach 2: Build from the command line
1. Navigate to InstancingAndroid\InstancingAndroid
2. Run the following:
android update project –p .
Details of the implementation
This sample implements instancing by means of a uniform buffer that contains transform matrices for the model instances. The implementation operates as follows:
1. The first step is filling the buffer with our transform data.
2. When rendering, we simply call glDrawElementsInstanced instead of glDrawElements and pass in the number of instances as a parameter.
- Submitting the geometry information only once, glDrawElementsInstanced uses those same resources repeatedly to draw the desired number of instances.
- Each instance is assigned a unique identifier, as a value of gl_InstanceID that ranges from 0 up to ((num instances)-1). That value is used as an index to the uniform buffer to extract the current instances transform matrix and other properties.
While instancing does not require significant added work on the developer’s part, it can significantly increase rendering efficiency and performance.
Performance comparison: instanced versus non-instanced rendering
Instanced rendering is traditionally used for very large numbers of instances, on relatively simple (low poly) meshes. As shown in this sample, however, this capability can also be used effectively for fairly complex structures. The following chart compares the performance using an instanced draw call versus the non-instanced approach with multiple draw calls. As the number of instances increases, instanced rendering demonstrates a clear performance benefit, measured in terms of higher frame rates.
The instancing technique shown in this sample gives developers a simple means of substantially increasing performance in their OpenGL ES 3.0 applications. Instanced rendering lowers the resource requirements to provide rich, dynamic backgrounds, allowing developers to replace more limited billboarding techniques. That helps bring visual experiences that approach desktop-quality 3D graphics on mobile devices.
For more such intel resources and tools from Intel on Game, please visit the Intel® Game Developer Zone
Other Popular Deals
- The 10 best job hunting apps on AndroidTop 10 Android launchers (June 2017)
- The 10 scariest horror games on AndroidAndroid app stores: 5 best alternatives to Google Play Store
- Best Android apps for rooted devices18 apps for a memorable Valentine's Day
- Top 15 Android games that you should playThe 20 best looking games for mobile phones
- 8 Android apps to tickle your funny bone17 must have apps for any Android device (plus alternatives)
- 5 apps to get the Android Lollipop look on your smartphoneTake control of your Android device with these apps
- 7 weird and strange apps for your Smartphone10 neat Google apps you may not know of
- Perfect Viewer10 essential Indian apps for Android devices