mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-07 00:10:00 +01:00
Using source mode UNINITIALIZED to replace initialized_ bool
info about source initialization was duplicated; using the mode state machine only avoids to keep a flag
This commit is contained in:
@@ -98,7 +98,6 @@ void MediaSource::init()
|
||||
++View::need_deep_update_;
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source '%s' linked to Media %s.", name().c_str(), std::to_string(mediaplayer_->id()).c_str());
|
||||
}
|
||||
}
|
||||
@@ -127,11 +126,12 @@ void MediaSource::update(float dt)
|
||||
|
||||
void MediaSource::render()
|
||||
{
|
||||
if (!initialized_)
|
||||
if ( mode_ < Source::VISIBLE )
|
||||
init();
|
||||
else {
|
||||
// render the media player into frame buffer
|
||||
renderbuffer_->begin();
|
||||
// apply fading
|
||||
texturesurface_->shader()->color = glm::vec4( glm::vec3(mediaplayer_->currentTimelineFading()), 1.f);
|
||||
texturesurface_->draw(glm::identity<glm::mat4>(), renderbuffer_->projection());
|
||||
renderbuffer_->end();
|
||||
|
||||
@@ -38,8 +38,8 @@ Session *SessionSource::detach()
|
||||
// work on a new session
|
||||
session_ = new Session;
|
||||
|
||||
// make disabled
|
||||
initialized_ = false;
|
||||
// un-ready
|
||||
ready_ = false;
|
||||
|
||||
// ask to delete me
|
||||
failed_ = true;
|
||||
@@ -91,7 +91,7 @@ void SessionSource::update(float dt)
|
||||
}
|
||||
|
||||
|
||||
SessionFileSource::SessionFileSource(uint64_t id) : SessionSource(id), path_("")
|
||||
SessionFileSource::SessionFileSource(uint64_t id) : SessionSource(id), path_(""), initialized_(false), wait_for_sources_(false)
|
||||
{
|
||||
// specific node for transition view
|
||||
groups_[View::TRANSITION]->visible_ = false;
|
||||
@@ -125,7 +125,6 @@ SessionFileSource::SessionFileSource(uint64_t id) : SessionSource(id), path_("")
|
||||
symbol_ = new Symbol(Symbol::SESSION, glm::vec3(0.75f, 0.75f, 0.01f));
|
||||
symbol_->scale_.y = 1.5f;
|
||||
|
||||
wait_for_sources_ = false;
|
||||
}
|
||||
|
||||
void SessionFileSource::load(const std::string &p, uint recursion)
|
||||
@@ -149,6 +148,9 @@ void SessionFileSource::load(const std::string &p, uint recursion)
|
||||
sessionLoader_ = std::async(std::launch::async, Session::load, path_, recursion);
|
||||
Log::Notify("Opening %s", p.c_str());
|
||||
}
|
||||
|
||||
// will be ready after init and one frame rendered
|
||||
ready_ = false;
|
||||
}
|
||||
|
||||
void SessionFileSource::init()
|
||||
@@ -220,6 +222,19 @@ void SessionFileSource::init()
|
||||
}
|
||||
}
|
||||
|
||||
void SessionFileSource::render()
|
||||
{
|
||||
if ( !initialized_ )
|
||||
init();
|
||||
else {
|
||||
// render the media player into frame buffer
|
||||
renderbuffer_->begin();
|
||||
texturesurface_->draw(glm::identity<glm::mat4>(), renderbuffer_->projection());
|
||||
renderbuffer_->end();
|
||||
ready_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SessionFileSource::accept(Visitor& v)
|
||||
{
|
||||
Source::accept(v);
|
||||
@@ -283,7 +298,6 @@ void SessionGroupSource::init()
|
||||
++View::need_deep_update_;
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source Group (%d x %d).", int(renderbuffer->resolution().x), int(renderbuffer->resolution().y) );
|
||||
}
|
||||
}
|
||||
@@ -318,7 +332,7 @@ RenderSource::RenderSource(uint64_t id) : Source(id), session_(nullptr)
|
||||
|
||||
bool RenderSource::failed() const
|
||||
{
|
||||
if (initialized_ && session_!=nullptr)
|
||||
if ( mode_ > Source::UNINITIALIZED && session_!=nullptr )
|
||||
return renderbuffer_->resolution() != session_->frame()->resolution();
|
||||
|
||||
return false;
|
||||
@@ -351,7 +365,6 @@ void RenderSource::init()
|
||||
++View::need_deep_update_;
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source Render linked to session (%d x %d).", int(fb->resolution().x), int(fb->resolution().y) );
|
||||
}
|
||||
}
|
||||
@@ -359,7 +372,7 @@ void RenderSource::init()
|
||||
|
||||
glm::vec3 RenderSource::resolution() const
|
||||
{
|
||||
if (initialized_)
|
||||
if (mode_ > Source::UNINITIALIZED)
|
||||
return renderbuffer_->resolution();
|
||||
else if (session_ && session_->frame())
|
||||
return session_->frame()->resolution();
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
|
||||
// implementation of source API
|
||||
void accept (Visitor& v) override;
|
||||
void render() override;
|
||||
|
||||
// SessionFile Source specific interface
|
||||
void load(const std::string &p = "", uint recursion = 0);
|
||||
@@ -45,6 +46,7 @@ protected:
|
||||
void init() override;
|
||||
|
||||
std::string path_;
|
||||
bool initialized_;
|
||||
bool wait_for_sources_;
|
||||
std::future<Session *> sessionLoader_;
|
||||
};
|
||||
|
||||
13
Source.cpp
13
Source.cpp
@@ -96,7 +96,7 @@ SourceCore& SourceCore::operator= (SourceCore const& other)
|
||||
}
|
||||
|
||||
|
||||
Source::Source(uint64_t id) : SourceCore(), id_(id), initialized_(false), ready_(false), symbol_(nullptr),
|
||||
Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(nullptr),
|
||||
active_(true), locked_(false), need_update_(true), dt_(0), workspace_(STAGE)
|
||||
{
|
||||
// create unique id
|
||||
@@ -414,7 +414,7 @@ bool Source::imageProcessingEnabled()
|
||||
|
||||
void Source::render()
|
||||
{
|
||||
if (!initialized_)
|
||||
if ( mode_ < Source::VISIBLE )
|
||||
init();
|
||||
else {
|
||||
// render the view into frame buffer
|
||||
@@ -708,7 +708,7 @@ void Source::update(float dt)
|
||||
|
||||
FrameBuffer *Source::frame() const
|
||||
{
|
||||
if (initialized_ && renderbuffer_)
|
||||
if ( mode_ > Source::UNINITIALIZED && renderbuffer_)
|
||||
{
|
||||
return renderbuffer_;
|
||||
}
|
||||
@@ -840,7 +840,7 @@ CloneSource *CloneSource::clone(uint64_t id)
|
||||
|
||||
void CloneSource::init()
|
||||
{
|
||||
if (origin_ && origin_->initialized_) {
|
||||
if (origin_ && origin_->mode_ > Source::UNINITIALIZED) {
|
||||
|
||||
// get the texture index from framebuffer of view, apply it to the surface
|
||||
texturesurface_->setTextureIndex( origin_->texture() );
|
||||
@@ -855,7 +855,6 @@ void CloneSource::init()
|
||||
++View::need_deep_update_;
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source %s cloning source %s.", name().c_str(), origin_->name().c_str() );
|
||||
}
|
||||
}
|
||||
@@ -868,14 +867,14 @@ void CloneSource::setActive (bool on)
|
||||
groups_[View::GEOMETRY]->visible_ = active_;
|
||||
groups_[View::LAYER]->visible_ = active_;
|
||||
|
||||
if (initialized_ && origin_ != nullptr)
|
||||
if ( mode_ > Source::UNINITIALIZED && origin_ != nullptr)
|
||||
origin_->touch();
|
||||
}
|
||||
|
||||
|
||||
uint CloneSource::texture() const
|
||||
{
|
||||
if (initialized_ && origin_ != nullptr)
|
||||
if (origin_ != nullptr)
|
||||
return origin_->texture();
|
||||
else
|
||||
return Resource::getTextureBlack();
|
||||
|
||||
5
Source.h
5
Source.h
@@ -231,10 +231,9 @@ protected:
|
||||
char initials_[3];
|
||||
uint64_t id_;
|
||||
|
||||
// every Source shall be initialized before first draw and ready after
|
||||
bool initialized_;
|
||||
bool ready_;
|
||||
// every Source shall be initialized to be ready after first draw
|
||||
virtual void init() = 0;
|
||||
bool ready_;
|
||||
|
||||
// render() fills in the renderbuffer at every frame
|
||||
// NB: rendershader_ is applied at render()
|
||||
|
||||
@@ -92,7 +92,6 @@ void StreamSource::init()
|
||||
++View::need_deep_update_;
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source '%s' linked to Stream %s", name().c_str(), std::to_string(stream_->id()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user