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
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2019-12-18 05:37:47 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <list>
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <map>
|
2019-08-07 15:14:44 +00:00
|
|
|
#include <random>
|
2019-12-18 05:37:47 +00:00
|
|
|
#include "gfx/shader/gfx-shader-param.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/gs/gs-effect.hpp"
|
2018-09-28 09:55:55 +00:00
|
|
|
|
2018-03-20 11:45:41 +00:00
|
|
|
namespace gfx {
|
2019-12-18 05:37:47 +00:00
|
|
|
namespace shader {
|
|
|
|
enum class size_type {
|
|
|
|
Pixel,
|
|
|
|
Percent,
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
enum class shader_mode {
|
|
|
|
Source,
|
|
|
|
Filter,
|
|
|
|
Transition,
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-12-25 18:18:44 +00:00
|
|
|
typedef std::map<std::string, std::shared_ptr<parameter>> shader_param_map_t;
|
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
class shader {
|
|
|
|
obs_source_t* _self;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Inputs
|
2020-03-28 21:17:33 +00:00
|
|
|
shader_mode _mode;
|
|
|
|
uint32_t _base_width;
|
|
|
|
uint32_t _base_height;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Shader
|
2019-12-25 18:18:44 +00:00
|
|
|
gs::effect _shader;
|
|
|
|
std::filesystem::path _shader_file;
|
|
|
|
std::string _shader_tech;
|
|
|
|
std::filesystem::file_time_type _shader_file_mt;
|
|
|
|
uintmax_t _shader_file_sz;
|
|
|
|
float_t _shader_file_tick;
|
|
|
|
shader_param_map_t _shader_params;
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Options
|
|
|
|
size_type _width_type;
|
|
|
|
double_t _width_value;
|
|
|
|
size_type _height_type;
|
|
|
|
double_t _height_value;
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
// Cache
|
2019-12-21 17:23:26 +00:00
|
|
|
float_t _time;
|
2020-03-28 21:17:33 +00:00
|
|
|
float_t _time_loop;
|
|
|
|
int32_t _loops;
|
2019-12-21 17:23:26 +00:00
|
|
|
std::mt19937_64 _random;
|
2019-12-22 05:14:26 +00:00
|
|
|
bool _have_current_params;
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2019-08-07 15:14:44 +00:00
|
|
|
public:
|
2019-12-18 05:37:47 +00:00
|
|
|
shader(obs_source_t* self, shader_mode mode);
|
|
|
|
~shader();
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool is_shader_different(const std::filesystem::path& file);
|
2019-08-07 18:39:55 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool is_technique_different(const std::string& tech);
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool load_shader(const std::filesystem::path& file, const std::string& tech, bool& shader_dirty,
|
|
|
|
bool& param_dirty);
|
2019-12-21 17:23:26 +00:00
|
|
|
|
2020-03-31 20:34:22 +00:00
|
|
|
static void defaults(obs_data_t* data);
|
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
void properties(obs_properties_t* props);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool on_properties_modified(obs_properties_t* props, obs_property_t* prop, obs_data_t* data);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-22 05:14:26 +00:00
|
|
|
bool update_shader(obs_data_t* data, bool& shader_dirty, bool& param_dirty);
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
void update(obs_data_t* data);
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
uint32_t width();
|
2019-08-07 15:14:44 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
uint32_t height();
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2019-08-07 16:42:54 +00:00
|
|
|
bool tick(float_t time);
|
2019-08-07 10:42:25 +00:00
|
|
|
|
2020-03-28 17:37:00 +00:00
|
|
|
void prepare_render();
|
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
void render();
|
2019-08-07 15:37:34 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
public:
|
|
|
|
void set_size(uint32_t w, uint32_t h);
|
2019-08-07 18:21:57 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
void set_input_a(std::shared_ptr<gs::texture> tex);
|
2019-08-07 18:39:55 +00:00
|
|
|
|
2019-12-18 05:37:47 +00:00
|
|
|
void set_input_b(std::shared_ptr<gs::texture> tex);
|
2020-03-28 17:37:00 +00:00
|
|
|
|
|
|
|
void set_transition_time(float_t t);
|
|
|
|
|
|
|
|
void set_transition_size(uint32_t w, uint32_t h);
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
2019-12-18 05:37:47 +00:00
|
|
|
} // namespace shader
|
2018-09-28 09:55:55 +00:00
|
|
|
} // namespace gfx
|