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"
|
#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_;
|
delete frame_buffer_;
|
||||||
if (fading_overlay_)
|
if (fading_overlay_)
|
||||||
delete fading_overlay_;
|
delete fading_overlay_;
|
||||||
|
if (frame_thumbnail_)
|
||||||
|
delete frame_thumbnail_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderView::setFading(float f)
|
void RenderView::setFading(float f)
|
||||||
@@ -106,27 +108,35 @@ void RenderView::drawThumbnail()
|
|||||||
if (thumbnailer_.size() > 0) {
|
if (thumbnailer_.size() > 0) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// new thumbnailing framebuffer
|
// set resolution of the thumbnail
|
||||||
FrameBuffer *frame_thumbnail = new FrameBuffer( glm::vec3(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio(), SESSION_THUMBNAIL_HEIGHT, 1.f) );
|
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
|
// render
|
||||||
if (Settings::application.render.blit) {
|
if (Settings::application.render.blit) {
|
||||||
if ( !frame_buffer_->blit(frame_thumbnail) )
|
if ( !frame_buffer_->blit(frame_thumbnail_) )
|
||||||
throw std::runtime_error("no blit");
|
throw std::runtime_error("no blit");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_);
|
FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_);
|
||||||
frame_thumbnail->begin();
|
frame_thumbnail_->begin();
|
||||||
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail->projection());
|
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail_->projection());
|
||||||
frame_thumbnail->end();
|
frame_thumbnail_->end();
|
||||||
delete thumb;
|
delete thumb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return valid thumbnail promise
|
// 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(...) {
|
catch(...) {
|
||||||
// return failed thumbnail promise
|
// return failed thumbnail promise
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ protected:
|
|||||||
// get a thumbnail outside of opengl context; wait for a promise to be fullfiled after draw
|
// get a thumbnail outside of opengl context; wait for a promise to be fullfiled after draw
|
||||||
void drawThumbnail();
|
void drawThumbnail();
|
||||||
FrameBufferImage *thumbnail ();
|
FrameBufferImage *thumbnail ();
|
||||||
|
FrameBuffer *frame_thumbnail_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RENDERVIEW_H
|
#endif // RENDERVIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user