split timelapse frame generation into multiple tasks
This commit is contained in:
@@ -92,8 +92,8 @@ void App::tick(float dt)
|
||||
PBO equirect;
|
||||
App::I->render_task([&] {
|
||||
Canvas::I->draw_merge(true);
|
||||
equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(Canvas::I->m_encoder->frame_size() / 4);
|
||||
});
|
||||
equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(Canvas::I->m_encoder->frame_size() / 4);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(rec_mutex);
|
||||
rec_frames.emplace_back(std::make_unique<PBO>(std::move(equirect)));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
16
src/rtt.cpp
16
src/rtt.cpp
@@ -464,7 +464,7 @@ bool PBO::create(RTT& rtt) noexcept
|
||||
rtt.bindFramebuffer();
|
||||
glGenBuffers(1, &buffer_id);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * 4, 0, GL_STREAM_DRAW);
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, width * height * 4, 0, GL_STREAM_READ);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
rtt.unbindFramebuffer();
|
||||
@@ -507,10 +507,10 @@ void PBO::unbind() noexcept
|
||||
glm::uint8_t* PBO::map() noexcept
|
||||
{
|
||||
App::I->render_task([this] {
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
|
||||
mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0,
|
||||
width * height * 4, GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
|
||||
mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0,
|
||||
width * height * 4, GL_MAP_READ_BIT);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
});
|
||||
return mapped_ptr;
|
||||
}
|
||||
@@ -518,8 +518,8 @@ glm::uint8_t* PBO::map() noexcept
|
||||
void PBO::unmap() noexcept
|
||||
{
|
||||
App::I->render_task([this] {
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
|
||||
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user