NE_API drawing_shape_id create_quad_array() { shapes.push_back(gl_drawing_shape()); drawing_shape_id shape_id = (drawing_shape_id) shapes.size() - 1; gl_drawing_shape* quad = &shapes[shape_id]; gl_vertex_array* vertex_array = &quad->vertex_array; create_vertex_array(vertex_array); create_gl_buffer(&vertex_array->index_buffer); create_gl_buffer(&vertex_array->vertex_buffer); bind_vertex_array(vertex_array); set_vertex_attribute(vertex_attribute::position, 4, sizeof(vertex), nullptr); set_vertex_attribute(vertex_attribute::color, 4, sizeof(vertex), (void*) (4 * sizeof(float))); set_vertex_attribute(vertex_attribute::tangent, 3, sizeof(vertex), (void*) (8 * sizeof(float))); set_vertex_attribute(vertex_attribute::normal, 3, sizeof(vertex), (void*) (11 * sizeof(float))); set_vertex_attribute(vertex_attribute::tex_coords, 2, sizeof(vertex), (void*) (14 * sizeof(float))); return (drawing_shape_id) (shapes.size() - 1); }
NE_API drawing_shape_id create_quad() { shapes.push_back(gl_drawing_shape()); drawing_shape_id shape_id = (drawing_shape_id) shapes.size() - 1; gl_drawing_shape* quad = &shapes[shape_id]; gl_vertex_array* vertex_array = &quad->vertex_array; create_vertex_array(vertex_array); quad->vertices.insert(quad->vertices.begin(), 4, vertex()); quad->indices = { 0, 1, 2, 3, 2, 0 }; quad->vertices[0].position = { 0.0f, 0.0f, 0.0f, 1.0f }; quad->vertices[1].position = { 1.0f, 0.0f, 0.0f, 1.0f }; quad->vertices[2].position = { 1.0f, 1.0f, 0.0f, 1.0f }; quad->vertices[3].position = { 0.0f, 1.0f, 0.0f, 1.0f }; quad->vertices[0].color = { 1.0f, 1.0f, 1.0f, 1.0f }; quad->vertices[1].color = { 1.0f, 1.0f, 1.0f, 1.0f }; quad->vertices[2].color = { 1.0f, 1.0f, 1.0f, 1.0f }; quad->vertices[3].color = { 1.0f, 1.0f, 1.0f, 1.0f }; vertex_array->index_count = 6; create_gl_buffer(&vertex_array->index_buffer); set_gl_buffer_memory(&vertex_array->index_buffer, (uint8*) &quad->indices[0], 6 * sizeof(uint32)); upload_gl_buffer_data(&vertex_array->index_buffer); create_gl_buffer(&vertex_array->vertex_buffer); set_gl_buffer_memory(&vertex_array->vertex_buffer, (uint8*) &quad->vertices[0], 4 * sizeof(vertex)); set_quad_tex_coords(shape_id, 0.0f, 0.0f, 1.0f, 1.0f); bind_vertex_array(vertex_array); set_vertex_attribute(vertex_attribute::position, 4, sizeof(vertex), nullptr); set_vertex_attribute(vertex_attribute::color, 4, sizeof(vertex), (void*) (4 * sizeof(float))); set_vertex_attribute(vertex_attribute::tangent, 3, sizeof(vertex), (void*) (8 * sizeof(float))); set_vertex_attribute(vertex_attribute::normal, 3, sizeof(vertex), (void*) (11 * sizeof(float))); set_vertex_attribute(vertex_attribute::tex_coords, 2, sizeof(vertex), (void*) (14 * sizeof(float))); return (drawing_shape_id) (shapes.size() - 1); }
int push_gl_srv_buffer(struct gl_buffer *gl_buffer) { struct gl_srv_buffer *self = b6_cast_of(gl_buffer, struct gl_srv_buffer, gl_buffer); float *p, *q; static const unsigned long int min_size = 32768; unsigned long int v_size = b6_array_memsize(&gl_buffer->v); unsigned long int t_size = b6_array_memsize(&gl_buffer->t); unsigned long int size = v_size + t_size; unsigned long int len = b6_array_length(&gl_buffer->t); unsigned long int max = gl_buffer->t.capacity; const float *v = b6_array_get(&gl_buffer->v, 0); const float *t = b6_array_get(&gl_buffer->t, 0); if (size < v_size || size < t_size) { log_e("integer overflow"); return -2; } if (size < min_size) size = min_size; if (size > self->size) { log_i("allocating %u bytes", size); self->size = size; if (self->id) { maybe_unbind_gl_buffer(self->id); destroy_gl_buffer(self->id); } create_gl_buffer(&self->id); maybe_bind_gl_buffer(self->id); alloc_gl_buffer(size); } log_i("pushing %u/%u vertices", len, max); p = map_gl_buffer(); q = p + max * 2; while (len--) { *p++ = *t++; *p++ = *t++; *q++ = *v++; *q++ = *v++; } unmap_gl_buffer(); glTexCoordPointer(2, GL_FLOAT, 0, NULL); glVertexPointer(2, GL_FLOAT, 0, ((float*)NULL) + max * 2); return 0; }