First implementation of image processing shader de-activation for

sources.
This commit is contained in:
brunoherbelin
2020-07-30 02:03:01 +02:00
parent a85ded6b5a
commit fd0979887a
7 changed files with 84 additions and 19 deletions

View File

@@ -182,12 +182,12 @@ void ImGuiVisitor::visit(ImageProcessingShader &n)
{ {
ImGui::PushID(n.id()); ImGui::PushID(n.id());
if (ImGuiToolkit::ButtonIcon(6, 2)) { // if (ImGuiToolkit::ButtonIcon(6, 2)) {
ImageProcessingShader defaultvalues; // ImageProcessingShader defaultvalues;
n = defaultvalues; // n = defaultvalues;
} // }
ImGui::SameLine(0, 10); // ImGui::SameLine(0, 10);
ImGui::Text("Filters"); // ImGui::Text("Filters");
if (ImGuiToolkit::ButtonIcon(6, 4)) n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f); if (ImGuiToolkit::ButtonIcon(6, 4)) n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f);
ImGui::SameLine(0, 10); ImGui::SameLine(0, 10);
@@ -271,7 +271,15 @@ void ImGuiVisitor::visit (Source& s)
ImVec2 imagesize ( preview_width, preview_width / s.frame()->aspectRatio()); ImVec2 imagesize ( preview_width, preview_width / s.frame()->aspectRatio());
ImGui::Image((void*)(uintptr_t) s.frame()->texture(), imagesize); ImGui::Image((void*)(uintptr_t) s.frame()->texture(), imagesize);
bool on = s.imageProcessingEnabled();
if (ImGuiToolkit::ButtonIconToggle(11, 4, 10, 4, &on)) {
s.setImageProcessingEnabled(on);
}
ImGui::SameLine(0, 10);
ImGui::Text("Filters");
// image processing pannel // image processing pannel
if (on)
s.processingShader()->accept(*this); s.processingShader()->accept(*this);
// geometry direct control // geometry direct control

View File

@@ -20,7 +20,7 @@ MediaSource::MediaSource() : Source(), path_("")
// - textured with original texture from media player // - textured with original texture from media player
// - crop & repeat UV can be managed here // - crop & repeat UV can be managed here
// - additional custom shader can be associated // - additional custom shader can be associated
mediasurface_ = new Surface(rendershader_); mediasurface_ = new Surface(renderingshader_);
} }
@@ -60,6 +60,11 @@ uint MediaSource::texture() const
return mediaplayer_->texture(); return mediaplayer_->texture();
} }
void MediaSource::replaceRenderingShader()
{
mediasurface_->replaceShader(renderingshader_);
}
void MediaSource::init() void MediaSource::init()
{ {
if ( mediaplayer_->isOpen() ) { if ( mediaplayer_->isOpen() ) {

View File

@@ -25,6 +25,7 @@ public:
protected: protected:
void init() override; void init() override;
void replaceRenderingShader() override;
Surface *mediasurface_; Surface *mediasurface_;
std::string path_; std::string path_;

View File

@@ -79,7 +79,7 @@ SessionSource::SessionSource() : Source(), path_("")
// - textured with original texture from session // - textured with original texture from session
// - crop & repeat UV can be managed here // - crop & repeat UV can be managed here
// - additional custom shader can be associated // - additional custom shader can be associated
sessionsurface_ = new Surface(rendershader_); sessionsurface_ = new Surface(processingshader_);
} }
SessionSource::~SessionSource() SessionSource::~SessionSource()
@@ -130,6 +130,11 @@ uint SessionSource::texture() const
return session_->frame()->texture(); return session_->frame()->texture();
} }
void SessionSource::replaceRenderingShader()
{
sessionsurface_->replaceShader(renderingshader_);
}
void SessionSource::init() void SessionSource::init()
{ {
if (session_ == nullptr) if (session_ == nullptr)
@@ -247,7 +252,7 @@ void SessionSource::accept(Visitor& v)
RenderSource::RenderSource(Session *session) : Source(), session_(session) RenderSource::RenderSource(Session *session) : Source(), session_(session)
{ {
// create surface: // create surface:
sessionsurface_ = new Surface(rendershader_); sessionsurface_ = new Surface(processingshader_);
} }
RenderSource::~RenderSource() RenderSource::~RenderSource()
@@ -269,6 +274,11 @@ uint RenderSource::texture() const
return session_->frame()->texture(); return session_->frame()->texture();
} }
void RenderSource::replaceRenderingShader()
{
sessionsurface_->replaceShader(renderingshader_);
}
void RenderSource::init() void RenderSource::init()
{ {
if (session_ == nullptr) if (session_ == nullptr)

View File

@@ -28,6 +28,7 @@ public:
protected: protected:
void init() override; void init() override;
void replaceRenderingShader() override;
static void loadSession(const std::string& filename, SessionSource *source); static void loadSession(const std::string& filename, SessionSource *source);
Surface *sessionsurface_; Surface *sessionsurface_;
@@ -55,6 +56,7 @@ public:
protected: protected:
void init() override; void init() override;
void replaceRenderingShader() override;
Surface *sessionsurface_; Surface *sessionsurface_;
Session *session_; Session *session_;
}; };

View File

@@ -121,13 +121,16 @@ Source::Source() : initialized_(false), active_(true), need_update_(true)
// those will be associated to nodes later // those will be associated to nodes later
blendingshader_ = new ImageShader; blendingshader_ = new ImageShader;
// rendershader_ = new ImageShader; processingshader_ = new ImageProcessingShader;
rendershader_ = new ImageProcessingShader; // default to image processing enabled
renderingshader_ = (Shader *) processingshader_;
renderbuffer_ = nullptr; renderbuffer_ = nullptr;
rendersurface_ = nullptr; rendersurface_ = nullptr;
} }
Source::~Source() Source::~Source()
{ {
// delete objects // delete objects
@@ -193,6 +196,31 @@ void Source::setMode(Source::Mode m)
mode_ = m; mode_ = m;
} }
void Source::setImageProcessingEnabled (bool on)
{
if ( on == imageProcessingEnabled() )
return;
// set pointer
if (on) {
processingshader_ = new ImageProcessingShader;
renderingshader_ = (Shader *) processingshader_;
} else {
processingshader_ = nullptr;
renderingshader_ = (Shader *) new ImageShader;
}
// apply to nodes in subclasses
replaceRenderingShader();
}
bool Source::imageProcessingEnabled()
{
return ( renderingshader_ == processingshader_ );
}
void Source::attach(FrameBuffer *renderbuffer) void Source::attach(FrameBuffer *renderbuffer)
{ {
renderbuffer_ = renderbuffer; renderbuffer_ = renderbuffer;
@@ -360,7 +388,7 @@ CloneSource *Source::clone()
CloneSource::CloneSource(Source *origin) : Source(), origin_(origin) CloneSource::CloneSource(Source *origin) : Source(), origin_(origin)
{ {
// create surface: // create surface:
clonesurface_ = new Surface(rendershader_); clonesurface_ = new Surface(renderingshader_);
} }
CloneSource::~CloneSource() CloneSource::~CloneSource()
@@ -378,6 +406,11 @@ CloneSource *CloneSource::clone()
return nullptr; return nullptr;
} }
void CloneSource::replaceRenderingShader()
{
clonesurface_->replaceShader(renderingshader_);
}
void CloneSource::init() void CloneSource::init()
{ {
if (origin_ && origin_->ready()) { if (origin_ && origin_->ready()) {

View File

@@ -62,9 +62,13 @@ public:
// tests if a given node is part of the source // tests if a given node is part of the source
bool contains (Node *node) const; bool contains (Node *node) const;
// a Source has a shader to control image processing effects // a Source has a shader used to render in fbo
// inline ImageShader *processingShader () const { return rendershader_; } inline Shader *renderingShader() const { return renderingshader_; }
inline ImageProcessingShader *processingShader () const { return rendershader_; }
// the rendering shader is either a simple or an image processing shader
inline ImageProcessingShader *processingShader () const { return processingshader_; }
void setImageProcessingEnabled (bool on);
bool imageProcessingEnabled();
// a Source has a shader to control mixing effects // a Source has a shader to control mixing effects
inline ImageShader *blendingShader () const { return blendingshader_; } inline ImageShader *blendingShader () const { return blendingshader_; }
@@ -137,9 +141,10 @@ protected:
// It is associated to the rendershader for mixing effects // It is associated to the rendershader for mixing effects
FrameBufferSurface *rendersurface_; FrameBufferSurface *rendersurface_;
// rendershader performs image processing // render and image processing shaders
// ImageShader *rendershader_; virtual void replaceRenderingShader() = 0;
ImageProcessingShader *rendershader_; Shader *renderingshader_;
ImageProcessingShader *processingshader_;
// blendingshader provides mixing controls // blendingshader provides mixing controls
ImageShader *blendingshader_; ImageShader *blendingshader_;
@@ -186,6 +191,7 @@ protected:
CloneSource(Source *origin); CloneSource(Source *origin);
void init() override; void init() override;
void replaceRenderingShader() override;
Surface *clonesurface_; Surface *clonesurface_;
Source *origin_; Source *origin_;
}; };