added timeline slider and export animation frames

This commit is contained in:
2017-05-15 00:43:37 +01:00
parent 95509956f3
commit 7b99f0510a
10 changed files with 132 additions and 12 deletions

View File

@@ -451,7 +451,6 @@ void ui::Canvas::resize(int width, int height)
{
l.create(width, height, "");
}
m_latlong.create(width * 4, height * 2); // NOTE: w and h must be equal to make sense
}
bool ui::Canvas::create(int width, int height)
{
@@ -473,7 +472,6 @@ bool ui::Canvas::create(int width, int height)
{
l.create(width, height, "");
}
m_latlong.create(width * 4, height * 2); // NOTE: w and h must be equal to make sense
return true;
}
@@ -506,7 +504,6 @@ void ui::Canvas::clear_context()
m_tex[i].destroy();
m_tex2[i].destroy();
}
m_latlong.destroy();
};
void ui::Canvas::export_equirectangular(std::string data_path)
@@ -522,6 +519,10 @@ void ui::Canvas::export_equirectangular(std::string data_path)
glViewport(0, 0, m_width, m_height);
glDisable(GL_BLEND);
RTT m_latlong;
m_latlong.create(m_width * 4, m_height * 2); // NOTE: w and h must be equal to make sense
GLuint cube_id;
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
for (GLuint i = 0; i < 6; i++)
@@ -603,6 +604,83 @@ void ui::Canvas::export_equirectangular(std::string data_path)
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
}
glDeleteTextures(1, &cube_id);
m_latlong.destroy();
// restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
glViewport(vp[0], vp[1], vp[2], vp[3]);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
glActiveTexture(GL_TEXTURE0);
}
void ui::Canvas::export_anim(std::string data_path)
{
// save viewport and clear color states
GLint vp[4];
GLfloat cc[4];
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
GLboolean blend = glIsEnabled(GL_BLEND);
// prepare common states
glViewport(0, 0, m_width, m_height);
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
RTT m_latlong;
m_latlong.create(m_width * 4, m_height * 2); // NOTE: w and h must be equal to make sense
GLuint cube_id;
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
for (GLuint i = 0; i < 6; i++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
int faces[]{
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, // front
GL_TEXTURE_CUBE_MAP_NEGATIVE_X, // right
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, // back
GL_TEXTURE_CUBE_MAP_POSITIVE_X, // left
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // top
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
for (auto layer_index : m_order)
{
for (int i = 0; i < 6; i++)
{
m_layers[layer_index].m_rtt[i].bindFramebuffer();
// copy result to cubemap
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
glCopyTexImage2D(faces[i], 0, GL_RGBA8, 0, 0, m_width, m_height, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
m_layers[layer_index].m_rtt[i].unbindFramebuffer();
}
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
m_latlong.clear({ 1, 1, 1, 1 });
m_latlong.bindFramebuffer();
ui::ShaderManager::use(kShader::Equirect);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
m_sampler.bind(0);
m_plane.draw_fill();
m_sampler.unbind();
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
m_latlong.unbindFramebuffer();
{
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
m_latlong.readTextureData(latlong_data.get());
static char name[128];
sprintf(name, "%s/latlong-frame%02d.png", data_path.c_str(), layer_index);
LOG("writing %s", name);
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
}
}
glDeleteTextures(1, &cube_id);
m_latlong.destroy();
// restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
glViewport(vp[0], vp[1], vp[2], vp[3]);