use PBO for timelapse data read
This commit is contained in:
111
src/rtt.cpp
111
src/rtt.cpp
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user