mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-28 06:13:01 +00:00
gfx-source-texture: Refactoring
This commit is contained in:
parent
d56f4f9eac
commit
999df5e6e5
2 changed files with 43 additions and 41 deletions
|
@ -19,57 +19,59 @@
|
|||
|
||||
gfx::source_texture::~source_texture()
|
||||
{
|
||||
obs_source_remove_active_child(target, source);
|
||||
if (source) {
|
||||
obs_source_release(source);
|
||||
source = nullptr;
|
||||
if (child) {
|
||||
if (parent) {
|
||||
obs_source_remove_active_child(parent, child);
|
||||
}
|
||||
obs_source_release(child);
|
||||
}
|
||||
m_rt = nullptr;
|
||||
}
|
||||
|
||||
gfx::source_texture::source_texture(obs_source_t* parent)
|
||||
gfx::source_texture::source_texture(obs_source_t* _parent)
|
||||
{
|
||||
m_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||
target = parent;
|
||||
render_target = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||
parent = _parent;
|
||||
}
|
||||
|
||||
gfx::source_texture::source_texture(const char* _name, obs_source_t* _parent) : source_texture(_parent)
|
||||
{
|
||||
child = obs_get_source_by_name(_name);
|
||||
if (!child) {
|
||||
throw std::invalid_argument("No such source.");
|
||||
}
|
||||
if (!obs_source_add_active_child(parent, child)) {
|
||||
throw std::runtime_error("Recursion is not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
gfx::source_texture::source_texture(std::string _name, obs_source_t* _parent) : source_texture(_name.c_str(), _parent)
|
||||
{}
|
||||
|
||||
gfx::source_texture::source_texture(obs_source_t* _source, obs_source_t* _parent) : source_texture(_parent)
|
||||
{
|
||||
child = _source;
|
||||
if (!child) {
|
||||
throw std::invalid_argument("No such source.");
|
||||
}
|
||||
if (!obs_source_add_active_child(parent, child)) {
|
||||
throw std::runtime_error("Recursion is not allowed.");
|
||||
}
|
||||
obs_source_addref(child);
|
||||
}
|
||||
|
||||
obs_source_t* gfx::source_texture::get_object()
|
||||
{
|
||||
return source;
|
||||
return child;
|
||||
}
|
||||
|
||||
obs_source_t* gfx::source_texture::get_parent()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
gfx::source_texture::source_texture(const char* name, obs_source_t* parent) : source_texture(parent)
|
||||
{
|
||||
source = obs_get_source_by_name(name);
|
||||
if (!source) {
|
||||
throw std::invalid_argument("No such source.");
|
||||
}
|
||||
if (!obs_source_add_active_child(target, source)) {
|
||||
throw std::runtime_error("Recursion is not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
gfx::source_texture::source_texture(std::string name, obs_source_t* parent) : source_texture(name.c_str(), parent) {}
|
||||
|
||||
gfx::source_texture::source_texture(obs_source_t* src, obs_source_t* parent) : source_texture(parent)
|
||||
{
|
||||
source = src;
|
||||
if (!source) {
|
||||
throw std::invalid_argument("No such source.");
|
||||
}
|
||||
if (!obs_source_add_active_child(target, source)) {
|
||||
throw std::runtime_error("Recursion is not allowed.");
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
std::shared_ptr<gs::texture> gfx::source_texture::render(size_t width, size_t height)
|
||||
{
|
||||
if (!source) {
|
||||
if (!child) {
|
||||
throw std::invalid_argument("Missing source to render.");
|
||||
}
|
||||
if ((width == 0) || (width >= 16384)) {
|
||||
|
@ -80,15 +82,15 @@ std::shared_ptr<gs::texture> gfx::source_texture::render(size_t width, size_t he
|
|||
}
|
||||
|
||||
{
|
||||
auto op = m_rt->render((uint32_t)width, (uint32_t)height);
|
||||
auto op = render_target->render((uint32_t)width, (uint32_t)height);
|
||||
vec4 black;
|
||||
vec4_zero(&black);
|
||||
gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1);
|
||||
gs_clear(GS_CLEAR_COLOR, &black, 0, 0);
|
||||
obs_source_video_render(source);
|
||||
obs_source_video_render(child);
|
||||
}
|
||||
|
||||
std::shared_ptr<gs::texture> tex;
|
||||
m_rt->get_texture(tex);
|
||||
render_target->get_texture(tex);
|
||||
return tex;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ extern "C" {
|
|||
|
||||
namespace gfx {
|
||||
class source_texture {
|
||||
obs_source_t* source;
|
||||
obs_source_t* target;
|
||||
obs_source_t* parent;
|
||||
obs_source_t* child;
|
||||
|
||||
std::shared_ptr<gs::rendertarget> m_rt;
|
||||
std::shared_ptr<gs::rendertarget> render_target;
|
||||
|
||||
source_texture(obs_source_t* parent);
|
||||
|
||||
|
|
Loading…
Reference in a new issue