OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Native.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
56 #include <jni.h>
57 #include <android/log.h>
58 
59 #include <GLES3/gl3.h>
60 
61 #include "CubeModel.h"
62 #include "Matrix.h"
63 #include "Shader.h"
64 
65 using namespace MaliSDK;
66 
68 #define WINDOW_RESOLUTION_DIVISOR (2)
69 
70 /* [Number of cubes] */
72 #define NUMBER_OF_CUBES (25)
73 /* [Number of cubes] */
74 
75 /* [Cube scalar] */
77 #define CUBE_SCALAR (0.8f)
78 /* [Cube scalar] */
79 
81 #define BLUR_RADIUS (3)
82 
84 #define NUMBER_OF_COMPONENTS_PER_VERTEX (3)
85 
87 #define MAX_NUMBER_OF_BLUR_PASSES (10)
88 
89 #define MIN_NUMBER_OF_BLUR_PASSES (2)
90 
92 #define BLUR_MIX_FACTOR_STEP_VALUE (0.05f)
93 
94 #define BLUR_EFFECT_INCREASE (1)
95 
96 #define BLUR_EFFECT_DECREASE (-1)
97 
98 #define TIME_INTERVAL (1.0f)
99 
100 /* [Color texture unit define] */
102 #define TEXTURE_UNIT_COLOR_TEXTURE (0)
103 /* [Color texture unit define] */
104 /* [Bloom source texture unit define] */
106 #define TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE (1)
107 /* [Bloom source texture unit define] */
109 #define TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE (2)
110 
111 #define TEXTURE_UNIT_BLURRED_TEXTURE (3)
112 
113 #define TEXTURE_UNIT_STRONGER_BLUR_TEXTURE (4)
114 
118 #define HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION (15.0f)
119 
122 #define VERTICAL_POSITION_CAMERA_DEPTH_LOCATION (20.0f)
123 
128 {
133 
134  /* Default values constructor. */
136  {
137  uniformMixFactor = -1;
138  uniformOriginalTexture = -1;
139  uniformStrongerBlurTexture = -1;
140  uniformWeakerBlurTexture = -1;
141  }
142 };
143 
147 {
151 
152  /* Default values constructor. */
154  {
155  framebufferObjectId = 0;
156  textureObjectIdHorizontal = 0;
157  textureObjectIdVertical = 0;
158  }
159 };
160 
165 {
168 
169  /* Default values constructor. */
171  {
172  uniformBlurRadius = -1;
173  uniformTextureSampler = -1;
174  }
175 };
176 
181 {
184 
185  /* Default values constructor. */
187  {
188  framebufferObjectId = 0;
189  textureObjectId = 0;
190  }
191 };
192 
197 {
201 
202  /* Default values constructor. */
204  {
205  fragmentShaderObjectId = 0;
206  programObjectId = 0;
207  vertexShaderObjectId = 0;
208  }
209 };
210 
215 {
222 
223  /* Default values constructor. */
225  {
226  bufferObjectIdCubeCoords = 0;
227  bufferObjectIdCubeNormals = 0;
228  bufferObjectIdElementLocations = 0;
229  framebufferObjectId = 0;
230  textureObjectIdDepthImage = 0;
231  textureObjectIdOriginalImage = 0;
232  }
233 };
234 
239 {
240  /* Attribute locations. */
243  /* Uniform locations. */
256 
257  /* Default values constructor. */
259  {
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;
274  }
275 };
276 
281 {
284 
285  /* Default values constructor. */
287  {
288  framebufferObjectId = 0;
289  textureObjectId = 0;
290  }
291 };
292 
293 /* Shader sources. */
294 /* [Blend fragment shader source] */
295 static const char blendFragmentShaderSource[] = "#version 300 es\n"
296  "precision mediump float;\n"
297  "/* UNIFORMS */\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"
306  "/* INPUTS */\n"
307  "/** Texture coordinates. */\n"
308  "in vec2 texture_coordinates;\n"
309  "/* OUTPUTS */\n"
310  "/** Fragment colour to be returned. */\n"
311  "out vec4 color;\n"
312  "void main()\n"
313  "{\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"
320  "}\n";
321 /* [Blend fragment shader source] */
322 /* [Blur fragment shader source for horizontal blurring] */
323 static const char blurHorizontalFragmentShaderSource[] = "#version 300 es\n"
324  "precision mediump float;\n"
325  "/** Defines gaussian weights. */\n"
326  "const float gaussian_weights[] = float[] (0.2270270270,\n"
327  " 0.3162162162,\n"
328  " 0.0702702703);\n"
329  "/* UNIFORMS */\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"
334  "/* INPUTS */\n"
335  "/** Texture coordinates. */\n"
336  "in vec2 texture_coordinates;\n"
337  "/* OUTPUTS */\n"
338  "/** Fragment colour that will be returned. */\n"
339  "out vec4 output_color;\n"
340  "void main()\n"
341  "{\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"
356  "}";
357 /* [Blur fragment shader source for horizontal blurring] */
358 /* [Blur fragment shader source for vertical blurring] */
359 static const char blurVerticalFragmentShaderSource[] = "#version 300 es\n"
360  "precision mediump float;\n"
361  "/** Defines gaussian weights. */\n"
362  "const float gaussian_weights[] = float[] (0.2270270270,\n"
363  " 0.3162162162,\n"
364  " 0.0702702703);\n"
365  "/* UNIFORMS */\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"
370  "/* INPUTS */\n"
371  "/** Texture coordinates. */\n"
372  "in vec2 texture_coordinates;\n"
373  "/* OUTPUTS */\n"
374  "/** Fragment colour that will be returned. */\n"
375  "out vec4 output_color;\n"
376  "void main()\n"
377  "{\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"
392  "}";
393 /* [Blur fragment shader source for vertical blurring] */
394 /* [Get luminance image fragment shader source] */
395 static const char getLuminanceImageFragmentShaderSource[] = "#version 300 es\n"
396  "precision highp float;\n"
397  "/* UNIFORMS */\n"
398  "uniform sampler2D texture_sampler;\n"
399  "/* INPUTS */\n"
400  "in vec2 texture_coordinates;\n"
401  "/* OUTPUTS */\n"
402  "out vec4 scene_color;\n"
403  "#define MIN_LUMINANCE (0.9)\n"
404  "void main()\n"
405  "{\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"
411  " {\n"
412  " scene_color = sample_color;\n"
413  " }\n"
414  " else\n"
415  " {\n"
416  " scene_color = vec4(0.0);\n"
417  " }\n"
418  "}";
419 /* [Get luminance image fragment shader source] */
420 /* [Render scene fragment shader source] */
421 static const char renderSceneFragmentShaderSource[] = "#version 300 es\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"
427  "{\n"
428  " vec3 ambient;\n"
429  " vec3 color;\n"
430  " float constant_attenuation;\n"
431  " float linear_attenuation;\n"
432  " vec3 position;\n"
433  " float quadratic_attenauation;\n"
434  " float shininess;\n"
435  " float strength;\n"
436  "};\n"
437  "/* UNIFORMS */\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"
442  "/* INPUTS */\n"
443  "/** Vertex normal. */\n"
444  " in vec3 normal;\n"
445  "/** Vertex coordinates. */\n"
446  " in vec4 vertex;\n"
447  "/** Indicates whether a cube is placed on diagonal. */\n"
448  "flat in int is_cube_placed_on_diagonal;\n"
449  "/* OUTPUTS */\n"
450  "/* Stores scene colour.*/\n"
451  "out vec4 scene_color;\n"
452  "void main()\n"
453  "{\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"
464  " {\n"
465  " specular = max(0.0, dot(half_vector, normal));\n"
466  " specular = pow(specular, light_properties.shininess) * light_properties.strength;\n"
467  " }\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"
475  " {\n"
476  " scene_color = light_cube_colour;\n"
477  " }\n"
478  " else\n"
479  " {\n"
480  " scene_color = vec4(dark_cube_colour_with_lighting, 1.0);\n"
481  " }\n"
482  "}\n";
483 /* [Render scene fragment shader source] */
484 /* [Render scene vertex shader source] */
485 static const char renderSceneVertexShaderSource[] = "#version 300 es\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"
491  " 0, 1, 0, 1, 0,\n"
492  " 0, 0, 1, 0, 0,\n"
493  " 0, 1, 0, 1, 0,\n"
494  " 1, 0, 0, 0, 1);\n"
495  "/* UNIFORMS */\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"
502  "{\n"
503  " /** Cubes' locations in a space. */\n"
504  " vec2 locations[NUMBER_OF_CUBES];\n"
505  "};\n"
506  "/* ATTRIBUTES */\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"
511  "/* OUTPUTS */\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"
518  "void main()\n"
519  "{\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"
534  "}\n";
535 /* [Render scene vertex shader source] */
536 /* [Texture rendering vertex shader] */
537 static const char renderTextureVertexShaderSource[] = "#version 300 es\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"
546  " vec2(0.0, 0.0),\n"
547  " vec2(0.0, 1.0),\n"
548  " vec2(1.0, 1.0) );\n"
549  "/* OUTPUTS */\n"
550  "/** Texture coordinates. */\n"
551  "out vec2 texture_coordinates;\n"
552  "void main()\n"
553  "{\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"
558  "}\n";
559 /* [Texture rendering vertex shader] */
560 
561 /* Variables used for scene view configurations. */
567 const float farPlane = 100.f;
568 Vec3f lightPosition = {0.0f, 0.0f, 10.0f};
569 const Vec3f lookAtPoint = {0.0f, 0.0f, 0.0f};
572 const float nearPlane = 0.01f;
573 const Vec3f upVector = {0.0f, 1.0f, 0.0f};
574 int windowHeight = 0;
575 int windowWidth = 0;
576 
577 /* Number of blur loop iterations. */
579 
580 /* Variables used for rendering a geometry. */
587 
588 /* Variables used for program object configurations. */
598 
599 /* Variables used to store generated objects IDs. */
604 
613 static void deleteBlurringObjects(BlurringObjects* objectIdsStoragePtr)
614 {
615  ASSERT(objectIdsStoragePtr != NULL);
616 
617  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectIdHorizontal) );
618  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectIdVertical) );
619  GL_CHECK(glDeleteFramebuffers(1, &objectIdsStoragePtr->framebufferObjectId) );
620 
621  objectIdsStoragePtr->textureObjectIdHorizontal = 0;
622  objectIdsStoragePtr->textureObjectIdVertical = 0;
623  objectIdsStoragePtr->framebufferObjectId = 0;
624 }
625 
635 {
636  ASSERT(objectIdsStoragePtr != NULL);
637 
638  GL_CHECK(glDeleteFramebuffers(1, &objectIdsStoragePtr->framebufferObjectId) );
639  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectId) );
640 
641  objectIdsStoragePtr->framebufferObjectId = 0;
642  objectIdsStoragePtr->textureObjectId = 0;
643 }
644 
652 static void deleteProgramShaderObjects(ProgramAndShadersIds* objectsToBeDeletedPtr)
653 {
654  ASSERT(objectsToBeDeletedPtr != NULL);
655 
656  GL_CHECK(glDeleteShader (objectsToBeDeletedPtr->fragmentShaderObjectId) );
657  GL_CHECK(glDeleteShader (objectsToBeDeletedPtr->vertexShaderObjectId) );
658  GL_CHECK(glDeleteProgram(objectsToBeDeletedPtr->programObjectId) );
659 
660  objectsToBeDeletedPtr->fragmentShaderObjectId = 0;
661  objectsToBeDeletedPtr->vertexShaderObjectId = 0;
662  objectsToBeDeletedPtr->programObjectId = 0;
663 }
664 
673 static void deleteSceneRenderingObjects(SceneRenderingObjects* objectIdsStoragePtr)
674 {
675  ASSERT(objectIdsStoragePtr != NULL);
676 
677  GL_CHECK(glDeleteBuffers (1, &objectIdsStoragePtr->bufferObjectIdCubeCoords) );
678  GL_CHECK(glDeleteBuffers (1, &objectIdsStoragePtr->bufferObjectIdCubeNormals) );
679  GL_CHECK(glDeleteBuffers (1, &objectIdsStoragePtr->bufferObjectIdElementLocations) );
680  GL_CHECK(glDeleteFramebuffers(1, &objectIdsStoragePtr->framebufferObjectId) );
681  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectIdDepthImage) );
682  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectIdOriginalImage) );
683 
684  objectIdsStoragePtr->bufferObjectIdCubeCoords = 0;
685  objectIdsStoragePtr->bufferObjectIdCubeNormals = 0;
686  objectIdsStoragePtr->bufferObjectIdElementLocations = 0;
687  objectIdsStoragePtr->framebufferObjectId = 0;
688  objectIdsStoragePtr->textureObjectIdDepthImage = 0;
689  objectIdsStoragePtr->textureObjectIdOriginalImage = 0;
690 }
691 
700 static void deleteStrongerBlurObjects(StrongerBlurObjects* objectIdsStoragePtr)
701 {
702  ASSERT(objectIdsStoragePtr != NULL);
703 
704  GL_CHECK(glDeleteFramebuffers(1, &objectIdsStoragePtr->framebufferObjectId) );
705  GL_CHECK(glDeleteTextures (1, &objectIdsStoragePtr->textureObjectId) );
706 
707  objectIdsStoragePtr->framebufferObjectId = 0;
708  objectIdsStoragePtr->textureObjectId = 0;
709 }
710 
722 static void generateAndPrepareObjectsUsedForBlurring(GLuint* framebufferObjectIdPtr,
723  GLuint* horizontalTextureObjectIdPtr,
724  GLuint* verticalTextureObjectIdPtr)
725 {
726  ASSERT(framebufferObjectIdPtr != NULL);
727  ASSERT(horizontalTextureObjectIdPtr != NULL);
728  ASSERT(verticalTextureObjectIdPtr != NULL);
729 
730  /* Generate objects. */
731  GL_CHECK(glGenFramebuffers(1,
732  framebufferObjectIdPtr) );
733  GL_CHECK(glGenTextures (1,
734  horizontalTextureObjectIdPtr) );
735  GL_CHECK(glGenTextures (1,
736  verticalTextureObjectIdPtr) );
737 
738  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
739  *horizontalTextureObjectIdPtr) );
740  GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
741  0,
742  GL_RGBA8,
745  0,
746  GL_RGBA,
747  GL_UNSIGNED_BYTE,
748  NULL) );
749  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
750  GL_TEXTURE_WRAP_S,
751  GL_CLAMP_TO_EDGE) );
752  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
753  GL_TEXTURE_WRAP_T,
754  GL_CLAMP_TO_EDGE) );
755  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
756  GL_TEXTURE_MAG_FILTER,
757  GL_LINEAR) );
758  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
759  GL_TEXTURE_MIN_FILTER,
760  GL_LINEAR) );
761 
762  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
763  *verticalTextureObjectIdPtr) );
764  GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
765  0,
766  GL_RGBA8,
769  0,
770  GL_RGBA,
771  GL_UNSIGNED_BYTE,
772  NULL) );
773  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
774  GL_TEXTURE_WRAP_S,
775  GL_CLAMP_TO_EDGE) );
776  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
777  GL_TEXTURE_WRAP_T,
778  GL_CLAMP_TO_EDGE) );
779  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
780  GL_TEXTURE_MAG_FILTER,
781  GL_LINEAR) );
782  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
783  GL_TEXTURE_MIN_FILTER,
784  GL_LINEAR) );
785 
786  /* At the end, restore default environment settings (bind default TO). */
787  GL_CHECK(glBindTexture(GL_TEXTURE_2D,
788  0) );
789 }
790 
802 static void generateAndPrepareObjectsUsedForSceneRendering(GLuint* framebufferObjectIdPtr,
803  GLuint* originalTextureObjectIdPtr,
804  GLuint* depthToIdPtr)
805 {
806  ASSERT(framebufferObjectIdPtr != NULL);
807  ASSERT(originalTextureObjectIdPtr!= NULL);
808  ASSERT(depthToIdPtr != NULL);
809 
810  /* [Generate Objects For Scene Rendering] */
811  /* Generate objects. */
812  GL_CHECK(glGenFramebuffers(1,
813  framebufferObjectIdPtr) );
814  GL_CHECK(glGenTextures (1,
815  originalTextureObjectIdPtr) );
816  GL_CHECK(glGenTextures (1,
817  depthToIdPtr) );
818 
819  /* Bind generated framebuffer and texture objects to specific binding points. */
820  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
821  *framebufferObjectIdPtr) );
822 
823  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
824  *originalTextureObjectIdPtr) );
825  GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
826  0,
827  GL_RGBA8,
828  windowWidth,
829  windowHeight,
830  0,
831  GL_RGBA,
832  GL_UNSIGNED_BYTE,
833  NULL) );
834  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
835  GL_TEXTURE_WRAP_S,
836  GL_CLAMP_TO_EDGE) );
837  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
838  GL_TEXTURE_WRAP_T,
839  GL_CLAMP_TO_EDGE) );
840  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
841  GL_TEXTURE_MAG_FILTER,
842  GL_LINEAR) );
843  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
844  GL_TEXTURE_MIN_FILTER,
845  GL_LINEAR) );
846 
847  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
848  *depthToIdPtr) );
849  GL_CHECK(glTexImage2D (GL_TEXTURE_2D,
850  0,
851  GL_DEPTH_COMPONENT32F,
852  windowWidth,
853  windowHeight,
854  0,
855  GL_DEPTH_COMPONENT,
856  GL_FLOAT,
857  NULL) );
858  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
859  GL_TEXTURE_MIN_FILTER,
860  GL_NEAREST) );
861  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
862  GL_TEXTURE_MAG_FILTER,
863  GL_NEAREST) );
864  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
865  GL_TEXTURE_WRAP_S,
866  GL_CLAMP_TO_EDGE) );
867  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
868  GL_TEXTURE_WRAP_T,
869  GL_CLAMP_TO_EDGE) );
870  /* [Generate Objects For Scene Rendering] */
871 
872  /* [Bind Textures to Framebuffer] */
873  /* Bind colour and depth textures to framebuffer object. */
874  GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
875  GL_COLOR_ATTACHMENT0,
876  GL_TEXTURE_2D,
877  *originalTextureObjectIdPtr,
878  0) );
879  GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
880  GL_DEPTH_ATTACHMENT,
881  GL_TEXTURE_2D,
882  *depthToIdPtr,
883  0) );
884  /* [Bind Textures to Framebuffer] */
885 
886  /* At the end, restore default environment settings (bind default FBO and TO). */
887  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
888  0) );
889  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
890  0) );
891 }
892 
893 /* [Generate downscaled objects] */
903 static void generateDownscaledObjects(GLuint* fboIdPtr,
904  GLuint* toIdPtr)
905 {
906  ASSERT(fboIdPtr != NULL);
907  ASSERT(toIdPtr != NULL);
908 
909  /* Generate objects. */
910  GL_CHECK(glGenFramebuffers(1,
911  fboIdPtr) );
912  GL_CHECK(glGenTextures (1,
913  toIdPtr) );
914 
915  /* Set texture parameters. */
916  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
917  *toIdPtr) );
918  GL_CHECK(glTexStorage2D (GL_TEXTURE_2D,
919  1,
920  GL_RGBA8,
923  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
924  GL_TEXTURE_WRAP_S,
925  GL_CLAMP_TO_EDGE) );
926  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
927  GL_TEXTURE_WRAP_T,
928  GL_CLAMP_TO_EDGE) );
929  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
930  GL_TEXTURE_MAG_FILTER,
931  GL_LINEAR) );
932  GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
933  GL_TEXTURE_MIN_FILTER,
934  GL_LINEAR) );
935 
936  /* Make framebuffer object active and bind texture object to it. */
937  GL_CHECK(glBindFramebuffer (GL_FRAMEBUFFER,
938  *fboIdPtr) );
939  GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
940  GL_COLOR_ATTACHMENT0,
941  GL_TEXTURE_2D,
942  *toIdPtr,
943  0) );
944 
945  /* Restore default bindings. */
946  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
947  0) );
948  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
949  0) );
950 }
951 /* [Generate downscaled objects] */
952 
953 /* [Calculate cube locations] */
968 static GLfloat* getCubeLocations(GLint numberOfColumns,
969  GLint numberOfRows,
970  GLfloat cubeScalar,
971  GLfloat distanceBetweenCubes,
972  GLint* numberOfCubeLocationCoordinatesPtr)
973 {
974  ASSERT(numberOfCubeLocationCoordinatesPtr != NULL);
975 
976  const float distance = distanceBetweenCubes + 2 * cubeScalar; /* A single cube spreads out from
977  * <-cubeScalar, -cubeScalar, -cubeScalar> to
978  * <cubeScalar, cubeScalar, cubeScalar>,
979  * with <0, 0, 0> representing the center of the cube.
980  * We have to enlarge the requested distance between cubes
981  * (2 * cubeScalar) times. */
982  int index = 0;
983  int numberOfCubeLocationCoordinates = 0;
984  const int numberOfPointCoordinates = 2;
985  GLfloat* result = NULL;
986  const float xStart = -( float(numberOfColumns - 1) / 2.0f * distance);
987  const float yStart = -( float(numberOfRows - 1) / 2.0f * distance);
988 
989  numberOfCubeLocationCoordinates = numberOfPointCoordinates * numberOfColumns * numberOfRows;
990  result = (GLfloat*) malloc(numberOfCubeLocationCoordinates * sizeof(GLfloat) );
991 
992  /* Make sure memory allocation succeeded. */
993  ASSERT(result != NULL);
994 
995  for (int rowIndex = 0; rowIndex < numberOfRows; rowIndex++)
996  {
997  for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++)
998  {
999  result[index++] = xStart + (rowIndex * distance);
1000  result[index++] = yStart + (columnIndex * distance);
1001  }
1002  }
1003 
1004  *numberOfCubeLocationCoordinatesPtr = numberOfCubeLocationCoordinates;
1005 
1006  return result;
1007 }
1008 /* [Calculate cube locations] */
1009 
1017 static void getLocationsForBlendingProgram(GLuint programObjectId,
1018  BlendingProgramLocations* locationsStoragePtr)
1019 {
1020  ASSERT(locationsStoragePtr != NULL);
1021  ASSERT(programObjectId != 0);
1022 
1023  locationsStoragePtr->uniformMixFactor = GL_CHECK(glGetUniformLocation(programObjectId, "mix_factor") );
1024  locationsStoragePtr->uniformOriginalTexture = GL_CHECK(glGetUniformLocation(programObjectId, "original_texture") );
1025  locationsStoragePtr->uniformStrongerBlurTexture = GL_CHECK(glGetUniformLocation(programObjectId, "stronger_blur_texture") );
1026  locationsStoragePtr->uniformWeakerBlurTexture = GL_CHECK(glGetUniformLocation(programObjectId, "weaker_blur_texture") );
1027 
1028  ASSERT(locationsStoragePtr->uniformMixFactor != -1);
1029  ASSERT(locationsStoragePtr->uniformOriginalTexture != -1);
1030  ASSERT(locationsStoragePtr->uniformStrongerBlurTexture != -1);
1031  ASSERT(locationsStoragePtr->uniformWeakerBlurTexture != -1);
1032 }
1033 
1041 static void getLocationsForBlurringProgram(GLuint programObjectId,
1042  BlurringProgramLocations* locationsStoragePtr)
1043 {
1044  ASSERT(locationsStoragePtr != NULL);
1045  ASSERT(programObjectId != 0);
1046 
1047  locationsStoragePtr->uniformBlurRadius = GL_CHECK(glGetUniformLocation(programObjectId, "blur_radius") );
1048  locationsStoragePtr->uniformTextureSampler = GL_CHECK(glGetUniformLocation(programObjectId, "texture_sampler") );
1049 
1050  ASSERT(locationsStoragePtr->uniformBlurRadius != -1);
1051  ASSERT(locationsStoragePtr->uniformTextureSampler != -1);
1052 }
1053 
1061 static void getLocationsForSceneRenderingProgram(GLuint programObjectId,
1062  SceneRenderingProgramLocations* locationsStoragePtr)
1063 {
1064  ASSERT(locationsStoragePtr != NULL);
1065  ASSERT(programObjectId != 0);
1066 
1067  /* [Get cube vertex coordinates attrib location] */
1068  locationsStoragePtr->attribCubeVertexCoordinates = GL_CHECK(glGetAttribLocation (programObjectId,
1069  "cube_vertex_coordinates") );
1070  /* [Get cube vertex coordinates attrib location] */
1071  locationsStoragePtr->attribCubeVertexNormals = GL_CHECK(glGetAttribLocation (programObjectId,
1072  "cube_vertex_normals") );
1073  /* [Get cube locations uniform block location] */
1074  locationsStoragePtr->uniformBlockCubeProperties = GL_CHECK(glGetUniformBlockIndex(programObjectId,
1075  "cube_properties") );
1076  /* [Get cube locations uniform block location] */
1077  locationsStoragePtr->uniformCameraPosition = GL_CHECK(glGetUniformLocation (programObjectId,
1078  "camera_position") );
1079  locationsStoragePtr->uniformLightPropertiesAmbient = GL_CHECK(glGetUniformLocation (programObjectId,
1080  "light_properties.ambient") );
1081  locationsStoragePtr->uniformLightPropertiesColor = GL_CHECK(glGetUniformLocation (programObjectId,
1082  "light_properties.color") );
1083  locationsStoragePtr->uniformLightPropertiesConstantAttenuation = GL_CHECK(glGetUniformLocation (programObjectId,
1084  "light_properties.constant_attenuation") );
1085  locationsStoragePtr->uniformLightPropertiesLinearAttenuation = GL_CHECK(glGetUniformLocation (programObjectId,
1086  "light_properties.linear_attenuation") );
1087  locationsStoragePtr->uniformLightPropertiesPosition = GL_CHECK(glGetUniformLocation (programObjectId,
1088  "light_properties.position") );
1089  locationsStoragePtr->uniformLightPropertiesQuadraticAttenauation = GL_CHECK(glGetUniformLocation (programObjectId,
1090  "light_properties.quadratic_attenauation") );
1091  locationsStoragePtr->uniformLightPropertiesShininess = GL_CHECK(glGetUniformLocation (programObjectId,
1092  "light_properties.shininess") );
1093  locationsStoragePtr->uniformLightPropertiesStrength = GL_CHECK(glGetUniformLocation (programObjectId,
1094  "light_properties.strength") );
1095  locationsStoragePtr->uniformMvMatrix = GL_CHECK(glGetUniformLocation (programObjectId,
1096  "mv_matrix") );
1097  locationsStoragePtr->uniformMvpMatrix = GL_CHECK(glGetUniformLocation (programObjectId,
1098  "mvp_matrix") );
1099 
1100  ASSERT(locationsStoragePtr->attribCubeVertexCoordinates != -1);
1101  ASSERT(locationsStoragePtr->attribCubeVertexNormals != -1);
1102  ASSERT(locationsStoragePtr->uniformBlockCubeProperties != GL_INVALID_INDEX);
1103  ASSERT(locationsStoragePtr->uniformCameraPosition != -1);
1104  ASSERT(locationsStoragePtr->uniformLightPropertiesAmbient != -1);
1105  ASSERT(locationsStoragePtr->uniformLightPropertiesColor != -1);
1106  ASSERT(locationsStoragePtr->uniformLightPropertiesConstantAttenuation != -1);
1107  ASSERT(locationsStoragePtr->uniformLightPropertiesLinearAttenuation != -1);
1108  ASSERT(locationsStoragePtr->uniformLightPropertiesPosition != -1);
1109  ASSERT(locationsStoragePtr->uniformLightPropertiesQuadraticAttenauation != -1);
1110  ASSERT(locationsStoragePtr->uniformLightPropertiesShininess != -1);
1111  ASSERT(locationsStoragePtr->uniformLightPropertiesStrength != -1);
1112  ASSERT(locationsStoragePtr->uniformMvMatrix != -1);
1113  ASSERT(locationsStoragePtr->uniformMvpMatrix != -1);
1114 }
1115 
1127  const char* fragmentShaderSource,
1128  const char* vertexShaderSource)
1129 {
1130  ASSERT(objectIdsPtr != NULL);
1131 
1132  GLint linkStatus = 0;
1133 
1134  objectIdsPtr->programObjectId = GL_CHECK(glCreateProgram() );
1135 
1137  fragmentShaderSource,
1138  GL_FRAGMENT_SHADER);
1140  vertexShaderSource,
1141  GL_VERTEX_SHADER);
1142 
1143  GL_CHECK(glAttachShader(objectIdsPtr->programObjectId, objectIdsPtr->fragmentShaderObjectId) );
1144  GL_CHECK(glAttachShader(objectIdsPtr->programObjectId, objectIdsPtr->vertexShaderObjectId) );
1145 
1146  GL_CHECK(glLinkProgram(objectIdsPtr->programObjectId) );
1147 
1148  GL_CHECK(glGetProgramiv(objectIdsPtr->programObjectId, GL_LINK_STATUS, &linkStatus) );
1149 
1150  ASSERT(linkStatus == GL_TRUE);
1151 }
1152 
1153 /* \brief Render the luminance image (which then can be bloomed) and store the result in corresponding texture object.
1154  */
1156 {
1157  /* [Render luminance image into downscaled texture] */
1158  /* Get the luminance image, store it in the downscaled texture. */
1160  {
1161  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1163  /* Set the viewport for the whole screen size. */
1164  GL_CHECK(glViewport(0,
1165  0,
1168  /* Clear the framebuffer's content. */
1169  GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1170  /* Draw texture. */
1171  GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1172  }
1173  /* [Render luminance image into downscaled texture] */
1174 }
1175 
1176 /* \brief Render the scene and store the result in corresponding texture object.
1177  */
1179 {
1180  /* [Render scene into texture objects] */
1181  /* Render scene.
1182  * The scene is rendered to two render targets:
1183  * - 1. First texture will store color data;
1184  * - 2. Second texture will store color data, but only for the cubes that should be
1185  * affected by the bloom operation (remaining objects will not be rendered).
1186  */
1188  {
1189  /* Bind a framebuffer object to the GL_DRAW_FRAMEBUFFER framebuffer binding point,
1190  * so that everything we render will end up in the FBO's attachments. */
1191  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1193  /* Set the viewport for the whole screen size. */
1194  GL_CHECK(glViewport(0,
1195  0,
1196  windowWidth,
1197  windowHeight) );
1198  /* Clear the framebuffer's content. */
1199  GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1200  /* [Instanced drawing] */
1201  /* Draw scene. */
1202  GL_CHECK(glDrawArraysInstanced(GL_TRIANGLES,
1203  0,
1205  NUMBER_OF_CUBES) );
1206  /* [Instanced drawing] */
1207  }
1208  /* [Render scene into texture objects] */
1209 }
1210 
1221  Matrix mvMatrix,
1222  Matrix mvpMatrix,
1225 {
1226  ASSERT(locationsPtr != NULL);
1227 
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;
1235  bool result = true;
1236 
1237  /* Set model-view-(projection) matrices. */
1238  GL_CHECK(glUniformMatrix4fv(locationsPtr->uniformMvMatrix,
1239  1,
1240  GL_FALSE,
1241  mvMatrix.getAsArray() ) );
1242  GL_CHECK(glUniformMatrix4fv(locationsPtr->uniformMvpMatrix,
1243  1,
1244  GL_FALSE,
1245  mvpMatrix.getAsArray() ) );
1246 
1247  /* Set light properties uniforms. */
1248  GL_CHECK(glUniform3f(locationsPtr->uniformCameraPosition, cameraPosition.x,
1249  cameraPosition.y,
1250  cameraPosition.z) );
1251  GL_CHECK(glUniform3f(locationsPtr->uniformLightPropertiesAmbient, lightAmbient.x,
1252  lightAmbient.y,
1253  lightAmbient.z) );
1254  GL_CHECK(glUniform3f(locationsPtr->uniformLightPropertiesColor, lightColor.x,
1255  lightColor.y,
1256  lightColor.z) );
1257  GL_CHECK(glUniform1f(locationsPtr->uniformLightPropertiesConstantAttenuation, lightConstantAttenuation) );
1258  GL_CHECK(glUniform1f(locationsPtr->uniformLightPropertiesLinearAttenuation, lightLinearAttenuation) );
1259  GL_CHECK(glUniform3f(locationsPtr->uniformLightPropertiesPosition, lightPosition.x,
1260  lightPosition.y,
1261  lightPosition.z) );
1262  GL_CHECK(glUniform1f(locationsPtr->uniformLightPropertiesQuadraticAttenauation, lightQuadraticAttenuation) );
1263  GL_CHECK(glUniform1f(locationsPtr->uniformLightPropertiesShininess, lightShininess) );
1264  GL_CHECK(glUniform1f(locationsPtr->uniformLightPropertiesStrength, lightStrength) );
1265 }
1266 
1275 {
1276  float cameraDepthPosition = 0.0f;
1277 
1278  /* Store window resolution. */
1279  windowHeight = height;
1280  windowWidth = width;
1281 
1282  if (windowHeight > windowWidth)
1283  {
1284  /* We are dealing with vertical position of a screen used for rendering. */
1285  cameraDepthPosition = VERTICAL_POSITION_CAMERA_DEPTH_LOCATION;
1288  }
1289  else
1290  {
1291  /* We are dealing with horizontal position of a screen used for rendering. */
1292  cameraDepthPosition = HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION;
1295  }
1296 
1297  /* Get geometry needed to render a scene. We will be drawing a cube in multiple instances. */
1298  /* [Get cube triangle representation] */
1300  /* [Get cube triangle representation] */
1301  /* [Get cube normals] */
1303  /* [Get cube normals] */
1304 
1306 
1307  /* Configure camera view on a scene. */
1308  cameraPosition.x = 0.0f;
1309  cameraPosition.y = 0.0f;
1310  cameraPosition.z = cameraDepthPosition;
1313  (float) windowWidth / windowHeight,
1314  nearPlane,
1315  farPlane);
1318 
1319  /* Create program object responsible for scene rendering. */
1323  /* Create program object responsible for blending. */
1327  /* Create program object responsible for blurring (horizontal blur). */
1331  /* Create program object responsible for blurring (vertical blur). */
1335  /* Create program object responsible for generating luminance image that will be then bloomed. */
1339 
1340  /* [Create cube vertices buffer object] */
1341  /* Generate buffer object and fill it with cube vertex coordinates data. */
1342  GL_CHECK(glGenBuffers(1,
1344  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
1346  GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
1347  nOfCubeCoordinates * sizeof(GLfloat),
1349  GL_STATIC_DRAW) );
1350  /* [Create cube vertices buffer object] */
1351 
1352  /* Generate buffer object and fill it with cube normals data. */
1353  GL_CHECK(glGenBuffers(1,
1355  GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
1357  GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
1358  nOfCubeNormals * sizeof(GLfloat),
1359  (GLfloat*)cubeNormals,
1360  GL_STATIC_DRAW) );
1361 
1362  /* [Uniform buffer with cube locations] */
1363  /* Generate uniform buffer object and fill it with cube positions data. */
1364  GL_CHECK(glGenBuffers(1,
1366  GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER,
1368  GL_CHECK(glBufferData(GL_UNIFORM_BUFFER,
1369  nOfCubeLocations * sizeof (GLfloat),
1370  cubeLocations,
1371  GL_STATIC_DRAW) );
1372  /* [Uniform buffer with cube locations] */
1373 
1374  /* Generate objects which will be used for scene rendering. */
1378 
1379  /* Generate objects which will be used for applying blur effect. */
1383  /* Generate objects that will be used for rendering into downscaled texture. */
1388 
1389  /* Set attribute/uniform values for program object responsible for scene rendering. */
1391  {
1392  /* Restore uniform locations for program object responsible for scene rendering. */
1395  /* Set values for uniforms, which are constant during rendering process. */
1397  cameraViewMatrix,
1400  lightPosition);
1401  /* [Uniform block settings] */
1402  /* Cube locations are constant during rendering process. Set them now. */
1405  0 ) );
1406  GL_CHECK(glBindBufferBase (GL_UNIFORM_BUFFER,
1407  0,
1409  /* [Uniform block settings] */
1410  }
1411 
1412  /* [Define vertex attrib data array] */
1413  /* Cube coordinates are constant during rendering process. Set them now. */
1414  GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1418  GL_FLOAT,
1419  GL_FALSE,
1420  0,
1421  NULL) );
1422  /* [Define vertex attrib data array] */
1423  GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1427  GL_FLOAT,
1428  GL_FALSE,
1429  0,
1430  NULL) );
1431 
1432  /* Enable VAAs. */
1433  /* [Enable cube vertex coordinates attrib array] */
1435  /* [Enable cube vertex coordinates attrib array] */
1437 
1438  /* Retrieve uniform and attribute locations for program object responsible for applying blur effect. */
1440  {
1443 
1444  /* Set values for uniforms which are constant during rendering process. */
1446  }
1447 
1448  /* Retrieve uniform and attribute locations for program object responsible for applying blur effect. */
1450  {
1453 
1454  /* Set values for uniforms which are constant during rendering process. */
1456  }
1457 
1458  /* Retrieve uniform and attribute locations for program object responsible for applying blend effect. */
1460  {
1463 
1464  /* Set values for uniforms which are constant during rendering process. */
1465  /* [Set original texture uniform value] */
1467  /* [Set original texture uniform value] */
1470  }
1471 
1472  /* Set up texture unit bindings. */
1473  /* [Bind colour texture object to specific binding point] */
1474  GL_CHECK(glActiveTexture(GL_TEXTURE0 + TEXTURE_UNIT_COLOR_TEXTURE) );
1475  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1477  /* [Bind colour texture object to specific binding point] */
1478  /* [Bind bloom source texture object to specific binding point] */
1479  GL_CHECK(glActiveTexture(GL_TEXTURE0 + TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE) );
1480  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1482  /* [Bind bloom source texture object to specific binding point] */
1483  GL_CHECK(glActiveTexture(GL_TEXTURE0 + TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE) );
1484  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1486  GL_CHECK(glActiveTexture(GL_TEXTURE0 + TEXTURE_UNIT_BLURRED_TEXTURE) );
1487  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1489  GL_CHECK(glActiveTexture(GL_TEXTURE0 + TEXTURE_UNIT_STRONGER_BLUR_TEXTURE) );
1490  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1492 
1493  /* Prepare for drawing. */
1494  GL_CHECK(glClearColor(0.0f,
1495  0.0f,
1496  0.0f,
1497  1.0f) );
1498  GL_CHECK(glEnable (GL_DEPTH_TEST) );
1499 
1500  GLint x = 0;
1501  GLint y = 0;
1502  GLsizei scissorBoxWidth = min_window_dimension / WINDOW_RESOLUTION_DIVISOR;
1503  GLsizei scissorBoxHeight = min_window_dimension / WINDOW_RESOLUTION_DIVISOR;
1504 
1505  if (windowWidth > windowHeight)
1506  {
1508  y = 0;
1509  }
1510  else
1511  {
1512  x = 0;
1514  }
1515 
1516  GL_CHECK(glScissor(x, y, scissorBoxWidth, scissorBoxHeight));
1517 
1518  /* The model is not changing during the rendering process (the only thing that changes is the strength of the bloom effect).
1519  * That is why it is enough to render the scene and the luminance image only once and then use them as an input for blooming
1520  * and blurring functions in the next steps. */
1523 }
1524 
1529 void renderFrame (float time)
1530 {
1531  /* True: if scene should be updated (number of blur iterations changes),
1532  * False: if there is no need to update the scene, but blend operations
1533  * will use updated mix factor value.
1534  */
1535  bool shouldSceneBeUpdated = false;
1536 
1537  /* Variables used for blur effect calculations. */
1538  int blurEffectDirection = BLUR_EFFECT_INCREASE;
1539  int currentNumberOfIterations = 0;
1540  float mixFactor = 0.0f;
1541  const int numberOfBlurPasses = (MAX_NUMBER_OF_BLUR_PASSES - MIN_NUMBER_OF_BLUR_PASSES + 1) * 2;
1542  int nOfIterations = 0;
1543  int timeIntervalIndex = 0;
1544 
1545  /* [Mix factor calculations] */
1546  /* Mix factor value is calculated for a specific frame (for a specific time).
1547  * - The number of blur passes varies from MIN_NUMBER_OF_BLUR_PASSES to MAX_NUMBER_OF_BLUR_PASSES
1548  * and to MIN_NUMBER_OF_BLUR_PASSES again which indicates the constant animation of increasing
1549  * and decreasing blur effect strength.
1550  * - For each frame (time) there is a check done to verify the current number of blur passes.
1551  * - Once we get the current number of blur passes, we have to calculate the mix factor:
1552  * It is changing from 0 to 1 (if the blur effect is increasing) or from 1 to 0 (if the blur effect is decreasing).
1553  * This value is set based on a time which passed from the beginning of current number of blur passes rendering in
1554  * compare to the total time requested for changing this number.
1555  *
1556  * The 'rendering frame for a specific time' approach is used to avoid a situation of a different effect for slower and faster devices.
1557  */
1558  /* Increase or decrease mixFactor value (depends on blurEffectDirection). */
1559  timeIntervalIndex = (int)(time / TIME_INTERVAL);
1560  nOfIterations = (int) timeIntervalIndex % numberOfBlurPasses;
1561 
1562  if (nOfIterations >= (numberOfBlurPasses / 2))
1563  {
1564  nOfIterations = numberOfBlurPasses - (nOfIterations % numberOfBlurPasses) - 1;
1565  blurEffectDirection = BLUR_EFFECT_DECREASE;
1566  }
1567 
1568  mixFactor = (time - ((int)(time / TIME_INTERVAL) * TIME_INTERVAL)) / TIME_INTERVAL;
1569  currentNumberOfIterations = MIN_NUMBER_OF_BLUR_PASSES + nOfIterations;
1570 
1571  if (blurEffectDirection == BLUR_EFFECT_DECREASE)
1572  {
1573  mixFactor = 1.0f - mixFactor;
1574  }
1575 
1576  if (currentNumberOfIterations != lastNumberOfIterations)
1577  {
1578  shouldSceneBeUpdated = true;
1579  }
1580 
1581  /* Store current number of iterations for future use. */
1582  lastNumberOfIterations = currentNumberOfIterations;
1583  /* [Mix factor calculations] */
1584 
1585  /* Update the scene only if needed. */
1586  if (shouldSceneBeUpdated)
1587  {
1588  /* [Blur loop] */
1589  /* Apply the blur effect.
1590  * The blur effect is applied in two basic steps (note that lower resolution textures are used).
1591  * a. First, we blur the downscaled bloom texture horizontally.
1592  * b. The result of horizontal blurring is then used for vertical blurring.
1593  * The result texture contains image blrured in both directions.
1594  * c. To amplify the blur effect, steps (a) and (b) are applied multiple times
1595  * (with an exception that we now use the resulting blurred texture from the previous pass
1596  * as an input to the horizontal blurring pass).
1597  * d. The result of last iteration of applying the total blur effect (which is the result after the vertical blur is applied)
1598  * is stored in a separate texture. Thanks to that, we have the last and previous blur result textures,
1599  * both of which will be then used for continuous sampling (for the blending pass).
1600  *
1601  */
1602  /* Bind a framebuffer object to the GL_DRAW_FRAMEBUFFER framebuffer binding point,
1603  * so that everything we render will end up in the FBO's attachments. */
1604  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1606  /* Set the lower viewport resolution. It corresponds to size of the texture we will be rendering to. */
1607  GL_CHECK(glViewport(0,
1608  0,
1611  GL_CHECK(glEnable (GL_SCISSOR_TEST) );
1612 
1613  /* Apply the blur effect multiple times. */
1614  for (int blurIterationIndex = 0;
1615  blurIterationIndex < currentNumberOfIterations;
1616  blurIterationIndex++)
1617  {
1618  /* FIRST PASS - HORIZONTAL BLUR
1619  * Take the texture showing cubes which should be bloomed and apply a horizontal blur operation.
1620  */
1622  {
1623  /* Attach the texture we want the color data to be rendered to the current draw framebuffer.*/
1624  GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
1625  GL_COLOR_ATTACHMENT0,
1626  GL_TEXTURE_2D,
1628  0) );
1629 
1630  /* In first iteration we have to take the texture which shows the cubes we want blurred.
1631  * Later, we have to take the same texture that has already been blurred vertically. */
1632  if (blurIterationIndex == 0)
1633  {
1636  }
1637  else
1638  {
1641  }
1642 
1643  /* Draw texture. */
1644  GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1645  } /* FIRST PASS - HORIZONTAL BLUR */
1646 
1647  /* SECOND PASS - VERTICAL BLUR
1648  * Take the result of the previous pass (horizontal blur) and apply a vertical blur to this texture.
1649  */
1651  {
1652  if (blurIterationIndex == currentNumberOfIterations - 1)
1653  {
1654  /* In case of the last iteration, use a different framebuffer object.
1655  * The rendering results will be written to the only color attachment of the fbo. */
1656  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER,
1658  }
1659  else
1660  {
1661  /* Bind a texture object we want the result data to be stored in.*/
1662  GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
1663  GL_COLOR_ATTACHMENT0,
1664  GL_TEXTURE_2D,
1666  0) );
1667  }
1668 
1669  /* Set uniform values. */
1671  TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE) ); /* Indicates which texture object content should be blurred. */
1672 
1673  /* Draw texture. */
1674  GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1675  } /* SECOND PASS - VERTICAL BLUR */
1676  } /* for (int blur_iteration_index = 0; i < numberOfIterations; blur_iteration_index++) */
1677 
1678  GL_CHECK(glDisable(GL_SCISSOR_TEST));
1679  /* [Blur loop] */
1680  } /* if (shouldSceneBeUpdated) */
1681 
1682  /* [Blending] */
1683  /* Apply blend effect.
1684  * Take the original scene texture and blend it with texture that contains the total blurring effect.
1685  */
1687  {
1688  /* Bind the default framebuffer object. That indicates that the result is to be drawn to the back buffer. */
1689  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
1690  /* Set viewport values so that the rendering will take whole screen space. */
1691  GL_CHECK(glViewport(0, 0, windowWidth, windowHeight) );
1692  /* Set uniform value. */
1693  GL_CHECK(glUniform1f(blendingProgramLocations.uniformMixFactor, mixFactor) ); /* Current mixFactor will be used for mixing two textures color values
1694  * (texture with higher and lower blur effect value). */
1695  /* Clear framebuffer content. */
1696  GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
1697  /* Draw texture. */
1698  GL_CHECK(glDrawArrays(GL_TRIANGLE_FAN, 0, 4) );
1699  }
1700  /* [Blending] */
1701 }
1702 
1706 void uninit()
1707 {
1708  /* Destroy created objects. */
1709  GL_CHECK(glUseProgram (0) );
1710  GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
1711  0) );
1712  GL_CHECK(glBindBuffer (GL_UNIFORM_BUFFER,
1713  0) );
1714  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER,
1715  0) );
1716  GL_CHECK(glActiveTexture (GL_TEXTURE0 + TEXTURE_UNIT_COLOR_TEXTURE) );
1717  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1718  0) );
1719  GL_CHECK(glActiveTexture (GL_TEXTURE0 + TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE) );
1720  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1721  0) );
1722  GL_CHECK(glActiveTexture (GL_TEXTURE0 + TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE) );
1723  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1724  0) );
1725  GL_CHECK(glActiveTexture (GL_TEXTURE0 + TEXTURE_UNIT_BLURRED_TEXTURE) );
1726  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1727  0) );
1728  GL_CHECK(glActiveTexture (GL_TEXTURE0 + TEXTURE_UNIT_STRONGER_BLUR_TEXTURE) );
1729  GL_CHECK(glBindTexture (GL_TEXTURE_2D,
1730  0) );
1731 
1741 
1742  /* Free allocated memory. */
1743  if (cubeCoordinates != NULL)
1744  {
1745  free(cubeCoordinates);
1746 
1747  cubeCoordinates = NULL;
1748  }
1749 
1750  if (cubeNormals != NULL)
1751  {
1752  free(cubeNormals);
1753 
1754  cubeNormals = NULL;
1755  }
1756 }
1757 
1758 extern "C"
1759 {
1760  JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_init (JNIEnv * env, jobject obj, jint width, jint height);
1761  JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_step (JNIEnv * env, jobject obj, jfloat time);
1762  JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_uninit(JNIEnv * env, jobject obj);
1763 };
1764 
1766  JNIEnv * env, jobject obj, jint width, jint height)
1767 {
1768  setupGraphics(width, height);
1769 }
1770 
1772  JNIEnv * env, jobject obj)
1773 {
1774  uninit();
1775 }
1776 
1777 
1779  JNIEnv * env, jobject obj, jfloat time)
1780 {
1781  renderFrame(time);
1782 }
void setupGraphics(int width, int height)
Definition: Native.cpp:1256
#define BLUR_EFFECT_INCREASE
Definition: Native.cpp:94
#define TEXTURE_UNIT_COLOR_TEXTURE
Definition: Native.cpp:102
static void getLocationsForBlendingProgram(GLuint programObjectId, BlendingProgramLocations *locationsStoragePtr)
Retrieve the locations of uniforms for the program object responsible for applying the blend effect...
Definition: Native.cpp:1017
const float farPlane
Definition: Native.cpp:567
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.
Definition: Native.cpp:802
int nOfCubeCoordinates
Definition: Native.cpp:584
ProgramAndShadersIds getLuminanceImageProgramShaderObjects
Definition: Native.cpp:595
#define TEXTURE_UNIT_HORIZONTAL_BLUR_TEXTURE
Definition: Native.cpp:109
const Vec3f upVector
Definition: Native.cpp:573
#define GL_CHECK(x)
Definition: Native.cpp:64
SceneRenderingProgramLocations sceneRenderingProgramLocations
Definition: Native.cpp:596
static void deleteProgramShaderObjects(ProgramAndShadersIds *objectsToBeDeletedPtr)
Delete program and shader objects. According to the OpenGL ES specification, program object will not ...
Definition: Native.cpp:652
Structure holding IDs of objects which were generated for generating downscaled texture with luminanc...
Definition: Native.cpp:180
#define WINDOW_RESOLUTION_DIVISOR
Definition: Native.cpp:68
static const char renderTextureVertexShaderSource[]
Definition: Native.cpp:537
#define MAX_NUMBER_OF_BLUR_PASSES
Definition: Native.cpp:87
SceneRenderingObjects sceneRenderingObjects
Definition: Native.cpp:602
int windowHeight
Definition: Native.cpp:574
GLuint textureObjectId
Definition: Native.cpp:283
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_step(JNIEnv *env, jobject obj, jfloat time)
Definition: Native.cpp:1778
#define NUMBER_OF_COMPONENTS_PER_VERTEX
Definition: Native.cpp:84
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
#define MIN_NUMBER_OF_BLUR_PASSES
Definition: Native.cpp:89
#define BLUR_EFFECT_DECREASE
Definition: Native.cpp:96
Matrix cameraLookAtMatrix
Definition: Native.cpp:562
BlurringProgramLocations blurringHorizontalProgramLocations
Definition: Native.cpp:591
#define TEXTURE_UNIT_STRONGER_BLUR_TEXTURE
Definition: Native.cpp:113
#define BLUR_RADIUS
Definition: Native.cpp:81
Structure holding IDs of objects which were generated for stronger texture blurring.
Definition: Native.cpp:280
static void getLocationsForBlurringProgram(GLuint programObjectId, BlurringProgramLocations *locationsStoragePtr)
Retrieve the locations of uniforms for the program object responsible for applying the blur effect...
Definition: Native.cpp:1041
GLuint textureObjectIdVertical
Definition: Native.cpp:150
Functions for manipulating matrices.
Definition: Matrix.h:31
GLint uniformLightPropertiesLinearAttenuation
Definition: Native.cpp:249
Structure holding locations of uniforms used by a program object responsible for blurring.
Definition: Native.cpp:164
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
Definition: Native.cpp:1765
#define TEXTURE_UNIT_BLURRED_TEXTURE
Definition: Native.cpp:111
Structure holding locations of attributes and uniforms used by a program object responsible for scene...
Definition: Native.cpp:238
GLuint vertexShaderObjectId
Definition: Native.cpp:200
static void getNormals(int *numberOfCoordinates, float **normals)
Create normals for a cube which was created with getTriangleRepresentation() function.
Definition: CubeModel.cpp:356
precision highp int
Definition: hiz_cull.cs:38
static void generateAndPrepareObjectsUsedForBlurring(GLuint *framebufferObjectIdPtr, GLuint *horizontalTextureObjectIdPtr, GLuint *verticalTextureObjectIdPtr)
Generate texture and framebuffer objects, configure texture parameters. Finally, reset GL_TEXTURE_2D ...
Definition: Native.cpp:722
static void setUniformValuesForSceneRenderingProgram(const SceneRenderingProgramLocations *locationsPtr, Matrix mvMatrix, Matrix mvpMatrix, Vec3f cameraPosition, Vec3f lightPosition)
Configure the scene rendering program's uniforms.
Definition: Native.cpp:1220
GLint uniformStrongerBlurTexture
Definition: Native.cpp:131
#define TIME_INTERVAL
Definition: Native.cpp:98
ProgramAndShadersIds blurringVerticalProgramShaderObjects
Definition: Native.cpp:594
GLuint framebufferObjectId
Definition: Native.cpp:282
ProgramAndShadersIds sceneRenderingProgramShaderObjects
Definition: Native.cpp:597
static void deleteGetLuminanceImageBloomObjects(GetLuminanceImageBloomObjects *objectIdsStoragePtr)
Delete objects which were generated for getting downscaled luminance image. According to the OpenGL E...
Definition: Native.cpp:634
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
Definition: Matrix.cpp:425
float distance
Definition: Native.cpp:156
GLuint index
Definition: gl2ext.h:300
static void renderDowscaledLuminanceTexture()
Definition: Native.cpp:1155
BlendingProgramLocations blendingProgramLocations
Definition: Native.cpp:589
static const char blendFragmentShaderSource[]
Definition: Native.cpp:295
int lastNumberOfIterations
Definition: Native.cpp:578
float * getAsArray(void)
Get the matrix elements as a column major order array.
Definition: Matrix.cpp:78
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.
Definition: Native.cpp:196
Vec3f lightPosition
Definition: Native.cpp:568
static const char blurHorizontalFragmentShaderSource[]
Definition: Native.cpp:323
#define VERTICAL_POSITION_CAMERA_DEPTH_LOCATION
Definition: Native.cpp:122
A 3D floating point vector.
Definition: VectorTypes.h:83
static void deleteSceneRenderingObjects(SceneRenderingObjects *objectIdsStoragePtr)
Delete objects which were generated for scene rendering purposes. According to the OpenGL ES specific...
Definition: Native.cpp:673
GLuint textureObjectIdHorizontal
Definition: Native.cpp:149
Structure holding ID of objects which were generated for blurring.
Definition: Native.cpp:146
GLint uniformLightPropertiesConstantAttenuation
Definition: Native.cpp:248
GLuint textureObjectIdDepthImage
Definition: Native.cpp:220
const Vec3f lookAtPoint
Definition: Native.cpp:569
int nOfCubeLocations
Definition: Native.cpp:585
void uninit()
Delete created objects and free allocated memory.
Definition: Native.cpp:1706
ProgramAndShadersIds blendingProgramShaderObjects
Definition: Native.cpp:590
Vec3f cameraPosition
Definition: Native.cpp:563
GLuint fragmentShaderObjectId
Definition: Native.cpp:198
static void getLocationsForSceneRenderingProgram(GLuint programObjectId, SceneRenderingProgramLocations *locationsStoragePtr)
Retrieve the locations of attributes and uniforms for the program object responsible for scene render...
Definition: Native.cpp:1061
GLfloat GLfloat f
Definition: gl2ext.h:2707
GLfloat * cubeCoordinates
Definition: Native.cpp:581
Matrix cameraViewMatrix
Definition: Native.cpp:565
#define CUBE_SCALAR
Definition: Native.cpp:77
static Matrix matrixCameraLookAt(Vec3f eye, Vec3f center, Vec3f up)
Create and return a camera matrix.
Definition: Matrix.cpp:441
static void getTriangleRepresentation(float scalingFactor, int *numberOfCoordinates, float **coordinates)
Compute coordinates of points which make up a cube.
Definition: CubeModel.cpp:29
static const char renderSceneFragmentShaderSource[]
Definition: Native.cpp:421
BlurringObjects blurringObjects
Definition: Native.cpp:600
void renderFrame(void)
Definition: Native.cpp:1536
static const char renderSceneVertexShaderSource[]
Definition: Native.cpp:485
int max_window_dimension
Definition: Native.cpp:570
#define TEXTURE_UNIT_BLOOM_SOURCE_TEXTURE
Definition: Native.cpp:106
static void deleteBlurringObjects(BlurringObjects *objectIdsStoragePtr)
Delete objects which were generated for blurring purposes. According to the OpenGL ES specification...
Definition: Native.cpp:613
static const char blurVerticalFragmentShaderSource[]
Definition: Native.cpp:359
Matrix cameraViewProjectionMatrix
Definition: Native.cpp:566
GLuint bufferObjectIdElementLocations
Definition: Native.cpp:218
ProgramAndShadersIds blurringHorizontalProgramShaderObjects
Definition: Native.cpp:592
float degreesToRadians(float degrees)
Convert an angle in degrees to radians.
Definition: Mathematics.h:86
GLuint bufferObjectIdCubeNormals
Definition: Native.cpp:217
StrongerBlurObjects strongerBlurObjects
Definition: Native.cpp:603
static void renderSceneColourTexture()
Definition: Native.cpp:1178
int windowWidth
Definition: Native.cpp:575
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...
Definition: Native.cpp:1126
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
GLuint framebufferObjectId
Definition: Native.cpp:219
GLuint framebufferObjectId
Definition: Native.cpp:148
GLfloat * cubeNormals
Definition: Native.cpp:583
#define ASSERT(x, s)
Definition: common.h:45
Structure holding ID of objects which were generated to support scene rendering.
Definition: Native.cpp:214
precision highp float
Definition: hiz_cull.cs:37
GLint GLsizei width
Definition: gl2ext.h:179
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.
Definition: Native.cpp:903
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
static const char getLuminanceImageFragmentShaderSource[]
Definition: Native.cpp:395
GLsizei GLsizei GLfloat distance
Definition: gl2ext.h:2507
int min_window_dimension
Definition: Native.cpp:571
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
Definition: Shader.cpp:29
GLuint textureObjectIdOriginalImage
Definition: Native.cpp:221
static void deleteStrongerBlurObjects(StrongerBlurObjects *objectIdsStoragePtr)
Delete objects which were generated for performing the stronger blur effect on downscaled textures...
Definition: Native.cpp:700
Matrix cameraProjectionMatrix
Definition: Native.cpp:564
Structure holding locations of uniforms used by a program object responsible for applying the blend e...
Definition: Native.cpp:127
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_bloom_NativeLibrary_uninit(JNIEnv *env, jobject obj)
Definition: Native.cpp:1771
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
#define HORIZONTAL_POSITION_CAMERA_DEPTH_LOCATION
Definition: Native.cpp:118
GLuint bufferObjectIdCubeCoords
Definition: Native.cpp:216
BlurringProgramLocations blurringVerticalProgramLocations
Definition: Native.cpp:593
GLint uniformLightPropertiesQuadraticAttenauation
Definition: Native.cpp:250
#define NUMBER_OF_CUBES
Definition: Native.cpp:72
GLint y
Definition: gl2ext.h:179
const float nearPlane
Definition: Native.cpp:572
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...
Definition: Native.cpp:968
GLfloat * cubeLocations
Definition: Native.cpp:582
GLuint programObjectId
Definition: Native.cpp:199
uniform float time
Definition: spawn.cs:50
int nOfCubeNormals
Definition: Native.cpp:586
GetLuminanceImageBloomObjects getLuminanceImageBloomObjects
Definition: Native.cpp:601