diff --git a/RenderView.cpp b/RenderView.cpp index 267fa6c..bcf537f 100644 --- a/RenderView.cpp +++ b/RenderView.cpp @@ -25,11 +25,6 @@ RenderView::~RenderView() delete fading_overlay_; } -bool RenderView::canSelect(Source *s) { - - return false; -} - void RenderView::setFading(float f) { if (fading_overlay_ == nullptr) @@ -83,11 +78,18 @@ void RenderView::draw() frame_buffer_->end(); } - if (thumbnailer_.valid()) { + // if a thumbnailer is pending + if (thumbnailer_.size() > 0) { - if (frame_buffer_) { + try { + // promise will fail if no framebuffer + if ( frame_buffer_ == nullptr ) + throw std::runtime_error("no frame"); + + // new thumbnailing framebuffer FrameBuffer *frame_thumbnail = new FrameBuffer( glm::vec3(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio(), SESSION_THUMBNAIL_HEIGHT, 1.f) ); + // render FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_); frame_thumbnail->begin(); thumb->draw(glm::identity(), frame_thumbnail->projection()); @@ -96,10 +98,19 @@ void RenderView::draw() // frame_buffer_->blit(frame_thumbnail); // a tester... - thumbnail_.set_value( frame_thumbnail->image() ); + // return valid thumbnail promise + thumbnailer_.back().set_value( frame_thumbnail->image() ); + // done with thumbnailing framebuffer delete frame_thumbnail; } + catch(...) { + // return failed thumbnail promise + thumbnailer_.back().set_exception(std::current_exception()); + } + + // done with this promise + thumbnailer_.pop_back(); } } @@ -107,7 +118,21 @@ void RenderView::draw() FrameBufferImage *RenderView::thumbnail () { - thumbnailer_ = thumbnail_.get_future(); + // by default null image + FrameBufferImage *img = nullptr; - return thumbnailer_.get(); + // create and store a promise for a FrameBufferImage + thumbnailer_.emplace_back( std::promise() ); + + // future will return the primised FrameBufferImage + std::future t = thumbnailer_.back().get_future(); + + try { + // wait for valid return value from promise + img = t.get(); + } + // catch any failed promise + catch (std::runtime_error&){ } + + return img; } diff --git a/RenderView.h b/RenderView.h index add1c62..cf3d38e 100644 --- a/RenderView.h +++ b/RenderView.h @@ -1,25 +1,26 @@ #ifndef RENDERVIEW_H #define RENDERVIEW_H -#include +#include #include #include "View.h" class RenderView : public View { + // rendering FBO FrameBuffer *frame_buffer_; Surface *fading_overlay_; - std::promise thumbnail_; - std::future thumbnailer_; + // promises of returning thumbnails after an update + std::vector< std::promise > thumbnailer_; public: RenderView (); ~RenderView (); void draw () override; - bool canSelect(Source *) override; + bool canSelect(Source *) override { return false; } void setResolution (glm::vec3 resolution = glm::vec3(0.f), bool useAlpha = false); glm::vec3 resolution() const { return frame_buffer_->resolution(); } @@ -29,6 +30,7 @@ public: inline FrameBuffer *frame () const { return frame_buffer_; } + // get a thumbnail; wait for a promise to be fullfiled FrameBufferImage *thumbnail (); };