use PBO for timelapse data read

This commit is contained in:
2019-11-05 18:25:25 +01:00
parent 4b6316bf68
commit 52ad58aec4
8 changed files with 212 additions and 9 deletions

View File

@@ -411,3 +411,114 @@ bool RTT::valid() const noexcept
{
return texID || rboID || fboID;
}
//////////////////////////////////////////////////////////////////////////
PBO::PBO(PBO&& other) noexcept
{
bound_slot = other.bound_slot;
buffer_id = other.buffer_id;
mapped_ptr = other.mapped_ptr;
width = other.width;
height = other.height;
other.bound_slot = 0;
other.buffer_id = 0;
other.mapped_ptr = nullptr;
other.width = 0;
other.height = 0;
}
PBO& PBO::operator=(PBO&& other) noexcept
{
bound_slot = other.bound_slot;
buffer_id = other.buffer_id;
mapped_ptr = other.mapped_ptr;
width = other.width;
height = other.height;
other.bound_slot = 0;
other.buffer_id = 0;
other.mapped_ptr = nullptr;
other.width = 0;
other.height = 0;
return *this;
}
PBO::~PBO() noexcept
{
destroy();
}
bool PBO::create() noexcept
{
App::I->render_task([this] {
glGenBuffers(1, &buffer_id);
});
return true;
}
bool PBO::create(RTT& rtt) noexcept
{
App::I->render_task([this, &rtt] {
width = rtt.getWidth();
height = rtt.getHeight();
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);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
rtt.unbindFramebuffer();
});
return true;
}
void PBO::destroy() noexcept
{
if (buffer_id)
{
App::I->render_task_async([id=buffer_id] {
glDeleteBuffers(1, &id);
});
buffer_id = 0;
bound_slot = 0;
width = 0;
height = 0;
mapped_ptr = nullptr;
}
}
/*
void PBO::bind_read() noexcept
{
App::I->render_task([this] {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_id);
bound_slot = GL_PIXEL_UNPACK_BUFFER;
});
}
void PBO::unbind() noexcept
{
App::I->render_task([this] {
glBindBuffer(bound_slot, buffer_id);
});
}
*/
glm::uint8_t* PBO::map() noexcept
{
App::I->render_task([this] {
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
mapped_ptr = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
});
return mapped_ptr;
}
void PBO::unmap() noexcept
{
App::I->render_task([this] {
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_id);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
});
}