filter-transform: Refactor to match source-mirror structure

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-01-24 04:32:14 +01:00
parent 9d55013ec2
commit c1441e72c0
2 changed files with 74 additions and 75 deletions

View file

@ -34,10 +34,10 @@
#endif #endif
// Initializer & Finalizer // Initializer & Finalizer
static filter::Transform* filterTransformInstance; static filter::TransformAddon* filterTransformInstance;
INITIALIZER(FilterTransformInit) INITIALIZER(FilterTransformInit)
{ {
initializerFunctions.push_back([] { filterTransformInstance = new filter::Transform(); }); initializerFunctions.push_back([] { filterTransformInstance = new filter::TransformAddon(); });
finalizerFunctions.push_back([] { delete filterTransformInstance; }); finalizerFunctions.push_back([] { delete filterTransformInstance; });
} }
@ -83,7 +83,7 @@ enum RotationOrder : int64_t {
ZYX, ZYX,
}; };
filter::Transform::Transform() filter::TransformAddon::TransformAddon()
{ {
memset(&sourceInfo, 0, sizeof(obs_source_info)); memset(&sourceInfo, 0, sizeof(obs_source_info));
sourceInfo.id = "obs-stream-effects-filter-transform"; sourceInfo.id = "obs-stream-effects-filter-transform";
@ -104,14 +104,14 @@ filter::Transform::Transform()
obs_register_source(&sourceInfo); obs_register_source(&sourceInfo);
} }
filter::Transform::~Transform() {} filter::TransformAddon::~TransformAddon() {}
const char* filter::Transform::get_name(void*) const char* filter::TransformAddon::get_name(void*)
{ {
return P_TRANSLATE(ST); return P_TRANSLATE(ST);
} }
void filter::Transform::get_defaults(obs_data_t* data) void filter::TransformAddon::get_defaults(obs_data_t* data)
{ {
obs_data_set_default_int(data, ST_CAMERA, (int64_t)CameraMode::Orthographic); obs_data_set_default_int(data, ST_CAMERA, (int64_t)CameraMode::Orthographic);
obs_data_set_default_double(data, ST_CAMERA_FIELDOFVIEW, 90.0); obs_data_set_default_double(data, ST_CAMERA_FIELDOFVIEW, 90.0);
@ -130,7 +130,7 @@ void filter::Transform::get_defaults(obs_data_t* data)
RotationOrder::ZXY); //ZXY RotationOrder::ZXY); //ZXY
} }
obs_properties_t* filter::Transform::get_properties(void*) obs_properties_t* filter::TransformAddon::get_properties(void*)
{ {
obs_properties_t* pr = obs_properties_create(); obs_properties_t* pr = obs_properties_create();
obs_property_t* p = NULL; obs_property_t* p = NULL;
@ -228,7 +228,7 @@ obs_properties_t* filter::Transform::get_properties(void*)
return pr; return pr;
} }
bool filter::Transform::modified_properties(obs_properties_t* pr, obs_property_t*, obs_data_t* d) bool filter::TransformAddon::modified_properties(obs_properties_t* pr, obs_property_t*, obs_data_t* d)
{ {
switch ((CameraMode)obs_data_get_int(d, ST_CAMERA)) { switch ((CameraMode)obs_data_get_int(d, ST_CAMERA)) {
case CameraMode::Orthographic: case CameraMode::Orthographic:
@ -252,52 +252,52 @@ bool filter::Transform::modified_properties(obs_properties_t* pr, obs_property_t
return true; return true;
} }
void* filter::Transform::create(obs_data_t* data, obs_source_t* source) void* filter::TransformAddon::create(obs_data_t* data, obs_source_t* source)
{ {
return new Instance(data, source); return new Transform(data, source);
} }
void filter::Transform::destroy(void* ptr) void filter::TransformAddon::destroy(void* ptr)
{ {
delete reinterpret_cast<Instance*>(ptr); delete reinterpret_cast<Transform*>(ptr);
} }
uint32_t filter::Transform::get_width(void* ptr) uint32_t filter::TransformAddon::get_width(void* ptr)
{ {
return reinterpret_cast<Instance*>(ptr)->get_width(); return reinterpret_cast<Transform*>(ptr)->get_width();
} }
uint32_t filter::Transform::get_height(void* ptr) uint32_t filter::TransformAddon::get_height(void* ptr)
{ {
return reinterpret_cast<Instance*>(ptr)->get_height(); return reinterpret_cast<Transform*>(ptr)->get_height();
} }
void filter::Transform::update(void* ptr, obs_data_t* data) void filter::TransformAddon::update(void* ptr, obs_data_t* data)
{ {
reinterpret_cast<Instance*>(ptr)->update(data); reinterpret_cast<Transform*>(ptr)->update(data);
} }
void filter::Transform::activate(void* ptr) void filter::TransformAddon::activate(void* ptr)
{ {
reinterpret_cast<Instance*>(ptr)->activate(); reinterpret_cast<Transform*>(ptr)->activate();
} }
void filter::Transform::deactivate(void* ptr) void filter::TransformAddon::deactivate(void* ptr)
{ {
reinterpret_cast<Instance*>(ptr)->deactivate(); reinterpret_cast<Transform*>(ptr)->deactivate();
} }
void filter::Transform::video_tick(void* ptr, float time) void filter::TransformAddon::video_tick(void* ptr, float time)
{ {
reinterpret_cast<Instance*>(ptr)->video_tick(time); reinterpret_cast<Transform*>(ptr)->video_tick(time);
} }
void filter::Transform::video_render(void* ptr, gs_effect_t* effect) void filter::TransformAddon::video_render(void* ptr, gs_effect_t* effect)
{ {
reinterpret_cast<Instance*>(ptr)->video_render(effect); reinterpret_cast<Transform*>(ptr)->video_render(effect);
} }
filter::Transform::Instance::Instance(obs_data_t* data, obs_source_t* context) filter::Transform::Transform(obs_data_t* data, obs_source_t* context)
: source_context(context), is_orthographic(true), field_of_view(90.0), is_inactive(false), is_hidden(false), : source_context(context), is_orthographic(true), field_of_view(90.0), is_inactive(false), is_hidden(false),
is_mesh_update_required(false), rotation_order(RotationOrder::ZXY) is_mesh_update_required(false), rotation_order(RotationOrder::ZXY)
{ {
@ -323,7 +323,7 @@ filter::Transform::Instance::Instance(obs_data_t* data, obs_source_t* context)
update(data); update(data);
} }
filter::Transform::Instance::~Instance() filter::Transform::~Transform()
{ {
obs_enter_graphics(); obs_enter_graphics();
shape_rt.reset(); shape_rt.reset();
@ -332,7 +332,7 @@ filter::Transform::Instance::~Instance()
obs_leave_graphics(); obs_leave_graphics();
} }
void filter::Transform::Instance::update(obs_data_t* data) void filter::Transform::update(obs_data_t* data)
{ {
// Camera // Camera
is_orthographic = obs_data_get_int(data, ST_CAMERA) == 0; is_orthographic = obs_data_get_int(data, ST_CAMERA) == 0;
@ -361,29 +361,29 @@ void filter::Transform::Instance::update(obs_data_t* data)
is_mesh_update_required = true; is_mesh_update_required = true;
} }
uint32_t filter::Transform::Instance::get_width() uint32_t filter::Transform::get_width()
{ {
return 0; return 0;
} }
uint32_t filter::Transform::Instance::get_height() uint32_t filter::Transform::get_height()
{ {
return 0; return 0;
} }
void filter::Transform::Instance::activate() void filter::Transform::activate()
{ {
is_inactive = false; is_inactive = false;
} }
void filter::Transform::Instance::deactivate() void filter::Transform::deactivate()
{ {
is_inactive = true; is_inactive = true;
} }
void filter::Transform::Instance::video_tick(float) {} void filter::Transform::video_tick(float) {}
void filter::Transform::Instance::video_render(gs_effect_t* paramEffect) void filter::Transform::video_render(gs_effect_t* paramEffect)
{ {
std::shared_ptr<gs::texture> source_tex; std::shared_ptr<gs::texture> source_tex;
std::shared_ptr<gs::texture> shape_tex; std::shared_ptr<gs::texture> shape_tex;

View file

@ -27,12 +27,12 @@
#include "plugin.hpp" #include "plugin.hpp"
namespace filter { namespace filter {
class Transform { class TransformAddon {
obs_source_info sourceInfo; obs_source_info sourceInfo;
public: public:
Transform(); TransformAddon();
~Transform(); ~TransformAddon();
static const char* get_name(void*); static const char* get_name(void*);
static void get_defaults(obs_data_t*); static void get_defaults(obs_data_t*);
@ -50,50 +50,49 @@ namespace filter {
static void hide(void*); static void hide(void*);
static void video_tick(void*, float); static void video_tick(void*, float);
static void video_render(void*, gs_effect_t*); static void video_render(void*, gs_effect_t*);
};
private: class Transform {
class Instance { obs_source_t* source_context;
obs_source_t* source_context;
// Graphics Data // Graphics Data
std::shared_ptr<gs::vertex_buffer> vertex_buffer; std::shared_ptr<gs::vertex_buffer> vertex_buffer;
std::shared_ptr<gs::rendertarget> source_rt; std::shared_ptr<gs::rendertarget> source_rt;
std::shared_ptr<gs::rendertarget> shape_rt; std::shared_ptr<gs::rendertarget> shape_rt;
// Mipmapping // Mipmapping
bool enable_mipmapping; bool enable_mipmapping;
double_t generator_strength; double_t generator_strength;
gs::mipmapper::generator generator; gs::mipmapper::generator generator;
std::shared_ptr<gs::texture> source_texture; std::shared_ptr<gs::texture> source_texture;
gs::mipmapper mipmapper; gs::mipmapper mipmapper;
// Camera // Camera
bool is_orthographic; bool is_orthographic;
float_t field_of_view; float_t field_of_view;
// Source // Source
bool is_inactive; bool is_inactive;
bool is_hidden; bool is_hidden;
bool is_mesh_update_required; bool is_mesh_update_required;
// 3D Information // 3D Information
uint32_t rotation_order; uint32_t rotation_order;
std::unique_ptr<util::vec3a> position; std::unique_ptr<util::vec3a> position;
std::unique_ptr<util::vec3a> rotation; std::unique_ptr<util::vec3a> rotation;
std::unique_ptr<util::vec3a> scale; std::unique_ptr<util::vec3a> scale;
std::unique_ptr<util::vec3a> shear; std::unique_ptr<util::vec3a> shear;
public: public:
Instance(obs_data_t*, obs_source_t*); Transform(obs_data_t*, obs_source_t*);
~Instance(); ~Transform();
void update(obs_data_t*); void update(obs_data_t*);
uint32_t get_width(); uint32_t get_width();
uint32_t get_height(); uint32_t get_height();
void activate(); void activate();
void deactivate(); void deactivate();
void video_tick(float); void video_tick(float);
void video_render(gs_effect_t*); void video_render(gs_effect_t*);
};
}; };
} // namespace filter } // namespace filter