gs-effect*: Finish up refactoring onto std::shared_ptr

This is most likely not the last refactor, the entire obs/gs stuff is very very basic right now and likely needs a complete rewrite.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-12-15 11:39:57 +01:00
parent 11a2329519
commit b54e95527a
30 changed files with 1040 additions and 309 deletions

View file

@ -130,66 +130,66 @@ filter::blur::blur_instance::blur_instance(obs_data_t* settings, obs_source_t* s
filter::blur::blur_instance::~blur_instance() {}
bool filter::blur::blur_instance::apply_mask_parameters(std::shared_ptr<gs::effect> effect,
gs_texture_t* original_texture, gs_texture_t* blurred_texture)
bool filter::blur::blur_instance::apply_mask_parameters(gs::effect effect, gs_texture_t* original_texture,
gs_texture_t* blurred_texture)
{
if (effect->has_parameter("image_orig")) {
effect->get_parameter("image_orig")->set_texture(original_texture);
if (effect.has_parameter("image_orig")) {
effect.get_parameter("image_orig").set_texture(original_texture);
}
if (effect->has_parameter("image_blur")) {
effect->get_parameter("image_blur")->set_texture(blurred_texture);
if (effect.has_parameter("image_blur")) {
effect.get_parameter("image_blur").set_texture(blurred_texture);
}
// Region
if (_mask.type == mask_type::Region) {
if (effect->has_parameter("mask_region_left")) {
effect->get_parameter("mask_region_left")->set_float(_mask.region.left);
if (effect.has_parameter("mask_region_left")) {
effect.get_parameter("mask_region_left").set_float(_mask.region.left);
}
if (effect->has_parameter("mask_region_right")) {
effect->get_parameter("mask_region_right")->set_float(_mask.region.right);
if (effect.has_parameter("mask_region_right")) {
effect.get_parameter("mask_region_right").set_float(_mask.region.right);
}
if (effect->has_parameter("mask_region_top")) {
effect->get_parameter("mask_region_top")->set_float(_mask.region.top);
if (effect.has_parameter("mask_region_top")) {
effect.get_parameter("mask_region_top").set_float(_mask.region.top);
}
if (effect->has_parameter("mask_region_bottom")) {
effect->get_parameter("mask_region_bottom")->set_float(_mask.region.bottom);
if (effect.has_parameter("mask_region_bottom")) {
effect.get_parameter("mask_region_bottom").set_float(_mask.region.bottom);
}
if (effect->has_parameter("mask_region_feather")) {
effect->get_parameter("mask_region_feather")->set_float(_mask.region.feather);
if (effect.has_parameter("mask_region_feather")) {
effect.get_parameter("mask_region_feather").set_float(_mask.region.feather);
}
if (effect->has_parameter("mask_region_feather_shift")) {
effect->get_parameter("mask_region_feather_shift")->set_float(_mask.region.feather_shift);
if (effect.has_parameter("mask_region_feather_shift")) {
effect.get_parameter("mask_region_feather_shift").set_float(_mask.region.feather_shift);
}
}
// Image
if (_mask.type == mask_type::Image) {
if (effect->has_parameter("mask_image")) {
if (effect.has_parameter("mask_image")) {
if (_mask.image.texture) {
effect->get_parameter("mask_image")->set_texture(_mask.image.texture);
effect.get_parameter("mask_image").set_texture(_mask.image.texture);
} else {
effect->get_parameter("mask_image")->set_texture(nullptr);
effect.get_parameter("mask_image").set_texture(nullptr);
}
}
}
// Source
if (_mask.type == mask_type::Source) {
if (effect->has_parameter("mask_image")) {
if (effect.has_parameter("mask_image")) {
if (_mask.source.texture) {
effect->get_parameter("mask_image")->set_texture(_mask.source.texture);
effect.get_parameter("mask_image").set_texture(_mask.source.texture);
} else {
effect->get_parameter("mask_image")->set_texture(nullptr);
effect.get_parameter("mask_image").set_texture(nullptr);
}
}
}
// Shared
if (effect->has_parameter("mask_color")) {
effect->get_parameter("mask_color")->set_float4(_mask.color.r, _mask.color.g, _mask.color.b, _mask.color.a);
if (effect.has_parameter("mask_color")) {
effect.get_parameter("mask_color").set_float4(_mask.color.r, _mask.color.g, _mask.color.b, _mask.color.a);
}
if (effect->has_parameter("mask_multiplier")) {
effect->get_parameter("mask_multiplier")->set_float(_mask.multiplier);
if (effect.has_parameter("mask_multiplier")) {
effect.get_parameter("mask_multiplier").set_float(_mask.multiplier);
}
return true;
@ -276,7 +276,7 @@ void filter::blur::blur_instance::update(obs_data_t* settings)
{ // Masking
_mask.enabled = obs_data_get_bool(settings, ST_MASK);
if (_mask.enabled) {
_mask.type = static_cast<mask_type>(obs_data_get_int(settings, ST_MASK_TYPE));
_mask.type = static_cast<filter::blur::mask_type>(obs_data_get_int(settings, ST_MASK_TYPE));
switch (_mask.type) {
case mask_type::Region:
_mask.region.left = float_t(obs_data_get_double(settings, ST_MASK_REGION_LEFT) / 100.0);
@ -444,7 +444,7 @@ void filter::blur::blur_instance::video_render(gs_effect_t* effect)
std::string technique = "";
switch (this->_mask.type) {
case Region:
case mask_type::Region:
if (this->_mask.region.feather > std::numeric_limits<float_t>::epsilon()) {
if (this->_mask.region.invert) {
technique = "RegionFeatherInverted";
@ -459,8 +459,8 @@ void filter::blur::blur_instance::video_render(gs_effect_t* effect)
}
}
break;
case Image:
case Source:
case mask_type::Image:
case mask_type::Source:
technique = "Image";
break;
}
@ -493,7 +493,7 @@ void filter::blur::blur_instance::video_render(gs_effect_t* effect)
gs_ortho(0, (float)baseW, 0, (float)baseH, -1, 1);
// Render
while (gs_effect_loop(_effect_mask->get_object(), technique.c_str())) {
while (gs_effect_loop(_effect_mask.get_object(), technique.c_str())) {
gs_draw_sprite(_output_texture->get_object(), 0, baseW, baseH);
}
} catch (const std::exception&) {
@ -574,7 +574,7 @@ void filter::blur::blur_factory::get_defaults2(obs_data_t* settings)
// Masking
obs_data_set_default_bool(settings, ST_MASK, false);
obs_data_set_default_int(settings, ST_MASK_TYPE, mask_type::Region);
obs_data_set_default_int(settings, ST_MASK_TYPE, static_cast<int64_t>(mask_type::Region));
obs_data_set_default_double(settings, ST_MASK_REGION_LEFT, 0.0);
obs_data_set_default_double(settings, ST_MASK_REGION_RIGHT, 0.0);
obs_data_set_default_double(settings, ST_MASK_REGION_TOP, 0.0);
@ -814,9 +814,9 @@ obs_properties_t* filter::blur::blur_factory::get_properties2(filter::blur::blur
OBS_COMBO_FORMAT_INT);
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_TYPE)));
obs_property_set_modified_callback2(p, modified_properties, this);
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_REGION), mask_type::Region);
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_IMAGE), mask_type::Image);
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_SOURCE), mask_type::Source);
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_REGION), static_cast<int64_t>(mask_type::Region));
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_IMAGE), static_cast<int64_t>(mask_type::Image));
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_SOURCE), static_cast<int64_t>(mask_type::Source));
/// Region
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_LEFT, D_TRANSLATE(ST_MASK_REGION_LEFT), 0.0, 100.0,
0.01);

View file

@ -44,7 +44,7 @@
namespace filter {
namespace blur {
enum mask_type : int64_t {
enum class mask_type : int64_t {
Region,
Image,
Source,
@ -52,7 +52,7 @@ namespace filter {
class blur_instance : public obs::source_instance {
// Effects
std::shared_ptr<gs::effect> _effect_mask;
gs::effect _effect_mask;
// Input
std::shared_ptr<gs::rendertarget> _source_rt;
@ -118,7 +118,7 @@ namespace filter {
virtual void video_render(gs_effect_t* effect) override;
private:
bool apply_mask_parameters(std::shared_ptr<gs::effect> effect, gs_texture_t* original_texture,
bool apply_mask_parameters(gs::effect effect, gs_texture_t* original_texture,
gs_texture_t* blurred_texture);
};

View file

@ -216,32 +216,20 @@ void filter::color_grade::color_grade_instance::video_render(gs_effect_t* effect
gs_enable_stencil_write(false);
gs_ortho(0, static_cast<float_t>(width), 0, static_cast<float_t>(height), -1., 1.);
if (_effect->has_parameter("image"))
_effect->get_parameter("image")->set_texture(_tex_source);
if (_effect->has_parameter("pLift"))
_effect->get_parameter("pLift")->set_float4(_lift);
if (_effect->has_parameter("pGamma"))
_effect->get_parameter("pGamma")->set_float4(_gamma);
if (_effect->has_parameter("pGain"))
_effect->get_parameter("pGain")->set_float4(_gain);
if (_effect->has_parameter("pOffset"))
_effect->get_parameter("pOffset")->set_float4(_offset);
if (_effect->has_parameter("pTintDetection"))
_effect->get_parameter("pTintDetection")->set_int(static_cast<int32_t>(_tint_detection));
if (_effect->has_parameter("pTintMode"))
_effect->get_parameter("pTintMode")->set_int(static_cast<int32_t>(_tint_luma));
if (_effect->has_parameter("pTintExponent"))
_effect->get_parameter("pTintExponent")->set_float(_tint_exponent);
if (_effect->has_parameter("pTintLow"))
_effect->get_parameter("pTintLow")->set_float3(_tint_low);
if (_effect->has_parameter("pTintMid"))
_effect->get_parameter("pTintMid")->set_float3(_tint_mid);
if (_effect->has_parameter("pTintHig"))
_effect->get_parameter("pTintHig")->set_float3(_tint_hig);
if (_effect->has_parameter("pCorrection"))
_effect->get_parameter("pCorrection")->set_float4(_correction);
_effect.get_parameter("image").set_texture(_tex_source);
_effect.get_parameter("pLift").set_float4(_lift);
_effect.get_parameter("pGamma").set_float4(_gamma);
_effect.get_parameter("pGain").set_float4(_gain);
_effect.get_parameter("pOffset").set_float4(_offset);
_effect.get_parameter("pTintDetection").set_int(static_cast<int32_t>(_tint_detection));
_effect.get_parameter("pTintMode").set_int(static_cast<int32_t>(_tint_luma));
_effect.get_parameter("pTintExponent").set_float(_tint_exponent);
_effect.get_parameter("pTintLow").set_float3(_tint_low);
_effect.get_parameter("pTintMid").set_float3(_tint_mid);
_effect.get_parameter("pTintHig").set_float3(_tint_hig);
_effect.get_parameter("pCorrection").set_float4(_correction);
while (gs_effect_loop(_effect->get_object(), "Draw")) {
while (gs_effect_loop(_effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, width, height);
}
@ -387,8 +375,8 @@ obs_properties_t* filter::color_grade::color_grade_factory::get_properties2(colo
0.01);
obs_properties_add_float_slider(grp, ST_TINT_(TONE_HIGH, GREEN), D_TRANSLATE(ST_TINT_(TONE_HIGH, GREEN)), 0,
1000.0, 0.01);
obs_properties_add_float_slider(grp, ST_TINT_(TONE_HIGH, BLUE), D_TRANSLATE(ST_TINT_(TONE_HIGH, BLUE)), 0, 1000.0,
0.01);
obs_properties_add_float_slider(grp, ST_TINT_(TONE_HIGH, BLUE), D_TRANSLATE(ST_TINT_(TONE_HIGH, BLUE)), 0,
1000.0, 0.01);
}
{

View file

@ -44,7 +44,7 @@ namespace filter {
};
class color_grade_instance : public obs::source_instance {
std::shared_ptr<gs::effect> _effect;
gs::effect _effect;
// Source
std::unique_ptr<gs::rendertarget> _rt_source;

View file

@ -42,7 +42,6 @@ filter::displacement::displacement_instance::displacement_instance(obs_data_t* d
filter::displacement::displacement_instance::~displacement_instance()
{
_effect.reset();
_texture.reset();
}
@ -78,7 +77,7 @@ void filter::displacement::displacement_instance::update(obs_data_t* settings)
std::string new_file = obs_data_get_string(settings, ST_FILE);
if (new_file != _texture_file) {
try {
_texture = std::make_shared<gs::texture>(new_file);
_texture = std::make_shared<gs::texture>(new_file);
_texture_file = new_file;
} catch (...) {
_texture.reset();
@ -103,15 +102,15 @@ void filter::displacement::displacement_instance::video_render(gs_effect_t*)
obs_source_skip_video_filter(_self);
return;
}
_effect->get_parameter("image_size")->set_float2(static_cast<float_t>(_width), static_cast<float_t>(_height));
_effect->get_parameter("image_inverse_size")
->set_float2(static_cast<float_t>(1.0 / _width), static_cast<float_t>(1.0 / _height));
_effect->get_parameter("normal")->set_texture(_texture->get_object());
_effect->get_parameter("scale")->set_float2(_scale[0], _scale[1]);
_effect->get_parameter("scale_type")->set_float(_scale_type);
obs_source_process_filter_end(_self, _effect->get_object(), _width, _height);
_effect.get_parameter("image_size").set_float2(static_cast<float_t>(_width), static_cast<float_t>(_height));
_effect.get_parameter("image_inverse_size")
.set_float2(static_cast<float_t>(1.0 / _width), static_cast<float_t>(1.0 / _height));
_effect.get_parameter("normal").set_texture(_texture->get_object());
_effect.get_parameter("scale").set_float2(_scale[0], _scale[1]);
_effect.get_parameter("scale_type").set_float(_scale_type);
obs_source_process_filter_end(_self, _effect.get_object(), _width, _height);
}
std::string filter::displacement::displacement_instance::get_file()

View file

@ -38,7 +38,7 @@
namespace filter {
namespace displacement {
class displacement_instance : public obs::source_instance {
std::shared_ptr<gs::effect> _effect;
gs::effect _effect;
// Displacement Map
std::shared_ptr<gs::texture> _texture;

View file

@ -51,7 +51,7 @@ static std::pair<filter::dynamic_mask::channel, const char*> channel_translation
filter::dynamic_mask::dynamic_mask_instance::dynamic_mask_instance(obs_data_t* settings, obs_source_t* self)
: obs::source_instance(settings, self), _have_filter_texture(false), _have_input_texture(false),
_have_final_texture(false), _precalc()
_have_final_texture(false), _precalc(), _effect()
{
this->_filter_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
this->_final_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
@ -61,7 +61,7 @@ filter::dynamic_mask::dynamic_mask_instance::dynamic_mask_instance(obs_data_t* s
try {
this->_effect = gs::effect::create(file);
} catch (const std::exception& ex) {
P_LOG_ERROR("Loading channel mask _effect failed with error(s):\n%s", ex.what());
P_LOG_ERROR("Loading channel mask effect failed with error(s):\n%s", ex.what());
}
assert(this->_effect != nullptr);
bfree(file);
@ -287,14 +287,14 @@ void filter::dynamic_mask::dynamic_mask_instance::video_render(gs_effect_t* in_e
gs_stencil_op(GS_STENCIL_BOTH, GS_KEEP, GS_KEEP, GS_KEEP);
gs_ortho(0, (float)width, 0, (float)height, -1., 1.);
this->_effect->get_parameter("pMaskInputA")->set_texture(this->_filter_texture);
this->_effect->get_parameter("pMaskInputB")->set_texture(this->_input_texture);
_effect.get_parameter("pMaskInputA").set_texture(this->_filter_texture);
_effect.get_parameter("pMaskInputB").set_texture(this->_input_texture);
this->_effect->get_parameter("pMaskBase")->set_float4(this->_precalc.base);
this->_effect->get_parameter("pMaskMatrix")->set_matrix(this->_precalc.matrix);
this->_effect->get_parameter("pMaskMultiplier")->set_float4(this->_precalc.scale);
_effect.get_parameter("pMaskBase").set_float4(this->_precalc.base);
_effect.get_parameter("pMaskMatrix").set_matrix(this->_precalc.matrix);
_effect.get_parameter("pMaskMultiplier").set_float4(this->_precalc.scale);
while (gs_effect_loop(this->_effect->get_object(), "Mask")) {
while (gs_effect_loop(_effect.get(), "Mask")) {
gs_draw_sprite(0, 0, width, height);
}

View file

@ -47,7 +47,7 @@ namespace filter {
class dynamic_mask_instance : public obs::source_instance {
std::map<std::tuple<channel, channel, std::string>, std::string> _translation_map;
std::shared_ptr<gs::effect> _effect;
gs::effect _effect;
bool _have_filter_texture;
std::shared_ptr<gs::rendertarget> _filter_rt;

View file

@ -94,9 +94,9 @@ filter::sdf_effects::sdf_effects_instance::sdf_effects_instance(obs_data_t* sett
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &transparent, 0, 0);
}
std::pair<const char*, std::shared_ptr<gs::effect>&> load_arr[] = {
{"effects/sdf/sdf-producer.effect", this->_sdf_producer_effect},
{"effects/sdf/sdf-consumer.effect", this->_sdf_consumer_effect},
std::pair<const char*, gs::effect&> load_arr[] = {
{"effects/sdf/sdf-producer.effect", _sdf_producer_effect},
{"effects/sdf/sdf-consumer.effect", _sdf_consumer_effect},
};
for (auto& kv : load_arr) {
char* path = obs_module_file(kv.first);
@ -339,8 +339,7 @@ void filter::sdf_effects::sdf_effects_instance::video_render(gs_effect_t* effect
throw std::runtime_error("SDF Backbuffer empty");
}
std::shared_ptr<gs::effect> sdf_effect = _sdf_producer_effect;
if (!sdf_effect) {
if (!_sdf_producer_effect) {
throw std::runtime_error("SDF Effect no loaded");
}
@ -360,12 +359,12 @@ void filter::sdf_effects::sdf_effects_instance::video_render(gs_effect_t* effect
gs_ortho(0, (float)sdfW, 0, (float)sdfH, -1, 1);
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &color_transparent, 0, 0);
sdf_effect->get_parameter("_image")->set_texture(this->_source_texture);
sdf_effect->get_parameter("_size")->set_float2(float_t(sdfW), float_t(sdfH));
sdf_effect->get_parameter("_sdf")->set_texture(this->_sdf_texture);
sdf_effect->get_parameter("_threshold")->set_float(this->_sdf_threshold);
_sdf_producer_effect.get_parameter("_image").set_texture(this->_source_texture);
_sdf_producer_effect.get_parameter("_size").set_float2(float_t(sdfW), float_t(sdfH));
_sdf_producer_effect.get_parameter("_sdf").set_texture(this->_sdf_texture);
_sdf_producer_effect.get_parameter("_threshold").set_float(this->_sdf_threshold);
while (gs_effect_loop(sdf_effect->get_object(), "Draw")) {
while (gs_effect_loop(_sdf_producer_effect.get_object(), "Draw")) {
gs_draw_sprite(this->_sdf_texture->get_object(), 0, uint32_t(sdfW), uint32_t(sdfH));
}
}
@ -389,8 +388,7 @@ void filter::sdf_effects::sdf_effects_instance::video_render(gs_effect_t* effect
if (!this->_output_rendered) {
this->_output_texture = this->_source_texture;
std::shared_ptr<gs::effect> consumer_effect = _sdf_consumer_effect;
if (!consumer_effect) {
if (!_sdf_consumer_effect) {
obs_source_skip_video_filter(this->_self);
return;
}
@ -427,67 +425,67 @@ void filter::sdf_effects::sdf_effects_instance::video_render(gs_effect_t* effect
gs_enable_blending(true);
gs_blend_function_separate(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA, GS_BLEND_ONE, GS_BLEND_ONE);
if (this->_outer_shadow) {
consumer_effect->get_parameter("pSDFTexture")->set_texture(this->_sdf_texture);
consumer_effect->get_parameter("pSDFThreshold")->set_float(this->_sdf_threshold);
consumer_effect->get_parameter("pImageTexture")->set_texture(this->_source_texture->get_object());
consumer_effect->get_parameter("pShadowColor")->set_float4(this->_outer_shadow_color);
consumer_effect->get_parameter("pShadowMin")->set_float(this->_outer_shadow_range_min);
consumer_effect->get_parameter("pShadowMax")->set_float(this->_outer_shadow_range_max);
consumer_effect->get_parameter("pShadowOffset")
->set_float2(this->_outer_shadow_offset_x / float_t(baseW),
this->_outer_shadow_offset_y / float_t(baseH));
while (gs_effect_loop(consumer_effect->get_object(), "ShadowOuter")) {
_sdf_consumer_effect.get_parameter("pSDFTexture").set_texture(this->_sdf_texture);
_sdf_consumer_effect.get_parameter("pSDFThreshold").set_float(this->_sdf_threshold);
_sdf_consumer_effect.get_parameter("pImageTexture").set_texture(this->_source_texture->get_object());
_sdf_consumer_effect.get_parameter("pShadowColor").set_float4(this->_outer_shadow_color);
_sdf_consumer_effect.get_parameter("pShadowMin").set_float(this->_outer_shadow_range_min);
_sdf_consumer_effect.get_parameter("pShadowMax").set_float(this->_outer_shadow_range_max);
_sdf_consumer_effect.get_parameter("pShadowOffset")
.set_float2(this->_outer_shadow_offset_x / float_t(baseW),
this->_outer_shadow_offset_y / float_t(baseH));
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowOuter")) {
gs_draw_sprite(0, 0, 1, 1);
}
}
if (this->_inner_shadow) {
consumer_effect->get_parameter("pSDFTexture")->set_texture(this->_sdf_texture);
consumer_effect->get_parameter("pSDFThreshold")->set_float(this->_sdf_threshold);
consumer_effect->get_parameter("pImageTexture")->set_texture(this->_source_texture->get_object());
consumer_effect->get_parameter("pShadowColor")->set_float4(this->_inner_shadow_color);
consumer_effect->get_parameter("pShadowMin")->set_float(this->_inner_shadow_range_min);
consumer_effect->get_parameter("pShadowMax")->set_float(this->_inner_shadow_range_max);
consumer_effect->get_parameter("pShadowOffset")
->set_float2(this->_inner_shadow_offset_x / float_t(baseW),
this->_inner_shadow_offset_y / float_t(baseH));
while (gs_effect_loop(consumer_effect->get_object(), "ShadowInner")) {
_sdf_consumer_effect.get_parameter("pSDFTexture").set_texture(this->_sdf_texture);
_sdf_consumer_effect.get_parameter("pSDFThreshold").set_float(this->_sdf_threshold);
_sdf_consumer_effect.get_parameter("pImageTexture").set_texture(this->_source_texture->get_object());
_sdf_consumer_effect.get_parameter("pShadowColor").set_float4(this->_inner_shadow_color);
_sdf_consumer_effect.get_parameter("pShadowMin").set_float(this->_inner_shadow_range_min);
_sdf_consumer_effect.get_parameter("pShadowMax").set_float(this->_inner_shadow_range_max);
_sdf_consumer_effect.get_parameter("pShadowOffset")
.set_float2(this->_inner_shadow_offset_x / float_t(baseW),
this->_inner_shadow_offset_y / float_t(baseH));
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowInner")) {
gs_draw_sprite(0, 0, 1, 1);
}
}
if (this->_outer_glow) {
consumer_effect->get_parameter("pSDFTexture")->set_texture(this->_sdf_texture);
consumer_effect->get_parameter("pSDFThreshold")->set_float(this->_sdf_threshold);
consumer_effect->get_parameter("pImageTexture")->set_texture(this->_source_texture->get_object());
consumer_effect->get_parameter("pGlowColor")->set_float4(this->_outer_glow_color);
consumer_effect->get_parameter("pGlowWidth")->set_float(this->_outer_glow_width);
consumer_effect->get_parameter("pGlowSharpness")->set_float(this->_outer_glow_sharpness);
consumer_effect->get_parameter("pGlowSharpnessInverse")->set_float(this->_outer_glow_sharpness_inv);
while (gs_effect_loop(consumer_effect->get_object(), "GlowOuter")) {
_sdf_consumer_effect.get_parameter("pSDFTexture").set_texture(this->_sdf_texture);
_sdf_consumer_effect.get_parameter("pSDFThreshold").set_float(this->_sdf_threshold);
_sdf_consumer_effect.get_parameter("pImageTexture").set_texture(this->_source_texture->get_object());
_sdf_consumer_effect.get_parameter("pGlowColor").set_float4(this->_outer_glow_color);
_sdf_consumer_effect.get_parameter("pGlowWidth").set_float(this->_outer_glow_width);
_sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(this->_outer_glow_sharpness);
_sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(this->_outer_glow_sharpness_inv);
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowOuter")) {
gs_draw_sprite(0, 0, 1, 1);
}
}
if (this->_inner_glow) {
consumer_effect->get_parameter("pSDFTexture")->set_texture(this->_sdf_texture);
consumer_effect->get_parameter("pSDFThreshold")->set_float(this->_sdf_threshold);
consumer_effect->get_parameter("pImageTexture")->set_texture(this->_source_texture->get_object());
consumer_effect->get_parameter("pGlowColor")->set_float4(this->_inner_glow_color);
consumer_effect->get_parameter("pGlowWidth")->set_float(this->_inner_glow_width);
consumer_effect->get_parameter("pGlowSharpness")->set_float(this->_inner_glow_sharpness);
consumer_effect->get_parameter("pGlowSharpnessInverse")->set_float(this->_inner_glow_sharpness_inv);
while (gs_effect_loop(consumer_effect->get_object(), "GlowInner")) {
_sdf_consumer_effect.get_parameter("pSDFTexture").set_texture(this->_sdf_texture);
_sdf_consumer_effect.get_parameter("pSDFThreshold").set_float(this->_sdf_threshold);
_sdf_consumer_effect.get_parameter("pImageTexture").set_texture(this->_source_texture->get_object());
_sdf_consumer_effect.get_parameter("pGlowColor").set_float4(this->_inner_glow_color);
_sdf_consumer_effect.get_parameter("pGlowWidth").set_float(this->_inner_glow_width);
_sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(this->_inner_glow_sharpness);
_sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(this->_inner_glow_sharpness_inv);
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowInner")) {
gs_draw_sprite(0, 0, 1, 1);
}
}
if (this->_outline) {
consumer_effect->get_parameter("pSDFTexture")->set_texture(this->_sdf_texture);
consumer_effect->get_parameter("pSDFThreshold")->set_float(this->_sdf_threshold);
consumer_effect->get_parameter("pImageTexture")->set_texture(this->_source_texture->get_object());
consumer_effect->get_parameter("pOutlineColor")->set_float4(this->_outline_color);
consumer_effect->get_parameter("pOutlineWidth")->set_float(this->_outline_width);
consumer_effect->get_parameter("pOutlineOffset")->set_float(this->_outline_offset);
consumer_effect->get_parameter("pOutlineSharpness")->set_float(this->_outline_sharpness);
consumer_effect->get_parameter("pOutlineSharpnessInverse")->set_float(this->_outline_sharpness_inv);
while (gs_effect_loop(consumer_effect->get_object(), "Outline")) {
_sdf_consumer_effect.get_parameter("pSDFTexture").set_texture(this->_sdf_texture);
_sdf_consumer_effect.get_parameter("pSDFThreshold").set_float(this->_sdf_threshold);
_sdf_consumer_effect.get_parameter("pImageTexture").set_texture(this->_source_texture->get_object());
_sdf_consumer_effect.get_parameter("pOutlineColor").set_float4(this->_outline_color);
_sdf_consumer_effect.get_parameter("pOutlineWidth").set_float(this->_outline_width);
_sdf_consumer_effect.get_parameter("pOutlineOffset").set_float(this->_outline_offset);
_sdf_consumer_effect.get_parameter("pOutlineSharpness").set_float(this->_outline_sharpness);
_sdf_consumer_effect.get_parameter("pOutlineSharpnessInverse").set_float(this->_outline_sharpness_inv);
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "Outline")) {
gs_draw_sprite(0, 0, 1, 1);
}
}

View file

@ -40,8 +40,8 @@
namespace filter {
namespace sdf_effects {
class sdf_effects_instance : public obs::source_instance {
std::shared_ptr<gs::effect> _sdf_producer_effect;
std::shared_ptr<gs::effect> _sdf_consumer_effect;
gs::effect _sdf_producer_effect;
gs::effect _sdf_consumer_effect;
// Input
std::shared_ptr<gs::rendertarget> _source_rt;

View file

@ -19,7 +19,7 @@
#pragma once
#include "gfx/gfx-effect-source.hpp"
#include "gfx/shader/gfx-shader.hpp"
#include "obs/gs/gs-rendertarget.hpp"
#include "plugin.hpp"

View file

@ -40,7 +40,7 @@ gfx::blur::box_linear_data::box_linear_data()
auto gctx = gs::context();
try {
char* file = obs_module_file("effects/blur/box-linear.effect");
_effect = std::make_shared<::gs::effect>(file);
_effect = gs::effect::create(file);
bfree(file);
} catch (...) {
P_LOG_ERROR("<gfx::blur::box_linear> Failed to load _effect.");
@ -53,7 +53,7 @@ gfx::blur::box_linear_data::~box_linear_data()
_effect.reset();
}
std::shared_ptr<::gs::effect> gfx::blur::box_linear_data::get_effect()
gs::effect gfx::blur::box_linear_data::get_effect()
{
return _effect;
}
@ -263,31 +263,31 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// Two Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
// Pass 1
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), 0.f);
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f);
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
// Pass 2
effect->get_parameter("pImage")->set_texture(_rendertarget2->get_texture());
effect->get_parameter("pImageTexel")->set_float2(0., float_t(1.f / height));
effect.get_parameter("pImage").set_texture(_rendertarget2->get_texture());
effect.get_parameter("pImageTexel").set_float2(0., float_t(1.f / height));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -340,19 +340,19 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear_directional::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// One Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")
->set_float2(float_t(1. / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel")
.set_float2(float_t(1. / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}

View file

@ -27,13 +27,13 @@
namespace gfx {
namespace blur {
class box_linear_data {
std::shared_ptr<::gs::effect> _effect;
gs::effect _effect;
public:
box_linear_data();
virtual ~box_linear_data();
std::shared_ptr<::gs::effect> get_effect();
gs::effect get_effect();
};
class box_linear_factory : public ::gfx::blur::ifactory {

View file

@ -40,7 +40,7 @@ gfx::blur::box_data::box_data()
auto gctx = gs::context();
try {
char* file = obs_module_file("effects/blur/box.effect");
_effect = std::make_shared<::gs::effect>(file);
_effect = gs::effect::create(file);
bfree(file);
} catch (...) {
P_LOG_ERROR("<gfx::blur::box> Failed to load _effect.");
@ -53,7 +53,7 @@ gfx::blur::box_data::~box_data()
_effect.reset();
}
std::shared_ptr<::gs::effect> gfx::blur::box_data::get_effect()
gs::effect gfx::blur::box_data::get_effect()
{
return _effect;
}
@ -271,31 +271,31 @@ std::shared_ptr<::gs::texture> gfx::blur::box::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// Two Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
// Pass 1
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), 0.f);
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f);
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
// Pass 2
effect->get_parameter("pImage")->set_texture(_rendertarget2->get_texture());
effect->get_parameter("pImageTexel")->set_float2(0.f, float_t(1.f / height));
effect.get_parameter("pImage").set_texture(_rendertarget2->get_texture());
effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -348,19 +348,19 @@ std::shared_ptr<::gs::texture> gfx::blur::box_directional::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// One Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")
->set_float2(float_t(1. / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel")
.set_float2(float_t(1. / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -418,20 +418,20 @@ std::shared_ptr<::gs::texture> gfx::blur::box_rotational::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// One Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), float_t(1.f / height));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect->get_parameter("pAngle")->set_float(float_t(_angle / _size));
effect->get_parameter("pCenter")->set_float2(float_t(_center.first), float_t(_center.second));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), float_t(1.f / height));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pAngle").set_float(float_t(_angle / _size));
effect.get_parameter("pCenter").set_float2(float_t(_center.first), float_t(_center.second));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Rotate")) {
while (gs_effect_loop(effect.get_object(), "Rotate")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -479,19 +479,19 @@ std::shared_ptr<::gs::texture> gfx::blur::box_zoom::render()
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
// One Pass Blur
std::shared_ptr<::gs::effect> effect = _data->get_effect();
gs::effect effect = _data->get_effect();
if (effect) {
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), float_t(1.f / height));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pSizeInverseMul")->set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect->get_parameter("pCenter")->set_float2(float_t(_center.first), float_t(_center.second));
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), float_t(1.f / height));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pSizeInverseMul").set_float(float_t(1.0f / (float_t(_size) * 2.0f + 1.0f)));
effect.get_parameter("pCenter").set_float2(float_t(_center.first), float_t(_center.second));
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Zoom")) {
while (gs_effect_loop(effect.get_object(), "Zoom")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}

View file

@ -27,13 +27,13 @@
namespace gfx {
namespace blur {
class box_data {
std::shared_ptr<::gs::effect> _effect;
gs::effect _effect;
public:
box_data();
virtual ~box_data();
std::shared_ptr<::gs::effect> get_effect();
gs::effect get_effect();
};
class box_factory : public ::gfx::blur::ifactory {

View file

@ -56,7 +56,7 @@ gfx::blur::dual_filtering_data::dual_filtering_data()
auto gctx = gs::context();
try {
char* file = obs_module_file("effects/blur/dual-filtering.effect");
_effect = std::make_shared<::gs::effect>(file);
_effect = gs::effect::create(file);
bfree(file);
} catch (...) {
P_LOG_ERROR("<gfx::blur::box_linear> Failed to load _effect.");
@ -69,7 +69,7 @@ gfx::blur::dual_filtering_data::~dual_filtering_data()
_effect.reset();
}
std::shared_ptr<::gs::effect> gfx::blur::dual_filtering_data::get_effect()
gs::effect gfx::blur::dual_filtering_data::get_effect()
{
return _effect;
}
@ -264,15 +264,15 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render()
}
// Apply
effect->get_parameter("pImage")->set_texture(tex_cur);
effect->get_parameter("pImageSize")->set_float2(float_t(width), float_t(height));
effect->get_parameter("pImageTexel")->set_float2(1.0f / width, 1.0f / height);
effect->get_parameter("pImageHalfTexel")->set_float2(0.5f / width, 0.5f / height);
effect.get_parameter("pImage").set_texture(tex_cur);
effect.get_parameter("pImageSize").set_float2(float_t(width), float_t(height));
effect.get_parameter("pImageTexel").set_float2(1.0f / width, 1.0f / height);
effect.get_parameter("pImageHalfTexel").set_float2(0.5f / width, 0.5f / height);
{
auto op = _rendertargets[n]->render(width, height);
gs_ortho(0., 1., 0., 1., 0., 1.);
while (gs_effect_loop(effect->get_object(), "Down")) {
while (gs_effect_loop(effect.get_object(), "Down")) {
gs_draw_sprite(tex_cur->get_object(), 0, 1, 1);
}
}
@ -288,10 +288,10 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render()
uint32_t height = tex_cur->get_height();
// Apply
effect->get_parameter("pImage")->set_texture(tex_cur);
effect->get_parameter("pImageSize")->set_float2(float_t(width), float_t(height));
effect->get_parameter("pImageTexel")->set_float2(1.0f / width, 1.0f / height);
effect->get_parameter("pImageHalfTexel")->set_float2(0.5f / width, 0.5f / height);
effect.get_parameter("pImage").set_texture(tex_cur);
effect.get_parameter("pImageSize").set_float2(float_t(width), float_t(height));
effect.get_parameter("pImageTexel").set_float2(1.0f / width, 1.0f / height);
effect.get_parameter("pImageHalfTexel").set_float2(0.5f / width, 0.5f / height);
// Increase Size
width *= 2;
@ -300,7 +300,7 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render()
{
auto op = _rendertargets[n - 1]->render(width, height);
gs_ortho(0., 1., 0., 1., 0., 1.);
while (gs_effect_loop(effect->get_object(), "Up")) {
while (gs_effect_loop(effect.get_object(), "Up")) {
gs_draw_sprite(tex_cur->get_object(), 0, 1, 1);
}
}

View file

@ -28,13 +28,13 @@
namespace gfx {
namespace blur {
class dual_filtering_data {
std::shared_ptr<::gs::effect> _effect;
gs::effect _effect;
public:
dual_filtering_data();
virtual ~dual_filtering_data();
std::shared_ptr<::gs::effect> get_effect();
gs::effect get_effect();
};
class dual_filtering_factory : public ::gfx::blur::ifactory {

View file

@ -87,7 +87,7 @@ gfx::blur::gaussian_linear_data::~gaussian_linear_data()
_effect.reset();
}
std::shared_ptr<::gs::effect> gfx::blur::gaussian_linear_data::get_effect()
gs::effect gfx::blur::gaussian_linear_data::get_effect()
{
return _effect;
}
@ -293,8 +293,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -317,35 +317,35 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
if (_step_scale.first > std::numeric_limits<double_t>::epsilon()) {
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), 0.f);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f);
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
std::swap(_rendertarget, _rendertarget2);
effect->get_parameter("pImage")->set_texture(_rendertarget->get_texture());
effect.get_parameter("pImage").set_texture(_rendertarget->get_texture());
}
// Second Pass
if (_step_scale.second > std::numeric_limits<double_t>::epsilon()) {
effect->get_parameter("pImageTexel")->set_float2(0.f, float_t(1.f / height));
effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height));
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -386,8 +386,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear_directional::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -410,18 +410,18 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear_directional::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")
->set_float2(float_t(1.f / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel")
.set_float2(float_t(1.f / width * cos(_angle)), float_t(1.f / height * sin(_angle)));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}

View file

@ -26,14 +26,14 @@
namespace gfx {
namespace blur {
class gaussian_linear_data {
std::shared_ptr<::gs::effect> _effect;
gs::effect _effect;
std::vector<std::vector<float_t>> _kernels;
public:
gaussian_linear_data();
virtual ~gaussian_linear_data();
std::shared_ptr<::gs::effect> get_effect();
gs::effect get_effect();
std::vector<float_t> const& get_kernel(size_t width);
};

View file

@ -88,7 +88,7 @@ gfx::blur::gaussian_data::~gaussian_data()
_effect.reset();
}
std::shared_ptr<::gs::effect> gfx::blur::gaussian_data::get_effect()
gs::effect gfx::blur::gaussian_data::get_effect()
{
return _effect;
}
@ -299,8 +299,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -323,35 +323,35 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
if (_step_scale.first > std::numeric_limits<double_t>::epsilon()) {
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), 0.f);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), 0.f);
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
std::swap(_rendertarget, _rendertarget2);
effect->get_parameter("pImage")->set_texture(_rendertarget->get_texture());
effect.get_parameter("pImage").set_texture(_rendertarget->get_texture());
}
// Second Pass
if (_step_scale.second > std::numeric_limits<double_t>::epsilon()) {
effect->get_parameter("pImageTexel")->set_float2(0.f, float_t(1.f / height));
effect.get_parameter("pImageTexel").set_float2(0.f, float_t(1.f / height));
{
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -392,8 +392,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_directional::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -417,18 +417,18 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_directional::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")
->set_float2(float_t(1.f / width * cos(m_angle)), float_t(1.f / height * sin(m_angle)));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel")
.set_float2(float_t(1.f / width * cos(m_angle)), float_t(1.f / height * sin(m_angle)));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Draw")) {
while (gs_effect_loop(effect.get_object(), "Draw")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -447,8 +447,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_rotational::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -471,19 +471,19 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_rotational::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), float_t(1.f / height));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pAngle")->set_float(float_t(m_angle / _size));
effect->get_parameter("pCenter")->set_float2(float_t(m_center.first), float_t(m_center.second));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), float_t(1.f / height));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pAngle").set_float(float_t(m_angle / _size));
effect.get_parameter("pCenter").set_float2(float_t(m_center.first), float_t(m_center.second));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Rotate")) {
while (gs_effect_loop(effect.get_object(), "Rotate")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}
@ -524,8 +524,8 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_zoom::render()
{
auto gctx = gs::context();
std::shared_ptr<::gs::effect> effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
gs::effect effect = _data->get_effect();
auto kernel = _data->get_kernel(size_t(_size));
if (!effect || ((_step_scale.first + _step_scale.second) < std::numeric_limits<double_t>::epsilon())) {
return _input_texture;
@ -548,18 +548,18 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_zoom::render()
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
effect->get_parameter("pImage")->set_texture(_input_texture);
effect->get_parameter("pImageTexel")->set_float2(float_t(1.f / width), float_t(1.f / height));
effect->get_parameter("pStepScale")->set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect->get_parameter("pSize")->set_float(float_t(_size));
effect->get_parameter("pCenter")->set_float2(float_t(m_center.first), float_t(m_center.second));
effect->get_parameter("pKernel")->set_float_array(kernel.data(), MAX_KERNEL_SIZE);
effect.get_parameter("pImage").set_texture(_input_texture);
effect.get_parameter("pImageTexel").set_float2(float_t(1.f / width), float_t(1.f / height));
effect.get_parameter("pStepScale").set_float2(float_t(_step_scale.first), float_t(_step_scale.second));
effect.get_parameter("pSize").set_float(float_t(_size));
effect.get_parameter("pCenter").set_float2(float_t(m_center.first), float_t(m_center.second));
effect.get_parameter("pKernel").set_float_array(kernel.data(), MAX_KERNEL_SIZE);
// First Pass
{
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
gs_ortho(0, 1., 0, 1., 0, 1.);
while (gs_effect_loop(effect->get_object(), "Zoom")) {
while (gs_effect_loop(effect.get_object(), "Zoom")) {
gs_draw_sprite(nullptr, 0, 1, 1);
}
}

View file

@ -26,14 +26,14 @@
namespace gfx {
namespace blur {
class gaussian_data {
std::shared_ptr<::gs::effect> _effect;
gs::effect _effect;
std::vector<std::vector<float_t>> _kernels;
public:
gaussian_data();
virtual ~gaussian_data();
std::shared_ptr<::gs::effect> get_effect();
gs::effect get_effect();
std::vector<float_t> const& get_kernel(size_t width);
};

View file

@ -23,6 +23,7 @@
#include "gs-effect-pass.hpp"
#include <graphics/effect.h>
#include <graphics/vec2.h>
gs::effect_parameter::effect_parameter(gs_eparam_t* param)
: _effect_parent(nullptr), _pass_parent(nullptr), _param_parent(nullptr)
@ -129,3 +130,536 @@ bool gs::effect_parameter::has_annotation(std::string name, effect_parameter::ty
return eprm->get_type() == type;
return false;
}
void gs::effect_parameter::set_bool(bool v)
{
if (get_type() != type::Boolean)
throw std::bad_cast();
gs_effect_set_bool(get(), v);
}
void gs::effect_parameter::get_bool(bool& v)
{
if (get_type() != type::Boolean)
throw std::bad_cast();
void* ptr = gs_effect_get_val(get());
if (ptr) {
v = *reinterpret_cast<bool*>(ptr);
bfree(ptr);
} else {
v = false;
}
}
void gs::effect_parameter::get_default_bool(bool& v)
{
if (get_type() != type::Boolean)
throw std::bad_cast();
void* ptr = gs_effect_get_default_val(get());
if (ptr) {
v = *reinterpret_cast<bool*>(ptr);
bfree(ptr);
} else {
v = false;
}
}
void gs::effect_parameter::set_bool_array(bool v[], size_t sz)
{
if (get_type() != type::Boolean)
throw std::bad_cast();
gs_effect_set_val(get(), v, sz);
}
void gs::effect_parameter::set_float(float_t x)
{
if (get_type() != type::Float)
throw std::bad_cast();
gs_effect_set_float(get(), x);
}
void gs::effect_parameter::get_float(float_t& x)
{
if (get_type() != type::Float)
throw std::bad_cast();
void* ptr = gs_effect_get_val(get());
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
bfree(ptr);
} else {
x = 0;
}
}
void gs::effect_parameter::get_default_float(float_t& x)
{
if (get_type() != type::Float)
throw std::bad_cast();
void* ptr = gs_effect_get_default_val(get());
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
bfree(ptr);
} else {
x = 0;
}
}
void gs::effect_parameter::set_float2(vec2 const& v)
{
if (get_type() != type::Float2)
throw std::bad_cast();
gs_effect_set_vec2(get(), &v);
}
void gs::effect_parameter::get_float2(vec2& v)
{
get_float2(v.x, v.y);
}
void gs::effect_parameter::get_default_float2(vec2& v)
{
get_default_float2(v.x, v.y);
}
void gs::effect_parameter::set_float2(float_t x, float_t y)
{
vec2 data;
data.x = x;
data.y = y;
set_float2(data);
}
void gs::effect_parameter::get_float2(float_t& x, float_t& y)
{
if (get_type() != type::Float2)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
bfree(ptr);
} else {
x = y = 0;
}
}
void gs::effect_parameter::get_default_float2(float_t& x, float_t& y)
{
if (get_type() != type::Float2)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
bfree(ptr);
} else {
x = y = 0;
}
}
void gs::effect_parameter::set_float3(vec3 const& v)
{
if (get_type() != type::Float3)
throw std::bad_cast();
gs_effect_set_vec3(get(), &v);
}
void gs::effect_parameter::get_float3(vec3& v)
{
get_float3(v.x, v.y, v.z);
}
void gs::effect_parameter::get_default_float3(vec3& v)
{
get_default_float3(v.x, v.y, v.z);
}
void gs::effect_parameter::set_float3(float_t x, float_t y, float_t z)
{
if (get_type() != type::Float3)
throw std::bad_cast();
vec3 v = {{x, y, z, 0}};
gs_effect_set_vec3(get(), &v);
}
void gs::effect_parameter::get_float3(float_t& x, float_t& y, float_t& z)
{
if (get_type() != type::Float3)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
bfree(ptr);
} else {
x = y = z = 0;
}
}
void gs::effect_parameter::get_default_float3(float_t& x, float_t& y, float_t& z)
{
if (get_type() != type::Float3)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
bfree(ptr);
} else {
x = y = z = 0;
}
}
void gs::effect_parameter::set_float4(vec4 const& v)
{
if (get_type() != type::Float4)
throw std::bad_cast();
gs_effect_set_vec4(get(), &v);
}
void gs::effect_parameter::get_float4(vec4& v)
{
get_float4(v.x, v.y, v.z, v.w);
}
void gs::effect_parameter::get_default_float4(vec4& v)
{
get_default_float4(v.x, v.y, v.z, v.w);
}
void gs::effect_parameter::set_float4(float_t x, float_t y, float_t z, float_t w)
{
if (get_type() != type::Float4)
throw std::bad_cast();
vec4 v = {{x, y, z, w}};
gs_effect_set_vec4(get(), &v);
}
void gs::effect_parameter::get_float4(float_t& x, float_t& y, float_t& z, float_t& w)
{
if (get_type() != type::Float4)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
bfree(ptr);
} else {
x = y = z = w = 0;
}
}
void gs::effect_parameter::get_default_float4(float_t& x, float_t& y, float_t& z, float_t& w)
{
if (get_type() != type::Float4)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<float_t*>(ptr);
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
bfree(ptr);
} else {
x = y = z = w = 0;
}
}
void gs::effect_parameter::set_float_array(float_t v[], size_t sz)
{
if ((get_type() != type::Float) && (get_type() != type::Float2) && (get_type() != type::Float3)
&& (get_type() != type::Float4))
throw std::bad_cast();
gs_effect_set_val(get(), v, sizeof(float_t) * sz);
}
void gs::effect_parameter::set_int(int32_t x)
{
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
throw std::bad_cast();
gs_effect_set_int(get(), x);
}
void gs::effect_parameter::get_int(int32_t& x)
{
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
bfree(ptr);
} else {
x = 0;
}
}
void gs::effect_parameter::get_default_int(int32_t& x)
{
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
bfree(ptr);
} else {
x = 0;
}
}
void gs::effect_parameter::set_int2(int32_t x, int32_t y)
{
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
throw std::bad_cast();
int32_t v[2] = {x, y};
gs_effect_set_val(get(), v, sizeof(int) * 2);
}
void gs::effect_parameter::get_int2(int32_t& x, int32_t& y)
{
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
bfree(ptr);
} else {
x = y = 0;
}
}
void gs::effect_parameter::get_default_int2(int32_t& x, int32_t& y)
{
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
bfree(ptr);
} else {
x = y = 0;
}
}
void gs::effect_parameter::set_int3(int32_t x, int32_t y, int32_t z)
{
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
throw std::bad_cast();
int32_t v[3] = {x, y, z};
gs_effect_set_val(get(), v, sizeof(int) * 3);
}
void gs::effect_parameter::get_int3(int32_t& x, int32_t& y, int32_t& z)
{
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
bfree(ptr);
} else {
x = y = z = 0;
}
}
void gs::effect_parameter::get_default_int3(int32_t& x, int32_t& y, int32_t& z)
{
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
bfree(ptr);
} else {
x = y = z = 0;
}
}
void gs::effect_parameter::set_int4(int32_t x, int32_t y, int32_t z, int32_t w)
{
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
throw std::bad_cast();
int32_t v[4] = {x, y, z, w};
gs_effect_set_val(get(), v, sizeof(int) * 4);
}
void gs::effect_parameter::get_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w)
{
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
w = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 3);
bfree(ptr);
} else {
x = y = z = w = 0;
}
}
void gs::effect_parameter::get_default_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w)
{
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
x = *reinterpret_cast<int32_t*>(ptr);
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
w = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 3);
bfree(ptr);
} else {
x = y = z = w = 0;
}
}
void gs::effect_parameter::set_int_array(int32_t v[], size_t sz)
{
if ((get_type() != type::Integer) && (get_type() != type::Integer2) && (get_type() != type::Integer3)
&& (get_type() != type::Integer4) && (get_type() != type::Unknown))
throw std::bad_cast();
gs_effect_set_val(get(), v, sizeof(int) * sz);
}
void gs::effect_parameter::set_matrix(matrix4 const& v)
{
if (get_type() != type::Matrix)
throw std::bad_cast();
gs_effect_set_matrix4(get(), &v);
}
void gs::effect_parameter::get_matrix(matrix4& v)
{
if (get_type() != type::Matrix)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
v.x.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 0);
v.x.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 1);
v.x.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
v.x.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
v.y.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 4);
v.y.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 5);
v.y.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 6);
v.y.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 7);
v.z.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 8);
v.z.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 9);
v.z.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 10);
v.z.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 11);
v.t.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 12);
v.t.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 13);
v.t.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 14);
v.t.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 15);
bfree(ptr);
} else {
v.x = vec4{};
v.y = vec4{};
v.z = vec4{};
v.t = vec4{};
}
}
void gs::effect_parameter::get_default_matrix(matrix4& v)
{
if (get_type() != type::Matrix)
throw std::bad_cast();
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
v.x.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 0);
v.x.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 1);
v.x.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
v.x.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
v.y.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 4);
v.y.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 5);
v.y.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 6);
v.y.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 7);
v.z.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 8);
v.z.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 9);
v.z.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 10);
v.z.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 11);
v.t.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 12);
v.t.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 13);
v.t.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 14);
v.t.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 15);
bfree(ptr);
} else {
v.x = vec4{};
v.y = vec4{};
v.z = vec4{};
v.t = vec4{};
}
}
void gs::effect_parameter::set_texture(std::shared_ptr<gs::texture> v)
{
if (get_type() != type::Texture)
throw std::bad_cast();
gs_effect_set_texture(get(), v->get_object());
}
void gs::effect_parameter::set_texture(gs_texture_t* v)
{
if (get_type() != type::Texture)
throw std::bad_cast();
gs_effect_set_texture(get(), v);
}
void gs::effect_parameter::set_sampler(std::shared_ptr<gs::sampler> v)
{
if (get_type() != type::Texture)
throw std::bad_cast();
gs_effect_set_next_sampler(get(), v->get_object());
}
void gs::effect_parameter::set_sampler(gs_sampler_state* v)
{
if (get_type() != type::Texture)
throw std::bad_cast();
gs_effect_set_next_sampler(get(), v);
}
void gs::effect_parameter::set_string(std::string const& v)
{
if (get_type() != type::String)
throw std::bad_cast();
gs_effect_set_val(get(), v.c_str(), v.length());
}
void gs::effect_parameter::get_string(std::string& v)
{
if (get_type() != type::String)
throw std::bad_cast();
size_t ptr_len = gs_effect_get_val_size(get());
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(get()));
if (ptr) {
v = std::string(ptr, ptr + ptr_len - 1);
bfree(ptr);
} else {
v = "";
}
}
void gs::effect_parameter::get_default_string(std::string& v)
{
if (get_type() != type::String)
throw std::bad_cast();
size_t ptr_len = gs_effect_get_default_val_size(get());
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(get()));
if (ptr) {
v = std::string(ptr, ptr + ptr_len - 1);
bfree(ptr);
} else {
v = "";
}
}

View file

@ -21,11 +21,24 @@
#include <cinttypes>
#include <memory>
#include <string>
#include "gs-sampler.hpp"
#include "gs-texture.hpp"
// OBS
extern "C" {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <graphics/graphics.h>
#include <graphics/matrix4.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
namespace gs {
class effect_parameter : protected std::shared_ptr<gs_eparam_t> {
class effect_parameter : public std::shared_ptr<gs_eparam_t> {
std::shared_ptr<gs_effect_t>* _effect_parent;
std::shared_ptr<gs_epass_t>* _pass_parent;
std::shared_ptr<gs_eparam_t>* _param_parent;
@ -65,5 +78,176 @@ namespace gs {
std::shared_ptr<effect_parameter> get_annotation(std::string name);
bool has_annotation(std::string name);
bool has_annotation(std::string name, effect_parameter::type type);
public /*value*/:
void set_bool(bool v);
void get_bool(bool& v);
void get_default_bool(bool& v);
void set_bool_array(bool v[], size_t sz);
void set_float(float_t x);
void get_float(float_t& x);
void get_default_float(float_t& x);
void set_float2(vec2 const& v);
void get_float2(vec2& v);
void get_default_float2(vec2& v);
void set_float2(float_t x, float_t y);
void get_float2(float_t& x, float_t& y);
void get_default_float2(float_t& x, float_t& y);
void set_float3(vec3 const& v);
void get_float3(vec3& v);
void get_default_float3(vec3& v);
void set_float3(float_t x, float_t y, float_t z);
void get_float3(float_t& x, float_t& y, float_t& z);
void get_default_float3(float_t& x, float_t& y, float_t& z);
void set_float4(vec4 const& v);
void get_float4(vec4& v);
void get_default_float4(vec4& v);
void set_float4(float_t x, float_t y, float_t z, float_t w);
void get_float4(float_t& x, float_t& y, float_t& z, float_t& w);
void get_default_float4(float_t& x, float_t& y, float_t& z, float_t& w);
void set_float_array(float_t v[], size_t sz);
void set_int(int32_t x);
void get_int(int32_t& x);
void get_default_int(int32_t& x);
void set_int2(int32_t x, int32_t y);
void get_int2(int32_t& x, int32_t& y);
void get_default_int2(int32_t& x, int32_t& y);
void set_int3(int32_t x, int32_t y, int32_t z);
void get_int3(int32_t& x, int32_t& y, int32_t& z);
void get_default_int3(int32_t& x, int32_t& y, int32_t& z);
void set_int4(int32_t x, int32_t y, int32_t z, int32_t w);
void get_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w);
void get_default_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w);
void set_int_array(int32_t v[], size_t sz);
void set_matrix(matrix4 const& v);
void get_matrix(matrix4& v);
void get_default_matrix(matrix4& v);
void set_texture(std::shared_ptr<gs::texture> v);
void set_texture(gs_texture_t* v);
void set_sampler(std::shared_ptr<gs::sampler> v);
void set_sampler(gs_sampler_state* v);
void set_string(std::string const& v);
void get_string(std::string& v);
void get_default_string(std::string& v);
public /* Helpers */:
inline float_t get_bool()
{
bool v;
get_bool(v);
return v;
};
inline bool get_default_bool()
{
bool v;
get_default_bool(v);
return v;
};
inline float_t get_float()
{
float_t v;
get_float(v);
return v;
};
inline float_t get_default_float()
{
float_t v;
get_default_float(v);
return v;
};
inline vec2 get_float2()
{
vec2 v;
get_float2(v);
return v;
};
inline vec2 get_default_float2()
{
vec2 v;
get_default_float2(v);
return v;
};
inline vec3 get_float3()
{
vec3 v;
get_float3(v);
return v;
};
inline vec3 get_default_float3()
{
vec3 v;
get_default_float3(v);
return v;
};
inline vec4 get_float4()
{
vec4 v;
get_float4(v);
return v;
};
inline vec4 get_default_float4()
{
vec4 v;
get_default_float4(v);
return v;
};
inline int32_t get_int()
{
int32_t v;
get_int(v);
return v;
};
inline int32_t get_default_int()
{
int32_t v;
get_default_int(v);
return v;
};
inline matrix4 get_matrix()
{
matrix4 v;
get_matrix(v);
return v;
};
inline matrix4 get_default_matrix()
{
matrix4 v;
get_default_matrix(v);
return v;
};
inline std::string get_string()
{
std::string v;
get_string(v);
return v;
};
inline std::string get_default_string()
{
std::string v;
get_default_string(v);
return v;
};
};
} // namespace gs

View file

@ -22,10 +22,20 @@
#include <memory>
#include <string>
// OBS
extern "C" {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <graphics/graphics.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
namespace gs {
class effect_pass : protected std::shared_ptr<gs_epass_t> {
class effect_pass : public std::shared_ptr<gs_epass_t> {
std::shared_ptr<gs_technique_t>* _parent;
public:

View file

@ -63,10 +63,7 @@ gs::effect_pass gs::effect_technique::get_pass(std::string name)
bool gs::effect_technique::has_pass(std::string name)
{
for (size_t idx = 0; idx < get()->passes.num; idx++) {
auto ptr = get()->passes.array + idx;
if (strcmp(ptr->name, name.c_str()) == 0)
return true;
}
if (get_pass(name) != nullptr)
return true;
return false;
}

View file

@ -23,10 +23,20 @@
#include <string>
#include "gs-effect-pass.hpp"
// OBS
extern "C" {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <graphics/graphics.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
namespace gs {
class effect_technique : protected std::shared_ptr<gs_technique_t> {
class effect_technique : public std::shared_ptr<gs_technique_t> {
std::shared_ptr<gs_effect_t>* _parent;
public:
@ -35,10 +45,9 @@ namespace gs {
std::string name();
size_t count_passes();
size_t count_passes();
gs::effect_pass get_pass(size_t idx);
gs::effect_pass get_pass(std::string name);
bool has_pass(std::string name);
bool has_pass(std::string name);
};
} // namespace gs

View file

@ -34,8 +34,7 @@
#pragma warning(pop)
#endif
//#define OBS_LOAD_EFFECT_FILE
#define MAX_EFFECT_SIZE 32 * 1024 * 1024;
#define MAX_EFFECT_SIZE 32 * 1024 * 1024
static std::string load_file_as_code(std::filesystem::path file)
{

View file

@ -26,9 +26,22 @@
#include "gs-effect-parameter.hpp"
#include "gs-effect-technique.hpp"
// OBS
extern "C" {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <graphics/graphics.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
namespace gs {
class effect : private std::shared_ptr<gs_effect_t> {
class effect : public std::shared_ptr<gs_effect_t> {
public:
effect() {};
effect(std::string code, std::string name);
effect(std::filesystem::path file);
~effect();

View file

@ -110,7 +110,7 @@ gs::mipmapper::mipmapper()
_vb->update();
char* effect_file = obs_module_file("effects/mipgen.effect");
_effect = std::make_unique<gs::effect>(effect_file);
_effect = gs::effect::create(effect_file);
bfree(effect_file);
}
@ -253,12 +253,12 @@ void gs::mipmapper::rebuild(std::shared_ptr<gs::texture> source, std::shared_ptr
vec4_zero(&black);
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &black, 0, 0);
_effect->get_parameter("image")->set_texture(target);
_effect->get_parameter("level")->set_int(int32_t(mip - 1));
_effect->get_parameter("imageTexel")->set_float2(texel_width, texel_height);
_effect->get_parameter("strength")->set_float(strength);
_effect.get_parameter("image").set_texture(target);
_effect.get_parameter("level").set_int(int32_t(mip - 1));
_effect.get_parameter("imageTexel").set_float2(texel_width, texel_height);
_effect.get_parameter("strength").set_float(strength);
while (gs_effect_loop(_effect->get_object(), technique.c_str())) {
while (gs_effect_loop(_effect.get_object(), technique.c_str())) {
gs_draw(gs_draw_mode::GS_TRIS, 0, _vb->size());
}
} catch (...) {

View file

@ -37,7 +37,7 @@ namespace gs {
class mipmapper {
std::unique_ptr<gs::vertex_buffer> _vb;
std::unique_ptr<gs::rendertarget> _rt;
std::unique_ptr<gs::effect> _effect;
gs::effect _effect;
public:
enum class generator : uint8_t {