OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Native.cpp File Reference

Demonstration of Transform Feedback functionality in OpenGL ES 3.0. More...

#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "Boids.h"
#include "Common.h"
#include "Shader.h"
#include "SphereModel.h"
#include "Timer.h"
#include <stdlib.h>

Go to the source code of this file.

Functions

void generateStartPositionAndVelocity ()
 Generate random positions and velocities of spheres which are used during first draw call. More...
 
void fillVertexColorsArray ()
 Fill vertexColors array with random color for each triangle vertex. More...
 
void createSpheresData ()
 Initialize data for spheres. More...
 
void initializeData ()
 Initializes data used for rendering. More...
 
void setupPrograms ()
 
void renderFrame ()
 Render new frame's contents into back buffer. More...
 
void setupGraphics (int width, int height)
 
void uninit ()
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_step (JNIEnv *env, jobject obj)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_uninit (JNIEnv *env, jobject obj)
 

Variables

Timer timer
 
GLuint fragmentShaderId = 0
 
GLuint vertexShaderId = 0
 
GLuint renderingProgramId = 0
 
GLuint movementFragmentShaderId = 0
 
GLuint movementVertexShaderId = 0
 
GLuint movementProgramId = 0
 
const int numberOfSamples = 20
 
const int numberOfSpheresToGenerate = 30
 
int numberOfSphereTriangleCoordinates = 0
 
int numberOfSphereTrianglePoints = 0
 
floatsphereTrianglesCoordinates = NULL
 
int colorArraySize = 0
 
floatvertexColors = NULL
 
int windowHeight = 0
 
int windowWidth = 0
 
GLint cameraPositionLocation = 0
 
GLuint movementUniformBlockIndex = 0
 
GLint perspectiveMatrixLocation = 0
 
GLint positionLocation = 0
 
GLint scalingMatrixLocation = 0
 
GLint sphereVertexColorLocation = 0
 
GLint timeLocation = 0
 
bool usePingBufferForTransformFeedbackOutput = true
 
const GLuint numberOfBufferObjectIds = 4
 
GLuint bufferObjectIds [numberOfBufferObjectIds] = {0}
 
const int spherePositionsAndVelocitiesLength = 4 * 2 * numberOfSpheresToGenerate
 
GLuint sphereColorsBufferObjectId = 0
 
GLuint sphereCoordinatesBufferObjectId = 0
 
GLuint spherePingPositionAndVelocityBufferObjectId = 0
 
GLuint spherePongPositionAndVelocityBufferObjectId = 0
 
float startPositionAndVelocity [spherePositionsAndVelocitiesLength] = {0}
 

Detailed Description

Demonstration of Transform Feedback functionality in OpenGL ES 3.0.

Also demonstrates the use of uniform buffers. The application displays 30 spheres on a screen. Locations and velocities of the spheres in 3D space are regularly updated to simulate bird flock. There is 1 leader sphere (red) and 29 followers (green). The leader follows a set looping path and the followers 'flock' in relation to the leader and the other followers. The calculation of the locations of the boids is done on the GPU each frame using a vertex shader prior to rendering the scene. All of the data for the boids stays in GPU memory (by using buffers) and is not transferred back to the CPU. Transform feedback buffers are used to store the output of the movement vertex shader, this data is then used as the input data on the next pass. The same data is used when rendering the scene.

Definition in file Native.cpp.

Function Documentation

void createSpheresData ( )

Initialize data for spheres.

Definition at line 177 of file Native.cpp.

void fillVertexColorsArray ( )

Fill vertexColors array with random color for each triangle vertex.

Definition at line 155 of file Native.cpp.

void generateStartPositionAndVelocity ( )

Generate random positions and velocities of spheres which are used during first draw call.

Definition at line 132 of file Native.cpp.

void initializeData ( )

Initializes data used for rendering.

Definition at line 196 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_init ( JNIEnv *  env,
jobject  obj,
jint  width,
jint  height 
)

Definition at line 581 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_step ( JNIEnv *  env,
jobject  obj 
)

Definition at line 594 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_uninit ( JNIEnv *  env,
jobject  obj 
)

Definition at line 587 of file Native.cpp.

void renderFrame ( void  )

Render new frame's contents into back buffer.

Definition at line 380 of file Native.cpp.

void setupGraphics ( int  width,
int  height 
)

Definition at line 506 of file Native.cpp.

void setupPrograms ( )

Definition at line 270 of file Native.cpp.

void uninit ( )

Definition at line 558 of file Native.cpp.

Variable Documentation

GLuint bufferObjectIds[numberOfBufferObjectIds] = {0}

Definition at line 113 of file Native.cpp.

GLint cameraPositionLocation = 0

Definition at line 93 of file Native.cpp.

int colorArraySize = 0

Definition at line 81 of file Native.cpp.

GLuint fragmentShaderId = 0

Definition at line 55 of file Native.cpp.

GLuint movementFragmentShaderId = 0

Definition at line 63 of file Native.cpp.

GLuint movementProgramId = 0

Definition at line 67 of file Native.cpp.

GLuint movementUniformBlockIndex = 0

Definition at line 95 of file Native.cpp.

GLuint movementVertexShaderId = 0

Definition at line 65 of file Native.cpp.

const GLuint numberOfBufferObjectIds = 4

Definition at line 111 of file Native.cpp.

const int numberOfSamples = 20

Definition at line 71 of file Native.cpp.

const int numberOfSpheresToGenerate = 30

Definition at line 73 of file Native.cpp.

int numberOfSphereTriangleCoordinates = 0

Definition at line 75 of file Native.cpp.

int numberOfSphereTrianglePoints = 0

Definition at line 77 of file Native.cpp.

GLint perspectiveMatrixLocation = 0

Definition at line 97 of file Native.cpp.

GLint positionLocation = 0

Definition at line 99 of file Native.cpp.

GLuint renderingProgramId = 0

Definition at line 59 of file Native.cpp.

GLint scalingMatrixLocation = 0

Definition at line 101 of file Native.cpp.

GLuint sphereColorsBufferObjectId = 0

Definition at line 117 of file Native.cpp.

GLuint sphereCoordinatesBufferObjectId = 0

Definition at line 119 of file Native.cpp.

GLuint spherePingPositionAndVelocityBufferObjectId = 0

Definition at line 121 of file Native.cpp.

GLuint spherePongPositionAndVelocityBufferObjectId = 0

Definition at line 123 of file Native.cpp.

const int spherePositionsAndVelocitiesLength = 4 * 2 * numberOfSpheresToGenerate

Definition at line 115 of file Native.cpp.

float* sphereTrianglesCoordinates = NULL

Definition at line 79 of file Native.cpp.

GLint sphereVertexColorLocation = 0

Definition at line 103 of file Native.cpp.

float startPositionAndVelocity[spherePositionsAndVelocitiesLength] = {0}

Definition at line 127 of file Native.cpp.

GLint timeLocation = 0

Definition at line 105 of file Native.cpp.

Timer timer

Definition at line 51 of file Native.cpp.

bool usePingBufferForTransformFeedbackOutput = true

Definition at line 109 of file Native.cpp.

float* vertexColors = NULL

Definition at line 83 of file Native.cpp.

GLuint vertexShaderId = 0

Definition at line 57 of file Native.cpp.

int windowHeight = 0

Definition at line 87 of file Native.cpp.

int windowWidth = 0

Definition at line 89 of file Native.cpp.