OpenGL ES SDK for Android
ARM Developer Center
|
The application shows a bloom effect implementation. It draws cubes arranged in a two-dimensional 5x5 array, from which only the diagonal ones are bloomed. The intensity of the bloom effect changes from very weak, where each cube affected by the effect looks exactly as the normal ones, to very strong, when bloomed cubes make up an X shape. More...
#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "CubeModel.h"
#include "Matrix.h"
#include "Shader.h"
Go to the source code of this file.
Classes | |
struct | BlendingProgramLocations |
Structure holding locations of uniforms used by a program object responsible for applying the blend effect. More... | |
struct | BlurringObjects |
Structure holding ID of objects which were generated for blurring. More... | |
struct | BlurringProgramLocations |
Structure holding locations of uniforms used by a program object responsible for blurring. More... | |
struct | GetLuminanceImageBloomObjects |
Structure holding IDs of objects which were generated for generating downscaled texture with luminance image. More... | |
struct | ProgramAndShadersIds |
Structure holding program object ID and IDs of two shader objects (fragment and vertex). It is assumed that shader objects are/will be attached to program object. More... | |
struct | SceneRenderingObjects |
Structure holding ID of objects which were generated to support scene rendering. More... | |
struct | SceneRenderingProgramLocations |
Structure holding locations of attributes and uniforms used by a program object responsible for scene rendering. More... | |
struct | StrongerBlurObjects |
Structure holding IDs of objects which were generated for stronger texture blurring. More... | |
Macros | |
#define | WINDOW_RESOLUTION_DIVISOR (2) |
#define | NUMBER_OF_CUBES (25) |
#define | CUBE_SCALAR (0.8f) |
#define | BLUR_RADIUS (3) |
#define | NUMBER_OF_COMPONENTS_PER_VERTEX (3) |
#define | MAX_NUMBER_OF_BLUR_PASSES (10) |
#define | MIN_NUMBER_OF_BLUR_PASSES (2) |
#define | BLUR_MIX_FACTOR_STEP_VALUE (0.05f) |
#define | BLUR_EFFECT_INCREASE (1) |
#define | BLUR_EFFECT_DECREASE (-1) |
#define | TIME_INTERVAL (1.0f) |
#define | TEXTURE_UNIT_COLOR_TEXTURE (0) |
#define | TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE (1) |
#define | TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE (2) |
#define | TEXTURE_UNIT_BLURRED_TEXTURE (3) |
#define | TEXTURE_UNIT_STRONGER_BLUR_TEXTURE (4) |
#define | HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION (15.0f) |
#define | VERTICAL_POSITION_CAMERA_DEPTH_LOCATION (20.0f) |
Functions | |
static void | deleteBlurringObjects (BlurringObjects *objectIdsStoragePtr) |
Delete objects which were generated for blurring purposes. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindBuffer(), glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point. More... | |
static void | deleteGetLuminanceImageBloomObjects (GetLuminanceImageBloomObjects *objectIdsStoragePtr) |
Delete objects which were generated for getting downscaled luminance image. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point. More... | |
static void | deleteProgramShaderObjects (ProgramAndShadersIds *objectsToBeDeletedPtr) |
Delete program and shader objects. According to the OpenGL ES specification, program object will not be deleted if it is active. It is the user's responsibility to call glUseProgram(0) at some point. More... | |
static void | deleteSceneRenderingObjects (SceneRenderingObjects *objectIdsStoragePtr) |
Delete objects which were generated for scene rendering purposes. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindBuffer(), glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point. More... | |
static void | deleteStrongerBlurObjects (StrongerBlurObjects *objectIdsStoragePtr) |
Delete objects which were generated for performing the stronger blur effect on downscaled textures. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point. More... | |
static void | generateAndPrepareObjectsUsedForBlurring (GLuint *framebufferObjectIdPtr, GLuint *horizontalTextureObjectIdPtr, GLuint *verticalTextureObjectIdPtr) |
Generate texture and framebuffer objects, configure texture parameters. Finally, reset GL_TEXTURE_2D texture binding to 0 for active texture unit. Objects will be used for applying blur effect. More... | |
static void | generateAndPrepareObjectsUsedForSceneRendering (GLuint *framebufferObjectIdPtr, GLuint *originalTextureObjectIdPtr, GLuint *depthToIdPtr) |
Generate texture and framebuffer objects and configure texture parameters accordingly. Finally, reset GL_FRAEMBUFFER and GL_TEXTURE_2D bindings to 0. Objects will be used for rendering the scene into texture. More... | |
static void | generateDownscaledObjects (GLuint *fboIdPtr, GLuint *toIdPtr) |
Generate texture and framebuffer objects and configure texture parameters accordingly. Finally, reset GL_FRAEMBUFFER and GL_TEXTURE_2D bindings to 0. Texture size is equal to window resolution / WINDOW_RESOLUTION_DIVISOR. More... | |
static GLfloat * | getCubeLocations (GLint numberOfColumns, GLint numberOfRows, GLfloat cubeScalar, GLfloat distanceBetweenCubes, GLint *numberOfCubeLocationCoordinatesPtr) |
Calculate the world space locations of all the cubes that we will be rendering. The cubes are arranged in a 2D array consisting of numberOfColumns columns and numberOfRows rows with the requested space between cubes. It is the user's responsibility to free allocated memory. More... | |
static void | getLocationsForBlendingProgram (GLuint programObjectId, BlendingProgramLocations *locationsStoragePtr) |
Retrieve the locations of uniforms for the program object responsible for applying the blend effect. Can be called only if programObjectId is currently active. More... | |
static void | getLocationsForBlurringProgram (GLuint programObjectId, BlurringProgramLocations *locationsStoragePtr) |
Retrieve the locations of uniforms for the program object responsible for applying the blur effect. Can be called only if programObjectId is currently active. More... | |
static void | getLocationsForSceneRenderingProgram (GLuint programObjectId, SceneRenderingProgramLocations *locationsStoragePtr) |
Retrieve the locations of attributes and uniforms for the program object responsible for scene rendering. Can be called only if programObjectId is currently active. More... | |
static void | initializeProgramObject (ProgramAndShadersIds *objectIdsPtr, const char *fragmentShaderSource, const char *vertexShaderSource) |
Create and compile shader objects. If successful, they are attached to the program object, which is then linked. More... | |
static void | renderDowscaledLuminanceTexture () |
static void | renderSceneColourTexture () |
static void | setUniformValuesForSceneRenderingProgram (const SceneRenderingProgramLocations *locationsPtr, Matrix mvMatrix, Matrix mvpMatrix, Vec3f cameraPosition, Vec3f lightPosition) |
Configure the scene rendering program's uniforms. More... | |
void | setupGraphics (int width, int height) |
Setup the environment: create and prepare objects for rendering purposes. More... | |
void | renderFrame (float time) |
Render one frame. More... | |
void | uninit () |
Delete created objects and free allocated memory. More... | |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_step (JNIEnv *env, jobject obj, jfloat time) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_uninit (JNIEnv *env, jobject obj) |
The application shows a bloom effect implementation. It draws cubes arranged in a two-dimensional 5x5 array, from which only the diagonal ones are bloomed. The intensity of the bloom effect changes from very weak, where each cube affected by the effect looks exactly as the normal ones, to very strong, when bloomed cubes make up an X shape.
The bloom effect is implemented as follows:
(*) The blend effect is not constant during the rendering process: it changes from very weak to very strong. This is achieved by repeating step 3 a varying amount of times (depending on the required intensity of the effect) - the only difference is that for the n-th iteration the generated result of (n-th - 1) is taken as a source for the horizontal blur. To make the bloom effect more smooth, we also use continuous sampling of the textures. The results of the last two iterations from step 3 are used for the final combination pass. The colours of those two textures are mixed together with an appropriate factor value. (for more details please see the mix() function description in the OpenGL ES Shading Language documentation).
Besides the bloom effect, the application also shows:
Definition in file Native.cpp.
#define BLUR_EFFECT_DECREASE (-1) |
Indicates negative sign, used in blur calculations when the effect should be decreased.
Definition at line 96 of file Native.cpp.
#define BLUR_EFFECT_INCREASE (1) |
Indicates positive sign, used in blur calculations when the effect should be increased.
Definition at line 94 of file Native.cpp.
#define BLUR_MIX_FACTOR_STEP_VALUE (0.05f) |
Step which is used for changing mix factor values (used while mixing colour textures to get a continuous sampling effect).
Definition at line 92 of file Native.cpp.
#define BLUR_RADIUS (3) |
Radius of the blur effect (in pixels).
Definition at line 81 of file Native.cpp.
#define CUBE_SCALAR (0.8f) |
Cube size scalar.
Definition at line 77 of file Native.cpp.
#define HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION (15.0f) |
Camera depth location for horizontal position (should be used when the window width is greater than window height).
Definition at line 118 of file Native.cpp.
#define MAX_NUMBER_OF_BLUR_PASSES (10) |
Maximum number of blur passes.
Definition at line 87 of file Native.cpp.
#define MIN_NUMBER_OF_BLUR_PASSES (2) |
Minimum number of blur passes.
Definition at line 89 of file Native.cpp.
#define NUMBER_OF_COMPONENTS_PER_VERTEX (3) |
Number of vertex coordinates. Each vertex is described in 3D space with 3 values: xyz.
Definition at line 84 of file Native.cpp.
#define NUMBER_OF_CUBES (25) |
Number of cubes drawn on screen.
Definition at line 72 of file Native.cpp.
#define TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE (1) |
Texture unit which a texture with bloomed elements will be bound to.
Definition at line 106 of file Native.cpp.
#define TEXTURE_UNIT_BLURRED_TEXTURE (3) |
Texture unit which a texture with weaker blur effect will be bound to.
Definition at line 111 of file Native.cpp.
#define TEXTURE_UNIT_COLOR_TEXTURE (0) |
Texture unit which a color texture will be bound to.
Definition at line 102 of file Native.cpp.
#define TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE (2) |
Texture unit which a texture with horizontally blurred elements will be bound to.
Definition at line 109 of file Native.cpp.
#define TEXTURE_UNIT_STRONGER_BLUR_TEXTURE (4) |
Texture unit which a texture with stronger blur effect will be bound to.
Definition at line 113 of file Native.cpp.
#define TIME_INTERVAL (1.0f) |
Indicates how much time should it take to switch between number of blur passes.
Definition at line 98 of file Native.cpp.
#define VERTICAL_POSITION_CAMERA_DEPTH_LOCATION (20.0f) |
Camera depth location for vertical position (should be used when the window height is greater than window width).
Definition at line 122 of file Native.cpp.
#define WINDOW_RESOLUTION_DIVISOR (2) |
Window resolution divisor will be used for downscaling the texture used for blurring.
Definition at line 68 of file Native.cpp.
|
static |
Delete objects which were generated for blurring purposes. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindBuffer(), glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point.
objectIdsStoragePtr | Objects described by the structure will be deleted by the function. Cannot be NULL. |
Definition at line 613 of file Native.cpp.
|
static |
Delete objects which were generated for getting downscaled luminance image. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point.
objectIdsStoragePtr | Objects described by the structure will be deleted by the function. Cannot be NULL. |
Definition at line 634 of file Native.cpp.
|
static |
Delete program and shader objects. According to the OpenGL ES specification, program object will not be deleted if it is active. It is the user's responsibility to call glUseProgram(0) at some point.
objectsToBeDeletedPtr | Objects described by the structure will be deleted by the function. Cannot be NULL. |
Definition at line 652 of file Native.cpp.
|
static |
Delete objects which were generated for scene rendering purposes. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindBuffer(), glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point.
objectIdsStoragePtr | Objects described by the structure will be deleted by the function. Cannot be NULL. |
Definition at line 673 of file Native.cpp.
|
static |
Delete objects which were generated for performing the stronger blur effect on downscaled textures. According to the OpenGL ES specification, objects will not be deleted if bound. It is the user's responsibility to call glBindFramebuffer() and glBindTexture() with default object ids (id = 0) at some point.
objectIdsStoragePtr | Objects described by the structure will be deleted by the function. Cannot be NULL. |
Definition at line 700 of file Native.cpp.
|
static |
Generate texture and framebuffer objects, configure texture parameters. Finally, reset GL_TEXTURE_2D texture binding to 0 for active texture unit. Objects will be used for applying blur effect.
framebufferObjectIdPtr | Deref will be used to store generated framebuffer object ID. Cannot be NULL. |
horizontalTextureObjectIdPtr | Deref will be used to store generated horizontal texture object ID. Cannot be NULL. |
verticalTextureObjectIdPtr | Deref will be used to store generated vertical texture object ID. Cannot be NULL. |
Definition at line 722 of file Native.cpp.
|
static |
Generate texture and framebuffer objects and configure texture parameters accordingly. Finally, reset GL_FRAEMBUFFER and GL_TEXTURE_2D bindings to 0. Objects will be used for rendering the scene into texture.
framebufferObjectIdPtr | Deref will be used to store generated framebuffer object ID. Cannot be NULL. |
originalTextureObjectIdPtr | Deref will be used to store generated original texture object ID. Cannot be NULL. |
depthToIdPtr | Deref will be used to store generated depth texture object ID. Cannot be NULL. |
Definition at line 802 of file Native.cpp.
Generate texture and framebuffer objects and configure texture parameters accordingly. Finally, reset GL_FRAEMBUFFER and GL_TEXTURE_2D bindings to 0. Texture size is equal to window resolution / WINDOW_RESOLUTION_DIVISOR.
fboIdPtr | Deref will be used to store generated framebuffer object ID. Cannot be NULL. |
toIdPtr | Deref will be used to store generated texture object ID. Cannot be NULL. |
Definition at line 903 of file Native.cpp.
|
static |
Calculate the world space locations of all the cubes that we will be rendering. The cubes are arranged in a 2D array consisting of numberOfColumns
columns and numberOfRows
rows with the requested space between cubes. It is the user's responsibility to free allocated memory.
numberOfColumns | Number of columns that cubes will be placed in. |
numberOfRows | Number of rows that cubes will be placed in. |
cubeScalar | Cube size scalar. |
distanceBetweenCubes | Distance between cubes. |
numberOfCubeLocationCoordinatesPtr | Deref will be used to store number of generated cubes. Cannot be NULL. |
Definition at line 968 of file Native.cpp.
|
static |
Retrieve the locations of uniforms for the program object responsible for applying the blend effect. Can be called only if programObjectId
is currently active.
programObjectId | A valid program object ID. Indicates the program object for which locations are queried. |
locationsStoragePtr | Deref will be used to store retrieved info. Cannot be NULL. |
Definition at line 1017 of file Native.cpp.
|
static |
Retrieve the locations of uniforms for the program object responsible for applying the blur effect. Can be called only if programObjectId
is currently active.
programObjectId | A valid program object ID. Indicates the program object for which locations are queried. |
locationsStoragePtr | Deref will be used to store retrieved info. Cannot be NULL. |
Definition at line 1041 of file Native.cpp.
|
static |
Retrieve the locations of attributes and uniforms for the program object responsible for scene rendering. Can be called only if programObjectId
is currently active.
programObjectId | A valid program object ID. Indicates the program object for which locations are queried. |
locationsStoragePtr | Deref will be used to store retrieved info. Cannot be NULL. |
Definition at line 1061 of file Native.cpp.
|
static |
Create and compile shader objects. If successful, they are attached to the program object, which is then linked.
objectIdsPtr | Deref where generated program and shader objects IDs will be stored. Cannot be NULL. |
fragmentShaderSource | Fragment shader source code. Cannot be NULL. |
vertexShaderSource | Vertex shader source code. Cannot be NULL. |
Definition at line 1126 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_init | ( | JNIEnv * | env, |
jobject | obj, | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 1765 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_step | ( | JNIEnv * | env, |
jobject | obj, | ||
jfloat | time | ||
) |
Definition at line 1778 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_uninit | ( | JNIEnv * | env, |
jobject | obj | ||
) |
Definition at line 1771 of file Native.cpp.
|
static |
Definition at line 1155 of file Native.cpp.
Render one frame.
time | Time passed from the beginning of the rendering to the current frame render request (in seconds). |
Definition at line 1529 of file Native.cpp.
|
static |
Definition at line 1178 of file Native.cpp.
|
static |
Configure the scene rendering program's uniforms.
locationsPtr | Pointer to structure object where uniform locations are stored. Cannot be NULL. |
mvMatrix | Model-View matrix. |
mvpMatrix | Model-View-Projection matrix. |
cameraPosition | Camera (eye) position in space. |
lightPosition | Light position in space. |
Definition at line 1220 of file Native.cpp.
Setup the environment: create and prepare objects for rendering purposes.
width | Window resolution: width. |
height | Window resolution: height. |
Definition at line 1274 of file Native.cpp.
static void uninit | ( | ) |
Delete created objects and free allocated memory.
Definition at line 1706 of file Native.cpp.
|
static |
Definition at line 295 of file Native.cpp.
BlendingProgramLocations blendingProgramLocations |
Definition at line 589 of file Native.cpp.
ProgramAndShadersIds blendingProgramShaderObjects |
Definition at line 590 of file Native.cpp.
|
static |
Definition at line 323 of file Native.cpp.
BlurringProgramLocations blurringHorizontalProgramLocations |
Definition at line 591 of file Native.cpp.
ProgramAndShadersIds blurringHorizontalProgramShaderObjects |
Definition at line 592 of file Native.cpp.
BlurringObjects blurringObjects |
Definition at line 600 of file Native.cpp.
BlurringProgramLocations blurringVerticalProgramLocations |
Definition at line 593 of file Native.cpp.
ProgramAndShadersIds blurringVerticalProgramShaderObjects |
Definition at line 594 of file Native.cpp.
|
static |
Definition at line 359 of file Native.cpp.
Matrix cameraLookAtMatrix |
Definition at line 562 of file Native.cpp.
Vec3f cameraPosition |
Definition at line 563 of file Native.cpp.
Matrix cameraProjectionMatrix |
Definition at line 564 of file Native.cpp.
Matrix cameraViewMatrix |
Definition at line 565 of file Native.cpp.
Matrix cameraViewProjectionMatrix |
Definition at line 566 of file Native.cpp.
GLfloat* cubeCoordinates = NULL |
Definition at line 581 of file Native.cpp.
GLfloat* cubeLocations = NULL |
Definition at line 582 of file Native.cpp.
GLfloat* cubeNormals = NULL |
Definition at line 583 of file Native.cpp.
Definition at line 567 of file Native.cpp.
GetLuminanceImageBloomObjects getLuminanceImageBloomObjects |
Definition at line 601 of file Native.cpp.
|
static |
Definition at line 395 of file Native.cpp.
ProgramAndShadersIds getLuminanceImageProgramShaderObjects |
Definition at line 595 of file Native.cpp.
int lastNumberOfIterations = 0 |
Definition at line 578 of file Native.cpp.
Vec3f lightPosition = {0.0f, 0.0f, 10.0f} |
Definition at line 568 of file Native.cpp.
const Vec3f lookAtPoint = {0.0f, 0.0f, 0.0f} |
Definition at line 569 of file Native.cpp.
int max_window_dimension = 0 |
Definition at line 570 of file Native.cpp.
int min_window_dimension = 0 |
Definition at line 571 of file Native.cpp.
const float nearPlane = 0.01f |
Definition at line 572 of file Native.cpp.
int nOfCubeCoordinates = 0 |
Definition at line 584 of file Native.cpp.
int nOfCubeLocations = 0 |
Definition at line 585 of file Native.cpp.
int nOfCubeNormals = 0 |
Definition at line 586 of file Native.cpp.
|
static |
Definition at line 421 of file Native.cpp.
|
static |
Definition at line 485 of file Native.cpp.
|
static |
Definition at line 537 of file Native.cpp.
SceneRenderingObjects sceneRenderingObjects |
Definition at line 602 of file Native.cpp.
SceneRenderingProgramLocations sceneRenderingProgramLocations |
Definition at line 596 of file Native.cpp.
ProgramAndShadersIds sceneRenderingProgramShaderObjects |
Definition at line 597 of file Native.cpp.
StrongerBlurObjects strongerBlurObjects |
Definition at line 603 of file Native.cpp.
const Vec3f upVector = {0.0f, 1.0f, 0.0f} |
Definition at line 573 of file Native.cpp.
int windowHeight = 0 |
Definition at line 574 of file Native.cpp.
int windowWidth = 0 |
Definition at line 575 of file Native.cpp.