mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-10 22:05:06 +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()
|
gfx::source_texture::~source_texture()
|
||||||
{
|
{
|
||||||
obs_source_remove_active_child(target, source);
|
if (child) {
|
||||||
if (source) {
|
if (parent) {
|
||||||
obs_source_release(source);
|
obs_source_remove_active_child(parent, child);
|
||||||
source = nullptr;
|
}
|
||||||
|
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);
|
render_target = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
||||||
target = parent;
|
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()
|
obs_source_t* gfx::source_texture::get_object()
|
||||||
{
|
{
|
||||||
return source;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_source_t* gfx::source_texture::get_parent()
|
obs_source_t* gfx::source_texture::get_parent()
|
||||||
{
|
{
|
||||||
return target;
|
return parent;
|
||||||
}
|
|
||||||
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<gs::texture> gfx::source_texture::render(size_t width, size_t height)
|
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.");
|
throw std::invalid_argument("Missing source to render.");
|
||||||
}
|
}
|
||||||
if ((width == 0) || (width >= 16384)) {
|
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 black;
|
||||||
vec4_zero(&black);
|
vec4_zero(&black);
|
||||||
gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1);
|
gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1);
|
||||||
gs_clear(GS_CLEAR_COLOR, &black, 0, 0);
|
gs_clear(GS_CLEAR_COLOR, &black, 0, 0);
|
||||||
obs_source_video_render(source);
|
obs_source_video_render(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<gs::texture> tex;
|
std::shared_ptr<gs::texture> tex;
|
||||||
m_rt->get_texture(tex);
|
render_target->get_texture(tex);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@ extern "C" {
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class source_texture {
|
class source_texture {
|
||||||
obs_source_t* source;
|
obs_source_t* parent;
|
||||||
obs_source_t* target;
|
obs_source_t* child;
|
||||||
|
|
||||||
std::shared_ptr<gs::rendertarget> m_rt;
|
std::shared_ptr<gs::rendertarget> render_target;
|
||||||
|
|
||||||
source_texture(obs_source_t* parent);
|
source_texture(obs_source_t* parent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue