mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +00:00
gfx/source-texture: Update to new classes
This commit is contained in:
parent
fc693e0210
commit
b108362ee1
5 changed files with 39 additions and 134 deletions
|
@ -377,7 +377,8 @@ void blur_instance::video_tick(float)
|
|||
} else if (_mask.type == mask_type::Source) {
|
||||
if (_mask.source.name_old != _mask.source.name) {
|
||||
try {
|
||||
_mask.source.source_texture = std::make_shared<streamfx::gfx::source_texture>(_mask.source.name, _self);
|
||||
_mask.source.source_texture = std::make_shared<streamfx::gfx::source_texture>(
|
||||
::streamfx::obs::weak_source(_mask.source.name), ::streamfx::obs::weak_source(_self));
|
||||
_mask.source.is_scene = (obs_scene_from_source(_mask.source.source_texture->get_object()) != nullptr);
|
||||
_mask.source.name_old = _mask.source.name;
|
||||
} catch (...) {
|
||||
|
|
|
@ -169,7 +169,7 @@ void dynamic_mask_instance::update(obs_data_t* settings)
|
|||
void dynamic_mask_instance::save(obs_data_t* settings)
|
||||
{
|
||||
if (_input) {
|
||||
obs_data_set_string(settings, ST_KEY_INPUT, obs_source_get_name(_input->get()));
|
||||
obs_data_set_string(settings, ST_KEY_INPUT, _input.lock().name().data());
|
||||
}
|
||||
|
||||
for (auto kv1 : channel_translations) {
|
||||
|
@ -197,13 +197,6 @@ void dynamic_mask_instance::save(obs_data_t* settings)
|
|||
}
|
||||
}
|
||||
|
||||
void dynamic_mask_instance::input_renamed(obs::deprecated_source*, std::string old_name, std::string new_name)
|
||||
{
|
||||
obs_data_t* settings = obs_source_get_settings(_self);
|
||||
obs_data_set_string(settings, ST_KEY_INPUT, new_name.c_str());
|
||||
obs_source_update(_self, settings);
|
||||
}
|
||||
|
||||
void dynamic_mask_instance::video_tick(float)
|
||||
{
|
||||
_have_input_texture = false;
|
||||
|
@ -217,11 +210,12 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect)
|
|||
obs_source_t* target = obs_filter_get_target(_self);
|
||||
uint32_t width = obs_source_get_base_width(target);
|
||||
uint32_t height = obs_source_get_base_height(target);
|
||||
auto input = _input.lock();
|
||||
|
||||
if (!_self || !parent || !target || !width || !height || !_input || !_input_capture || !_effect) {
|
||||
obs_source_skip_video_filter(_self);
|
||||
return;
|
||||
} else if (!_input->width() || !_input->height()) {
|
||||
} else if (!input.width() || !input.height()) {
|
||||
obs_source_skip_video_filter(_self);
|
||||
return;
|
||||
}
|
||||
|
@ -276,7 +270,7 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect)
|
|||
obs_source_get_name(_input_capture->get_object())};
|
||||
#endif
|
||||
|
||||
_input_texture = _input_capture->render(_input->width(), _input->height());
|
||||
_input_texture = _input_capture->render(input.width(), input.height());
|
||||
_have_input_texture = true;
|
||||
}
|
||||
|
||||
|
@ -371,13 +365,13 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect)
|
|||
void dynamic_mask_instance::enum_active_sources(obs_source_enum_proc_t enum_callback, void* param)
|
||||
{
|
||||
if (_input)
|
||||
enum_callback(_self, _input->get(), param);
|
||||
enum_callback(_self, _input.lock().get(), param);
|
||||
}
|
||||
|
||||
void dynamic_mask_instance::enum_all_sources(obs_source_enum_proc_t enum_callback, void* param)
|
||||
{
|
||||
if (_input)
|
||||
enum_callback(_self, _input->get(), param);
|
||||
enum_callback(_self, _input.lock().get(), param);
|
||||
}
|
||||
|
||||
void streamfx::filter::dynamic_mask::dynamic_mask_instance::show()
|
||||
|
@ -385,7 +379,7 @@ void streamfx::filter::dynamic_mask::dynamic_mask_instance::show()
|
|||
if (!_input || !obs_source_showing(obs_filter_get_parent(_self)))
|
||||
return;
|
||||
|
||||
_input_vs = std::make_shared<obs::tools::visible_source>(_input->get());
|
||||
_input_vs = std::make_shared<obs::tools::visible_source>(_input.lock().get());
|
||||
}
|
||||
|
||||
void streamfx::filter::dynamic_mask::dynamic_mask_instance::hide()
|
||||
|
@ -398,7 +392,7 @@ void streamfx::filter::dynamic_mask::dynamic_mask_instance::activate()
|
|||
if (!_input || !obs_source_active(obs_filter_get_parent(_self)))
|
||||
return;
|
||||
|
||||
_input_ac = std::make_shared<obs::tools::active_source>(_input->get());
|
||||
_input_ac = std::make_shared<obs::tools::active_source>(_input.lock().get());
|
||||
}
|
||||
|
||||
void streamfx::filter::dynamic_mask::dynamic_mask_instance::deactivate()
|
||||
|
@ -414,15 +408,11 @@ try {
|
|||
}
|
||||
|
||||
// Acquire a reference to the actual source.
|
||||
auto input = std::make_shared<obs::deprecated_source>(std::string(name), true, true);
|
||||
::streamfx::obs::source input = name;
|
||||
|
||||
// Acquire a texture renderer for the source, with the parent source as the parent.
|
||||
auto capture = std::make_shared<streamfx::gfx::source_texture>(input, obs_filter_get_parent(_self));
|
||||
|
||||
// Listed to the rename event.
|
||||
input->events.rename += std::bind(&dynamic_mask_instance::input_renamed, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
// Update our local storage.
|
||||
_input = input;
|
||||
_input_capture = capture;
|
||||
|
@ -442,7 +432,7 @@ try {
|
|||
|
||||
void dynamic_mask_instance::release()
|
||||
{
|
||||
_input.reset();
|
||||
_input = {};
|
||||
_input_capture.reset();
|
||||
|
||||
deactivate();
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace streamfx::filter::dynamic_mask {
|
|||
std::shared_ptr<streamfx::obs::gs::texture> _filter_texture;
|
||||
|
||||
bool _have_input_texture;
|
||||
std::shared_ptr<obs::deprecated_source> _input;
|
||||
::streamfx::obs::weak_source _input;
|
||||
std::shared_ptr<streamfx::gfx::source_texture> _input_capture;
|
||||
std::shared_ptr<streamfx::obs::gs::texture> _input_texture;
|
||||
std::shared_ptr<obs::tools::visible_source> _input_vs;
|
||||
|
@ -73,8 +73,6 @@ namespace streamfx::filter::dynamic_mask {
|
|||
virtual void update(obs_data_t* settings) override;
|
||||
virtual void save(obs_data_t* settings) override;
|
||||
|
||||
void input_renamed(obs::deprecated_source* src, std::string old_name, std::string new_name);
|
||||
|
||||
virtual void video_tick(float_t _time) override;
|
||||
virtual void video_render(gs_effect_t* effect) override;
|
||||
|
||||
|
|
|
@ -18,94 +18,52 @@
|
|||
#include "gfx-source-texture.hpp"
|
||||
#include <stdexcept>
|
||||
#include "obs/gs/gs-helper.hpp"
|
||||
#include "obs/obs-tools.hpp"
|
||||
|
||||
streamfx::gfx::source_texture::~source_texture()
|
||||
{
|
||||
if (_child && _parent) {
|
||||
obs_source_remove_active_child(_parent->get(), _child->get());
|
||||
obs_source_remove_active_child(_parent.get(), _child.get());
|
||||
}
|
||||
|
||||
_parent.reset();
|
||||
_child.reset();
|
||||
}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(obs_source_t* parent)
|
||||
streamfx::gfx::source_texture::source_texture(streamfx::obs::weak_source child, streamfx::obs::weak_source parent)
|
||||
: _child(child.lock()), _parent(parent.lock())
|
||||
{
|
||||
if (!parent) {
|
||||
throw std::invalid_argument("_parent must not be null");
|
||||
// Verify that 'child' and 'parent' exist.
|
||||
if (!_child || !_parent) {
|
||||
throw std::invalid_argument("Child or Parent does not exist.");
|
||||
}
|
||||
_parent = std::make_shared<streamfx::obs::deprecated_source>(parent, false, false);
|
||||
_rt = std::make_shared<streamfx::obs::gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||
|
||||
// Verify that 'child' does not contain 'parent'.
|
||||
if (::streamfx::obs::tools::source_find_source(_child, _parent)) {
|
||||
throw std::runtime_error("Child contains Parent");
|
||||
} else if (!obs_source_add_active_child(_parent.get(), _child.get())) {
|
||||
throw std::runtime_error("Child contains Parent");
|
||||
}
|
||||
|
||||
_rt = std::make_shared<streamfx::obs::gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||
}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(obs_source_t* _source, obs_source_t* _parent) : source_texture(_parent)
|
||||
{
|
||||
if (!_source) {
|
||||
throw std::invalid_argument("source must not be null");
|
||||
}
|
||||
if (!obs_source_add_active_child(_parent, _source)) {
|
||||
throw std::runtime_error("_parent is contained in _child");
|
||||
}
|
||||
_child = std::make_shared<streamfx::obs::deprecated_source>(_source, true, true);
|
||||
}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(const char* _name, obs_source_t* _parent) : source_texture(_parent)
|
||||
{
|
||||
if (!_name) {
|
||||
throw std::invalid_argument("name must not be null");
|
||||
}
|
||||
_child = std::make_shared<streamfx::obs::deprecated_source>(_name, true, true);
|
||||
if (!obs_source_add_active_child(_parent, _child->get())) {
|
||||
throw std::runtime_error("_parent is contained in _child");
|
||||
}
|
||||
}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(std::string _name, obs_source_t* _parent)
|
||||
: source_texture(_name.c_str(), _parent)
|
||||
{}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(std::shared_ptr<streamfx::obs::deprecated_source> pchild,
|
||||
std::shared_ptr<streamfx::obs::deprecated_source> pparent)
|
||||
{
|
||||
if (!pchild) {
|
||||
throw std::invalid_argument("_child must not be null");
|
||||
}
|
||||
if (!pparent) {
|
||||
throw std::invalid_argument("_parent must not be null");
|
||||
}
|
||||
if (!obs_source_add_active_child(pparent->get(), pchild->get())) {
|
||||
throw std::runtime_error("_parent is contained in _child");
|
||||
}
|
||||
this->_child = pchild;
|
||||
this->_parent = pparent;
|
||||
this->_rt = std::make_shared<streamfx::obs::gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||
}
|
||||
|
||||
streamfx::gfx::source_texture::source_texture(std::shared_ptr<streamfx::obs::deprecated_source> _child,
|
||||
obs_source_t* _parent)
|
||||
: source_texture(_child, std::make_shared<streamfx::obs::deprecated_source>(_parent, false, false))
|
||||
{}
|
||||
|
||||
obs_source_t* streamfx::gfx::source_texture::get_object()
|
||||
{
|
||||
if (_child) {
|
||||
return _child->get();
|
||||
return _child.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obs_source_t* streamfx::gfx::source_texture::get_parent()
|
||||
{
|
||||
return _parent->get();
|
||||
return _parent.get();
|
||||
}
|
||||
|
||||
void streamfx::gfx::source_texture::clear()
|
||||
{
|
||||
if (_child && _parent) {
|
||||
obs_source_remove_active_child(_parent->get(), _child->get());
|
||||
obs_source_remove_active_child(_parent.get(), _child.get());
|
||||
}
|
||||
_child->clear();
|
||||
_child.reset();
|
||||
_child = {};
|
||||
}
|
||||
|
||||
std::shared_ptr<streamfx::obs::gs::texture> streamfx::gfx::source_texture::render(std::size_t width, std::size_t height)
|
||||
|
@ -116,7 +74,7 @@ std::shared_ptr<streamfx::obs::gs::texture> streamfx::gfx::source_texture::rende
|
|||
if ((height == 0) || (height >= 16384)) {
|
||||
throw std::runtime_error("Height too large or too small.");
|
||||
}
|
||||
if (_child->destroyed() || _parent->destroyed()) {
|
||||
if (!_child || !_parent) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -130,7 +88,7 @@ std::shared_ptr<streamfx::obs::gs::texture> streamfx::gfx::source_texture::rende
|
|||
vec4_zero(&black);
|
||||
gs_ortho(0, static_cast<float>(width), 0, static_cast<float_t>(height), 0, 1);
|
||||
gs_clear(GS_CLEAR_COLOR, &black, 0, 0);
|
||||
obs_source_video_render(_child->get());
|
||||
obs_source_video_render(_child.get());
|
||||
}
|
||||
|
||||
std::shared_ptr<streamfx::obs::gs::texture> tex;
|
||||
|
|
|
@ -20,26 +20,18 @@
|
|||
#include <map>
|
||||
#include "obs/gs/gs-rendertarget.hpp"
|
||||
#include "obs/gs/gs-texture.hpp"
|
||||
#include "obs/obs-source.hpp"
|
||||
#include "obs/obs-weak-source.hpp"
|
||||
|
||||
namespace streamfx::gfx {
|
||||
class source_texture {
|
||||
std::shared_ptr<streamfx::obs::deprecated_source> _parent;
|
||||
std::shared_ptr<streamfx::obs::deprecated_source> _child;
|
||||
streamfx::obs::source _parent;
|
||||
streamfx::obs::source _child;
|
||||
|
||||
std::shared_ptr<streamfx::obs::gs::rendertarget> _rt;
|
||||
|
||||
source_texture(obs_source_t* parent);
|
||||
|
||||
public:
|
||||
~source_texture();
|
||||
source_texture(obs_source_t* src, obs_source_t* parent);
|
||||
source_texture(const char* name, obs_source_t* parent);
|
||||
source_texture(std::string name, obs_source_t* parent);
|
||||
|
||||
source_texture(std::shared_ptr<streamfx::obs::deprecated_source> child,
|
||||
std::shared_ptr<streamfx::obs::deprecated_source> parent);
|
||||
source_texture(std::shared_ptr<streamfx::obs::deprecated_source> child, obs_source_t* parent);
|
||||
source_texture(streamfx::obs::weak_source child, streamfx::obs::weak_source parent);
|
||||
|
||||
public /*copy*/:
|
||||
source_texture(source_texture const& other) = delete;
|
||||
|
@ -58,38 +50,4 @@ namespace streamfx::gfx {
|
|||
obs_source_t* get_object();
|
||||
obs_source_t* get_parent();
|
||||
};
|
||||
|
||||
class source_texture_factory {
|
||||
friend class source_texture;
|
||||
|
||||
std::map<std::shared_ptr<obs_weak_source_t>, std::weak_ptr<source_texture>> _cache;
|
||||
|
||||
public:
|
||||
source_texture_factory();
|
||||
~source_texture_factory();
|
||||
|
||||
std::shared_ptr<source_texture> get_source_texture(std::shared_ptr<obs_source_t> source);
|
||||
|
||||
protected:
|
||||
void free_source_texture(std::shared_ptr<obs_source_t> source);
|
||||
|
||||
private: // Singleton
|
||||
static std::shared_ptr<source_texture_factory> factory_instance;
|
||||
|
||||
public: // Singleton
|
||||
static void initialize()
|
||||
{
|
||||
factory_instance = std::make_shared<source_texture_factory>();
|
||||
}
|
||||
|
||||
static void finalize()
|
||||
{
|
||||
factory_instance.reset();
|
||||
}
|
||||
|
||||
static std::shared_ptr<source_texture_factory> get()
|
||||
{
|
||||
return factory_instance;
|
||||
}
|
||||
};
|
||||
} // namespace streamfx::gfx
|
||||
|
|
Loading…
Reference in a new issue