26 using namespace MaliSDK;
30 :
mesh(size, levels, clip_scale), heightmap(size * 4 - 1, levels), frame(0)
40 GL_CHECK(GLint heightmap_loc = glGetUniformLocation(
program,
"sHeightmap"));
41 GL_CHECK(glUniform1i(heightmap_loc, 0));
43 vector<GLfloat> inv_level_size;
44 float inv_size = 1.0f / (clip_scale * (size * 4 - 1));
45 for (
unsigned int i = 0; i <
levels; i++)
47 inv_level_size.push_back(inv_size);
51 GL_CHECK(GLint inv_level_size_loc = glGetUniformLocation(
program,
"uInvLevelSize"));
52 GL_CHECK(glUniform1fv(inv_level_size_loc, inv_level_size.size(), &inv_level_size[0]));
67 GL_CHECK(glAttachShader(prog, vertex));
68 GL_CHECK(glAttachShader(prog, fragment));
72 GL_CHECK(glGetProgramiv(prog, GL_LINK_STATUS, &status));
76 GL_CHECK(glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &info_len));
79 char *
buffer =
new char[info_len];
81 GL_CHECK(glGetProgramInfoLog(prog, info_len, &actual_len, buffer));
82 LOGE(
"Program failed to link: %s.\n", buffer);
96 GL_CHECK(glShaderSource(shader, 1, &source, NULL));
100 GL_CHECK(glGetShaderiv(shader, GL_COMPILE_STATUS, &status));
105 GL_CHECK(glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len));
108 char *
buffer =
new char[info_len];
110 GL_CHECK(glGetShaderInfoLog(shader, info_len, &actual_len, buffer));
112 LOGE(
"Shader error: %s.\n", buffer);
123 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
126 GL_CHECK(glViewport(0, 0, width, height));
134 vec3 world_camera_pos =
vec3(camera_pos.
c.x, 20, camera_pos.
c.y);
138 mat4 vp = proj * view;
153 GL_CHECK(glActiveTexture(GL_TEXTURE0));
void set_frustum(const Frustum &frustum)
void update_heightmap(const std::vector< vec2 > &level_offsets)
mat4 mat_look_at(const vec3 &eye, const vec3 ¢er, const vec3 &up)
GLint GLsizei GLsizei height
GLuint get_texture() const
static const char vertex_shader_source[]
void update_level_offsets(const vec2 &camera_pos)
[Snapping clipmap level to a grid]
GLsizei GLsizei GLchar * source
GLuint compile_shader(GLenum type, const char *source)
void render()
[Rendering the entire terrain]
ClipmapApplication(unsigned int size, unsigned int levels, float clip_scale)
mat4 mat_perspective_fov(float fovy, float aspect, float zn, float zf)
const std::vector< vec2 > & get_level_offsets() const
#define GL_TEXTURE_2D_ARRAY
GLenum GLuint GLintptr GLsizeiptr size
GLuint compile_program(const char *vertex_shader_source, const char *fragment_shader_source)
void render(unsigned int viewport_width, unsigned int viewport_height)
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
static const char fragment_shader_source[]