2018-03-20 11:45:41 +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-08-07 15:14:44 +00:00
|
|
|
#include <limits>
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <map>
|
2018-03-20 11:45:41 +00:00
|
|
|
#include <memory>
|
2019-08-07 15:14:44 +00:00
|
|
|
#include <random>
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "gfx-source-texture.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/gs/gs-effect.hpp"
|
|
|
|
#include "obs/gs/gs-mipmapper.hpp"
|
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
#include "obs/gs/gs-texture.hpp"
|
|
|
|
#include "obs/gs/gs-vertexbuffer.hpp"
|
2018-09-28 09:55:55 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
// OBS
|
2019-08-07 10:42:25 +00:00
|
|
|
extern "C" {
|
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 09:55:55 +00:00
|
|
|
#include <obs.h>
|
2019-08-07 10:42:25 +00:00
|
|
|
#include <util/platform.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
|
2019-08-07 10:42:25 +00:00
|
|
|
}
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
namespace gfx {
|
2019-08-07 10:42:25 +00:00
|
|
|
namespace effect_source {
|
2019-08-07 15:14:44 +00:00
|
|
|
enum class value_mode {
|
|
|
|
INPUT,
|
|
|
|
SLIDER,
|
|
|
|
};
|
|
|
|
enum class string_mode {
|
|
|
|
TEXT,
|
|
|
|
MULTILINE,
|
|
|
|
PASSWORD,
|
|
|
|
};
|
|
|
|
enum class texture_mode {
|
|
|
|
FILE,
|
|
|
|
SOURCE,
|
|
|
|
};
|
|
|
|
|
|
|
|
class parameter {
|
|
|
|
protected:
|
|
|
|
std::shared_ptr<gs::effect> _effect;
|
|
|
|
std::shared_ptr<gs::effect_parameter> _param;
|
|
|
|
|
|
|
|
std::string _name;
|
|
|
|
std::string _visible_name;
|
|
|
|
std::string _description;
|
|
|
|
std::string _formulae;
|
|
|
|
bool _visible;
|
|
|
|
|
|
|
|
public:
|
|
|
|
parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
virtual ~parameter();
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) = 0;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) = 0;
|
2018-04-29 01:04:29 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
virtual void update(obs_data_t* data) = 0;
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
virtual void tick(float_t time) = 0;
|
|
|
|
|
|
|
|
virtual void prepare() = 0;
|
|
|
|
|
|
|
|
virtual void assign() = 0;
|
|
|
|
|
|
|
|
std::shared_ptr<gs::effect_parameter> get_param();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<gfx::effect_source::parameter> create(std::shared_ptr<gs::effect> effect,
|
|
|
|
std::shared_ptr<gs::effect_parameter> param);
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
class bool_parameter : public parameter {
|
|
|
|
bool _value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool_parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual void tick(float_t time) override;
|
|
|
|
|
|
|
|
virtual void prepare() override;
|
|
|
|
|
|
|
|
virtual void assign() override;
|
2019-08-07 10:42:25 +00:00
|
|
|
};
|
2019-08-07 15:14:44 +00:00
|
|
|
|
|
|
|
class value_parameter : public parameter {
|
|
|
|
union {
|
|
|
|
float_t f[4];
|
|
|
|
int32_t i[4];
|
|
|
|
} _value;
|
2019-08-07 10:42:25 +00:00
|
|
|
union {
|
2019-08-07 15:14:44 +00:00
|
|
|
float_t f[4];
|
2019-08-07 10:42:25 +00:00
|
|
|
int32_t i[4];
|
2019-08-07 15:14:44 +00:00
|
|
|
} _minimum;
|
2019-08-07 10:42:25 +00:00
|
|
|
union {
|
2019-08-07 15:14:44 +00:00
|
|
|
float_t f[4];
|
2019-08-07 10:42:25 +00:00
|
|
|
int32_t i[4];
|
2019-08-07 15:14:44 +00:00
|
|
|
} _maximum;
|
2019-08-07 10:42:25 +00:00
|
|
|
union {
|
2019-08-07 15:14:44 +00:00
|
|
|
float_t f[4];
|
2019-08-07 10:42:25 +00:00
|
|
|
int32_t i[4];
|
2019-08-07 15:14:44 +00:00
|
|
|
} _step;
|
|
|
|
value_mode _mode = value_mode::INPUT;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
std::string name[4];
|
|
|
|
std::string visible_name[4];
|
|
|
|
} _cache;
|
|
|
|
|
|
|
|
public:
|
|
|
|
value_parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual void tick(float_t time) override;
|
|
|
|
|
|
|
|
virtual void prepare() override;
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
virtual void assign() override;
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
class matrix_parameter : public parameter {
|
|
|
|
matrix4 _value;
|
|
|
|
matrix4 _minimum;
|
|
|
|
matrix4 _maximum;
|
|
|
|
matrix4 _step;
|
|
|
|
value_mode _mode = value_mode::INPUT;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
std::string name[16];
|
|
|
|
std::string visible_name[16];
|
|
|
|
} _cache;
|
|
|
|
|
|
|
|
public:
|
|
|
|
matrix_parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual void tick(float_t time) override;
|
|
|
|
|
|
|
|
virtual void prepare() override;
|
|
|
|
|
|
|
|
virtual void assign() override;
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
class string_parameter : public parameter {
|
|
|
|
std::string _value;
|
|
|
|
string_mode _mode = string_mode::TEXT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
string_parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual void tick(float_t time) override;
|
|
|
|
|
|
|
|
virtual void prepare() override;
|
|
|
|
|
|
|
|
virtual void assign() override;
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
class texture_parameter : public parameter {
|
|
|
|
std::string _file_name;
|
|
|
|
std::shared_ptr<gs::texture> _file;
|
|
|
|
|
|
|
|
std::string _source_name;
|
|
|
|
std::shared_ptr<obs::source> _source;
|
|
|
|
std::shared_ptr<gfx::source_texture> _source_renderer;
|
|
|
|
|
|
|
|
texture_mode _mode = texture_mode::FILE;
|
|
|
|
|
|
|
|
public:
|
|
|
|
texture_parameter(std::shared_ptr<gs::effect> effect, std::shared_ptr<gs::effect_parameter> param);
|
|
|
|
|
|
|
|
virtual void properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void remove_properties(obs_properties_t* props) override;
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual void tick(float_t time) override;
|
|
|
|
|
|
|
|
virtual void prepare() override;
|
|
|
|
|
|
|
|
virtual void assign() override;
|
2019-08-07 10:42:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::pair<gs::effect_parameter::type, std::string> param_ident_t;
|
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
class effect_source {
|
2019-08-07 10:42:25 +00:00
|
|
|
std::string _file;
|
|
|
|
std::shared_ptr<gs::effect> _effect;
|
2019-08-07 15:14:44 +00:00
|
|
|
std::string _tech;
|
2019-08-07 10:42:25 +00:00
|
|
|
std::map<param_ident_t, std::shared_ptr<parameter>> _params;
|
|
|
|
|
|
|
|
std::shared_ptr<gs::vertex_buffer> _tri;
|
|
|
|
|
|
|
|
float_t _last_check;
|
|
|
|
size_t _last_size;
|
|
|
|
time_t _last_modify_time;
|
|
|
|
time_t _last_create_time;
|
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
float_t _time;
|
|
|
|
float_t _time_active;
|
|
|
|
float_t _time_since_last_tick;
|
|
|
|
|
|
|
|
std::uniform_real_distribution<float_t> _random_dist{0.f, 1.f};
|
|
|
|
std::default_random_engine _random_generator;
|
|
|
|
|
|
|
|
bool modified2(obs_properties_t* props, obs_property_t* property, obs_data_t* settings);
|
|
|
|
|
2019-08-07 10:42:25 +00:00
|
|
|
void load_file(std::string file);
|
|
|
|
|
|
|
|
public:
|
2019-08-07 15:14:44 +00:00
|
|
|
effect_source();
|
|
|
|
~effect_source();
|
|
|
|
|
|
|
|
void properties(obs_properties_t* props);
|
|
|
|
|
|
|
|
void update(obs_data_t* data);
|
2019-08-07 10:42:25 +00:00
|
|
|
|
|
|
|
void tick(float_t time);
|
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
void render();
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
} // namespace effect_source
|
2018-09-28 09:55:55 +00:00
|
|
|
} // namespace gfx
|