split timelapse frame generation into multiple tasks
This commit is contained in:
@@ -92,8 +92,8 @@ void App::tick(float dt)
|
|||||||
PBO equirect;
|
PBO equirect;
|
||||||
App::I->render_task([&] {
|
App::I->render_task([&] {
|
||||||
Canvas::I->draw_merge(true);
|
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);
|
std::lock_guard<std::mutex> lock(rec_mutex);
|
||||||
rec_frames.emplace_back(std::make_unique<PBO>(std::move(equirect)));
|
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 Layer::gen_cube()
|
||||||
{
|
{
|
||||||
TextureCube ret;
|
TextureCube ret;
|
||||||
App::I->render_task([&]
|
|
||||||
{
|
|
||||||
ret.create(w);
|
ret.create(w);
|
||||||
ret.bind();
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
|
App::I->render_task([&]
|
||||||
|
{
|
||||||
|
ret.bind();
|
||||||
rtt(i).bindFramebuffer();
|
rtt(i).bindFramebuffer();
|
||||||
glCopyTexSubImage2D(TextureCube::m_faces_map[i], 0, 0, 0, 0, 0, w, w);
|
glCopyTexSubImage2D(TextureCube::m_faces_map[i], 0, 0, 0, 0, 0, w, w);
|
||||||
rtt(i).unbindFramebuffer();
|
rtt(i).unbindFramebuffer();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,29 +103,20 @@ Texture2D Layer::gen_equirect(glm::ivec2 size /*= { 0, 0 }*/)
|
|||||||
|
|
||||||
PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
|
PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
|
||||||
{
|
{
|
||||||
PBO pbo;
|
|
||||||
App::I->render_task([&]
|
|
||||||
{
|
|
||||||
gl_state gl;
|
|
||||||
gl.save();
|
|
||||||
|
|
||||||
auto t0 = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
TextureCube cube;
|
|
||||||
RTT latlong;
|
|
||||||
|
|
||||||
if (size.x == 0 || size.y == 0)
|
if (size.x == 0 || size.y == 0)
|
||||||
size = { w, h };
|
size = { w, h };
|
||||||
|
|
||||||
cube = gen_cube();
|
PBO pbo;
|
||||||
auto t1 = std::chrono::high_resolution_clock::now();
|
TextureCube cube = gen_cube();
|
||||||
|
RTT latlong;
|
||||||
latlong.create(size.x * 4, size.y * 2);
|
latlong.create(size.x * 4, size.y * 2);
|
||||||
auto t2 = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
|
App::I->render_task([&]
|
||||||
|
{
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
latlong.bindFramebuffer();
|
latlong.bindFramebuffer();
|
||||||
//latlong.clear({ 0, 1, 1, 1 });
|
|
||||||
glViewport(0, 0, latlong.getWidth(), latlong.getHeight());
|
glViewport(0, 0, latlong.getWidth(), latlong.getHeight());
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cube.m_cubetex_id);
|
||||||
@@ -137,29 +128,12 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
|
|||||||
Canvas::I->m_plane.draw_fill();
|
Canvas::I->m_plane.draw_fill();
|
||||||
|
|
||||||
latlong.unbindFramebuffer();
|
latlong.unbindFramebuffer();
|
||||||
auto t3 = std::chrono::high_resolution_clock::now();
|
});
|
||||||
|
|
||||||
pbo.create(latlong);
|
pbo.create(latlong);
|
||||||
auto t4 = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
latlong.destroy();
|
latlong.destroy();
|
||||||
cube.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();
|
|
||||||
});
|
|
||||||
return pbo;
|
return pbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/rtt.cpp
16
src/rtt.cpp
@@ -464,7 +464,7 @@ bool PBO::create(RTT& rtt) noexcept
|
|||||||
rtt.bindFramebuffer();
|
rtt.bindFramebuffer();
|
||||||
glGenBuffers(1, &buffer_id);
|
glGenBuffers(1, &buffer_id);
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 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);
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
rtt.unbindFramebuffer();
|
rtt.unbindFramebuffer();
|
||||||
@@ -507,10 +507,10 @@ void PBO::unbind() noexcept
|
|||||||
glm::uint8_t* PBO::map() noexcept
|
glm::uint8_t* PBO::map() noexcept
|
||||||
{
|
{
|
||||||
App::I->render_task([this] {
|
App::I->render_task([this] {
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
|
||||||
mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0,
|
mapped_ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0,
|
||||||
width * height * 4, GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
width * height * 4, GL_MAP_READ_BIT);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
});
|
});
|
||||||
return mapped_ptr;
|
return mapped_ptr;
|
||||||
}
|
}
|
||||||
@@ -518,8 +518,8 @@ glm::uint8_t* PBO::map() noexcept
|
|||||||
void PBO::unmap() noexcept
|
void PBO::unmap() noexcept
|
||||||
{
|
{
|
||||||
App::I->render_task([this] {
|
App::I->render_task([this] {
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
|
||||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user