mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user