OpenGL ES SDK for Android
ARM Developer Center
|
The application displays a rotating solid torus with a low-polygon wireframed mesh surrounding it. The torus is drawn by means of instanced tessellation technique using OpenGL ES 3.0. More...
#include <jni.h>
#include <android/log.h>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include "Common.h"
#include "InstancedSolidTorus.h"
#include "Matrix.h"
#include "Shader.h"
#include "Torus.h"
#include "WireframeTorus.h"
Go to the source code of this file.
Functions | |
void | setupGraphics (int width, int height) |
Function that sets up shaders, programs, uniforms locations, generates buffer objects and query objects. More... | |
void | renderFrame () |
Render one frame. More... | |
void | uninit () |
Releases all OpenGL objects that were created with glGen*() or glCreate*() functions. More... | |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_init (JNIEnv *, jobject, jint width, jint height) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_step (JNIEnv *, jobject) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_uninit (JNIEnv *, jobject) |
Variables | |
const string | resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.instancedTessellation/files/" |
int | windowWidth = 0 |
int | windowHeight = 0 |
Torus * | wireframeTorus |
Torus * | solidTorus |
static float | angleX = 0.0f |
static float | angleY = 0.0f |
static float | angleZ = 0.0f |
The application displays a rotating solid torus with a low-polygon wireframed mesh surrounding it. The torus is drawn by means of instanced tessellation technique using OpenGL ES 3.0.
To perform instanced tessellation, we need to divide our model into several patches. Each patch is densely packed with triangles and *improves the effect of round surfaces. In the first stage of tessellation, patches consist of vertices placed in a form of a square. Once passed to the shader, they are transformed into Bezier surfaces on the basis of control points stored in uniform blocks. Each instance of a draw call renders next part of the torus.
The following application instantiates 2 classes, these manage both the solid torus model and the wireframe that surrounds it. The first class is responsible for configuration of a program with shaders capable of instanced drawing, initialization of data buffers and handling instanced draw calls. To simplify the mathematics and satisfy conditions for C1 continuity between patches, we assume that torus is constructed by 12 circles, each also defined by 12 points. In that manner, we are able to divide "big" and "small" circle of torus into four quadrants and build Bezier surfaces that approximate perfectly round shapes. For that purpose, the control points cannot lay on the surface of the torus, but have to be distorted as appropriate.
The second class manages components corresponding to the wireframe. It uses vertices placed on the surface of torus and uses a simple draw call with GL_LINES mode. The size of its "small circle" is slightly bigger than the corresponding dimension of the solid torus, so there is a space between both the models.
Common elements for both classes are placed in an abstract Torus class.
Definition in file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_init | ( | JNIEnv * | , |
jobject | , | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 176 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_step | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 183 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_instancedTessellation_NativeLibrary_uninit | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 188 of file Native.cpp.
Render one frame.
Definition at line 130 of file Native.cpp.
Function that sets up shaders, programs, uniforms locations, generates buffer objects and query objects.
width | Window width. |
height | Window height. |
Definition at line 89 of file Native.cpp.
void uninit | ( | ) |
Releases all OpenGL objects that were created with glGen*() or glCreate*() functions.
Definition at line 160 of file Native.cpp.
|
static |
Definition at line 79 of file Native.cpp.
|
static |
Definition at line 80 of file Native.cpp.
|
static |
Definition at line 81 of file Native.cpp.
const string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.instancedTessellation/files/" |
Definition at line 67 of file Native.cpp.
Torus* solidTorus |
Definition at line 76 of file Native.cpp.
int windowHeight = 0 |
Definition at line 71 of file Native.cpp.
int windowWidth = 0 |
Definition at line 70 of file Native.cpp.
Torus* wireframeTorus |
Definition at line 74 of file Native.cpp.