From 1c072d67cb605237d23933ae83351957684313c0 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Fri, 15 Feb 2019 13:52:44 +0100 Subject: [PATCH] filter-transform: Validate source size each tick Rendering happens with cached Geometry that is only updated when necessary, such as when the user changes settings. This optimization was necessary to reduce CPU and GPU usage as we can simply re-use the same geomtry instead of recalculating it. However, the actual source size was never checked. That meant that when a source changed size through any means, the filter would not update the geomtry accordingly, and the result was a squished or stretched image. With this, the source size is now checked each tick. Fixes #48 --- source/filters/filter-transform.cpp | 29 ++++++++++++++++++++--------- source/filters/filter-transform.hpp | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 42b36f3..cfab01a 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -399,18 +399,29 @@ void filter::transform::transform_instance::deactivate() void filter::transform::transform_instance::video_tick(float) { + uint32_t width = 0; + uint32_t height = 0; + + // Grab parent and target. + obs_source_t* target = obs_filter_get_target(m_self); + if (target) { + // Grab width an height of the target source (child filter or source). + width = obs_source_get_base_width(target); + height = obs_source_get_base_height(target); + } + + // If size mismatch, force an update. + if (width != m_source_size.first) { + m_update_mesh = true; + } else if (height != m_source_size.second) { + m_update_mesh = true; + } + // Update Mesh if (m_update_mesh) { - uint32_t width = 0; - uint32_t height = 0; + m_source_size.first = width; + m_source_size.second = height; - // Grab parent and target. - obs_source_t* target = obs_filter_get_target(m_self); - if (target) { - // Grab width an height of the target source (child filter or source). - width = obs_source_get_base_width(target); - height = obs_source_get_base_height(target); - } if (width == 0) { width = 1; } diff --git a/source/filters/filter-transform.hpp b/source/filters/filter-transform.hpp index b528778..510bb69 100644 --- a/source/filters/filter-transform.hpp +++ b/source/filters/filter-transform.hpp @@ -68,6 +68,7 @@ namespace filter { std::shared_ptr m_source_rendertarget; std::shared_ptr m_source_texture; bool m_source_rendered; + std::pair m_source_size; // Mipmapping bool m_mipmap_enabled;