39 #include <android/log.h>
45 #include "GLES3/gl3.h"
47 #include "EGL/eglext.h"
52 #define LOG_TAG "libNative"
53 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
54 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
57 using namespace MaliSDK;
66 "/** Structure that describes parameters of a single sphere moving across the scalar field. */\n"
67 "struct sphere_descriptor\n"
69 " /* Coefficients for Lissajou equations. Current coordinates calculated by formula:\n"
70 " * v(t) = start_center + lissajou_amplitude * sin(lissajou_frequency * t + lissajou_phase) */\n"
71 " vec3 start_center; /* Center in space around which sphere moves. */\n"
72 " vec3 lissajou_amplitude; /* Lissajou equation amplitudes for all axes. */\n"
73 " vec3 lissajou_frequency; /* Lissajou equation frequencies for all axes. */\n"
74 " vec3 lissajou_phase; /* Lissajou equation phases for all axes. */\n"
75 " /* Other sphere parameters. */\n"
76 " float size; /* Size of a sphere (weight or charge). */\n"
79 "/* [Stage 1 Uniforms] */\n"
80 "/** Current time moment. */\n"
81 "uniform float time;\n"
82 "/* [Stage 1 Uniforms] */\n"
84 "/* [Stage 1 Output data] */\n"
85 "/** Calculated sphere positions. */\n"
86 "out vec4 sphere_position;\n"
87 "/* [Stage 1 Output data] */\n"
89 "/** Shader entry point. */\n"
92 " /* Stores information on spheres moving across the scalar field. Specified in model coordinates (range 0..1]) */\n"
93 " sphere_descriptor spheres[] = sphere_descriptor[]\n"
95 " /* (---- center ----) (--- amplitude --) (--- frequency ---) (----- phase -----) (weight)*/\n"
96 " sphere_descriptor( vec3(0.50, 0.50, 0.50), vec3(0.20, 0.25, 0.25), vec3( 11.0, 21.0, 31.0), vec3( 30.0, 45.0, 90.0), 0.100),\n"
97 " sphere_descriptor( vec3(0.50, 0.50, 0.50), vec3(0.25, 0.20, 0.25), vec3( 22.0, 32.0, 12.0), vec3( 45.0, 90.0,120.0), 0.050),\n"
98 " sphere_descriptor( vec3(0.50, 0.50, 0.50), vec3(0.25, 0.25, 0.20), vec3( 33.0, 13.0, 23.0), vec3( 90.0,120.0,150.0), 0.250)\n"
101 " /* Calculate new xyz coordinates of the sphere. */\n"
102 " vec3 sphere_position3 = spheres[gl_VertexID].start_center\n"
103 " + spheres[gl_VertexID].lissajou_amplitude\n"
104 " * sin(radians(spheres[gl_VertexID].lissajou_frequency) * time + radians(spheres[gl_VertexID].lissajou_phase));\n"
106 " /* Update sphere position coordinates. w-coordinte represents sphere weight. */\n"
107 " sphere_position = vec4(sphere_position3, spheres[gl_VertexID].size);\n"
116 "/** Shader entry point. */\n"
128 "/** Precision to avoid division-by-zero errors. */\n"
129 "#define EPSILON 0.000001f\n"
131 "/** Amount of spheres defining scalar field. This value should be synchronized between all files. */\n"
132 "#define N_SPHERES 3\n"
134 "/* [Stage 2 Uniforms] */\n"
136 "/** Amount of samples taken for each axis of a scalar field; */\n"
137 "uniform int samples_per_axis;\n"
139 "/** Uniform block encapsulating sphere locations. */\n"
140 "uniform spheres_uniform_block\n"
142 " vec4 input_spheres[N_SPHERES];\n"
144 "/* [Stage 2 Uniforms] */\n"
146 "/* [Stage 2 Output data] */\n"
147 "/* Output data: */\n"
148 "/** Calculated scalar field value. */\n"
149 "out float scalar_field_value;\n"
150 "/* [Stage 2 Output data] */\n"
152 "/* [Stage 2 decode_space_position] */\n"
153 "/** Decode coordinates in space from vertex number.\n"
154 " * Assume 3D space of samples_per_axis length for each axis and following encoding:\n"
155 " * encoded_position = x + y * samples_per_axis + z * samples_per_axis * samples_per_axis\n"
157 " * @param vertex_index Encoded vertex position\n"
158 " * @return Coordinates of a vertex in space ranged [0 .. samples_per_axis-1]\n"
160 "ivec3 decode_space_position(in int vertex_index)\n"
162 " int encoded_position = vertex_index;\n"
163 " ivec3 space_position;\n"
165 " /* Calculate coordinates from vertex number. */\n"
166 " space_position.x = encoded_position % samples_per_axis;\n"
167 " encoded_position = encoded_position / samples_per_axis;\n"
169 " space_position.y = encoded_position % samples_per_axis;\n"
170 " encoded_position = encoded_position / samples_per_axis;\n"
172 " space_position.z = encoded_position;\n"
174 " return space_position;\n"
176 "/* [Stage 2 decode_space_position] */\n"
178 "/** Normalizes each coordinate interpolating input coordinates\n"
179 " * from range [0 .. samples_per_axis-1] to [0.0 .. 1.0] range.\n"
181 " * @param space_position Coordinates in range [0 .. samples_per_axis-1]\n"
182 " * @return Coordinates in range [0.0 .. 1.0]\n"
184 "/* [Stage 2 normalize_space_position_coordinates] */\n"
185 "vec3 normalize_space_position_coordinates(in ivec3 space_position)\n"
187 " vec3 normalized_space_position = vec3(space_position) / float(samples_per_axis - 1);\n"
189 " return normalized_space_position;\n"
191 "/* [Stage 2 normalize_space_position_coordinates] */\n"
193 "/** Calculates scalar field at user-defined location.\n"
195 " * @param position Space position for which scalar field value is calculated\n"
196 " * @return Scalar field value\n"
198 "/* [Stage 2 calculate_scalar_field_value] */\n"
199 "float calculate_scalar_field_value(in vec3 position)\n"
201 " float field_value = 0.0f;\n"
203 " /* Field value in given space position influenced by all spheres. */\n"
204 " for (int i = 0; i < N_SPHERES; i++)\n"
206 " vec3 sphere_position = input_spheres[i].xyz;\n"
207 " float vertex_sphere_distance = length(distance(sphere_position, position));\n"
209 " /* Field value is a sum of all spheres fields in a given space position.\n"
210 " * Sphere weight (or charge) is stored in w-coordinate.\n"
212 " field_value += input_spheres[i].w / pow(max(EPSILON, vertex_sphere_distance), 2.0);\n"
215 " return field_value;\n"
217 "/* [Stage 2 calculate_scalar_field_value] */\n"
219 "/** Shader entry point. */\n"
222 " /* Decode point space position defined by gl_VertexID. */\n"
223 " ivec3 space_position = decode_space_position(gl_VertexID);\n"
225 " /* Normalize point space position. */\n"
226 " vec3 normalized_position = normalize_space_position_coordinates(space_position);\n"
228 " /* Calculate field value and assign field value to output variable. */\n"
229 " scalar_field_value = calculate_scalar_field_value(normalized_position);\n"
238 "/** Shader entry point. */\n"
252 "/** Specify low precision for sampler3D type. */\n"
253 "precision lowp sampler3D;\n"
256 "/** Scalar field is stored in a 3D texture. */\n"
257 "uniform sampler3D scalar_field;\n"
259 "/** Amount of samples taken for each axis of a scalar field. */\n"
260 "uniform int cells_per_axis;\n"
262 "/** Isosurface level. */\n"
263 "uniform float iso_level;\n"
265 "/* Output data: */\n"
266 "/** Cell type index. */\n"
267 "flat out int cell_type_index;\n"
269 "/** Calculates cell type index for provided cell and isosurface level.\n"
271 " * @param cell_corner_field_value Scalar field values in cell corners\n"
272 " * @param isolevel Scalar field value which defines isosurface level\n"
274 "/* [Stage 3 get_cell_type_index] */\n"
275 "int get_cell_type_index(in float cell_corner_field_value[8], in float isolevel)\n"
277 " int cell_type_index = 0;\n"
279 " /* Iterate through all cell corners. */\n"
280 " for (int i = 0; i < 8; i++)\n"
282 " /* If corner is inside isosurface then set bit in cell type index index. */\n"
283 " if (cell_corner_field_value[i] < isolevel)\n"
285 " /* Set appropriate corner bit in cell type index. */\n"
286 " cell_type_index |= (1<<i);\n"
290 " return cell_type_index;\n"
292 "/* [Stage 3 get_cell_type_index] */\n"
294 "/** Decode coordinates in space from cell number.\n"
295 " * Assume cubical space of cells_per_axis cells length by each axis and following encoding:\n"
296 " * encoded_position = x + y * cells_per_axis + z * cells_per_axis * cells_per_axis\n"
298 " * @param cell_index Encoded cell position\n"
299 " * @return Coordinates of a cell in space ranged [0 .. cells_per_axis-1]\n"
301 "/* [Stage 3 decode_space_position] */\n"
302 "ivec3 decode_space_position(in int cell_index)\n"
304 " ivec3 space_position;\n"
305 " int encoded_position = cell_index;\n"
307 " /* Calculate coordinates from encoded position */\n"
308 " space_position.x = encoded_position % cells_per_axis;\n"
309 " encoded_position = encoded_position / cells_per_axis;\n"
311 " space_position.y = encoded_position % cells_per_axis;\n"
312 " encoded_position = encoded_position / cells_per_axis;\n"
314 " space_position.z = encoded_position;\n"
316 " return space_position;\n"
318 "/* [Stage 3 decode_space_position] */\n"
320 "/** Shader entry point. */\n"
323 " /* Cubic cell has exactly 8 corners. */\n"
324 " const int corners_in_cell = 8;\n"
326 " /* Cell corners in space relatively to cell's base point [0]. */\n"
327 " const ivec3 cell_corners_offsets[corners_in_cell] = ivec3[]\n"
339 " /* Scalar field texture size, used for normalization purposes. */\n"
340 " vec3 scalar_field_normalizers = vec3(textureSize(scalar_field, 0)) - vec3(1, 1, 1);\n"
342 " /* Scalar field value in corners. Corners numbered according to Marching Cubes algorithm. */\n"
343 " float scalar_field_in_cell_corners[8];\n"
345 " /* Find cell position processed by this shader instance (defined by gl_VertexID). */\n"
346 " ivec3 space_position = decode_space_position(gl_VertexID);\n"
348 " /* [Stage 3 Gather values for the current cell] */\n"
349 " /* Find scalar field values in cell corners. */\n"
350 " for (int i = 0; i < corners_in_cell; i++)\n"
352 " /* Calculate cell corner processed at this iteration. */\n"
353 " ivec3 cell_corner = space_position + cell_corners_offsets[i];\n"
355 " /* Calculate cell corner's actual position ([0.0 .. 1.0] range.) */\n"
356 " vec3 normalized_cell_corner = vec3(cell_corner) / scalar_field_normalizers;\n"
358 " /* Get scalar field value in cell corner from scalar field texture. */\n"
359 " scalar_field_in_cell_corners[i] = textureLod(scalar_field, normalized_cell_corner, 0.0).r;\n"
361 " /* [Stage 3 Gather values for the current cell] */\n"
363 " /* Get cube type index. */\n"
364 " cell_type_index = get_cell_type_index(scalar_field_in_cell_corners, iso_level);\n"
373 "/** Shader entry point. */\n"
390 "precision highp isampler2D; /**< Specify high precision for isampler2D type. */\n"
391 "precision highp isampler3D; /**< Specify high precision for isampler3D type. */\n"
392 "precision highp sampler2D; /**< Specify high precision for sampler2D type. */\n"
393 "precision highp sampler3D; /**< Specify high precision for sampler3D type. */\n"
395 "/** Precision to avoid division-by-zero errors. */\n"
396 "#define EPSILON 0.000001f\n"
398 "/** Amount of cells taken for each axis of a scalar field. */\n"
399 "#define CELLS_PER_AXIS (samples_per_axis - 1)\n"
401 "/** Maximum amount of vertices a single cell can define. */\n"
402 "const int mc_vertices_per_cell = 15;\n"
405 "/** Amount of samples taken for each axis of a scalar field. */\n"
406 "uniform int samples_per_axis;\n"
408 "/** A signed integer 3D texture is used to deliver cell type data. */\n"
409 "uniform isampler3D cell_types;\n"
411 "/** A 3D texture is used to deliver scalar field data. */\n"
412 "uniform sampler3D scalar_field;\n"
414 "/** A 2D texture representing tri_table lookup array. Array contains edge numbers (in sense of Marching Cubes algorithm).\n"
415 " As input parameters (indices to texture) should be specified cell type index and combined vertex-triangle number. */\n"
416 "uniform isampler2D tri_table;\n"
418 "/** Combined model view and projection matrices. */\n"
419 "uniform mat4 mvp;\n"
421 "/** Isosurface level. */\n"
422 "uniform float iso_level;\n"
424 "/* Phong shading output variables for fragment shader. */\n"
425 "out vec4 phong_vertex_position; /**< position of the vertex in world space. */\n"
426 "out vec3 phong_vertex_normal_vector; /**< surface normal vector in world space. */\n"
427 "out vec3 phong_vertex_color; /**< vertex color for fragment colorisation. */\n"
430 "/** Function approximates scalar field derivative along begin_vertex<->end_vertex axis.\n"
431 " * Field derivative calculated as a scalar field difference between specified vertices\n"
432 " * divided by distance between vertices.\n"
434 " * @param begin_vertex begin vertex\n"
435 " * @param end_vertex end vertex\n"
436 " * @return scalar field derivative along begin_vertex<->end_vertex axis\n"
438 "float calc_partial_derivative(vec3 begin_vertex, vec3 end_vertex)\n"
440 " float field_value_begin = textureLod(scalar_field, begin_vertex, 0.0).r;\n"
441 " float field_value_end = textureLod(scalar_field, end_vertex, 0.0).r;\n"
443 " return (field_value_end - field_value_begin) / distance(begin_vertex, end_vertex);\n"
446 "/** Finds normal in given cell corner vertex. Normal calculated as a vec3(dF/dx, dF/dy, dF/dz)\n"
447 " * dFs are calculated as difference of scalar field values in corners of this or adjacent cells.\n"
449 " * @param p1 vertex for which normal is to be calculated\n"
450 " * @return normal vector to surface in p1\n"
452 "vec3 calc_cell_corner_normal(in vec3 p1)\n"
457 " /* Use neighbour samples to calculate derivative. */\n"
458 " delta = vec3(1.0/float(samples_per_axis - 1), 0, 0);\n"
459 " result.x = calc_partial_derivative(p1 - delta, p1 + delta);\n"
461 " delta = vec3(0.0, 1.0/float(samples_per_axis - 1), 0.0);\n"
462 " result.y = calc_partial_derivative(p1 - delta, p1 + delta);\n"
464 " delta = vec3(0.0, 0.0, 1.0/float(samples_per_axis - 1));\n"
465 " result.z = calc_partial_derivative(p1 - delta, p1 + delta);\n"
470 "/** Calculates normal for an edge vertex like in an orignal SIGGRAPH paper.\n"
471 " * First finds normal vectors in edge begin vertex and in edge end vertex, then interpolate.\n"
473 " * @param start_vertex_portion influence of edge_start vertex\n"
474 " * @param edge_start normalized coordinates of edge start vertex\n"
475 " * @param edge_end normalized coordinates of edge end vertex\n"
476 " * @return normal to surface vector in edge position specified\n"
478 "vec3 calc_phong_normal(in float start_vertex_portion, in vec3 edge_start, in vec3 edge_end)\n"
480 " /* Find normal vector in begin vertex of the edge. */\n"
481 " vec3 edge_start_normal = calc_cell_corner_normal(edge_start);\n"
482 " /* Find normal vector in end vertex of the edge. */\n"
483 " vec3 edge_end_normal = calc_cell_corner_normal(edge_end);\n"
485 " /* Interpolate normal vector. */\n"
486 " return mix(edge_end_normal, edge_start_normal, start_vertex_portion);\n"
489 "/** Decodes cell coordinates from vertex identifier.\n"
490 " * Assumes 3D space of CELLS_PER_AXIS cells for each axis and\n"
491 " * mc_vertices_per_cell triangles-generating vertices per cell\n"
492 " * encoded in vertex identifier according to following formula:\n"
493 " * encoded_position = mc_vertex_no + mc_vertices_per_cell * (x + CELLS_PER_AXIS * (y + CELLS_PER_AXIS * z))\n"
495 " * @param encoded_position_argument encoded position\n"
496 " * @return cell coordinates ranged [0 .. CELLS_PER_AXIS-1] in x,y,z, and decoded vertex number in w.\n"
498 "/* [Stage 4 decode_cell_position] */\n"
499 "ivec4 decode_cell_position(in int encoded_position_argument)\n"
501 " ivec4 cell_position;\n"
502 " int encoded_position = encoded_position_argument;\n"
504 " /* Decode combined triangle and vertex number. */\n"
505 " cell_position.w = encoded_position % mc_vertices_per_cell;\n"
506 " encoded_position = encoded_position / mc_vertices_per_cell;\n"
508 " /* Decode coordinates from encoded position. */\n"
509 " cell_position.x = encoded_position % CELLS_PER_AXIS;\n"
510 " encoded_position = encoded_position / CELLS_PER_AXIS;\n"
512 " cell_position.y = encoded_position % CELLS_PER_AXIS;\n"
513 " encoded_position = encoded_position / CELLS_PER_AXIS;\n"
515 " cell_position.z = encoded_position;\n"
517 " return cell_position;\n"
519 "/* [Stage 4 decode_cell_position] */\n"
521 "/** Identifies cell type for provided cell position.\n"
523 " * @param cell_position non-normalized cell position in space\n"
524 " * @return cell type in sense of Macrhing Cubes algorithm\n"
526 "int get_cell_type(in ivec3 cell_position)\n"
528 " vec3 cell_position_normalized = vec3(cell_position) / float(CELLS_PER_AXIS - 1);\n"
530 " /* Get cell type index of cell to which currently processed vertex (triangle_and_vertex_number) belongs */\n"
531 " int cell_type_index = textureLod(cell_types, cell_position_normalized, 0.0).r;\n"
533 " return cell_type_index;\n"
536 "/** Performs a table lookup with cell type index and combined vertex-triangle number specified\n"
537 " * to locate an edge number which vertex is currently processed.\n"
539 " * @param cell_type_index cell type index (in Marching Cubes algorthm sense)\n"
540 " * @param combined_triangle_no_and_vertex_no combined vertex and triangle numbers (by formula tringle*3 + vertex)\n"
542 " * @return edge number (in sense of Marching Cubes algorithm) or -1 if vertex does not belong to any edge\n"
544 "int get_edge_number(in int cell_type_index, in int combined_triangle_no_and_vertex_no)\n"
546 " /* Normalize indices for texture lookup: [0..14] -> [0.0..1.0], [0..255] -> [0.0..1.0]. */\n"
547 " vec2 tri_table_index = vec2(float(combined_triangle_no_and_vertex_no)/14.0, float(cell_type_index)/255.0);\n"
549 " return textureLod(tri_table, tri_table_index, 0.0).r;\n"
552 "/** Function calculates edge begin or edge end coordinates for specified cell and edge.\n"
554 " * @param cell_origin_corner_coordinates normalized cell origin coordinates\n"
555 " * @param edge_number edge number which coorinates being calculated\n"
556 " * @param is_edge_start_vertex true to request edge start vertex coordinates, false for end edge vertex\n"
557 " * @return normalized edge start or end vertex coordinates\n"
559 "vec3 get_edge_coordinates(in vec3 cell_origin_corner_coordinates, in int edge_number, in bool is_edge_start_vertex)\n"
561 " /* These two arrays contain vertex indices which define a cell edge specified by index of arrays. */\n"
562 " const int edge_begins_in_cell_corner[12] = int[] ( 0,1,2,3,4,5,6,7,0,1,2,3 );\n"
563 " const int edge_ends_in_cell_corner[12] = int[] ( 1,2,3,0,5,6,7,4,4,5,6,7 );\n"
564 " /* Defines offsets by axes for each of 8 cell corneres. */\n"
565 " const ivec3 cell_corners_offsets[8] = ivec3[8]\n"
577 " /* Edge corner number (number is in sense of Marching Cubes algorithm). */\n"
578 " int edge_corner_no;\n"
580 " if (is_edge_start_vertex)\n"
582 " /* Use start cell corner of the edge. */\n"
583 " edge_corner_no = edge_begins_in_cell_corner[edge_number];\n"
587 " /* Use end cell corner of the edge. */\n"
588 " edge_corner_no = edge_ends_in_cell_corner[edge_number];\n"
591 " /* Normalized cell corner coordinate offsets (to cell origin corner). */\n"
592 " vec3 normalized_corner_offsets = vec3(cell_corners_offsets[edge_corner_no]) / float(samples_per_axis - 1);\n"
594 " /* Normalized cell corner coordinates. */\n"
595 " vec3 edge_corner = cell_origin_corner_coordinates + normalized_corner_offsets;\n"
597 " return edge_corner;\n"
600 "/** Function calculates how close start_corner vertex to intersetction point.\n"
602 " * @param start_corner beginning of edge\n"
603 " * @param end_corner end of edge\n"
604 " * @param iso_level scalar field value level defining isosurface\n"
605 " * @return start vertex portion (1.0, if isosurface comes through start vertex)\n"
607 "float get_start_corner_portion(in vec3 start_corner, in vec3 end_corner, in float iso_level)\n"
610 " float start_field_value = textureLod(scalar_field, start_corner, 0.0).r;\n"
611 " float end_field_value = textureLod(scalar_field, end_corner, 0.0).r;\n"
612 " float field_delta = abs(start_field_value - end_field_value);\n"
614 " if (field_delta > EPSILON)\n"
616 " /* Calculate start vertex portion. */\n"
617 " result = abs(end_field_value - iso_level) / field_delta;\n"
621 " /* Field values are too close in value to evaluate. Assume middle of an edge. */\n"
628 "/** Shader entry point. */\n"
631 " /* [Stage 4 Decode space position] */\n"
632 " /* Split gl_vertexID into cell position and vertex number processed by this shader instance. */\n"
633 " ivec4 cell_position_and_vertex_no = decode_cell_position(gl_VertexID);\n"
634 " ivec3 cell_position = cell_position_and_vertex_no.xyz;\n"
635 " int triangle_and_vertex_number = cell_position_and_vertex_no.w;\n"
636 " /* [Stage 4 Decode space position] */\n"
638 " /* [Stage 4 Get cell type and edge number] */\n"
639 " /* Get cell type for cell current vertex belongs to. */\n"
640 " int cell_type_index = get_cell_type(cell_position);\n"
642 " /* Get edge of the cell to which belongs processed vertex. */\n"
643 " int edge_number = get_edge_number(cell_type_index, triangle_and_vertex_number);\n"
644 " /* [Stage 4 Get cell type and edge number] */\n"
646 " /* Check if this is not a vertex of dummy triangle. */\n"
647 " if (edge_number != -1)\n"
649 " /* [Stage 4 Calculate cell origin] */\n"
650 " /* Calculate normalized coordinates in space of cell origin corner. */\n"
651 " vec3 cell_origin_corner = vec3(cell_position) / float(samples_per_axis - 1);\n"
652 " /* [Stage 4 Calculate cell origin] */\n"
654 " /* [Stage 4 Calculate start and end edge coordinates] */\n"
655 " /* Calculate start and end edge coordinates. */\n"
656 " vec3 start_corner = get_edge_coordinates(cell_origin_corner, edge_number, true);\n"
657 " vec3 end_corner = get_edge_coordinates(cell_origin_corner, edge_number, false);\n"
658 " /* [Stage 4 Calculate start and end edge coordinates] */\n"
660 " /* [Stage 4 Calculate middle edge vertex] */\n"
661 " /* Calculate share of start point of an edge. */\n"
662 " float start_vertex_portion = get_start_corner_portion(start_corner, end_corner, iso_level);\n"
664 " /* Calculate ''middle'' edge vertex. This vertex is moved closer to start or end vertices of the edge. */\n"
665 " vec3 edge_middle_vertex = mix(end_corner, start_corner, start_vertex_portion);\n"
666 " /* [Stage 4 Calculate middle edge vertex] */\n"
668 " /* [Stage 4 Calculate middle edge normal] */\n"
669 " /* Calculate normal to surface in the ''middle'' vertex. */\n"
670 " vec3 vertex_normal = calc_phong_normal(start_vertex_portion, start_corner, end_corner);\n"
671 " /* [Stage 4 Calculate middle edge normal] */\n"
673 " /* Update vertex shader outputs. */\n"
674 " gl_Position = mvp * vec4(edge_middle_vertex, 1.0); /* Transform vertex position with MVP-matrix. */\n"
675 " phong_vertex_position = gl_Position; /* Set vertex position for fragment shader. */\n"
676 " phong_vertex_normal_vector = vertex_normal; /* Set normal vector to surface for fragment shader. */\n"
677 " phong_vertex_color = vec3(0.7); /* Set vertex color for fragment shader. */\n"
681 " /* [Stage 4 Discard dummy triangle] */\n"
682 " /* This cell type generates fewer triangles, and this particular one should be discarded. */\n"
683 " gl_Position = vec4(0); /* Discard vertex by setting its coordinate in infinity. */\n"
684 " phong_vertex_position = gl_Position;\n"
685 " phong_vertex_normal_vector = vec3(0);\n"
686 " phong_vertex_color = vec3(0);\n"
687 " /* [Stage 4 Discard dummy triangle] */\n"
698 "/** Specify low precision for float type. */\n"
699 "precision lowp float;\n"
702 "/** Current time moment. */\n"
703 "uniform float time;\n"
705 "/** Position of the vertex (and fragment) in world space. */\n"
706 "in vec4 phong_vertex_position;\n"
708 "/** Surface normal vector in world space. */\n"
709 "in vec3 phong_vertex_normal_vector;\n"
711 "/** Color passed from vertex shader. */\n"
712 "in vec3 phong_vertex_color;\n"
714 "/* Output data: */\n"
715 "/** Fragment color. */\n"
716 "out vec4 FragColor;\n"
718 "/** Shader entry point. Main steps are described in comments below. */\n"
721 " /* Distance to light source. */\n"
722 " const float light_distance = 5.0;\n"
724 " /* Add some movement to light source. */\n"
725 " float theta = float(time);\n"
726 " float phi = float(time)/3.0;\n"
728 " vec3 light_location = vec3\n"
730 " light_distance * cos(theta) * sin(phi),\n"
731 " light_distance * cos(theta) * cos(phi),\n"
732 " light_distance * sin(theta)\n"
735 " /* Scene ambient color. */\n"
736 " const vec3 ambient_color = vec3(0.1, 0.1, 0.1);\n"
737 " const float attenuation = 1.0;\n"
738 " const float shiness = 3.0;\n"
740 " /* Normalize directions. */\n"
741 " vec3 normal_direction = normalize(phong_vertex_normal_vector);\n"
742 " vec3 view_direction = normalize(vec3(vec4(0.0, 0.0, 1.0, 0.0) - phong_vertex_position));\n"
743 " vec3 light_direction = normalize(light_location);\n"
745 " /** Calculate ambient lighting component of directional light. */\n"
746 " vec3 ambient_lighting = ambient_color * phong_vertex_color;\n"
748 " /** Calculate diffuse reflection lighting component of directional light. */\n"
749 " vec3 diffuse_reflection = attenuation * phong_vertex_color\n"
750 " * max(0.0, dot(normal_direction, light_direction));\n"
752 " /** Calculate specular reflection lighting component of directional light. */\n"
753 " vec3 specular_reflection = vec3(0.0, 0.0, 0.0);\n"
755 " if (dot(normal_direction, light_direction) >= 0.0)\n"
757 " /* Light source on the right side. */\n"
758 " specular_reflection = attenuation * phong_vertex_color\n"
759 " * pow(max(0.0, dot(reflect(-light_direction, normal_direction), view_direction)), shiness);\n"
762 " /** Calculate fragment lighting as sum of previous three component. */\n"
763 " FragColor = vec4(ambient_lighting + diffuse_reflection + specular_reflection, 1.0);\n"
799 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
800 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
801 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
802 1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
804 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
805 0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1,
806 9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1,
807 2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1,
808 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
809 0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
810 1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
811 1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1,
812 3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1,
813 0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1,
814 3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1,
815 9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
816 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
817 4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
818 0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
819 4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1,
820 1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
821 3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1,
822 9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1,
823 2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1,
824 8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
825 11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1,
826 9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1,
827 4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1,
828 3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1,
829 1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1,
830 4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1,
831 4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1,
832 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
833 9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1,
834 0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
835 8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1,
836 1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
837 3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1,
838 5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1,
839 2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1,
840 9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
841 0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1,
842 0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1,
843 2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1,
844 10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1,
845 4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1,
846 5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1,
847 5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1,
848 9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1,
849 9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1,
850 0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1,
851 1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
852 9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1,
853 10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1,
854 8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1,
855 2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1,
856 7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1,
857 9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1,
858 2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1,
859 11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1,
860 9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1,
861 5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0,
862 11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0,
863 11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1,
864 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
865 0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
866 9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
867 1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1,
868 1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
869 1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1,
870 9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1,
871 5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1,
872 2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1,
873 11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1,
874 0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1,
875 5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1,
876 6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1,
877 0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1,
878 3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1,
879 6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1,
880 5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
881 4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1,
882 1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1,
883 10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1,
884 6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1,
885 1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1,
886 8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1,
887 7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9,
888 3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1,
889 5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1,
890 0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1,
891 9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6,
892 8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1,
893 5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11,
894 0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7,
895 6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1,
896 10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1,
897 4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1,
898 10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1,
899 8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1,
900 1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1,
901 3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1,
902 0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
903 8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1,
904 10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1,
905 0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1,
906 3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1,
907 6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1,
908 9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1,
909 8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1,
910 3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1,
911 6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
912 7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1,
913 0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1,
914 10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1,
915 10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1,
916 1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1,
917 2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9,
918 7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1,
919 7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
920 2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1,
921 2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7,
922 1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11,
923 11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1,
924 8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6,
925 0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
926 7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1,
927 7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
928 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
929 3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
930 0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
931 8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1,
932 10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
933 1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1,
934 2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1,
935 6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1,
936 7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
937 7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1,
938 2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1,
939 1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1,
940 10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1,
941 10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1,
942 0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1,
943 7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1,
944 6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
945 3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1,
946 8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1,
947 9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1,
948 6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1,
949 1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1,
950 4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1,
951 10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3,
952 8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1,
953 0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
954 1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1,
955 1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1,
956 8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1,
957 10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1,
958 4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3,
959 10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
960 4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
961 0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1,
962 5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1,
963 11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1,
964 9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1,
965 6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1,
966 7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1,
967 3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6,
968 7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1,
969 9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1,
970 3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1,
971 6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8,
972 9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1,
973 1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4,
974 4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10,
975 7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1,
976 6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1,
977 3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1,
978 0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1,
979 6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1,
980 1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1,
981 0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10,
982 11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5,
983 6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1,
984 5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1,
985 9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1,
986 1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8,
987 1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1,
988 1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6,
989 10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1,
990 0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1,
991 10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
992 11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
993 11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1,
994 5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1,
995 10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1,
996 11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1,
997 0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1,
998 9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1,
999 7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2,
1000 2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1,
1001 8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1,
1002 9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1,
1003 9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2,
1004 1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1005 0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1,
1006 9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1,
1007 9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1008 5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1,
1009 5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1,
1010 0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1,
1011 10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4,
1012 2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1,
1013 0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11,
1014 0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5,
1015 9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1016 2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1,
1017 5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1,
1018 3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9,
1019 5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1,
1020 8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1,
1021 0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1022 8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1,
1023 9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1024 4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1,
1025 0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1,
1026 1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1,
1027 3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4,
1028 4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1,
1029 9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3,
1030 11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1,
1031 11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1,
1032 2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1,
1033 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7,
1034 3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10,
1035 1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1036 4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1,
1037 4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1,
1038 4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1039 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1040 9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1041 3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1,
1042 0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1,
1043 3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1044 1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1,
1045 3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1,
1046 0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1047 3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1048 2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1,
1049 9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1050 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1,
1051 1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1052 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1053 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1054 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1055 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
1223 float degreesToRadiansCoefficient = atanf(1) / 45;
1224 float frustum_fovy = 45.0f;
1226 float frustum_z_near = 0.01f;
1227 float frustum_z_far = 100.0f;
1228 float camera_distance = 2.5f;
1238 Matrix mat4_model_view = mat4_scale * mat4_translate;
1241 mat4_model_view[14] -=
float(camera_distance);
1247 mvp = mat4_perspective * mat4_model_view;
1263 GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
1264 GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1));
1299 GL_CHECK(glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0));
1349 GL_CHECK(glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0));
1364 GL_CHECK(glActiveTexture(GL_TEXTURE1));
1416 GL_CHECK(glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0));
1431 GL_CHECK(glActiveTexture(GL_TEXTURE2));
1494 GL_CHECK(glActiveTexture(GL_TEXTURE4));
1498 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ));
1499 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ));
1500 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 ));
1501 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0 ));
1502 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1503 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1507 GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D,
1527 GL_CHECK(glEnable (GL_DEPTH_TEST));
1528 GL_CHECK(glEnable (GL_CULL_FACE ));
1545 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
1560 GL_CHECK(glEnable(GL_RASTERIZER_DISCARD));
1573 GL_CHECK(glBeginTransformFeedback(GL_POINTS));
1582 GL_CHECK(glEndTransformFeedback());
1586 GL_CHECK(glDisable(GL_RASTERIZER_DISCARD));
1607 GL_CHECK(glEnable(GL_RASTERIZER_DISCARD));
1613 GL_CHECK(glBeginTransformFeedback(GL_POINTS));
1618 GL_CHECK(glEndTransformFeedback());
1620 GL_CHECK(glDisable(GL_RASTERIZER_DISCARD));
1631 GL_CHECK(glActiveTexture(GL_TEXTURE1));
1658 GL_CHECK(glEnable(GL_RASTERIZER_DISCARD));
1664 GL_CHECK(glBeginTransformFeedback(GL_POINTS));
1671 GL_CHECK(glEndTransformFeedback());
1673 GL_CHECK(glDisable(GL_RASTERIZER_DISCARD));
1682 GL_CHECK(glActiveTexture(GL_TEXTURE2));
1704 GL_CHECK(glActiveTexture(GL_TEXTURE0));
1756 (JNIEnv *env, jclass jcls)
float getTime()
Returns the time passed since object creation or since reset() was last called.
GLint GLsizei GLsizei height
Functions for manipulating matrices.
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
Provides a platform independent high resolution timer.
static Matrix createScaling(float x, float y, float z)
Create and return a scaling matrix.
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
#define GL_TRANSFORM_FEEDBACK
float * getAsArray(void)
Get the matrix elements as a column major order array.
void reset()
Resets the timer to 0.0f.
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count