43 #include <android/log.h>
45 #include <GLES3/gl3.h>
57 using namespace MaliSDK;
106 const char* fragmentShaderFileName,
107 const char* vertexShaderFileName);
174 if (isCameraPointOfView)
230 if (isCameraPointOfView)
281 GLsizei imageHeight = 0;
282 GLsizei imageWidth = 0;
293 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
297 GL_CHECK(glTexStorage2D (GL_TEXTURE_2D,
302 GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D,
313 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
314 GL_TEXTURE_MIN_FILTER,
316 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
317 GL_TEXTURE_MAG_FILTER,
319 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
322 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
325 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
331 if (textureData != NULL)
339 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
349 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
353 GL_CHECK(glTexStorage2D(GL_TEXTURE_2D,
355 GL_DEPTH_COMPONENT24,
360 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
361 GL_TEXTURE_MIN_FILTER,
363 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
364 GL_TEXTURE_MAG_FILTER,
366 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
369 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
372 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
375 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
376 GL_TEXTURE_COMPARE_FUNC,
378 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
379 GL_TEXTURE_COMPARE_MODE,
380 GL_COMPARE_REF_TO_TEXTURE));
387 GL_CHECK(glBindFramebuffer (GL_FRAMEBUFFER,
391 GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
403 ASSERT(programObjectId != 0,
404 "Cannot use default program object to retrieve attribute/uniform locations.");
405 ASSERT(locationsStoragePtr != NULL,
406 "Invalid pointer used to store retrieved attribute/uniform locations.");
451 "At least one of uniform/attribute locations retrieved is not valid. The uniform/attribute seems to be inactive.");
456 const char* fragmentShaderFileName,
457 const char* vertexShaderFileName)
459 ASSERT(objectIdsPtr != NULL,
460 "NULL pointer used to store generated object IDs");
462 GLint linkStatus = GL_FALSE;
467 fragmentShaderFileName,
470 vertexShaderFileName,
482 ASSERT(linkStatus == GL_TRUE,
483 "Linking program object failed.");
572 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
598 GL_CHECK(glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT));
606 GL_CHECK(glEnable(GL_POLYGON_OFFSET_FILL));
614 GL_CHECK(glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE));
625 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
628 GL_CHECK(glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT));
634 GL_CHECK(glDisable(GL_POLYGON_OFFSET_FILL));
637 GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
668 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
670 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
676 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
678 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
684 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
686 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
692 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
694 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
805 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
813 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
826 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
834 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
849 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
855 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
877 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER, 0));
878 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
879 GL_CHECK(glBindTexture (GL_TEXTURE_2D, 0));
974 colorTextureTranslationMatrix *
975 inverseCameraViewMatrix;
981 inverseCameraViewMatrix;
994 JNIEnv * env, jobject obj, jint
width, jint
height)
1000 JNIEnv * env, jobject obj)
1007 JNIEnv * env, jobject obj)
GeometryProperties planeGeometryProperties
static void getTriangleRepresentation(int *numberOfCoordinates, float **coordinates)
Get coordinates of points which make up a plane. The plane is located in XZ space.
Vec4f spotLightPositionInEyeSpace
GLint uniformDirectionalLightAmbient
GLint uniformModelViewMatrix
GLuint coordinatesBufferObjectId
float getTime()
Returns the time passed since object creation or since reset() was last called.
static void generateAndPrepareColorTextureObject()
Generate a colour texture object and fill it with data.
#define CAMERA_PERSPECTIVE_FOV_IN_DEGREES
Matrix modelViewProjectionMatrix
static void initializeProgramObject(ProgramAndShaderObjectIds *objectIdsPtr, const char *fragmentShaderFileName, const char *vertexShaderFileName)
Create and compile shader objects. If successful, they are attached to the program object...
GLint GLsizei GLsizei height
GLint uniformSpotLightCosAngle
GLuint vertexArrayObjectId
RenderSceneObjects renderSceneObjects
#define SPOT_LIGHT_TRANSLATION_RADIUS
static void generateAndPrepareDepthTextureObject()
Generate a depth texture object, set its properties and bind it to the generated framebuffer object...
static void getRenderSceneProgramLocations(GLuint programObjectId, RenderSceneProgramLocations *locationsStoragePtr)
Retrieve locations for attributes and uniforms used in a program object responsible for rendering a s...
Functions for manipulating matrices.
ProgramAndShaderObjectIds renderSceneProgramAndShadersIds
static void getNormals(int *numberOfCoordinates, float **normals)
Create normals for a cube which was created with getTriangleRepresentation() function.
static Matrix matrixInvert(Matrix *matrix)
Get the inverse of a matrix.
GLuint framebufferObjectId
GLint uniformNormalMatrix
#define SPOT_LIGHT_ANGLE_IN_DEGREES
GLuint depthTextureObjectId
GLint uniformSpotLightLookAtPointInEyeSpace
#define TEXTURE_UNIT_FOR_COLOR_TEXTURE
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
static void setupGeometryData()
Prepare the geometry data that will be used while rendering the scene.
Provides a platform independent high resolution timer.
#define COLOR_TEXTURE_NAME
GLint uniformDirectionalLightPosition
static Matrix matrixLookAt(Vec3f eye, Vec3f center, Vec3f up)
Create and return a look at matrix.
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
GLint uniformModelViewProjectionMatrix
static Matrix biasMatrix
The bias matrix.
float * getAsArray(void)
Get the matrix elements as a column major order array.
#define VERTEX_SHADER_FILE_NAME
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
GLint uniformColorTexture
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_uninit(JNIEnv *env, jobject obj)
#define CUBE_SCALING_FACTOR
RenderGeometryObjects renderPlane
GLint attributeVertexNormals
ModelViewProperties planeViewProperties
void uninit()
Delete created objects and free allocated memory.
static void updateSpotLightDirection()
Calculate the updated direction of the spot light and update the corresponding OpenGLES object settin...
ModelViewProperties planeViewProperties
CameraViewProperties cameraViewProperties
GLint uniformSpotLightColor
static void getTriangleRepresentation(float scalingFactor, int *numberOfCoordinates, float **coordinates)
Compute coordinates of points which make up a cube.
Matrix viewToDepthTextureMatrix
GLint attributeVertexCoordinates
#define FRAGMENT_SHADER_FILE_NAME
static Vec4f vertexTransform(Vec4f *vector, Matrix *matrix)
Transform a 4D vertex by a matrix.
static void getNormals(int *numberOfCoordinates, float **normals)
Get normals for plane placed in XZ space.
GLuint normalsBufferObjectId
GLint uniformViewToColorTextureMatrix
static Matrix createRotationY(float angle)
Create and return a rotation matrix around the y-axis matrix.
static void drawCubeAndPlane(bool isCameraPointOfView)
Draw cube and plane model.
Matrix viewToColorTextureMatrix
int numberOfElementsInCoordinatesArray
unsigned char * textureData
float degreesToRadians(float degrees)
Convert an angle in degrees to radians.
static void matrixTranspose(Matrix *matrix)
Transpose a matrix in-place.
GLuint colorTextureObjectId
GLint uniformDirectionalLightColor
int numberOfElementsInNormalsArray
#define LIGHT_PERSPECTIVE_FOV_IN_DEGREES
#define TEXTURE_UNIT_FOR_SHADOW_MAP_TEXTURE
Vec4f spotLightLookAtPointInEyeSpace
GLint uniformViewToDepthTextureMatrix
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_projectedLights_NativeLibrary_step(JNIEnv *env, jobject obj)
#define NUMBER_OF_POINT_COORDINATES
Number of coordinates for a point in 3D space.
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
ModelViewProperties cubeViewProperties
RenderSceneProgramLocations renderSceneProgramLocations
#define COLOR_TEXTURE_TRANSLATION
GLuint vertexShaderObjectId
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
#define MODEL_Y_ROTATION_ANGLE_IN_DEGREES
GLint uniformGeometryColor
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
ModelViewProperties cubeViewProperties
A 4D floating point vector.
SpotLightProperties spotLightProperties
GLint uniformSpotLightPositionInEyeSpace
GLuint fragmentShaderObjectId
static void loadBmpImageData(const char *fileName, int *imageWidthPtr, int *imageHeightPtr, unsigned char **textureDataPtrPtr)
Load BMP texture data from a file into memory.
RenderGeometryObjects renderCube
GeometryProperties cubeGeometryProperties
#define PLANE_SCALING_FACTOR
static void initializeViewMatrices()
Initilize data that will be used to translate vertices into eye- and NDC-space.
SpotLightViewProperites lightViewProperties
DirectionalLightProperties directionalLightProperties