Using std future promises to get thumbnail of render view

This commit is contained in:
Bruno
2021-04-24 13:14:57 +02:00
parent 5473c0b38b
commit f643e80de7
4 changed files with 32 additions and 16 deletions

View File

@@ -13,6 +13,7 @@
RenderView::RenderView() : View(RENDERING), frame_buffer_(nullptr), fading_overlay_(nullptr)
// ,thumbnail_(nullptr), thumbnail_ready_(false)
{
}
@@ -81,26 +82,32 @@ void RenderView::draw()
fading_overlay_->draw(glm::identity<glm::mat4>(), projection);
frame_buffer_->end();
}
}
if (thumbnailer_.valid()) {
FrameBufferImage *RenderView::thumbnail () const
{
FrameBufferImage *thumbnail = nullptr;
if (frame_buffer_) {
FrameBuffer *frame_thumbnail = new FrameBuffer( glm::vec3(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio(), SESSION_THUMBNAIL_HEIGHT, 1.f) );
if (frame_buffer_) {
FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_);
FrameBuffer *frame_thumbnail = new FrameBuffer( glm::vec3(SESSION_THUMBNAIL_HEIGHT * frame_buffer_->aspectRatio(), SESSION_THUMBNAIL_HEIGHT, 1.f) );
FrameBufferSurface *thumb = new FrameBufferSurface(frame_buffer_);
frame_thumbnail->begin();
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail->projection());
frame_thumbnail->end();
delete thumb;
frame_thumbnail->begin();
thumb->draw(glm::identity<glm::mat4>(), frame_thumbnail->projection());
frame_thumbnail->end();
// frame_buffer_->blit(frame_thumbnail); // a tester...
thumbnail = frame_thumbnail->image();
thumbnail_.set_value( frame_thumbnail->image() );
delete thumb;
delete frame_thumbnail;
delete frame_thumbnail;
}
}
return thumbnail;
}
FrameBufferImage *RenderView::thumbnail ()
{
thumbnailer_ = thumbnail_.get_future();
return thumbnailer_.get();
}

View File

@@ -1,6 +1,9 @@
#ifndef RENDERVIEW_H
#define RENDERVIEW_H
#include <mutex>
#include <future>
#include "View.h"
class RenderView : public View
@@ -8,6 +11,9 @@ class RenderView : public View
FrameBuffer *frame_buffer_;
Surface *fading_overlay_;
std::promise<FrameBufferImage *> thumbnail_;
std::future<FrameBufferImage *> thumbnailer_;
public:
RenderView ();
~RenderView ();
@@ -23,7 +29,7 @@ public:
inline FrameBuffer *frame () const { return frame_buffer_; }
FrameBufferImage *thumbnail () const;
FrameBufferImage *thumbnail ();
};
#endif // RENDERVIEW_H

View File

@@ -128,7 +128,6 @@ void Session::update(float dt)
// draw render view in Frame Buffer
render_.draw();
}
SourceList::iterator Session::addSource(Source *s)

View File

@@ -83,6 +83,9 @@ public:
// get frame result of render
inline FrameBuffer *frame () const { return render_.frame(); }
// get thumbnail image
inline FrameBufferImage *thumbnail () { return render_.thumbnail(); }
// configure rendering resolution
void setResolution (glm::vec3 resolution, bool useAlpha = false);
@@ -138,6 +141,7 @@ protected:
SessionSnapshots snapshots_;
float fading_target_;
std::mutex access_;
};