obs-StreamFX/source/filters/filter-displacement.hpp

88 lines
2.4 KiB
C++
Raw Normal View History

/*
* 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
#include <memory>
#include <string>
#include "obs/gs/gs-effect.hpp"
#include "plugin.hpp"
2017-07-03 00:43:33 +00:00
// OBS
#ifdef _MSC_VER
2018-11-07 14:24:25 +00:00
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <obs-source.h>
#include <util/platform.h>
#ifdef _MSC_VER
2018-11-07 14:24:25 +00:00
#pragma warning(pop)
#endif
2018-09-30 16:49:52 +00:00
namespace filter {
2019-01-25 16:54:18 +00:00
namespace displacement {
2019-01-27 22:33:12 +00:00
class displacement_factory {
2019-08-04 14:20:26 +00:00
obs_source_info _source_info;
2019-01-25 16:54:18 +00:00
public: // Singleton
2019-04-02 22:19:01 +00:00
static void initialize();
static void finalize();
2019-01-27 22:33:12 +00:00
static std::shared_ptr<displacement_factory> get();
2019-01-25 16:54:18 +00:00
public:
2019-01-27 22:33:12 +00:00
displacement_factory();
~displacement_factory();
2019-01-25 16:54:18 +00:00
};
2019-01-27 22:33:12 +00:00
class displacement_instance {
2019-08-04 14:20:26 +00:00
obs_source_t* _self;
float_t _timer;
2019-01-25 16:54:18 +00:00
// Rendering
2019-08-04 14:20:26 +00:00
std::shared_ptr<gs::effect> _effect;
float_t _distance;
vec2 _displacement_scale;
2019-01-25 16:54:18 +00:00
// Displacement Map
2019-08-04 14:20:26 +00:00
std::string _file_name;
std::shared_ptr<gs::texture> _file_texture;
time_t _file_create_time;
time_t _file_modified_time;
size_t _file_size;
2019-01-25 16:54:18 +00:00
void validate_file_texture(std::string file);
public:
2019-01-27 22:33:12 +00:00
displacement_instance(obs_data_t*, obs_source_t*);
~displacement_instance();
2019-01-25 16:54:18 +00:00
void update(obs_data_t*);
uint32_t get_width();
uint32_t get_height();
void activate();
void deactivate();
void show();
void hide();
void video_tick(float);
void video_render(gs_effect_t*);
std::string get_file();
};
} // namespace displacement
2018-11-07 14:24:25 +00:00
} // namespace filter