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 instanced drawing and uniform buffers in OpenGL ES 3.0. More...

#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "Common.h"
#include "CubeModel.h"
#include "Instancing.h"
#include "Shader.h"
#include "Timer.h"
#include <cstring>

Go to the source code of this file.

Functions

void generateStartPosition ()
 Generate positions of cubes which are used during first draw call. More...
 
void fillCubeColorsArray ()
 Fill cubeColors array with random color (used for setting random color for each cube). More...
 
void fillVertexColorsArray ()
 
void createCubesData ()
 
void initializeData ()
 
void setupProgram ()
 
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_instancing_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_instancing_NativeLibrary_step (JNIEnv *env, jobject obj)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_instancing_NativeLibrary_uninit (JNIEnv *env, jobject obj)
 

Variables

Timer timer
 
GLuint fragmentShaderId = 0
 
GLuint vertexShaderId = 0
 
GLuint renderingProgramId = 0
 
int numberOfCubeTriangleCoordinates = 0
 
int numberOfCubeVertices = 0
 
floatcubeTrianglesCoordinates = NULL
 
int numberOfValuesInVertexColorsArray = 0
 
GLfloatvertexColors = NULL
 
const int numberOfValuesInCubeColorsArray = NUMBER_OF_COLOR_COMPONENTS * NUMBER_OF_CUBES
 
GLfloat cubeColors [numberOfValuesInCubeColorsArray] = {0}
 
const float cubeSize = 2.5f
 
GLint cameraPositionLocation = 0
 
GLuint uniformBlockIndex = 0
 
GLint perspectiveMatrixLocation = 0
 
GLint positionLocation = 0
 
GLint cubeVertexColorLocation = 0
 
GLint timeLocation = 0
 
const GLuint numberOfBufferObjectIds = 3
 
GLuint bufferObjectIds [numberOfBufferObjectIds] = {0}
 
GLuint cubeColorsBufferObjectId = 0
 
GLuint cubeCoordinatesBufferObjectId = 0
 
GLuint uniformBlockDataBufferObjectId = 0
 
GLfloat startPosition [NUMBER_OF_CUBES] = {0}
 
Vec4f perspectiveVector
 
Vec3f cameraVector
 

Detailed Description

Demonstration of instanced drawing and uniform buffers in OpenGL ES 3.0.

There is only one copy of the cube vertex data in memory, each of the cubes drawn is an instance of that data. This reduces the amount of memory which needs to be transferred to the GPU. By using gl_instanceID in the shader, each of the cubes can have a different position, rotation speed and colour. This technique can be used everywhere repeated geometry is used in a scene.

Definition in file Native.cpp.

Function Documentation

void createCubesData ( )

Initialize data for cubes.

Definition at line 173 of file Native.cpp.

void fillCubeColorsArray ( )

Fill cubeColors array with random color (used for setting random color for each cube).

Definition at line 137 of file Native.cpp.

void fillVertexColorsArray ( )

Definition at line 152 of file Native.cpp.

void generateStartPosition ( )

Generate positions of cubes which are used during first draw call.

Note
Cubes are located on a circular curve.

Definition at line 121 of file Native.cpp.

void initializeData ( )

Definition at line 200 of file Native.cpp.

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

Definition at line 440 of file Native.cpp.

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

Definition at line 453 of file Native.cpp.

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

Definition at line 446 of file Native.cpp.

void renderFrame ( void  )

Render new frame's contents into back buffer.

Definition at line 325 of file Native.cpp.

void setupGraphics ( int  width,
int  height 
)

Definition at line 346 of file Native.cpp.

void setupProgram ( )

Definition at line 273 of file Native.cpp.

void uninit ( )

Definition at line 412 of file Native.cpp.

Variable Documentation

GLuint bufferObjectIds[numberOfBufferObjectIds] = {0}

Definition at line 93 of file Native.cpp.

GLint cameraPositionLocation = 0

Definition at line 73 of file Native.cpp.

Vec3f cameraVector

Definition at line 114 of file Native.cpp.

Definition at line 67 of file Native.cpp.

GLuint cubeColorsBufferObjectId = 0

Definition at line 95 of file Native.cpp.

GLuint cubeCoordinatesBufferObjectId = 0

Definition at line 97 of file Native.cpp.

const float cubeSize = 2.5f

Definition at line 69 of file Native.cpp.

float* cubeTrianglesCoordinates = NULL

Definition at line 59 of file Native.cpp.

GLint cubeVertexColorLocation = 0

Definition at line 81 of file Native.cpp.

GLuint fragmentShaderId = 0

Definition at line 47 of file Native.cpp.

const GLuint numberOfBufferObjectIds = 3

Definition at line 91 of file Native.cpp.

int numberOfCubeTriangleCoordinates = 0

Definition at line 55 of file Native.cpp.

int numberOfCubeVertices = 0

Definition at line 57 of file Native.cpp.

const int numberOfValuesInCubeColorsArray = NUMBER_OF_COLOR_COMPONENTS * NUMBER_OF_CUBES

Definition at line 65 of file Native.cpp.

int numberOfValuesInVertexColorsArray = 0

Definition at line 61 of file Native.cpp.

GLint perspectiveMatrixLocation = 0

Definition at line 77 of file Native.cpp.

Vec4f perspectiveVector

Definition at line 112 of file Native.cpp.

GLint positionLocation = 0

Definition at line 79 of file Native.cpp.

GLuint renderingProgramId = 0

Definition at line 51 of file Native.cpp.

GLfloat startPosition[NUMBER_OF_CUBES] = {0}

Definition at line 103 of file Native.cpp.

GLint timeLocation = 0

Definition at line 83 of file Native.cpp.

Timer timer

Definition at line 44 of file Native.cpp.

GLuint uniformBlockDataBufferObjectId = 0

Definition at line 99 of file Native.cpp.

GLuint uniformBlockIndex = 0

Definition at line 75 of file Native.cpp.

GLfloat* vertexColors = NULL

Definition at line 63 of file Native.cpp.

GLuint vertexShaderId = 0

Definition at line 49 of file Native.cpp.