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
.
tools/android
command to install it. (As of this writing, version 24 of these tools are installed by default.)export ANDROID_HOME=/Users/[username]/Library/Android/sdk
export ANDROID_NDK_HOME=/Users/[username]/Library/Android/sdk/ndk-bundle
cd android
into the root directory of Android project../gradlew assembleDebug
android/app/build/outputs/apk/app-debug.apk
adb install -r <path-to-your-apk>
cd wasm
./recompile
. The wasm files will be compiled in the wasm/build
android avd
first and create an Emulator. After you have created one, use emulator -avd <name>
to start it. Then you can run adb install -r <path-to-your-apk>
to install apk on your emulator.adb install -r <path-to-your-apk>
to install apk on your phone.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
.
TEAPOT
if you want to draw one instance as a teapot. Define TRIANGLE
if you want to draw one instance as a simple triangle. Define Zero
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.NUM_TEAPOT_X
, NUM_TEAPOT_Y
and NUM_TEAPOT_Z
defined in app/src/main/jni/MoreTeapotsNativeActivity.cpp
controls the number of instances drawn along X-axis, Y-axis, Z-axis in Android application. Variables NUM_TEAPOTS_X
, NUM_TEAPOTS_Y
and NUM_TEAPOTS_Z
defined in wasm/MoreTeapots-wasm.cpp
controls the number of instances in wasm application.size_instance_
defined in common/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 variable offset
in Init()
larger than 0, then each 'copy' of the original instance will have an offset in the new 'larger' instance.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.SIMPLE_SHADER
if you want use a really simple shader to output solid color.MULTI_GL_SET_UNIFORM
if you want to call glUniform4f
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.
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.