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 shadow mapping functionality using OpenGL ES 3.0. More...

#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "Common.h"
#include "CubeModel.h"
#include "Mathematics.h"
#include "Matrix.h"
#include "PlaneModel.h"
#include "ShadowMapping.h"
#include "Shader.h"
#include "Texture.h"
#include "Timer.h"
#include <cstring>

Go to the source code of this file.

Classes

struct  GeometryProperties
 
struct  WindowProperties
 
struct  LightProperties
 
struct  ShadowMapTextureProperties
 
struct  CubesAndPlaneProgramProperties
 
struct  LightRepresentationProgramProperties
 

Functions

void initializeStructureData ()
 Initialize structure data. More...
 
void createObjects ()
 Creates GL objects. More...
 
void deleteObjects ()
 Deletes all created GL objects. More...
 
void deallocateMemory ()
 
void calculateLookAtMatrix ()
 Calculates depth values written to shadow map texture. More...
 
void createDataForObjectsToBeDrawn ()
 Initialize data used for drawing the scene. More...
 
void initializeData ()
 Initialize the data used for rendering. Store data in buffer objects so that it can be used during draw calls. More...
 
void setUpAndUseProgramObject (GLint programId, const char *fragmentShaderFileName, const char *vertexShaderFileName)
 Create, compile and attach vertex and fragment shaders to previously created program object, link and set program object to be used. More...
 
void setupCubesAndPlaneProgram ()
 Create a program that will be used to convert vertices into eye-space and then rasterize cubes and plane. More...
 
void setupLightRepresentationProgram ()
 Create a program that will be used to rasterize the geometry of light cube. More...
 
void draw (bool hasShadowMapBeenCalculated)
 Draw geometry. More...
 
void createShadowMap ()
 Draw the scene from the light's point of view to calculate depth values (calculated values are held in shadow map texture). More...
 
void drawScene ()
 Draw the lit shadow-mapped scene from the camera's point of view. More...
 
void renderFrame ()
 Function called to render the new frame into the back buffer. More...
 
void setupGraphics (int width, int height)
 
void uninit ()
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_shadowMapping_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_shadowMapping_NativeLibrary_step (JNIEnv *env, jobject obj)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_shadowMapping_NativeLibrary_uninit (JNIEnv *env, jobject obj)
 

Variables

struct GeometryProperties plane
 
struct GeometryProperties cube
 
struct GeometryProperties lightRepresentation
 
struct WindowProperties window
 
struct LightProperties light
 
struct ShadowMapTextureProperties shadowMap
 
struct
CubesAndPlaneProgramProperties 
cubesAndPlaneProgram
 
struct
LightRepresentationProgramProperties 
lightRepresentationProgram
 
Timer timer
 
GLuint cubeCoordinatesBufferObjectId = 0
 
GLuint cubeNormalsBufferObjectId = 0
 
GLuint lightRepresentationCoordinatesBufferObjectId = 0
 
GLuint planeCoordinatesBufferObjectId = 0
 
GLuint planeNormalsBufferObjectId = 0
 
GLuint uniformBlockDataBufferObjectId = 0
 
GLuint cubesVertexArrayObjectId = 0
 
GLuint lightRepresentationCoordinatesVertexArrayObjectId = 0
 
GLuint planeVertexArrayObjectId = 0
 
Matrix cameraProjectionMatrix
 
Matrix lightProjectionMatrix
 
const Vec3f cameraPosition = {0.0f, 0.0f, 30.0f}
 
Vec3f lookAtPoint = {0.0f, 0.0f, 0.0f}
 
Matrix viewMatrixForShadowMapPass
 
const float cubesColor [] = {0.8f, 0.1f, 0.2f, 0.6f}
 
const float planeColor [] = {0.2f, 0.4f, 0.8f, 0.6f}
 

Detailed Description

Demonstration of shadow mapping functionality using OpenGL ES 3.0.

Application displays two cubes on a plane which are lit with directional and spot lights. Location and direction of the spot light source (represented by a small yellow cube flying above the scene) in 3D space are regularly updated. The cube and planes models are shadow receivers, but only the cubes are shadow casters. The application uses shadow mapping for rendering and displaying shadows.

Definition in file Native.cpp.

Function Documentation

void calculateLookAtMatrix ( )

Calculates depth values written to shadow map texture.

Fills viewMatrixForShadowMapPass matrix with data. That matrix is then used to set the viewMatrix in the shader from the light's point of view.

Definition at line 397 of file Native.cpp.

void createDataForObjectsToBeDrawn ( )

Initialize data used for drawing the scene.

Retrieve the coordinates of the triangles that make up the cubes and the plane and their normal vectors.

Definition at line 423 of file Native.cpp.

void createObjects ( )

Creates GL objects.

Definition at line 226 of file Native.cpp.

void createShadowMap ( )

Draw the scene from the light's point of view to calculate depth values (calculated values are held in shadow map texture).

Definition at line 772 of file Native.cpp.

void deallocateMemory ( )

brief Cleans up. Frees all allocated memory.

Definition at line 333 of file Native.cpp.

void deleteObjects ( )

Deletes all created GL objects.

Definition at line 308 of file Native.cpp.

void draw ( bool  hasShadowMapBeenCalculated)

Draw geometry.

Parameters
[in]hasShadowMapBeenCalculatedIf true, will draw the whole scene from the camera's point of view. If false, will draw only the scene cubes and the plane from the light's point of view.

Definition at line 677 of file Native.cpp.

void drawScene ( )

Draw the lit shadow-mapped scene from the camera's point of view.

Definition at line 817 of file Native.cpp.

void initializeData ( )

Initialize the data used for rendering. Store data in buffer objects so that it can be used during draw calls.

Definition at line 459 of file Native.cpp.

void initializeStructureData ( )

Initialize structure data.

Definition at line 151 of file Native.cpp.

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

Definition at line 943 of file Native.cpp.

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

Definition at line 956 of file Native.cpp.

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

Definition at line 949 of file Native.cpp.

void renderFrame ( void  )

Function called to render the new frame into the back buffer.

Definition at line 841 of file Native.cpp.

void setUpAndUseProgramObject ( GLint  programId,
const char *  fragmentShaderFileName,
const char *  vertexShaderFileName 
)

Create, compile and attach vertex and fragment shaders to previously created program object, link and set program object to be used.

Parameters
[in]programIdPreviously created program object name to be used.
[in]fragmentShaderFileNameFile name of a fragment shader to be attached to the program object.
[in]vertexShaderFileNameFile name of a vertex shader to be attached to the program object.

Definition at line 525 of file Native.cpp.

void setupCubesAndPlaneProgram ( )

Create a program that will be used to convert vertices into eye-space and then rasterize cubes and plane.

Definition at line 546 of file Native.cpp.

void setupGraphics ( int  width,
int  height 
)

Definition at line 873 of file Native.cpp.

void setupLightRepresentationProgram ( )

Create a program that will be used to rasterize the geometry of light cube.

Definition at line 629 of file Native.cpp.

void uninit ( )

Definition at line 929 of file Native.cpp.

Variable Documentation

const Vec3f cameraPosition = {0.0f, 0.0f, 30.0f}

Definition at line 140 of file Native.cpp.

Matrix cameraProjectionMatrix

Definition at line 137 of file Native.cpp.

struct GeometryProperties cube
GLuint cubeCoordinatesBufferObjectId = 0

Definition at line 123 of file Native.cpp.

GLuint cubeNormalsBufferObjectId = 0

Definition at line 124 of file Native.cpp.

struct CubesAndPlaneProgramProperties cubesAndPlaneProgram
const float cubesColor[] = {0.8f, 0.1f, 0.2f, 0.6f}

Definition at line 145 of file Native.cpp.

GLuint cubesVertexArrayObjectId = 0

Definition at line 131 of file Native.cpp.

struct LightProperties light
Matrix lightProjectionMatrix

Definition at line 138 of file Native.cpp.

struct GeometryProperties lightRepresentation
GLuint lightRepresentationCoordinatesBufferObjectId = 0

Definition at line 125 of file Native.cpp.

GLuint lightRepresentationCoordinatesVertexArrayObjectId = 0

Definition at line 132 of file Native.cpp.

struct LightRepresentationProgramProperties lightRepresentationProgram
Vec3f lookAtPoint = {0.0f, 0.0f, 0.0f}

Definition at line 141 of file Native.cpp.

struct GeometryProperties plane
const float planeColor[] = {0.2f, 0.4f, 0.8f, 0.6f}

Definition at line 146 of file Native.cpp.

GLuint planeCoordinatesBufferObjectId = 0

Definition at line 126 of file Native.cpp.

GLuint planeNormalsBufferObjectId = 0

Definition at line 127 of file Native.cpp.

GLuint planeVertexArrayObjectId = 0

Definition at line 133 of file Native.cpp.

struct ShadowMapTextureProperties shadowMap
Timer timer

Definition at line 120 of file Native.cpp.

GLuint uniformBlockDataBufferObjectId = 0

Definition at line 128 of file Native.cpp.

Matrix viewMatrixForShadowMapPass

Definition at line 142 of file Native.cpp.

struct WindowProperties window