split timelapse frame generation into multiple tasks

This commit is contained in:
2019-11-09 12:40:30 +01:00
parent 21d0ff23c7
commit faff1dd979
3 changed files with 39 additions and 65 deletions

View File

@@ -37,17 +37,17 @@ LayerFrame& Layer::frame(int frame /*= -1*/)
TextureCube Layer::gen_cube()
{
TextureCube ret;
App::I->render_task([&]
ret.create(w);
for (int i = 0; i < 6; i++)
{
ret.create(w);
ret.bind();
for (int i = 0; i < 6; i++)
App::I->render_task([&]
{
ret.bind();
rtt(i).bindFramebuffer();
glCopyTexSubImage2D(TextureCube::m_faces_map[i], 0, 0, 0, 0, 0, w, w);
rtt(i).unbindFramebuffer();
}
});
});
}
return ret;
}
@@ -103,63 +103,37 @@ Texture2D Layer::gen_equirect(glm::ivec2 size /*= { 0, 0 }*/)
PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
{
if (size.x == 0 || size.y == 0)
size = { w, h };
PBO pbo;
TextureCube cube = gen_cube();
RTT latlong;
latlong.create(size.x * 4, size.y * 2);
App::I->render_task([&]
{
gl_state gl;
gl.save();
auto t0 = std::chrono::high_resolution_clock::now();
{
glDisable(GL_BLEND);
TextureCube cube;
RTT latlong;
latlong.bindFramebuffer();
glViewport(0, 0, latlong.getWidth(), latlong.getHeight());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id);
if (size.x == 0 || size.y == 0)
size = { w, h };
ShaderManager::use(kShader::Equirect);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::Tex, 0);
Canvas::I->m_sampler.bind(0);
Canvas::I->m_plane.draw_fill();
cube = gen_cube();
auto t1 = std::chrono::high_resolution_clock::now();
latlong.create(size.x * 4, size.y * 2);
auto t2 = std::chrono::high_resolution_clock::now();
latlong.unbindFramebuffer();
});
glDisable(GL_BLEND);
pbo.create(latlong);
latlong.bindFramebuffer();
//latlong.clear({ 0, 1, 1, 1 });
glViewport(0, 0, latlong.getWidth(), latlong.getHeight());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id);
ShaderManager::use(kShader::Equirect);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::Tex, 0);
Canvas::I->m_sampler.bind(0);
Canvas::I->m_plane.draw_fill();
latlong.unbindFramebuffer();
auto t3 = std::chrono::high_resolution_clock::now();
pbo.create(latlong);
auto t4 = std::chrono::high_resolution_clock::now();
latlong.destroy();
cube.destroy();
typedef std::chrono::duration<int, std::micro> micro;
LOG("frame time: %d\n"
"- gen cube: %d\n"
"- create latlong: %d\n"
"- draw latlong: %d\n"
"- create pbo: %d\n",
std::chrono::duration_cast<micro>(t4-t0).count(), // total
std::chrono::duration_cast<micro>(t1-t0).count(), // gen cube
std::chrono::duration_cast<micro>(t2-t1).count(), // create latlong
std::chrono::duration_cast<micro>(t3-t2).count(), // draw latlong
std::chrono::duration_cast<micro>(t4-t3).count() // create pbo
);
gl.restore();
});
latlong.destroy();
cube.destroy();
return pbo;
}