This repository is a porting from the Android NDK example More Teapots to a WebAssembly application. The porting code may be found under the directory of wasm
.
The project has two goals. The first one is to evaluate the engineering cost of porting an Android application to WASM. The other one is trying to figure out the performance overhead of WASM, compared to native Androis apps. In addition, I also ported a comparative WebJS version of this teapot program, which is under webGL
.
- Download and install Android Studio 2.1 from the link or you may choose just to download the command line tools. Both will work.
- Download and install the latest version of NDK from the link.
- Make sure the Android SDK Build-tools version 23.0.3 are installed. (This is referenced by android/nativeactivity/build.gradle .) Use the
tools/android
command to install it. (As of this writing, version 24 of these tools are installed by default.) - Set the ANDROID_HOME and ANDROID_NDK_HOME environment variables. On macOS these are typically:
export ANDROID_HOME=/Users/[username]/Library/Android/sdk
export ANDROID_NDK_HOME=/Users/[username]/Library/Android/sdk/ndk-bundle
- Emscripten version 1.36.5
- Emscripten clang version 1.36.5 (https://github.com/kripken/emscripten-fastcomp-clang 4fddcbc67c8950a54b169030ad9b2d66288d5d5f)
- Emscripten llvm version 1.36.5 (https://github.com/kripken/emscripten-fastcomp 21f1267bad4d8c523fae483104d4348cfb279cfe)
- For building emscripten and other required toolchains from source, you may refer to this page
cd android
into the root directory of Android project.- Run
./gradlew assembleDebug
- The generated apk file should be located at
android/app/build/outputs/apk/app-debug.apk
- To install it on the phone (In our experiment, we use Nexus 5 Build/LMY49P, Android 5.1.1), you first
connect the phone to the desktop in debug mode, and then run
adb install -r <path-to-your-apk>
cd wasm
- Run script
./recompile
. The wasm files will be compiled in thewasm/build
- To run it on emulator: run
android avd
first and create an Emulator. After you have created one, useemulator -avd <name>
to start it. Then you can runadb install -r <path-to-your-apk>
to install apk on your emulator. - To run it on the phone, just connect the phone to the desktop in debug mode and then run
adb install -r <path-to-your-apk>
to install apk on your phone.
- To run wams application on Chrome, you need to build the latest chromium from source. In our experiment, we used Version 53.0.2775.0 (64-bit).
- To run wasm on Chrome on Android, you need also get the Developer version Chrome (You can actually download it from Play Store). In our experiment, we use Chrome Dev 53.0.2782.9.
- The webGL files are under the directory
webGL
Because what we want to do is a comparative experiment finding the graphical performance bottlenecks in wasm, we defined some macros in order to play around and see what kind of things affect the performance most.
All macros should be defined in the 'Define macros' section in common/MoreTeapotsRenderer.cpp
.
- Define
TEAPOT
if you want to draw one instance as a teapot. DefineTRIANGLE
if you want to draw one instance as a simple triangle. DefineZero
if you want to draw one instance as purely a bunch of points located at 0. You must and can only define one macro from one of these three macros. - To control the number of instances and the size of one instance,
- Variables
NUM_TEAPOT_X
,NUM_TEAPOT_Y
andNUM_TEAPOT_Z
defined inapp/src/main/jni/MoreTeapotsNativeActivity.cpp
controls the number of instances drawn along X-axis, Y-axis, Z-axis in Android application. VariablesNUM_TEAPOTS_X
,NUM_TEAPOTS_Y
andNUM_TEAPOTS_Z
defined inwasm/MoreTeapots-wasm.cpp
controls the number of instances in wasm application. - Variable
size_instance_
defined incommon/MoreTeapotsRenderer.cpp
defined the size (number of vertices, also the number of indices) of per instance. That is to say, if you set it to 1, then it remains the same size for one instance. It you set to 2, the size of per instance will become two times than the original one. If you also set the variableoffset
inInit()
larger than 0, then each 'copy' of the original instance will have an offset in the new 'larger' instance.
- Variables
- (Optional) Define
DRAW_ALL_IN_MIDDLE
if you want to draw all instances in the middle of the screen. Otherwise, each instance will have a distance from other instances. - (Optional) Define
SIMPLE_SHADER
if you want use a really simple shader to output solid color. - (Optional) Define
MULTI_GL_SET_UNIFORM
if you want to callglUniform4f
in a loop in order to find whether indirect calls to GL APIs is a heavy bottleneck for the performance.
Below is the README from the original project.
More Teapots is an Android C++ sample that draws multiple instances of the same Teapot mesh using GLES 3.0 Instanced Rendering and NativeActivity.
This sample uses the new Gradle Experimental Android plugin with C++ support.
- Android Studio 1.3+ with NDK bundle.
- Download Android Studio
- Launch Android Studio.
- Open the sample directory.
- Open File/Project Structure...
- Click Download or Select NDK location.
- Click Tools/Android/Sync Project with Gradle Files.
- Click Run/Run 'app'.
If you've found an error in these samples, please file an issue.
Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.