BugFix Update linked sources and Texture view on Source change

When source change stream (e.g. change pattern), Texture view was not updated, and sources with mask texture were not adapted.
This commit is contained in:
Bruno Herbelin
2024-01-02 10:38:37 +01:00
parent b599fbf88d
commit 8924d81e0a
5 changed files with 90 additions and 62 deletions

View File

@@ -1471,6 +1471,8 @@ void ImGuiVisitor::visit (PatternSource& s)
std::ostringstream oss;
oss << s.name() << ": Pattern " << Pattern::get(p).label;
Action::manager().store(oss.str());
// ensure all sources are updated after the texture change of this one
Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); });
}
}
ImGui::EndCombo();
@@ -1527,6 +1529,8 @@ void ImGuiVisitor::visit (DeviceSource& s)
oss << s.name() << " Device " << namedev;
Action::manager().store(oss.str());
}
// ensure all sources are updated after the texture change of this one
Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); });
}
}
ImGui::EndCombo();
@@ -1594,6 +1598,8 @@ void ImGuiVisitor::visit (ScreenCaptureSource& s)
oss << s.name() << " Window " << namedev;
Action::manager().store(oss.str());
}
// ensure all sources are updated after the texture change of this one
Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); });
}
}
ImGui::EndCombo();
@@ -1778,11 +1784,7 @@ void ImGuiVisitor::visit (GenericStreamSource& s)
// Editor
std::string _description = s.description();
if ( ImGuiToolkit::InputCodeMultiline("Pipeline", &_description, fieldsize, &numlines) ) {
info.reset();
s.setDescription(_description);
Action::manager().store( s.name() + ": Change pipeline");
}
bool changed = ImGuiToolkit::InputCodeMultiline("Pipeline", &_description, fieldsize, &numlines);
ImVec2 botom = ImGui::GetCursorPos();
// Actions on the pipeline
@@ -1792,9 +1794,15 @@ void ImGuiVisitor::visit (GenericStreamSource& s)
ImGui::SetCursorPos( ImVec2(top.x + 0.9 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight()));
if (ImGuiToolkit::IconButton(ICON_FA_PASTE, "Paste")) {
_description = std::string ( ImGui::GetClipboardText() );
changed = true;
}
if (changed) {
info.reset();
s.setDescription(_description);
Action::manager().store( s.name() + ": Change pipeline");
// ensure all sources are updated after the texture change of this one
Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); });
}
if ( !s.failed() ) {

View File

@@ -1005,3 +1005,11 @@ void Session::applySnapshot(uint64_t key)
}
}
void Session::execute(void (*func)(Source *))
{
for (SourceList::const_iterator it = sources_.cbegin(); it != sources_.cend(); ++it) {
func(*it);
}
}

View File

@@ -72,19 +72,18 @@ public:
// management of list of sources
bool empty() const;
uint size() const;
SourceList getDepthSortedList () const;
SourceIdList getIdList() const;
std::list<std::string> getNameList(uint64_t exceptid=0) const;
SourceList::iterator begin ();
SourceList::iterator end ();
SourceList::iterator find (Source *s);
SourceList::iterator find (std::string name);
SourceList::iterator find (Node *node);
SourceList::iterator find (float depth_from, float depth_to);
SourceList getDepthSortedList () const;
SourceList::iterator find (uint64_t id);
SourceIdList getIdList() const;
std::list<std::string> getNameList(uint64_t exceptid=0) const;
// manage sources by #id (ordered index)
SourceList::iterator at (int index);
int index (SourceList::iterator it) const;
void move (int current_index, int target_index);
@@ -97,6 +96,8 @@ public:
void update (float dt);
uint64_t runtime() const;
void execute(void (*func)(Source *));
// update mode (active or not)
void setActive (bool on);
inline bool active () { return active_; }

View File

@@ -243,9 +243,10 @@ void TextureView::update(float dt)
View::update(dt);
// a more complete update is requested (e.g. after switching to view)
if (View::need_deep_update_ > 0 || edit_source_ != Mixer::manager().currentSource()) {
if (View::need_deep_update_ > 0 ||
(Mixer::manager().currentSource() != nullptr && edit_source_ != Mixer::manager().currentSource() )) {
// request update
need_edit_update_ = true;
// change grid color
const ImVec4 c = ImGuiToolkit::HighlightColor();
translation_grid_->setColor( glm::vec4(c.x, c.y, c.z, 0.3) );
@@ -505,8 +506,10 @@ std::pair<Node *, glm::vec2> TextureView::pick(glm::vec2 P)
return pick;
}
void TextureView::adjustBackground()
bool TextureView::adjustBackground()
{
bool ret = false;
// by default consider edit source is null
mask_node_->visible_ = false;
float image_original_width = 1.f;
@@ -515,7 +518,8 @@ void TextureView::adjustBackground()
preview_surface_->setTextureIndex( Resource::getTextureTransparent() );
// if its a valid index
if (edit_source_ != nullptr && edit_source_->ready()) {
if (edit_source_ != nullptr) {
if (edit_source_->ready()) {
// update rendering frame to match edit source AR
image_original_width = edit_source_->frame()->aspectRatio();
scale_crop_.x = (edit_source_->group(View::GEOMETRY)->crop_[1]
@@ -529,13 +533,14 @@ void TextureView::adjustBackground()
scale_crop_.x *= edit_source_->frame()->aspectRatio();
shift_crop_.x *= edit_source_->frame()->aspectRatio();
preview_surface_->setTextureIndex( edit_source_->frame()->texture() );
preview_surface_->setTextureIndex(edit_source_->frame()->texture());
preview_shader_->mask_texture = edit_source_->blendingShader()->mask_texture;
preview_surface_->scale_ = scale_crop_;
preview_surface_->translation_ = shift_crop_;
// mask appearance
mask_node_->visible_ = edit_source_->maskShader()->mode == MaskShader::SHAPE && mask_cursor_shape_ > 0;
mask_node_->visible_ = edit_source_->maskShader()->mode == MaskShader::SHAPE
&& mask_cursor_shape_ > 0;
int shape = edit_source_->maskShader()->shape;
mask_circle_->visible_ = shape == MaskShader::ELLIPSE;
@@ -544,23 +549,31 @@ void TextureView::adjustBackground()
mask_vertical_->visible_ = shape == MaskShader::VERTICAL;
// symetrical shapes
if ( shape < MaskShader::HORIZONTAL){
if (shape < MaskShader::HORIZONTAL) {
mask_node_->scale_ = scale_crop_ * glm::vec3(edit_source_->maskShader()->size, 1.f);
mask_node_->translation_ = glm::vec3(0.f);
}
// vertical
else if ( shape > MaskShader::HORIZONTAL ) {
else if (shape > MaskShader::HORIZONTAL) {
mask_node_->scale_ = glm::vec3(1.f, scale_crop_.y, 1.f);
mask_node_->translation_ = glm::vec3(edit_source_->maskShader()->size.x * scale_crop_.x, 0.f, 0.f);
mask_node_->translation_ = glm::vec3(edit_source_->maskShader()->size.x
* scale_crop_.x,
0.f,
0.f);
}
// horizontal
else {
mask_node_->scale_ = glm::vec3(scale_crop_.x, 1.f, 1.f);
mask_node_->translation_ = glm::vec3(0.f, edit_source_->maskShader()->size.y * scale_crop_.y, 0.f);
mask_node_->translation_ = glm::vec3(0.f,
edit_source_->maskShader()->size.y
* scale_crop_.y,
0.f);
}
mask_node_->translation_ += shift_crop_;
}
else
ret = true;
}
// background scene
@@ -576,6 +589,7 @@ void TextureView::adjustBackground()
static glm::mat4 Tra = glm::scale(glm::translate(glm::identity<glm::mat4>(), glm::vec3( -32.f, -32.f, 0.f)), glm::vec3( 64.f, 64.f, 1.f));
preview_checker_->shader()->iTransform = Ar * Tra;
return ret;
}
Source *TextureView::getEditOrCurrentSource()
@@ -607,16 +621,14 @@ Source *TextureView::getEditOrCurrentSource()
void TextureView::draw()
{
// edit view needs to be updated (source changed)
if ( need_edit_update_ )
{
need_edit_update_ = false;
if (need_edit_update_) {
// now, follow the change of current source
// & remember source to edit
edit_source_ = getEditOrCurrentSource();
// update background and frame to match editsource
adjustBackground();
// & return true if still needs to edit update
need_edit_update_ = adjustBackground();
}
// Display grid
@@ -1121,9 +1133,8 @@ View::Cursor TextureView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pa
edit_source_->maskShader()->size.x = val.x;
else
edit_source_->maskShader()->size = glm::max(glm::abs(glm::vec2(val)), glm::vec2(0.2));
// edit_source_->maskShader()->size = glm::max( glm::min( glm::vec2(val), glm::vec2(2.f)), glm::vec2(hv?-2.f:0.2f));
edit_source_->touch(Source::SourceUpdate_Mask);
// update
edit_source_->touch(Source::SourceUpdate_Mask);
need_edit_update_ = true;
// action label
info << "Texture Mask " << std::fixed << std::setprecision(3) << edit_source_->maskShader()->size.x;

View File

@@ -33,7 +33,7 @@ private:
Source *edit_source_;
bool need_edit_update_;
Source *getEditOrCurrentSource();
void adjustBackground();
bool adjustBackground();
glm::vec3 scale_crop_;
glm::vec3 shift_crop_;