mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Fixed RenderView thumbnailer
This commit is contained in:
@@ -25,11 +25,6 @@ RenderView::~RenderView()
|
|||||||
delete fading_overlay_;
|
delete fading_overlay_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderView::canSelect(Source *s) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderView::setFading(float f)
|
void RenderView::setFading(float f)
|
||||||
{
|
{
|
||||||
if (fading_overlay_ == nullptr)
|
if (fading_overlay_ == nullptr)
|
||||||
@@ -83,11 +78,18 @@ void RenderView::draw()
|
|||||||
frame_buffer_->end();
|
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) );
|
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_);
|
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());
|
||||||
@@ -96,10 +98,19 @@ void RenderView::draw()
|
|||||||
|
|
||||||
// frame_buffer_->blit(frame_thumbnail); // a tester...
|
// 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;
|
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 ()
|
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<FrameBufferImage *>() );
|
||||||
|
|
||||||
|
// future will return the primised FrameBufferImage
|
||||||
|
std::future<FrameBufferImage *> 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;
|
||||||
}
|
}
|
||||||
|
|||||||
10
RenderView.h
10
RenderView.h
@@ -1,25 +1,26 @@
|
|||||||
#ifndef RENDERVIEW_H
|
#ifndef RENDERVIEW_H
|
||||||
#define RENDERVIEW_H
|
#define RENDERVIEW_H
|
||||||
|
|
||||||
#include <mutex>
|
#include <vector>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
|
||||||
#include "View.h"
|
#include "View.h"
|
||||||
|
|
||||||
class RenderView : public View
|
class RenderView : public View
|
||||||
{
|
{
|
||||||
|
// rendering FBO
|
||||||
FrameBuffer *frame_buffer_;
|
FrameBuffer *frame_buffer_;
|
||||||
Surface *fading_overlay_;
|
Surface *fading_overlay_;
|
||||||
|
|
||||||
std::promise<FrameBufferImage *> thumbnail_;
|
// promises of returning thumbnails after an update
|
||||||
std::future<FrameBufferImage *> thumbnailer_;
|
std::vector< std::promise<FrameBufferImage *> > thumbnailer_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderView ();
|
RenderView ();
|
||||||
~RenderView ();
|
~RenderView ();
|
||||||
|
|
||||||
void draw () override;
|
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);
|
void setResolution (glm::vec3 resolution = glm::vec3(0.f), bool useAlpha = false);
|
||||||
glm::vec3 resolution() const { return frame_buffer_->resolution(); }
|
glm::vec3 resolution() const { return frame_buffer_->resolution(); }
|
||||||
@@ -29,6 +30,7 @@ public:
|
|||||||
|
|
||||||
inline FrameBuffer *frame () const { return frame_buffer_; }
|
inline FrameBuffer *frame () const { return frame_buffer_; }
|
||||||
|
|
||||||
|
// get a thumbnail; wait for a promise to be fullfiled
|
||||||
FrameBufferImage *thumbnail ();
|
FrameBufferImage *thumbnail ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user