57 #include <android/log.h>
59 #include <GLES3/gl3.h>
65 using namespace MaliSDK;
68 #define WINDOW_RESOLUTION_DIVISOR (2)
72 #define NUMBER_OF_CUBES (25)
77 #define CUBE_SCALAR (0.8f)
81 #define BLUR_RADIUS (3)
84 #define NUMBER_OF_COMPONENTS_PER_VERTEX (3)
87 #define MAX_NUMBER_OF_BLUR_PASSES (10)
89 #define MIN_NUMBER_OF_BLUR_PASSES (2)
92 #define BLUR_MIX_FACTOR_STEP_VALUE (0.05f)
94 #define BLUR_EFFECT_INCREASE (1)
96 #define BLUR_EFFECT_DECREASE (-1)
98 #define TIME_INTERVAL (1.0f)
102 #define TEXTURE_UNIT_COLOR_TEXTURE (0)
106 #define TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE (1)
109 #define TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE (2)
111 #define TEXTURE_UNIT_BLURRED_TEXTURE (3)
113 #define TEXTURE_UNIT_STRONGER_BLUR_TEXTURE (4)
118 #define HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION (15.0f)
122 #define VERTICAL_POSITION_CAMERA_DEPTH_LOCATION (20.0f)
137 uniformMixFactor = -1;
138 uniformOriginalTexture = -1;
139 uniformStrongerBlurTexture = -1;
140 uniformWeakerBlurTexture = -1;
155 framebufferObjectId = 0;
156 textureObjectIdHorizontal = 0;
157 textureObjectIdVertical = 0;
172 uniformBlurRadius = -1;
173 uniformTextureSampler = -1;
188 framebufferObjectId = 0;
205 fragmentShaderObjectId = 0;
207 vertexShaderObjectId = 0;
226 bufferObjectIdCubeCoords = 0;
227 bufferObjectIdCubeNormals = 0;
228 bufferObjectIdElementLocations = 0;
229 framebufferObjectId = 0;
230 textureObjectIdDepthImage = 0;
231 textureObjectIdOriginalImage = 0;
260 attribCubeVertexCoordinates = -1;
261 attribCubeVertexNormals = -1;
262 uniformCameraPosition = -1;
263 uniformBlockCubeProperties = GL_INVALID_INDEX;
264 uniformLightPropertiesAmbient = -1;
265 uniformLightPropertiesColor = -1;
266 uniformLightPropertiesConstantAttenuation = -1;
267 uniformLightPropertiesLinearAttenuation = -1;
268 uniformLightPropertiesQuadraticAttenauation = -1;
269 uniformLightPropertiesPosition = -1;
270 uniformLightPropertiesShininess = -1;
271 uniformLightPropertiesStrength = -1;
272 uniformMvMatrix = -1;
273 uniformMvpMatrix = -1;
288 framebufferObjectId = 0;
296 "precision mediump float;\n"
298 "/** Factor which will be used for mixing higher and lower blur effect texture colours. */\n"
299 "uniform float mix_factor;\n"
300 "/** Texture storing colour data (with all the cubes). */\n"
301 "uniform sampler2D original_texture;\n"
302 "/** Texture in which (n+1) blur operations have been applied to the input texture. */\n"
303 "uniform sampler2D stronger_blur_texture;\n"
304 "/** Texture in which (n) blur operations have been applied to the input texture. */\n"
305 "uniform sampler2D weaker_blur_texture;\n"
307 "/** Texture coordinates. */\n"
308 "in vec2 texture_coordinates;\n"
310 "/** Fragment colour to be returned. */\n"
314 " vec4 stronger_blur_texture_color = texture(stronger_blur_texture, texture_coordinates);\n"
315 " vec4 weaker_blur_texture_color = texture(weaker_blur_texture, texture_coordinates);\n"
316 " vec4 mixed_blur_color = mix(weaker_blur_texture_color, stronger_blur_texture_color, mix_factor);\n"
317 " vec4 original_color = texture(original_texture, texture_coordinates);\n"
318 " /* Return blended colour. */\n"
319 " color = original_color + mixed_blur_color;\n"
324 "precision mediump float;\n"
325 "/** Defines gaussian weights. */\n"
326 "const float gaussian_weights[] = float[] (0.2270270270,\n"
330 "/** Radius of a blur effect to be applied. */\n"
331 "uniform float blur_radius;\n"
332 "/** Texture sampler on which the effect will be applied. */\n"
333 "uniform sampler2D texture_sampler;\n"
335 "/** Texture coordinates. */\n"
336 "in vec2 texture_coordinates;\n"
338 "/** Fragment colour that will be returned. */\n"
339 "out vec4 output_color;\n"
342 " vec4 total_color = vec4(0.0);\n"
343 " float image_resolution = float((textureSize(texture_sampler, 0)).x);\n"
344 " float blur_step = blur_radius / image_resolution;\n"
345 " /* Calculate blurred colour. */\n"
346 " /* Blur a texel on the right. */\n"
347 " total_color = texture(texture_sampler, vec2(texture_coordinates.x + 1.0 * blur_step, texture_coordinates.y)) * gaussian_weights[0] +\n"
348 " texture(texture_sampler, vec2(texture_coordinates.x + 2.0 * blur_step, texture_coordinates.y)) * gaussian_weights[1] +\n"
349 " texture(texture_sampler, vec2(texture_coordinates.x + 3.0 * blur_step, texture_coordinates.y)) * gaussian_weights[2];\n"
350 " /* Blur a texel on the left. */\n"
351 " total_color += texture(texture_sampler, vec2(texture_coordinates.x - 1.0 * blur_step, texture_coordinates.y)) * gaussian_weights[0] +\n"
352 " texture(texture_sampler, vec2(texture_coordinates.x - 2.0 * blur_step, texture_coordinates.y)) * gaussian_weights[1] +\n"
353 " texture(texture_sampler, vec2(texture_coordinates.x - 3.0 * blur_step, texture_coordinates.y)) * gaussian_weights[2];\n"
354 " /* Set the output colour. */\n"
355 " output_color = vec4(total_color.xyz, 1.0);\n"
360 "precision mediump float;\n"
361 "/** Defines gaussian weights. */\n"
362 "const float gaussian_weights[] = float[] (0.2270270270,\n"
366 "/** Radius of a blur effect to be applied. */\n"
367 "uniform float blur_radius;\n"
368 "/** Texture sampler on which the effect will be applied. */\n"
369 "uniform sampler2D texture_sampler;\n"
371 "/** Texture coordinates. */\n"
372 "in vec2 texture_coordinates;\n"
374 "/** Fragment colour that will be returned. */\n"
375 "out vec4 output_color;\n"
378 " vec4 total_color = vec4(0.0);\n"
379 " float image_resolution = float((textureSize(texture_sampler, 0)).y);\n"
380 " float blur_step = blur_radius / image_resolution;\n"
381 " /* Calculate blurred colour. */\n"
382 " /* Blur a texel to the top. */\n"
383 " total_color = texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y + 1.0 * blur_step)) * gaussian_weights[0] +\n"
384 " texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y + 2.0 * blur_step)) * gaussian_weights[1] +\n"
385 " texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y + 3.0 * blur_step)) * gaussian_weights[2];\n"
386 " /* Blur a texel to the bottom. */\n"
387 " total_color += texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y - 1.0 * blur_step)) * gaussian_weights[0] +\n"
388 " texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y - 2.0 * blur_step)) * gaussian_weights[1] +\n"
389 " texture(texture_sampler, vec2(texture_coordinates.x, texture_coordinates.y - 3.0 * blur_step)) * gaussian_weights[2];\n"
390 " /* Set the output colour. */\n"
391 " output_color = vec4(total_color.xyz, 1.0);\n"
396 "precision highp float;\n"
398 "uniform sampler2D texture_sampler;\n"
400 "in vec2 texture_coordinates;\n"
402 "out vec4 scene_color;\n"
403 "#define MIN_LUMINANCE (0.9)\n"
406 " vec4 sample_color = texture(texture_sampler, texture_coordinates);\n"
407 " float luminance = 0.2125 * sample_color.x +\n"
408 " 0.7154 * sample_color.y +\n"
409 " 0.0721 * sample_color.z;\n"
410 " if (luminance > MIN_LUMINANCE)\n"
412 " scene_color = sample_color;\n"
416 " scene_color = vec4(0.0);\n"
422 "precision lowp float;\n"
423 "/** Defines epsilon used for float values comparison. */\n"
424 "#define EPSILON (0.00001)\n"
425 "/** Structure holding light properties. */\n"
426 "struct _light_properties\n"
430 " float constant_attenuation;\n"
431 " float linear_attenuation;\n"
433 " float quadratic_attenauation;\n"
434 " float shininess;\n"
438 "/** Camera position in a space. */\n"
439 "uniform vec3 camera_position;\n"
440 "/** Directional light properties. */\n"
441 "uniform _light_properties light_properties;\n"
443 "/** Vertex normal. */\n"
445 "/** Vertex coordinates. */\n"
447 "/** Indicates whether a cube is placed on diagonal. */\n"
448 "flat in int is_cube_placed_on_diagonal;\n"
450 "/* Stores scene colour.*/\n"
451 "out vec4 scene_color;\n"
454 " vec4 dark_cube_colour = vec4(0.2, 0.4, 0.8, 1.0);\n"
455 " vec4 light_cube_colour = vec4(1.0);\n"
456 " vec3 normalized_normals = normalize(normal);\n"
457 " vec3 light_direction = normalize(vec3(light_properties.position - vertex.xyz));\n"
458 " float attenuation = 1.0 / (light_properties.constant_attenuation + (light_properties.linear_attenuation + light_properties.quadratic_attenauation));\n"
459 " vec3 camera_direction = camera_position - vec3(vertex);\n"
460 " float diffuse = max(0.0, dot(normalized_normals, light_direction));\n"
461 " vec3 half_vector = normalize(light_direction + camera_direction);\n"
462 " float specular = 0.0;\n"
463 " if (abs(diffuse - 0.0) > EPSILON)\n"
465 " specular = max(0.0, dot(half_vector, normal));\n"
466 " specular = pow(specular, light_properties.shininess) * light_properties.strength;\n"
468 " vec3 scattered_light = light_properties.ambient * attenuation + diffuse * attenuation * light_properties.color;\n"
469 " vec3 reflected_light = light_properties.color * specular * attenuation;\n"
470 " vec3 dark_cube_colour_with_lighting = min(dark_cube_colour.xyz * scattered_light + reflected_light, vec3(1.0) );\n"
471 " /* If we are dealing with a cube placed on a diagonal, use white colour.\n"
472 " * Otherwise, we want to output a regular cube (which means the previously\n"
473 " * calculated cube colour with lighting applied). */\n"
474 " if (is_cube_placed_on_diagonal == 1)\n"
476 " scene_color = light_cube_colour;\n"
480 " scene_color = vec4(dark_cube_colour_with_lighting, 1.0);\n"
486 "precision mediump float;\n"
487 "/** Defines number of cubes that will be rendered. */\n"
488 "#define NUMBER_OF_CUBES (25)\n"
489 "/** Array holding information whether a cube is placed on diagonal (1) or not (0). */\n"
490 "const int is_diagonal_cube[NUMBER_OF_CUBES] = int[NUMBER_OF_CUBES](1, 0, 0, 0, 1,\n"
496 "/** Model * View matrix. */\n"
497 "uniform mat4 mv_matrix;\n"
498 "/** Model * View * Projection matrix. */\n"
499 "uniform mat4 mvp_matrix;\n"
500 "/** Cubes' properties. */\n"
501 "uniform cube_properties\n"
503 " /** Cubes' locations in a space. */\n"
504 " vec2 locations[NUMBER_OF_CUBES];\n"
507 "/** Cube vertex coordinates. */\n"
508 "in vec3 cube_vertex_coordinates;\n"
509 "/** Cube vertex normals. */\n"
510 "in vec3 cube_vertex_normals;\n"
512 "/** Cube vertex normals in eye space. */\n"
513 " out vec3 normal;\n"
514 "/** Cube vertex coordinates in eye space. */\n"
515 " out vec4 vertex;\n"
516 "/** 1, if cube is placed on diagonal, 0 otherwise. */\n"
517 "flat out int is_cube_placed_on_diagonal;\n"
520 " /* Prepare translation matrix. */\n"
521 " mat4 cube_location_matrix = mat4(1.0, 0.0, 0.0, 0.0,\n"
522 " 0.0, 1.0, 0.0, 0.0,\n"
523 " 0.0, 0.0, 1.0, 0.0,\n"
524 " locations[gl_InstanceID].x, locations[gl_InstanceID].y, 0.0, 1.0);\n"
525 " /* Calculate matrices. */\n"
526 " mat4 model_view_matrix = mv_matrix * cube_location_matrix;\n"
527 " mat4 model_view_projection_matrix = mvp_matrix * cube_location_matrix;\n"
528 " /* Set output values. */\n"
529 " is_cube_placed_on_diagonal = is_diagonal_cube[gl_InstanceID];\n"
530 " normal = vec3(model_view_matrix * vec4(cube_vertex_normals, 0.0)).xyz;\n"
531 " vertex = model_view_matrix * vec4(cube_vertex_coordinates, 1.0);\n"
532 " /* Set vertex position in NDC space. */\n"
533 " gl_Position = model_view_projection_matrix * vec4(cube_vertex_coordinates, 1.0);\n"
538 "precision mediump float;\n"
539 "/** GL_TRIANGLE_FAN-type quad vertex data. */\n"
540 "const vec4 vertex_positions[4] = vec4[4](vec4( 1.0, -1.0, 0.0, 1.0),\n"
541 " vec4(-1.0, -1.0, 0.0, 1.0),\n"
542 " vec4(-1.0, 1.0, 0.0, 1.0),\n"
543 " vec4( 1.0, 1.0, 0.0, 1.0) );\n"
544 "/** Texture UVs. */\n"
545 "const vec2 texture_uv[4] = vec2[4](vec2(1.0, 0.0),\n"
548 " vec2(1.0, 1.0) );\n"
550 "/** Texture coordinates. */\n"
551 "out vec2 texture_coordinates;\n"
554 " /* Return vertex coordinates. */\n"
555 " gl_Position = vertex_positions[gl_VertexID];\n"
556 " /* Pass texture coordinated to fragment shader. */\n"
557 " texture_coordinates = texture_uv[gl_VertexID];\n"
615 ASSERT(objectIdsStoragePtr != NULL);
636 ASSERT(objectIdsStoragePtr != NULL);
654 ASSERT(objectsToBeDeletedPtr != NULL);
675 ASSERT(objectIdsStoragePtr != NULL);
702 ASSERT(objectIdsStoragePtr != NULL);
723 GLuint* horizontalTextureObjectIdPtr,
724 GLuint* verticalTextureObjectIdPtr)
726 ASSERT(framebufferObjectIdPtr != NULL);
727 ASSERT(horizontalTextureObjectIdPtr != NULL);
728 ASSERT(verticalTextureObjectIdPtr != NULL);
732 framebufferObjectIdPtr) );
734 horizontalTextureObjectIdPtr) );
736 verticalTextureObjectIdPtr) );
738 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
739 *horizontalTextureObjectIdPtr) );
740 GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
749 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
752 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
755 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
756 GL_TEXTURE_MAG_FILTER,
758 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
759 GL_TEXTURE_MIN_FILTER,
762 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
763 *verticalTextureObjectIdPtr) );
764 GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
773 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
776 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
779 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
780 GL_TEXTURE_MAG_FILTER,
782 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
783 GL_TEXTURE_MIN_FILTER,
787 GL_CHECK(glBindTexture(GL_TEXTURE_2D,
803 GLuint* originalTextureObjectIdPtr,
806 ASSERT(framebufferObjectIdPtr != NULL);
807 ASSERT(originalTextureObjectIdPtr!= NULL);
808 ASSERT(depthToIdPtr != NULL);
813 framebufferObjectIdPtr) );
815 originalTextureObjectIdPtr) );
820 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
821 *framebufferObjectIdPtr) );
823 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
824 *originalTextureObjectIdPtr) );
825 GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
834 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
837 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
840 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
841 GL_TEXTURE_MAG_FILTER,
843 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
844 GL_TEXTURE_MIN_FILTER,
847 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
849 GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
851 GL_DEPTH_COMPONENT32F,
858 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
859 GL_TEXTURE_MIN_FILTER,
861 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
862 GL_TEXTURE_MAG_FILTER,
864 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
867 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
874 GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
875 GL_COLOR_ATTACHMENT0,
877 *originalTextureObjectIdPtr,
879 GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
887 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
889 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
916 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
918 GL_CHECK(glTexStorage2D (GL_TEXTURE_2D,
923 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
926 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
929 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
930 GL_TEXTURE_MAG_FILTER,
932 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
933 GL_TEXTURE_MIN_FILTER,
937 GL_CHECK(glBindFramebuffer (GL_FRAMEBUFFER,
939 GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
940 GL_COLOR_ATTACHMENT0,
946 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
948 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
972 GLint* numberOfCubeLocationCoordinatesPtr)
974 ASSERT(numberOfCubeLocationCoordinatesPtr != NULL);
976 const float distance = distanceBetweenCubes + 2 * cubeScalar;
983 int numberOfCubeLocationCoordinates = 0;
984 const int numberOfPointCoordinates = 2;
986 const float xStart = -(
float(numberOfColumns - 1) / 2.0f *
distance);
987 const float yStart = -(
float(numberOfRows - 1) / 2.0f *
distance);
989 numberOfCubeLocationCoordinates = numberOfPointCoordinates * numberOfColumns * numberOfRows;
990 result = (
GLfloat*) malloc(numberOfCubeLocationCoordinates *
sizeof(
GLfloat) );
995 for (
int rowIndex = 0; rowIndex < numberOfRows; rowIndex++)
997 for (
int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++)
999 result[index++] = xStart + (rowIndex *
distance);
1000 result[index++] = yStart + (columnIndex *
distance);
1004 *numberOfCubeLocationCoordinatesPtr = numberOfCubeLocationCoordinates;
1020 ASSERT(locationsStoragePtr != NULL);
1021 ASSERT(programObjectId != 0);
1044 ASSERT(locationsStoragePtr != NULL);
1045 ASSERT(programObjectId != 0);
1064 ASSERT(locationsStoragePtr != NULL);
1065 ASSERT(programObjectId != 0);
1069 "cube_vertex_coordinates") );
1072 "cube_vertex_normals") );
1075 "cube_properties") );
1078 "camera_position") );
1080 "light_properties.ambient") );
1082 "light_properties.color") );
1084 "light_properties.constant_attenuation") );
1086 "light_properties.linear_attenuation") );
1088 "light_properties.position") );
1090 "light_properties.quadratic_attenauation") );
1092 "light_properties.shininess") );
1094 "light_properties.strength") );
1127 const char* fragmentShaderSource,
1128 const char* vertexShaderSource)
1130 ASSERT(objectIdsPtr != NULL);
1132 GLint linkStatus = 0;
1137 fragmentShaderSource,
1138 GL_FRAGMENT_SHADER);
1150 ASSERT(linkStatus == GL_TRUE);
1161 GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1169 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1171 GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1191 GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1199 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1202 GL_CHECK(glDrawArraysInstanced(GL_TRIANGLES,
1226 ASSERT(locationsPtr != NULL);
1228 const Vec3f lightAmbient = {0.3f, 0.3f, 0.3f};
1229 const Vec3f lightColor = {1.0f, 1.0f, 1.0f};
1230 const float lightConstantAttenuation = 0.9f;
1231 const float lightLinearAttenuation = 0.0f;
1232 const float lightQuadraticAttenuation = 0.05f;
1233 const float lightShininess = 0.1f;
1234 const float lightStrength = 0.01f;
1250 cameraPosition.
z) );
1276 float cameraDepthPosition = 0.0f;
1344 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
1346 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
1355 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
1357 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
1366 GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER,
1368 GL_CHECK(glBufferData(GL_UNIFORM_BUFFER,
1406 GL_CHECK(glBindBufferBase (GL_UNIFORM_BUFFER,
1414 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1423 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1475 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1480 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1484 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1487 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1490 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1498 GL_CHECK(glEnable (GL_DEPTH_TEST) );
1516 GL_CHECK(glScissor(x, y, scissorBoxWidth, scissorBoxHeight));
1535 bool shouldSceneBeUpdated =
false;
1539 int currentNumberOfIterations = 0;
1540 float mixFactor = 0.0f;
1542 int nOfIterations = 0;
1543 int timeIntervalIndex = 0;
1560 nOfIterations = (
int) timeIntervalIndex % numberOfBlurPasses;
1562 if (nOfIterations >= (numberOfBlurPasses / 2))
1564 nOfIterations = numberOfBlurPasses - (nOfIterations % numberOfBlurPasses) - 1;
1573 mixFactor = 1.0f - mixFactor;
1578 shouldSceneBeUpdated =
true;
1586 if (shouldSceneBeUpdated)
1604 GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1611 GL_CHECK(glEnable (GL_SCISSOR_TEST) );
1614 for (
int blurIterationIndex = 0;
1615 blurIterationIndex < currentNumberOfIterations;
1616 blurIterationIndex++)
1624 GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
1625 GL_COLOR_ATTACHMENT0,
1632 if (blurIterationIndex == 0)
1644 GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1652 if (blurIterationIndex == currentNumberOfIterations - 1)
1656 GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1662 GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
1663 GL_COLOR_ATTACHMENT0,
1674 GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1678 GL_CHECK(glDisable(GL_SCISSOR_TEST));
1689 GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
1696 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1698 GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1710 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1712 GL_CHECK(glBindBuffer (GL_UNIFORM_BUFFER,
1714 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
1717 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1720 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1723 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1726 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1729 GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1766 JNIEnv * env, jobject obj, jint
width, jint
height)
1772 JNIEnv * env, jobject obj)
1779 JNIEnv * env, jobject obj, jfloat
time)
#define BLUR_EFFECT_INCREASE
#define TEXTURE_UNIT_COLOR_TEXTURE
static void getLocationsForBlendingProgram(GLuint programObjectId, BlendingProgramLocations *locationsStoragePtr)
Retrieve the locations of uniforms for the program object responsible for applying the blend effect...
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.
ProgramAndShadersIds getLuminanceImageProgramShaderObjects
GLint attribCubeVertexCoordinates
#define TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE
GLint uniformLightPropertiesShininess
SceneRenderingProgramLocations sceneRenderingProgramLocations
GetLuminanceImageBloomObjects()
static void deleteProgramShaderObjects(ProgramAndShadersIds *objectsToBeDeletedPtr)
Delete program and shader objects. According to the OpenGL ES specification, program object will not ...
Structure holding IDs of objects which were generated for generating downscaled texture with luminanc...
#define WINDOW_RESOLUTION_DIVISOR
static const char renderTextureVertexShaderSource[]
#define MAX_NUMBER_OF_BLUR_PASSES
SceneRenderingObjects sceneRenderingObjects
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_step(JNIEnv *env, jobject obj, jfloat time)
#define NUMBER_OF_COMPONENTS_PER_VERTEX
SceneRenderingProgramLocations()
GLint GLsizei GLsizei height
#define MIN_NUMBER_OF_BLUR_PASSES
#define BLUR_EFFECT_DECREASE
Matrix cameraLookAtMatrix
BlurringProgramLocations blurringHorizontalProgramLocations
#define TEXTURE_UNIT_STRONGER_BLUR_TEXTURE
Structure holding IDs of objects which were generated for stronger texture blurring.
static void getLocationsForBlurringProgram(GLuint programObjectId, BlurringProgramLocations *locationsStoragePtr)
Retrieve the locations of uniforms for the program object responsible for applying the blur effect...
GLint uniformLightPropertiesStrength
GLuint textureObjectIdVertical
Functions for manipulating matrices.
GLint uniformLightPropertiesLinearAttenuation
Structure holding locations of uniforms used by a program object responsible for blurring.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
#define TEXTURE_UNIT_BLURRED_TEXTURE
Structure holding locations of attributes and uniforms used by a program object responsible for scene...
GLuint vertexShaderObjectId
static void getNormals(int *numberOfCoordinates, float **normals)
Create normals for a cube which was created with getTriangleRepresentation() function.
static void generateAndPrepareObjectsUsedForBlurring(GLuint *framebufferObjectIdPtr, GLuint *horizontalTextureObjectIdPtr, GLuint *verticalTextureObjectIdPtr)
Generate texture and framebuffer objects, configure texture parameters. Finally, reset GL_TEXTURE_2D ...
static void setUniformValuesForSceneRenderingProgram(const SceneRenderingProgramLocations *locationsPtr, Matrix mvMatrix, Matrix mvpMatrix, Vec3f cameraPosition, Vec3f lightPosition)
Configure the scene rendering program's uniforms.
GLint uniformStrongerBlurTexture
ProgramAndShadersIds blurringVerticalProgramShaderObjects
GLuint framebufferObjectId
ProgramAndShadersIds sceneRenderingProgramShaderObjects
static void deleteGetLuminanceImageBloomObjects(GetLuminanceImageBloomObjects *objectIdsStoragePtr)
Delete objects which were generated for getting downscaled luminance image. According to the OpenGL E...
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
BlendingProgramLocations()
static void renderDowscaledLuminanceTexture()
BlendingProgramLocations blendingProgramLocations
static const char blendFragmentShaderSource[]
int lastNumberOfIterations
float * getAsArray(void)
Get the matrix elements as a column major order array.
GLint uniformLightPropertiesPosition
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.
static const char blurHorizontalFragmentShaderSource[]
#define VERTICAL_POSITION_CAMERA_DEPTH_LOCATION
A 3D floating point vector.
static void deleteSceneRenderingObjects(SceneRenderingObjects *objectIdsStoragePtr)
Delete objects which were generated for scene rendering purposes. According to the OpenGL ES specific...
GLuint textureObjectIdHorizontal
Structure holding ID of objects which were generated for blurring.
GLuint framebufferObjectId
GLint uniformLightPropertiesConstantAttenuation
GLuint textureObjectIdDepthImage
void uninit()
Delete created objects and free allocated memory.
ProgramAndShadersIds blendingProgramShaderObjects
GLuint fragmentShaderObjectId
static void getLocationsForSceneRenderingProgram(GLuint programObjectId, SceneRenderingProgramLocations *locationsStoragePtr)
Retrieve the locations of attributes and uniforms for the program object responsible for scene render...
GLfloat * cubeCoordinates
static Matrix matrixCameraLookAt(Vec3f eye, Vec3f center, Vec3f up)
Create and return a camera matrix.
static void getTriangleRepresentation(float scalingFactor, int *numberOfCoordinates, float **coordinates)
Compute coordinates of points which make up a cube.
static const char renderSceneFragmentShaderSource[]
BlurringObjects blurringObjects
static const char renderSceneVertexShaderSource[]
#define TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE
static void deleteBlurringObjects(BlurringObjects *objectIdsStoragePtr)
Delete objects which were generated for blurring purposes. According to the OpenGL ES specification...
static const char blurVerticalFragmentShaderSource[]
GLint uniformWeakerBlurTexture
Matrix cameraViewProjectionMatrix
GLuint bufferObjectIdElementLocations
ProgramAndShadersIds blurringHorizontalProgramShaderObjects
float degreesToRadians(float degrees)
Convert an angle in degrees to radians.
GLint uniformCameraPosition
GLuint bufferObjectIdCubeNormals
StrongerBlurObjects strongerBlurObjects
static void renderSceneColourTexture()
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...
GLint GLint GLint GLint GLint x
GLuint framebufferObjectId
GLuint framebufferObjectId
GLint attribCubeVertexNormals
Structure holding ID of objects which were generated to support scene rendering.
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.
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
BlurringProgramLocations()
static const char getLuminanceImageFragmentShaderSource[]
GLsizei GLsizei GLfloat distance
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
GLuint textureObjectIdOriginalImage
static void deleteStrongerBlurObjects(StrongerBlurObjects *objectIdsStoragePtr)
Delete objects which were generated for performing the stronger blur effect on downscaled textures...
Matrix cameraProjectionMatrix
Structure holding locations of uniforms used by a program object responsible for applying the blend e...
GLint uniformOriginalTexture
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_uninit(JNIEnv *env, jobject obj)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
#define HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION
GLuint bufferObjectIdCubeCoords
GLint uniformLightPropertiesColor
BlurringProgramLocations blurringVerticalProgramLocations
GLint uniformLightPropertiesQuadraticAttenauation
GLint uniformBlockCubeProperties
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 arrange...
GLint uniformLightPropertiesAmbient
GetLuminanceImageBloomObjects getLuminanceImageBloomObjects
GLint uniformTextureSampler