25 using namespace MaliSDK;
41 unsigned int num_vertices = size *
size;
44 unsigned int ring_vertices = size * 3;
45 num_vertices += 2 * ring_vertices;
49 unsigned int trim_vertices = (2 * size + 1) * 2;
50 num_vertices += trim_vertices * 4;
59 unsigned int degenerate_vertices = 2 * (size - 1) * 5;
60 num_vertices += degenerate_vertices * 2;
62 GLubyte *
vertices =
new GLubyte[2 * num_vertices];
67 for (
unsigned int z = 0; z <
size; z++)
69 for (
unsigned int x = 0;
x <
size;
x++)
79 for (
unsigned int z = 0; z <
size; z++)
81 for (
unsigned int x = 0;
x < 3;
x++)
90 for (
unsigned int z = 0; z < 3; z++)
92 for (
unsigned int x = 0;
x <
size;
x++)
102 for (
unsigned int z = 0; z < 2; z++)
104 for (
unsigned int x = 0;
x < 2 * size + 1;
x++)
113 for (
int x = 1;
x >= 0;
x--)
115 for (
unsigned int z = 0; z < 2 * size + 1; z++)
117 pv[0] =
x + 2 * size - 1;
124 for (
int z = 1; z >= 0; z--)
126 for (
unsigned int x = 0;
x < 2 * size + 1;
x++)
128 pv[0] = 2 * size -
x;
129 pv[1] = z + 2 * size - 1;
135 for (
unsigned int x = 0;
x < 2;
x++)
137 for (
unsigned int z = 0; z < 2 * size + 1; z++)
140 pv[1] = 2 * size - z;
147 for (
unsigned int y = 0;
y < (size - 1) * 2;
y++)
163 for (
unsigned int x = 0;
x < (size - 1) * 2;
x++)
180 GL_CHECK(glGenBuffers(1, &vertex_buffer));
181 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer));
182 GL_CHECK(glBufferData(GL_ARRAY_BUFFER, 2 * num_vertices *
sizeof(GLubyte), vertices, GL_STATIC_DRAW));
183 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));
191 unsigned int strips = height - 1;
192 return strips * (2 * width - 1) + 1;
200 int pos = vertex_buffer_offset;
201 unsigned int strips = height - 1;
207 for (
unsigned int z = 0; z < strips; z++)
209 int step_even =
width;
210 int step_odd = ((z & 1) ? -1 : 1) - step_even;
214 for (
unsigned int x = 0;
x < 2 * width - 1;
x++)
217 pos += (
x & 1) ? step_odd : step_even;
233 block.range =
vec2(size - 1);
235 vertical.range =
vec2(2, size - 1);
236 horizontal.range =
vec2(size - 1, 2);
238 trim_full.range =
vec2(2 * size);
239 trim_top_left.range =
vec2(2 * size);
240 trim_bottom_right.range =
vec2(2 * size);
241 trim_top_right.range =
vec2(2 * size);
242 trim_bottom_left.range =
vec2(2 * size);
244 degenerate_left.range =
vec2(0, 4 * size - 2);
245 degenerate_right.range =
vec2(0, 4 * size - 2);
246 degenerate_top.range =
vec2(4 * size - 2, 0);
247 degenerate_bottom.range =
vec2(4 * size - 2, 0);
252 unsigned int vertex_buffer_offset = 0;
260 trim_full.count = 4 * trim_region_indices;
261 trim_top_left.count = 2 * trim_region_indices;
262 trim_bottom_right = trim_bottom_left = trim_top_right = trim_top_left;
267 degenerate_left.count = (size - 1) * 2 * 6;
268 degenerate_right = degenerate_bottom = degenerate_top = degenerate_left;
270 num_indices = block.count + vertical.count + horizontal.count + trim_full.count +
271 4 * trim_top_left.count +
272 4 * degenerate_left.count;
274 GLushort *
indices =
new GLushort[num_indices];
280 vertex_buffer_offset += size *
size;
283 vertical.offset = pi -
indices;
285 vertex_buffer_offset += 3 *
size;
288 horizontal.offset = pi -
indices;
290 vertex_buffer_offset += 3 *
size;
296 trim_full.offset = pi -
indices;
297 unsigned int full_trim_offset = vertex_buffer_offset;
298 unsigned int trim_vertices = (2 * size + 1) * 2;
300 full_trim_offset += trim_vertices;
302 full_trim_offset += trim_vertices;
304 full_trim_offset += trim_vertices;
306 full_trim_offset += trim_vertices;
310 trim_top_right.offset = pi -
indices;
313 vertex_buffer_offset += trim_vertices;
317 trim_bottom_right.offset = pi -
indices;
320 vertex_buffer_offset += trim_vertices;
324 trim_bottom_left.offset = pi -
indices;
327 vertex_buffer_offset += trim_vertices;
331 trim_top_left.offset = pi -
indices;
334 vertex_buffer_offset += trim_vertices;
340 degenerate_left.offset = pi -
indices;
341 for (
unsigned int z = 0; z < (size - 1) * 2; z++)
343 pi[0] = (5 * z) + 0 + vertex_buffer_offset;
344 pi[1] = (5 * z) + 1 + vertex_buffer_offset;
345 pi[2] = (5 * z) + 2 + vertex_buffer_offset;
346 pi[3] = (5 * z) + 3 + vertex_buffer_offset;
347 pi[4] = (5 * z) + 4 + vertex_buffer_offset;
348 pi[5] = (5 * z) + 4 + vertex_buffer_offset;
353 degenerate_right.offset = pi -
indices;
354 unsigned int start_z = (size - 1) * 2 - 1;
355 for (
unsigned int z = 0; z < (size - 1) * 2; z++)
358 pi[0] = (5 * (start_z - z)) + 4 + vertex_buffer_offset;
359 pi[1] = (5 * (start_z - z)) + 3 + vertex_buffer_offset;
360 pi[2] = (5 * (start_z - z)) + 2 + vertex_buffer_offset;
361 pi[3] = (5 * (start_z - z)) + 1 + vertex_buffer_offset;
362 pi[4] = (5 * (start_z - z)) + 0 + vertex_buffer_offset;
363 pi[5] = (5 * (start_z - z)) + 0 + vertex_buffer_offset;
367 vertex_buffer_offset += (size - 1) * 2 * 5;
370 degenerate_top.offset = pi -
indices;
371 for (
unsigned int x = 0;
x < (size - 1) * 2;
x++)
373 pi[0] = (5 *
x) + 0 + vertex_buffer_offset;
374 pi[1] = (5 *
x) + 1 + vertex_buffer_offset;
375 pi[2] = (5 *
x) + 2 + vertex_buffer_offset;
376 pi[3] = (5 *
x) + 3 + vertex_buffer_offset;
377 pi[4] = (5 *
x) + 4 + vertex_buffer_offset;
378 pi[5] = (5 *
x) + 4 + vertex_buffer_offset;
383 degenerate_bottom.offset = pi -
indices;
384 unsigned int start_x = (size - 1) * 2 - 1;
385 for (
unsigned int x = 0;
x < (size - 1) * 2;
x++)
388 pi[0] = (5 * (start_x -
x)) + 4 + vertex_buffer_offset;
389 pi[1] = (5 * (start_x -
x)) + 3 + vertex_buffer_offset;
390 pi[2] = (5 * (start_x -
x)) + 2 + vertex_buffer_offset;
391 pi[3] = (5 * (start_x -
x)) + 1 + vertex_buffer_offset;
392 pi[4] = (5 * (start_x -
x)) + 0 + vertex_buffer_offset;
393 pi[5] = (5 * (start_x -
x)) + 0 + vertex_buffer_offset;
397 GL_CHECK(glGenBuffers(1, &index_buffer));
398 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer));
399 GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, num_indices *
sizeof(GLushort), indices, GL_STATIC_DRAW));
400 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
407 GL_CHECK(glGenBuffers(1, &uniform_buffer));
408 GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, uniform_buffer));
413 GL_CHECK(glBufferData(GL_UNIFORM_BUFFER, uniform_buffer_size, NULL, GL_STREAM_DRAW));
415 GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
419 #define LOCATION_VERTEX 0
423 GL_CHECK(glGenVertexArrays(1, &vertex_array));
424 GL_CHECK(glBindVertexArray(vertex_array));
425 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer));
426 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer));
432 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));
434 GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
void setup_vertex_buffer(unsigned int size)
void setup_block_ranges(unsigned int size)
[Generating index buffer]
GLint GLsizei GLsizei height
void setup_uniform_buffer()
GLsizei GLenum const void * indices
void setup_index_buffer(unsigned int size)
void setup_vertex_array()
GLenum GLuint GLintptr GLsizeiptr size
GLint GLint GLint GLint GLint x
static unsigned int block_index_count(unsigned int width, unsigned int height)
static GLushort * generate_block_indices(GLushort *pi, unsigned int vertex_buffer_offset, unsigned int width, unsigned int height)
[Generating index buffer]