OpenGL ES SDK for Android
ARM Developer Center
|
Demonstration of Occlusion Query functionality in 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 "CubeModel.h"
#include "Matrix.h"
#include "Native.h"
#include "PlaneModel.h"
#include "Shader.h"
#include "SuperEllipsoidModel.h"
#include "Text.h"
#include "Texture.h"
#include "Timer.h"
Go to the source code of this file.
Functions | |
float | distanceBetweenPoints (const Vec2f &point1, const Vec2f &point2) |
Compute Euclidean 2-dimensional distance between two points on XY plane. More... | |
bool | inNeighbourhood (const Vec2f &point, float minDistance, int j) |
Check if the rounded cubes are a proper distance from each other to prevent cubes overlapping. More... | |
float | uniformRandomNumber () |
Generate random number in the 0.0 to 1.0 range. More... | |
void | generateCubesLocations (float planeWidth, float planeHeight, float minDistance) |
Generate random cubes' center locations. More... | |
void | sortCubePositions (float *arrayToSort) |
Function that is used to sort cubes' center positions from the nearest to the furthest, relative to the camera position. More... | |
void | rewriteVec2fArrayToFloatArray () |
convert Vec2f array to an array of floats. More... | |
void | sendCubeLocationVectorToUniform (int whichCube) |
Sends center position of a cube to the vertex shader's uniform. More... | |
void | setupGraphics (int width, int height) |
Function that sets up shaders, programs, uniforms locations, generates buffer objects and query objects. More... | |
void | draw (void) |
Draw the plane and cubes. 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_occlusionQueries_NativeLibrary_init (JNIEnv *, jobject, jint width, jint height) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_occlusionQueries_NativeLibrary_step (JNIEnv *, jobject) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_occlusionQueries_NativeLibrary_uninit (JNIEnv *, jobject) |
Demonstration of Occlusion Query functionality in OpenGL ES 3.0.
The main purpose of the application is to show the difference in performance when the occlusion query mode is on or off. If the occlusion query mode is on, then only the cubes that are visible to the viewer are rendered. In the other case, when the occlusion query mode is off, then all of the cubes are rendered, which leads to a massive decrease in performance.
We are rendering rounded cubes - the objects are more complicated than the normal cubes, which means the time needed for rendering this kind of objects is longer. We are using this fact to demonstrate the occlusion query mode. When we want to verify whether the object is visible for a viewer, we can draw a simpler object (located in the same position as the requested one and being almost of the same size and shape), and once we get the results, we are able to render only those rounded cubes which passed the test.
There is also text displayed (at the bottom left corner of the screen) showing whether the occlusion query mode is currently on or off. The mode changes every 10 seconds.
Definition in file Native.cpp.
Compute Euclidean 2-dimensional distance between two points on XY plane.
[in] | point1 | First point. |
[in] | point2 | Second point. |
Definition at line 215 of file Native.cpp.
Draw the plane and cubes.
Renders all rounded cubes if occlusion queries turned on, otherwise just draws those visible.
Definition at line 722 of file Native.cpp.
Generate random cubes' center locations.
This algorithm ensures that cube will be the required distance apart.
[in] | planeWidth | Width of the plane. |
[in] | planeHeight | Height of the plane. |
[in] | minDistance | Determines minimum distance between cubes. |
Definition at line 260 of file Native.cpp.
Check if the rounded cubes are a proper distance from each other to prevent cubes overlapping.
[in] | point | The point for which we check distance. |
[in] | minDistance | Determines minimum distance between points. |
[in] | j | Tells how many points are already saved in the randomCubesPositions array. |
Definition at line 229 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_occlusionQueries_NativeLibrary_init | ( | JNIEnv * | , |
jobject | , | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 955 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_occlusionQueries_NativeLibrary_step | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 962 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_occlusionQueries_NativeLibrary_uninit | ( | JNIEnv * | , |
jobject | |||
) |
Definition at line 967 of file Native.cpp.
Render one frame.
Definition at line 847 of file Native.cpp.
void rewriteVec2fArrayToFloatArray | ( | ) |
convert Vec2f array to an array of floats.
Rewrite coordinates from randomCubesPositions array which type is Vec2f to a simple array of floats (sortedCubesPositions) that we can easily pass to the uniform.
Definition at line 374 of file Native.cpp.
Sends center position of a cube to the vertex shader's uniform.
[in] | whichCube | Determines which cube's center position we should send to the vertex shader. |
Definition at line 388 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 428 of file Native.cpp.
Function that is used to sort cubes' center positions from the nearest to the furthest, relative to the camera position.
We use bubble sort algorithm that checks whether an array is sorted or not.
[in,out] | arrayToSort | An array to be sorted. |
Definition at line 325 of file Native.cpp.
|
inline |
Generate random number in the 0.0 to 1.0 range.
Definition at line 246 of file Native.cpp.
void uninit | ( | ) |
Releases all OpenGL objects that were created with glGen*() or glCreate*() functions.
Definition at line 925 of file Native.cpp.
float angleY = 0.0f |
Definition at line 118 of file Native.cpp.
const float cameraRadius = 22.0f |
Definition at line 121 of file Native.cpp.
GLint colorUniformLocation = -1 |
Definition at line 143 of file Native.cpp.
const float cubeColor[] = {0.0f, 0.75f, 0.0f, 1.0f} |
Definition at line 154 of file Native.cpp.
Matrix cubeModelMatrix |
Definition at line 129 of file Native.cpp.
Matrix cubeMvpMatrix |
Definition at line 128 of file Native.cpp.
Matrix cubeNormalMatrix |
Definition at line 127 of file Native.cpp.
GLuint cubeQuery[NUMBER_OF_CUBES] = {0} |
Definition at line 112 of file Native.cpp.
Matrix cubeWorldInverseMatrix |
Definition at line 130 of file Native.cpp.
Timer fpsTimer |
Definition at line 85 of file Native.cpp.
const float minimumDistance = ROUNDED_CUBE_SCALE_FACTOR * 2.0f + 0.1f |
Definition at line 109 of file Native.cpp.
bool modeChanged = false |
Definition at line 199 of file Native.cpp.
GLint mvpMatrixUniformLocation = -1 |
Definition at line 141 of file Native.cpp.
GLuint normalCubeBufferId = 0 |
Definition at line 170 of file Native.cpp.
GLuint normalCubeVertexArrayObjectId = 0 |
Definition at line 160 of file Native.cpp.
float* normalCubeVertices = NULL |
Definition at line 179 of file Native.cpp.
GLint normalMatrixUniformLocation = -1 |
Definition at line 140 of file Native.cpp.
int numberOfCubeCoordinates = 0 |
Definition at line 182 of file Native.cpp.
int numberOfCubeVertices = 0 |
Definition at line 183 of file Native.cpp.
int numberOfPlaneVertexCoordinates = 0 |
Definition at line 190 of file Native.cpp.
int numberOfPlaneVertices = 0 |
Definition at line 189 of file Native.cpp.
int numberOfRoundedCubeCoordinates = 0 |
Definition at line 100 of file Native.cpp.
int numberOfRoundedCubeNormalVectors = 0 |
Definition at line 103 of file Native.cpp.
int numberOfRoundedCubesDrawn = 0 |
Definition at line 202 of file Native.cpp.
int numberOfRoundedCubesVertices = 0 |
Definition at line 97 of file Native.cpp.
bool occlusionQueriesOn = false |
Definition at line 115 of file Native.cpp.
const float planeColor[] = {1.0f, 0.8f, 0.0f, 1.0f} |
Definition at line 155 of file Native.cpp.
const float planeDividend = 3.0f |
Definition at line 152 of file Native.cpp.
const float planeLocation[] = {0.0f, 0.0f, 0.0f} |
Definition at line 156 of file Native.cpp.
Matrix planeModelMatrix |
Definition at line 133 of file Native.cpp.
Matrix planeMvpMatrix |
Definition at line 132 of file Native.cpp.
Matrix planeNormalMatrix |
Definition at line 131 of file Native.cpp.
float* planeNormalVectors = NULL |
Definition at line 193 of file Native.cpp.
GLuint planeNormalVectorsBufferId = 0 |
Definition at line 167 of file Native.cpp.
const float planeScalingFactor = 40.0f |
Definition at line 149 of file Native.cpp.
GLuint planeVertexArrayObjectId = 0 |
Definition at line 159 of file Native.cpp.
float* planeVertices = NULL |
Definition at line 186 of file Native.cpp.
GLuint planeVerticesBufferId = 0 |
Definition at line 164 of file Native.cpp.
Matrix planeWorldInverseMatrix |
Definition at line 134 of file Native.cpp.
GLuint programId = 0 |
Definition at line 88 of file Native.cpp.
Matrix projectionMatrix |
Definition at line 135 of file Native.cpp.
Vec2f randomCubesPositions[NUMBER_OF_CUBES] |
Definition at line 106 of file Native.cpp.
const string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.occlusionQueries/files/" |
Definition at line 75 of file Native.cpp.
Matrix rotatedViewMatrix |
Definition at line 136 of file Native.cpp.
float* roundedCubeCoordinates = NULL |
Definition at line 91 of file Native.cpp.
float* roundedCubeNormalVectors = NULL |
Definition at line 94 of file Native.cpp.
GLuint roundedCubeNormalVectorsBufferId = 0 |
Definition at line 176 of file Native.cpp.
GLuint roundedCubeVertexArrayObjectId = 0 |
Definition at line 161 of file Native.cpp.
GLuint roundedCubeVerticesBufferId = 0 |
Definition at line 173 of file Native.cpp.
int sizeOfPlaneNormalsArray = 0 |
Definition at line 196 of file Native.cpp.
float sortedCubesPositions[2 *NUMBER_OF_CUBES] = {0.0f} |
Definition at line 146 of file Native.cpp.
Text* text |
Definition at line 205 of file Native.cpp.
Timer timer |
Definition at line 82 of file Native.cpp.
Matrix viewMatrix |
Definition at line 137 of file Native.cpp.
int windowHeight = 0 |
Definition at line 79 of file Native.cpp.
int windowWidth = 0 |
Definition at line 78 of file Native.cpp.
GLint worldInverseMatrixUniformLocation = -1 |
Definition at line 142 of file Native.cpp.
const float yCameraTranslation = 1.25f |
Definition at line 124 of file Native.cpp.