28 using namespace MaliSDK;
32 : size(size), level_size(4 * size - 1), levels(levels), clipmap_scale(clip_scale)
75 vec2 pos = snapped_pos -
vec2((2 * (
size - 1)) << level);
84 for (
unsigned int i = 0; i <
levels; i++)
118 for (
unsigned int i = 1; i <
levels; i++)
138 *instances++ = instance;
151 *instances++ = instance;
170 for (
unsigned int i = 1; i <
levels; i++)
184 *instances++ = instance;
196 *instances++ = instance;
214 for (
unsigned int i = 0; i <
levels - 1; i++)
225 instance.
offset += ring_offset * vec2(1 << i);
232 *instances++ = instance;
280 *instances = instance;
297 for (
unsigned int i = 2; i <
levels; i++)
306 if (!cond(offset_prev_level - offset_current_level))
320 *instances++ = instance;
332 return offset.
c.x < 0.5f && offset.
c.y > 0.5f;
337 return offset.
c.x > 0.5f && offset.
c.y > 0.5f;
342 return offset.
c.x < 0.5f && offset.
c.y < 0.5f;
347 return offset.
c.x > 0.5f && offset.
c.y < 0.5f;
383 for (
unsigned int z = 0; z < 4; z++)
385 for (
unsigned int x = 0;
x < 4;
x++)
395 *instances++ = instance;
403 for (
unsigned int i = 1; i <
levels; i++)
407 for (
unsigned int z = 0; z < 4; z++)
409 for (
unsigned int x = 0;
x < 4;
x++)
411 if (z != 0 && z != 3 &&
x != 0 &&
x != 3)
434 *instances++ = instance;
449 float y_min = -20.0f;
464 return reinterpret_cast<T*
>(
reinterpret_cast<uint8_t*
>(
buffer) + offset);
470 return (offset + align - 1) & ~(align - 1);
494 LOGE(
"Failed to map uniform buffer.\n");
499 size_t uniform_buffer_offset = 0;
552 GL_CHECK(glUnmapBuffer(GL_UNIFORM_BUFFER));
558 for (std::vector<DrawInfo>::const_iterator itr =
draw_list.begin(); itr !=
draw_list.end(); ++itr)
568 GL_CHECK(glDrawElementsInstanced(GL_TRIANGLE_STRIP, itr->indices, GL_UNSIGNED_SHORT,
569 reinterpret_cast<const GLvoid*>(itr->index_buffer_offset *
sizeof(GLushort)), itr->instances));
584 GL_CHECK(glBindBuffer(GL_UNIFORM_BUFFER, 0));
585 GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0));
T vec_fract(const T &vec)
T vec_floor(const T &vec)
DrawInfo get_draw_info_vert_fixup(InstanceData *instance_data)
bool intersects_aabb(const AABB &aabb) const
[Compute plane equations]
vec2 get_offset_level(const vec2 &camera_pos, unsigned int level)
[Snapping clipmap level to a grid]
void setup_vertex_buffer(unsigned int size)
void setup_block_ranges(unsigned int size)
[Generating index buffer]
static bool trim_bottom_right_cond(const vec2 &offset)
DrawInfo get_draw_info_degenerate_top(InstanceData *instance_data)
GLint uniform_buffer_align
DrawInfo get_draw_info_trim_bottom_left(InstanceData *instance_data)
GLenum GLuint GLintptr offset
static bool trim_top_left_cond(const vec2 &offset)
Frustum view_proj_frustum
DrawInfo get_draw_info_degenerate_bottom(InstanceData *instance_data)
void setup_uniform_buffer()
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
DrawInfo get_draw_info_trim_top_left(InstanceData *instance_data)
size_t uniform_buffer_offset
DrawInfo get_draw_info_degenerate_left(InstanceData *instance_data)
DrawInfo get_draw_info_horiz_fixup(InstanceData *instance_data)
void update_level_offsets(const vec2 &camera_pos)
[Snapping clipmap level to a grid]
DrawInfo get_draw_info_degenerate_right(InstanceData *instance_data)
DrawInfo get_draw_info_trim(InstanceData *instance_data, const Block &block, TrimConditional cond)
DrawInfo get_draw_info_degenerate(InstanceData *instance_data, const Block &block, const vec2 &offset, const vec2 &ring_offset)
size_t index_buffer_offset
DrawInfo get_draw_info_trim_top_right(InstanceData *instance_data)
void setup_index_buffer(unsigned int size)
GroundMesh(unsigned int size, unsigned int levels, float clip_scale)
void render()
[Rendering the entire terrain]
DrawInfo get_draw_info_blocks(InstanceData *instance_data)
static unsigned int realign_offset(size_t offset, size_t align)
static bool trim_bottom_left_cond(const vec2 &offset)
void setup_vertex_array()
std::vector< DrawInfo > draw_list
GLenum GLuint GLintptr GLsizeiptr size
static bool trim_top_right_cond(const vec2 &offset)
std::vector< vec2 > level_offsets
GLint GLint GLint GLint GLint x
void render_draw_list()
[Rendering the entire terrain]
GLenum GLuint GLint level
bool intersects_frustum(const vec2 &offset, const vec2 &range, unsigned int level)
static T * buffer_offset(T *buffer, size_t offset)
size_t uniform_buffer_size
DrawInfo get_draw_info_trim_full(InstanceData *instance_data)
DrawInfo get_draw_info_trim_bottom_right(InstanceData *instance_data)