This commit is contained in:
2018-03-24 16:58:05 +01:00

View File

@@ -1123,7 +1123,6 @@ void ui::Canvas::export_anim(std::string data_path)
// prepare common states
glViewport(0, 0, m_width, m_height);
glEnable(GL_BLEND);
RTT m_latlong;
m_latlong.create(m_width * 4, m_height * 2); // NOTE: w and h must be equal to make sense
@@ -1141,18 +1140,29 @@ void ui::Canvas::export_anim(std::string data_path)
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // top
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
int seq = 0;
for (auto layer_index : m_order)
{
glViewport(0, 0, m_width, m_height);
for (int i = 0; i < 6; i++)
{
m_tmp[i].bindFramebuffer();
m_tmp[i].clear({ 1, 1, 1, 1 });
ui::ShaderManager::use(kShader::Checkerboard);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
m_plane.draw_fill();
if (seq == 0)
{
m_tmp[i].clear({ 1, 1, 1, 1 });
ui::ShaderManager::use(kShader::Checkerboard);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
m_plane.draw_fill();
glEnable(GL_BLEND);
}
else
{
m_tmp[i].clear({ 1, 1, 1, 0 });
glDisable(GL_BLEND);
}
glActiveTexture(GL_TEXTURE0);
ShaderManager::use(ui::kShader::TextureAlpha);
ShaderManager::u_float(kShaderUniform::Alpha, 1);
@@ -1174,29 +1184,32 @@ void ui::Canvas::export_anim(std::string data_path)
m_tmp[i].unbindFramebuffer();
}
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
glActiveTexture(GL_TEXTURE0);
m_latlong.bindFramebuffer();
m_latlong.clear({ 1, 1, 1, 1 });
m_latlong.clear({ 1, 1, 1, 0 });
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);
glDisable(GL_BLEND);
m_sampler_mask.bind(0);
m_plane.draw_fill();
m_sampler.unbind();
m_sampler_mask.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.jpg", data_path.c_str(), layer_index);
sprintf(name, "%s/latlong-frame%02d.png", data_path.c_str(), seq);
seq++;
LOG("writing %s", name);
//int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
jpge::params params;
params.m_quality = 100;
bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
//jpge::params params;
//params.m_quality = 100;
//bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
}
}