2018-03-05 14:17:34 +00:00
|
|
|
// Modern effects for a modern Streamer
|
|
|
|
// Copyright (C) 2017 Michael Fabian Dirks
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
|
|
|
#pragma once
|
2019-12-21 16:43:12 +00:00
|
|
|
#include <map>
|
2018-03-05 14:17:34 +00:00
|
|
|
#include <memory>
|
2018-09-28 21:31:21 +00:00
|
|
|
#include <string>
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
#include "obs/gs/gs-texture.hpp"
|
|
|
|
#include "obs/obs-source.hpp"
|
2018-09-28 21:31:21 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
// OBS
|
2019-01-14 22:21:29 +00:00
|
|
|
#ifdef _MSC_VER
|
2019-01-14 10:23:21 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
2019-01-14 22:21:29 +00:00
|
|
|
#endif
|
2018-09-28 21:31:21 +00:00
|
|
|
#include <obs.h>
|
2019-01-14 22:21:29 +00:00
|
|
|
#ifdef _MSC_VER
|
2019-01-14 10:23:21 +00:00
|
|
|
#pragma warning(pop)
|
2019-01-14 22:21:29 +00:00
|
|
|
#endif
|
2018-03-05 14:17:34 +00:00
|
|
|
|
2018-03-08 10:28:23 +00:00
|
|
|
namespace gfx {
|
2018-03-20 11:50:17 +00:00
|
|
|
class source_texture {
|
2019-12-21 16:43:12 +00:00
|
|
|
std::shared_ptr<obs::deprecated_source> _parent;
|
|
|
|
std::shared_ptr<obs::deprecated_source> _child;
|
2018-09-28 21:31:21 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
std::shared_ptr<gs::rendertarget> _rt;
|
2018-03-05 14:17:34 +00:00
|
|
|
|
2018-04-24 11:48:42 +00:00
|
|
|
source_texture(obs_source_t* parent);
|
2018-09-28 21:31:21 +00:00
|
|
|
|
2018-03-05 14:17:34 +00:00
|
|
|
public:
|
2018-03-20 11:50:17 +00:00
|
|
|
~source_texture();
|
2018-11-07 13:09:03 +00:00
|
|
|
source_texture(obs_source_t* src, obs_source_t* parent);
|
2018-04-24 11:48:42 +00:00
|
|
|
source_texture(const char* name, obs_source_t* parent);
|
|
|
|
source_texture(std::string name, obs_source_t* parent);
|
2018-03-05 14:17:34 +00:00
|
|
|
|
2019-12-21 16:43:12 +00:00
|
|
|
source_texture(std::shared_ptr<obs::deprecated_source> child, std::shared_ptr<obs::deprecated_source> parent);
|
|
|
|
source_texture(std::shared_ptr<obs::deprecated_source> child, obs_source_t* parent);
|
2018-03-05 15:19:42 +00:00
|
|
|
|
2019-01-27 21:50:35 +00:00
|
|
|
public /*copy*/:
|
|
|
|
source_texture(source_texture const& other) = delete;
|
|
|
|
source_texture& operator=(source_texture const& other) = delete;
|
|
|
|
|
|
|
|
public /*move*/:
|
|
|
|
source_texture(source_texture&& other) = delete;
|
|
|
|
source_texture& operator=(source_texture&& other) = delete;
|
|
|
|
|
|
|
|
public:
|
2018-03-20 11:50:17 +00:00
|
|
|
std::shared_ptr<gs::texture> render(size_t width, size_t height);
|
2018-11-07 13:09:03 +00:00
|
|
|
|
|
|
|
public: // Unsafe Methods
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
obs_source_t* get_object();
|
|
|
|
obs_source_t* get_parent();
|
2018-03-05 14:17:34 +00:00
|
|
|
};
|
2019-12-21 16:43:12 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2018-09-28 21:31:21 +00:00
|
|
|
} // namespace gfx
|