Improvement: reuse FBO for Thumbnailing

Avoid create and delete a new FBO for each thumbnail, as they are often the same size.
This commit is contained in:
Bruno Herbelin
2022-04-17 12:51:55 +02:00
parent 05eb62bb35
commit 07e2bd4bcf
2 changed files with 21 additions and 10 deletions

View File

@@ -33,7 +33,7 @@
#include "RenderView.h"
RenderView::RenderView() : View(RENDERING), frame_buffer_(nullptr), fading_overlay_(nullptr)
RenderView::RenderView() : View(RENDERING), frame_buffer_(nullptr), fading_overlay_(nullptr), frame_thumbnail_(nullptr)
{
}
@@ -43,6 +43,8 @@ RenderView::~RenderView()
delete frame_buffer_;
if (fading_overlay_)
delete fading_overlay_;
if (frame_thumbnail_)
delete frame_thumbnail_;
}
void RenderView::setFading(float f)
@@ -106,27 +108,35 @@ void RenderView::drawThumbnail()
if (thumbnailer_.size() > 0) {
try {
// new thumbnailing framebuffer
FrameBuffer *frame_thumbnail = new FrameBuffer( glm::vec3(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio(), SESSION_THUMBNAIL_HEIGHT, 1.f) );
// set resolution of the thumbnail
glm::vec3 res_thumbnail( round(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio()), SESSION_THUMBNAIL_HEIGHT, 0.f);
// try to reuse the stored frame_thumbnail_ FBO
if ( frame_thumbnail_ != nullptr && frame_thumbnail_->resolution() != res_thumbnail ) {
delete frame_thumbnail_;
frame_thumbnail_ = nullptr;
}
// new thumbnailing framebuffer if necessary
if (frame_thumbnail_ == nullptr)
frame_thumbnail_ = new FrameBuffer( res_thumbnail );
// render
if (Settings::application.render.blit) {
if ( !frame_buffer_->blit(frame_thumbnail) )
if ( !frame_buffer_->blit(frame_thumbnail_) )
throw std::runtime_error("no blit");
}
else {
FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_);
frame_thumbnail->begin();
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail->projection());
frame_thumbnail->end();
frame_thumbnail_->begin();
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail_->projection());
frame_thumbnail_->end();
delete thumb;
}
// return valid thumbnail promise
thumbnailer_.back().set_value( frame_thumbnail->image() );
thumbnailer_.back().set_value( frame_thumbnail_->image() );
// done with thumbnailing framebuffer
delete frame_thumbnail;
}
catch(...) {
// return failed thumbnail promise