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
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <map>
|
2018-03-20 11:45:41 +00:00
|
|
|
#include <memory>
|
2018-09-28 09:55:55 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include "gfx-source-texture.h"
|
2018-03-20 11:45:41 +00:00
|
|
|
#include "gs-effect.h"
|
2018-09-28 09:55:55 +00:00
|
|
|
#include "gs-mipmapper.h"
|
2018-03-20 11:45:41 +00:00
|
|
|
#include "gs-rendertarget.h"
|
|
|
|
#include "gs-texture.h"
|
2018-04-29 01:04:29 +00:00
|
|
|
#include "gs-vertexbuffer.h"
|
2018-09-28 09:55:55 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <obs.h>
|
|
|
|
}
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
// Data Defines
|
2018-09-28 09:55:55 +00:00
|
|
|
#define D_TYPE "CustomShader.Type"
|
|
|
|
#define D_INPUT_TEXT "CustomShader.Input.Text"
|
|
|
|
#define D_INPUT_FILE "CustomShader.Input.File"
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
// Translation Defines
|
2018-09-28 09:55:55 +00:00
|
|
|
#define T_TYPE "CustomShader.Type"
|
|
|
|
#define T_TYPE_TEXT "CustomShader.Type.Text"
|
|
|
|
#define T_TYPE_FILE "CustomShader.Type.File"
|
|
|
|
#define T_INPUT_TEXT "CustomShader.Input.Text"
|
|
|
|
#define T_INPUT_FILE "CustomShader.Input.File"
|
|
|
|
#define T_TEXTURE_TYPE "CustomShader.Texture.Type"
|
|
|
|
#define T_TEXTURE_TYPE_FILE "CustomShader.Texture.Type.File"
|
|
|
|
#define T_TEXTURE_TYPE_SOURCE "CustomShader.Texture.Type.Source"
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
namespace gfx {
|
2018-03-20 11:50:17 +00:00
|
|
|
class effect_source {
|
2018-04-29 01:04:29 +00:00
|
|
|
public:
|
2018-04-09 11:27:22 +00:00
|
|
|
struct parameter {
|
2018-09-28 09:55:55 +00:00
|
|
|
std::string name = "";
|
2018-04-09 11:27:22 +00:00
|
|
|
std::shared_ptr<gs::effect_parameter> param;
|
2018-04-29 01:04:29 +00:00
|
|
|
|
2018-04-09 11:27:22 +00:00
|
|
|
struct {
|
2018-09-28 09:55:55 +00:00
|
|
|
std::vector<char> buffer;
|
2018-04-09 11:27:22 +00:00
|
|
|
std::vector<const char*> names;
|
|
|
|
std::vector<const char*> descs;
|
|
|
|
} ui;
|
|
|
|
};
|
|
|
|
struct bool_parameter : parameter {
|
|
|
|
bool value = false;
|
|
|
|
};
|
|
|
|
struct int_parameter : parameter {
|
2018-09-28 09:55:55 +00:00
|
|
|
int32_t value[4] = {0, 0, 0, 0};
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
|
|
|
struct float_parameter : parameter {
|
2018-09-28 09:55:55 +00:00
|
|
|
float_t value[4] = {0, 0, 0, 0};
|
2018-04-09 11:27:22 +00:00
|
|
|
};
|
|
|
|
struct texture_parameter : parameter {
|
|
|
|
bool isSource = false;
|
|
|
|
|
|
|
|
struct {
|
2018-09-28 09:55:55 +00:00
|
|
|
std::string path = "";
|
2018-04-09 11:27:22 +00:00
|
|
|
std::shared_ptr<gs::texture> tex;
|
|
|
|
struct {
|
2018-09-28 09:55:55 +00:00
|
|
|
float_t time_updated = 0;
|
|
|
|
time_t time_create = 0;
|
|
|
|
time_t time_modified = 0;
|
|
|
|
size_t file_size = 0;
|
|
|
|
bool modified = true;
|
2018-04-09 11:27:22 +00:00
|
|
|
} info;
|
|
|
|
} file;
|
|
|
|
struct {
|
2018-09-28 09:55:55 +00:00
|
|
|
std::string name = "";
|
2018-04-09 11:27:22 +00:00
|
|
|
std::shared_ptr<gfx::source_texture> tex;
|
2018-09-28 09:55:55 +00:00
|
|
|
std::shared_ptr<gs::texture> final_tex;
|
|
|
|
gs::mipmapper mipmapper;
|
2018-04-09 11:27:22 +00:00
|
|
|
} source;
|
|
|
|
|
|
|
|
struct {
|
2018-09-28 09:55:55 +00:00
|
|
|
bool doResample = false;
|
|
|
|
std::pair<uint32_t, uint32_t> resolution = {10, 10};
|
2018-04-09 11:27:22 +00:00
|
|
|
std::shared_ptr<gs::rendertarget> rt;
|
|
|
|
} resample;
|
|
|
|
};
|
2018-09-28 09:55:55 +00:00
|
|
|
struct matrix_parameter : parameter {};
|
2018-04-09 11:27:22 +00:00
|
|
|
typedef std::pair<std::string, gs::effect_parameter::type> paramident_t;
|
2018-04-29 01:04:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
2018-09-28 09:55:55 +00:00
|
|
|
obs_source_t* m_source;
|
2018-04-29 01:04:29 +00:00
|
|
|
std::shared_ptr<gs::vertex_buffer> m_quadBuffer;
|
|
|
|
|
|
|
|
// Effect Information
|
|
|
|
struct {
|
|
|
|
std::shared_ptr<gs::effect> effect;
|
2018-09-28 09:55:55 +00:00
|
|
|
std::string text;
|
|
|
|
std::string path;
|
2018-04-29 01:04:29 +00:00
|
|
|
struct {
|
|
|
|
float_t time_updated;
|
2018-09-28 09:55:55 +00:00
|
|
|
time_t time_create;
|
|
|
|
time_t time_modified;
|
|
|
|
size_t file_size;
|
|
|
|
bool modified;
|
2018-04-29 01:04:29 +00:00
|
|
|
} file_info;
|
|
|
|
} m_shader;
|
|
|
|
std::map<paramident_t, std::shared_ptr<parameter>> m_parameters;
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
// Status
|
2018-04-29 01:04:29 +00:00
|
|
|
float_t m_timeExisting;
|
|
|
|
float_t m_timeActive;
|
2018-03-20 11:45:41 +00:00
|
|
|
|
2018-04-29 01:04:29 +00:00
|
|
|
std::string m_defaultShaderPath = "shaders/";
|
2018-04-09 11:27:22 +00:00
|
|
|
|
2018-03-20 11:45:41 +00:00
|
|
|
static bool property_type_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett);
|
2018-09-28 09:55:55 +00:00
|
|
|
static bool property_input_modified(void* priv, obs_properties_t* props, obs_property_t* prop,
|
|
|
|
obs_data_t* sett);
|
|
|
|
static void fill_source_list(obs_property_t* prop);
|
|
|
|
static bool property_texture_type_modified(void* priv, obs_properties_t* props, obs_property_t* prop,
|
|
|
|
obs_data_t* sett);
|
|
|
|
static bool property_texture_input_modified(void* priv, obs_properties_t* props, obs_property_t* prop,
|
|
|
|
obs_data_t* sett);
|
|
|
|
|
2018-04-09 11:27:22 +00:00
|
|
|
virtual bool is_special_parameter(std::string name, gs::effect_parameter::type type) = 0;
|
|
|
|
|
2018-09-28 09:55:55 +00:00
|
|
|
virtual bool video_tick_impl(float_t time) = 0;
|
2018-04-29 01:04:29 +00:00
|
|
|
virtual bool video_render_impl(gs_effect_t* parent_effect, uint32_t viewW, uint32_t viewH) = 0;
|
2018-04-09 11:27:22 +00:00
|
|
|
|
2018-03-20 11:45:41 +00:00
|
|
|
public:
|
2018-03-20 11:50:17 +00:00
|
|
|
effect_source(obs_data_t* data, obs_source_t* owner);
|
|
|
|
~effect_source();
|
2018-03-20 11:45:41 +00:00
|
|
|
|
2018-09-28 09:55:55 +00:00
|
|
|
void get_properties(obs_properties_t* properties);
|
2018-04-09 11:27:22 +00:00
|
|
|
static void get_defaults(obs_data_t* data);
|
2018-09-28 09:55:55 +00:00
|
|
|
void update(obs_data_t* data);
|
|
|
|
bool test_for_updates(const char* text, const char* path);
|
|
|
|
void update_parameters(obs_data_t* data);
|
|
|
|
void apply_parameters();
|
2018-03-20 11:45:41 +00:00
|
|
|
|
2018-04-09 11:27:22 +00:00
|
|
|
void activate();
|
2018-03-20 11:45:41 +00:00
|
|
|
void deactivate();
|
2018-09-28 09:55:55 +00:00
|
|
|
|
2018-04-09 11:27:22 +00:00
|
|
|
std::string get_shader_file();
|
2018-03-20 11:45:41 +00:00
|
|
|
|
|
|
|
uint32_t get_width();
|
|
|
|
uint32_t get_height();
|
2018-09-28 09:55:55 +00:00
|
|
|
void video_tick(float time);
|
|
|
|
void video_render(gs_effect_t* parent_effect);
|
2018-04-29 01:04:29 +00:00
|
|
|
|
2018-03-20 11:45:41 +00:00
|
|
|
public:
|
2018-09-28 09:55:55 +00:00
|
|
|
enum class InputTypes { Text, File };
|
2018-03-20 11:45:41 +00:00
|
|
|
};
|
2018-09-28 09:55:55 +00:00
|
|
|
} // namespace gfx
|