From 8aa8745a3acda37e0ecf56578f4b88fe93804cdf Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 28 Nov 2022 09:11:55 +0100 Subject: [PATCH] gfx/util: Move draw_fullscreen_triangle here for consistency --- source/filters/filter-blur.cpp | 5 +-- source/filters/filter-blur.hpp | 4 ++- source/filters/filter-color-grade.cpp | 16 +++++----- source/filters/filter-color-grade.hpp | 3 +- source/filters/filter-dynamic-mask.cpp | 3 +- source/filters/filter-dynamic-mask.hpp | 2 ++ source/filters/filter-sdf-effects.cpp | 30 +++++++++--------- source/filters/filter-sdf-effects.hpp | 6 ++-- source/filters/filter-transform.cpp | 8 ++--- source/filters/filter-transform.hpp | 3 ++ source/gfx/blur/gfx-blur-box-linear.cpp | 13 +++++--- source/gfx/blur/gfx-blur-box-linear.hpp | 6 +++- source/gfx/blur/gfx-blur-box.cpp | 15 ++++++--- source/gfx/blur/gfx-blur-box.hpp | 6 +++- source/gfx/blur/gfx-blur-dual-filtering.cpp | 11 +++++-- source/gfx/blur/gfx-blur-dual-filtering.hpp | 6 +++- source/gfx/blur/gfx-blur-gaussian-linear.cpp | 13 +++++--- source/gfx/blur/gfx-blur-gaussian-linear.hpp | 8 +++-- source/gfx/blur/gfx-blur-gaussian.cpp | 18 +++++++---- source/gfx/blur/gfx-blur-gaussian.hpp | 4 +++ source/gfx/gfx-util.cpp | 28 +++++++++++++++++ source/gfx/gfx-util.hpp | 4 +++ source/gfx/lut/gfx-lut-producer.cpp | 4 +-- source/gfx/lut/gfx-lut-producer.hpp | 2 ++ source/gfx/shader/gfx-shader.cpp | 4 +-- source/gfx/shader/gfx-shader.hpp | 3 ++ source/obs/gs/gs-mipmapper.cpp | 4 +-- source/obs/gs/gs-mipmapper.hpp | 2 ++ source/plugin.cpp | 33 -------------------- source/plugin.hpp | 2 -- 30 files changed, 165 insertions(+), 101 deletions(-) diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index 4250585d..ad3059a4 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -140,7 +140,8 @@ static std::map list_of_subtypes = { }; blur_instance::blur_instance(obs_data_t* settings, obs_source_t* self) - : obs::source_instance(settings, self), _source_rendered(false), _output_rendered(false) + : obs::source_instance(settings, self), _gfx_util(::streamfx::gfx::util::get()), _source_rendered(false), + _output_rendered(false) { { auto gctx = streamfx::obs::gs::context(); @@ -546,7 +547,7 @@ void blur_instance::video_render(gs_effect_t* effect) // Render while (gs_effect_loop(_effect_mask.get_object(), technique.c_str())) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } catch (const std::exception&) { gs_blend_state_pop(); diff --git a/source/filters/filter-blur.hpp b/source/filters/filter-blur.hpp index f2ee74f9..81292f74 100644 --- a/source/filters/filter-blur.hpp +++ b/source/filters/filter-blur.hpp @@ -21,6 +21,7 @@ #include "common.hpp" #include "gfx/blur/gfx-blur-base.hpp" #include "gfx/gfx-source-texture.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-rendertarget.hpp" @@ -43,7 +44,8 @@ namespace streamfx::filter::blur { class blur_instance : public obs::source_instance { // Effects - streamfx::obs::gs::effect _effect_mask; + streamfx::obs::gs::effect _effect_mask; + std::shared_ptr _gfx_util; // Input std::shared_ptr _source_rt; diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 9bdf929f..c919c788 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -19,6 +19,7 @@ #include "filter-color-grade.hpp" #include "strings.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-helper.hpp" #include "util/util-logging.hpp" @@ -128,10 +129,11 @@ static constexpr std::string_view HELP_URL = "https://github.com/Xaymar/obs-Stre color_grade_instance::~color_grade_instance() {} color_grade_instance::color_grade_instance(obs_data_t* data, obs_source_t* self) - : obs::source_instance(data, self), _effect(), _lift(), _gamma(), _gain(), _offset(), _tint_detection(), - _tint_luma(), _tint_exponent(), _tint_low(), _tint_mid(), _tint_hig(), _correction(), _lut_enabled(true), - _lut_depth(), _ccache_rt(), _ccache_texture(), _ccache_fresh(false), _lut_initialized(false), _lut_dirty(true), - _lut_producer(), _lut_consumer(), _lut_rt(), _lut_texture(), _cache_rt(), _cache_texture(), _cache_fresh(false) + : obs::source_instance(data, self), _effect(), _gfx_util(::streamfx::gfx::util::get()), _lift(), _gamma(), _gain(), + _offset(), _tint_detection(), _tint_luma(), _tint_exponent(), _tint_low(), _tint_mid(), _tint_hig(), + _correction(), _lut_enabled(true), _lut_depth(), _ccache_rt(), _ccache_texture(), _ccache_fresh(false), + _lut_initialized(false), _lut_dirty(true), _lut_producer(), _lut_consumer(), _lut_rt(), _lut_texture(), + _cache_rt(), _cache_texture(), _cache_fresh(false) { { auto gctx = streamfx::obs::gs::context(); @@ -330,7 +332,7 @@ void color_grade_instance::rebuild_lut() gs_enable_stencil_write(false); while (gs_effect_loop(_effect.get_object(), "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } gs_blend_state_pop(); @@ -479,7 +481,7 @@ void color_grade_instance::video_render(gs_effect_t* shader) auto effect = _lut_consumer->prepare(_lut_depth, _lut_texture); effect->get_parameter("image").set_texture(_ccache_texture); while (gs_effect_loop(effect->get_object(), "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } // Restore original blend mode. @@ -538,7 +540,7 @@ void color_grade_instance::video_render(gs_effect_t* shader) // Render the effect. _effect.get_parameter("image").set_texture(_ccache_texture); while (gs_effect_loop(_effect.get_object(), "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } // Restore original blend mode. diff --git a/source/filters/filter-color-grade.hpp b/source/filters/filter-color-grade.hpp index fcdc887d..8a6f4011 100644 --- a/source/filters/filter-color-grade.hpp +++ b/source/filters/filter-color-grade.hpp @@ -48,7 +48,8 @@ namespace streamfx::filter::color_grade { }; class color_grade_instance : public obs::source_instance { - streamfx::obs::gs::effect _effect; + streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; // User Configuration vec4 _lift; diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 2f6f0d49..d53f0ae1 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -111,6 +111,7 @@ std::shared_ptr data::get() dynamic_mask_instance::dynamic_mask_instance(obs_data_t* settings, obs_source_t* self) : obs::source_instance(settings, self), // _data(streamfx::filter::dynamic_mask::data::get()), // + _gfx_util(::streamfx::gfx::util::get()), // _translation_map(), // _input(), // _input_child(), // @@ -544,7 +545,7 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect) effect.get_parameter("pMaskMultiplier").set_float4(_precalc.scale); while (gs_effect_loop(effect.get(), "Mask")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } // Pop the old blend state. diff --git a/source/filters/filter-dynamic-mask.hpp b/source/filters/filter-dynamic-mask.hpp index 49610b18..5e6bda96 100644 --- a/source/filters/filter-dynamic-mask.hpp +++ b/source/filters/filter-dynamic-mask.hpp @@ -20,6 +20,7 @@ #pragma once #include "common.hpp" #include "gfx/gfx-source-texture.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/obs-source-active-child.hpp" #include "obs/obs-source-active-reference.hpp" @@ -54,6 +55,7 @@ namespace streamfx::filter::dynamic_mask { class dynamic_mask_instance : public obs::source_instance { std::shared_ptr _data; + std::shared_ptr _gfx_util; std::map, std::string> _translation_map; diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index 3b73af7f..945146b9 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -118,14 +118,14 @@ using namespace streamfx::filter::sdf_effects; static constexpr std::string_view HELP_URL = "https://github.com/Xaymar/obs-StreamFX/wiki/Filter-SDF-Effects"; sdf_effects_instance::sdf_effects_instance(obs_data_t* settings, obs_source_t* self) - : obs::source_instance(settings, self), _source_rendered(false), _sdf_scale(1.0), _sdf_threshold(), - _output_rendered(false), _inner_shadow(false), _inner_shadow_color(), _inner_shadow_range_min(), - _inner_shadow_range_max(), _inner_shadow_offset_x(), _inner_shadow_offset_y(), _outer_shadow(false), - _outer_shadow_color(), _outer_shadow_range_min(), _outer_shadow_range_max(), _outer_shadow_offset_x(), - _outer_shadow_offset_y(), _inner_glow(false), _inner_glow_color(), _inner_glow_width(), _inner_glow_sharpness(), - _inner_glow_sharpness_inv(), _outer_glow(false), _outer_glow_color(), _outer_glow_width(), - _outer_glow_sharpness(), _outer_glow_sharpness_inv(), _outline(false), _outline_color(), _outline_width(), - _outline_offset(), _outline_sharpness(), _outline_sharpness_inv() + : obs::source_instance(settings, self), _gfx_util(::streamfx::gfx::util::get()), _source_rendered(false), + _sdf_scale(1.0), _sdf_threshold(), _output_rendered(false), _inner_shadow(false), _inner_shadow_color(), + _inner_shadow_range_min(), _inner_shadow_range_max(), _inner_shadow_offset_x(), _inner_shadow_offset_y(), + _outer_shadow(false), _outer_shadow_color(), _outer_shadow_range_min(), _outer_shadow_range_max(), + _outer_shadow_offset_x(), _outer_shadow_offset_y(), _inner_glow(false), _inner_glow_color(), _inner_glow_width(), + _inner_glow_sharpness(), _inner_glow_sharpness_inv(), _outer_glow(false), _outer_glow_color(), + _outer_glow_width(), _outer_glow_sharpness(), _outer_glow_sharpness_inv(), _outline(false), _outline_color(), + _outline_width(), _outline_offset(), _outline_sharpness(), _outline_sharpness_inv() { { auto gctx = streamfx::obs::gs::context(); @@ -412,7 +412,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_producer_effect.get_parameter("_threshold").set_float(_sdf_threshold); while (gs_effect_loop(_sdf_producer_effect.get_object(), "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } std::swap(_sdf_read, _sdf_write); @@ -470,7 +470,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) gs_effect_set_texture(param, _output_texture->get_object()); } while (gs_effect_loop(default_effect, "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } gs_enable_blending(true); @@ -485,7 +485,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_consumer_effect.get_parameter("pShadowOffset") .set_float2(_outer_shadow_offset_x / float_t(baseW), _outer_shadow_offset_y / float_t(baseH)); while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowOuter")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } if (_inner_shadow) { @@ -498,7 +498,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_consumer_effect.get_parameter("pShadowOffset") .set_float2(_inner_shadow_offset_x / float_t(baseW), _inner_shadow_offset_y / float_t(baseH)); while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowInner")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } if (_outer_glow) { @@ -510,7 +510,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(_outer_glow_sharpness); _sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(_outer_glow_sharpness_inv); while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowOuter")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } if (_inner_glow) { @@ -522,7 +522,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(_inner_glow_sharpness); _sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(_inner_glow_sharpness_inv); while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowInner")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } if (_outline) { @@ -535,7 +535,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) _sdf_consumer_effect.get_parameter("pOutlineSharpness").set_float(_outline_sharpness); _sdf_consumer_effect.get_parameter("pOutlineSharpnessInverse").set_float(_outline_sharpness_inv); while (gs_effect_loop(_sdf_consumer_effect.get_object(), "Outline")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } } catch (...) { diff --git a/source/filters/filter-sdf-effects.hpp b/source/filters/filter-sdf-effects.hpp index 3abc8b1b..084716ca 100644 --- a/source/filters/filter-sdf-effects.hpp +++ b/source/filters/filter-sdf-effects.hpp @@ -19,6 +19,7 @@ #pragma once #include "common.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-sampler.hpp" @@ -28,8 +29,9 @@ namespace streamfx::filter::sdf_effects { class sdf_effects_instance : public obs::source_instance { - streamfx::obs::gs::effect _sdf_producer_effect; - streamfx::obs::gs::effect _sdf_consumer_effect; + streamfx::obs::gs::effect _sdf_producer_effect; + streamfx::obs::gs::effect _sdf_consumer_effect; + std::shared_ptr _gfx_util; // Input std::shared_ptr _source_rt; diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index ac61f74a..1af38f9a 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -108,9 +108,9 @@ enum RotationOrder : int64_t { }; transform_instance::transform_instance(obs_data_t* data, obs_source_t* context) - : obs::source_instance(data, context), _camera_mode(), _camera_fov(), _params(), _corners(), _standard_effect(), - _transform_effect(), _sampler(), _cache_rendered(), _mipmap_enabled(), _source_rendered(), _source_size(), - _update_mesh(true) + : obs::source_instance(data, context), _gfx_util(::streamfx::gfx::util::get()), _camera_mode(), _camera_fov(), + _params(), _corners(), _standard_effect(), _transform_effect(), _sampler(), _cache_rendered(), _mipmap_enabled(), + _source_rendered(), _source_size(), _update_mesh(true) { { auto gctx = obs::gs::context(); @@ -565,7 +565,7 @@ void transform_instance::video_render(gs_effect_t* effect) v.set_float2(_corners.br); } while (gs_effect_loop(_transform_effect.get_object(), "CornerPin")) { - ::streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } } diff --git a/source/filters/filter-transform.hpp b/source/filters/filter-transform.hpp index 3d3f46b0..ccac8d5a 100644 --- a/source/filters/filter-transform.hpp +++ b/source/filters/filter-transform.hpp @@ -19,6 +19,7 @@ #pragma once #include "common.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-mipmapper.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -37,6 +38,8 @@ namespace streamfx::filter::transform { }; class transform_instance : public obs::source_instance { + std::shared_ptr _gfx_util; + // Settings transform_mode _camera_mode; float _camera_fov; diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index 59f5306a..efd98f3f 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -28,7 +28,7 @@ #define ST_MAX_BLUR_SIZE 128 // Also change this in box-linear.effect if modified. -streamfx::gfx::blur::box_linear_data::box_linear_data() +streamfx::gfx::blur::box_linear_data::box_linear_data() : _gfx_util(::streamfx::gfx::util::get()) { auto gctx = streamfx::obs::gs::context(); { @@ -47,6 +47,11 @@ streamfx::gfx::blur::box_linear_data::~box_linear_data() _effect.reset(); } +std::shared_ptr streamfx::gfx::blur::box_linear_data::get_gfx_util() +{ + return _gfx_util; +} + streamfx::obs::gs::effect streamfx::gfx::blur::box_linear_data::get_effect() { return _effect; @@ -279,7 +284,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_linear::r 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -295,7 +300,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_linear::r 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } @@ -366,7 +371,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_linear_di 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } diff --git a/source/gfx/blur/gfx-blur-box-linear.hpp b/source/gfx/blur/gfx-blur-box-linear.hpp index 031604ed..f2416ee9 100644 --- a/source/gfx/blur/gfx-blur-box-linear.hpp +++ b/source/gfx/blur/gfx-blur-box-linear.hpp @@ -18,6 +18,7 @@ #pragma once #include "common.hpp" #include "gfx-blur-base.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -29,12 +30,15 @@ namespace streamfx::gfx { namespace blur { class box_linear_data { - streamfx::obs::gs::effect _effect; + streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; public: box_linear_data(); virtual ~box_linear_data(); + std::shared_ptr get_gfx_util(); + streamfx::obs::gs::effect get_effect(); }; diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index 369c68c4..415e9e4c 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -47,6 +47,11 @@ streamfx::gfx::blur::box_data::~box_data() _effect.reset(); } +std::shared_ptr streamfx::gfx::blur::box_data::get_gfx_util() +{ + return _gfx_util; +} + streamfx::obs::gs::effect streamfx::gfx::blur::box_data::get_effect() { return _effect; @@ -289,7 +294,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box::render() 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -305,7 +310,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box::render() 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } @@ -375,7 +380,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_direction 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } @@ -451,7 +456,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_rotationa 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } @@ -516,7 +521,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::box_zoom::ren 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } diff --git a/source/gfx/blur/gfx-blur-box.hpp b/source/gfx/blur/gfx-blur-box.hpp index 6e489ace..d353c0e0 100644 --- a/source/gfx/blur/gfx-blur-box.hpp +++ b/source/gfx/blur/gfx-blur-box.hpp @@ -18,6 +18,7 @@ #pragma once #include "common.hpp" #include "gfx-blur-base.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -29,12 +30,15 @@ namespace streamfx::gfx { namespace blur { class box_data { - streamfx::obs::gs::effect _effect; + streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; public: box_data(); virtual ~box_data(); + std::shared_ptr get_gfx_util(); + streamfx::obs::gs::effect get_effect(); }; diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index 40ae3dba..402d441d 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -45,7 +45,7 @@ #define ST_MAX_LEVELS 16 -streamfx::gfx::blur::dual_filtering_data::dual_filtering_data() +streamfx::gfx::blur::dual_filtering_data::dual_filtering_data() : _gfx_util(::streamfx::gfx::util::get()) { auto gctx = streamfx::obs::gs::context(); { @@ -64,6 +64,11 @@ streamfx::gfx::blur::dual_filtering_data::~dual_filtering_data() _effect.reset(); } +std::shared_ptr streamfx::gfx::blur::dual_filtering_data::get_gfx_util() +{ + return _gfx_util; +} + streamfx::obs::gs::effect streamfx::gfx::blur::dual_filtering_data::get_effect() { return _effect; @@ -281,7 +286,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::dual_filterin auto op = _rts[n]->render(owidth, oheight); gs_ortho(0., 1., 0., 1., 0., 1.); while (gs_effect_loop(effect.get_object(), "Down")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } @@ -311,7 +316,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::dual_filterin auto op = _rts[n - 1]->render(owidth, oheight); gs_ortho(0., 1., 0., 1., 0., 1.); while (gs_effect_loop(effect.get_object(), "Up")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } } diff --git a/source/gfx/blur/gfx-blur-dual-filtering.hpp b/source/gfx/blur/gfx-blur-dual-filtering.hpp index 2afb8942..fa262698 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.hpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.hpp @@ -18,6 +18,7 @@ #pragma once #include "common.hpp" #include "gfx-blur-base.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -30,12 +31,15 @@ namespace streamfx::gfx { namespace blur { class dual_filtering_data { - streamfx::obs::gs::effect _effect; + streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; public: dual_filtering_data(); virtual ~dual_filtering_data(); + std::shared_ptr get_gfx_util(); + streamfx::obs::gs::effect get_effect(); }; diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index d9a11312..dadaddbc 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -34,7 +34,7 @@ #define ST_SEARCH_EXTENSION 1 #define ST_SEARCH_RANGE ST_MAX_KERNEL_SIZE * 2 -streamfx::gfx::blur::gaussian_linear_data::gaussian_linear_data() +streamfx::gfx::blur::gaussian_linear_data::gaussian_linear_data() : _gfx_util(::streamfx::gfx::util::get()) { { auto gctx = streamfx::obs::gs::context(); @@ -101,6 +101,11 @@ std::vector const& streamfx::gfx::blur::gaussian_linear_data::get_kerne return _kernels[width]; } +std::shared_ptr streamfx::gfx::blur::gaussian_linear_data::get_gfx_util() +{ + return _gfx_util; +} + streamfx::gfx::blur::gaussian_linear_factory::gaussian_linear_factory() {} streamfx::gfx::blur::gaussian_linear_factory::~gaussian_linear_factory() {} @@ -337,7 +342,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_line 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -357,7 +362,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_line 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -438,7 +443,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_line 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.hpp b/source/gfx/blur/gfx-blur-gaussian-linear.hpp index e3f356d0..b849c443 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.hpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.hpp @@ -18,6 +18,7 @@ #pragma once #include "common.hpp" #include "gfx-blur-base.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -30,13 +31,16 @@ namespace streamfx::gfx { namespace blur { class gaussian_linear_data { - streamfx::obs::gs::effect _effect; - std::vector> _kernels; + streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; + std::vector> _kernels; public: gaussian_linear_data(); virtual ~gaussian_linear_data(); + std::shared_ptr get_gfx_util(); + streamfx::obs::gs::effect get_effect(); std::vector const& get_kernel(std::size_t width); diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index 6cc447a6..e18bdf53 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -17,6 +17,7 @@ #include "gfx-blur-gaussian.hpp" #include "common.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" @@ -31,7 +32,7 @@ #define ST_OVERSAMPLE_MULTIPLIER 2 #define ST_MAX_BLUR_SIZE ST_KERNEL_SIZE / ST_OVERSAMPLE_MULTIPLIER -streamfx::gfx::blur::gaussian_data::gaussian_data() +streamfx::gfx::blur::gaussian_data::gaussian_data() : _gfx_util(::streamfx::gfx::util::get()) { using namespace streamfx::util; @@ -114,6 +115,11 @@ streamfx::obs::gs::effect streamfx::gfx::blur::gaussian_data::get_effect() return _effect; } +std::shared_ptr streamfx::gfx::blur::gaussian_data::get_gfx_util() +{ + return _gfx_util; +} + std::vector const& streamfx::gfx::blur::gaussian_data::get_kernel(std::size_t width) { width = std::clamp(width, 1, ST_MAX_BLUR_SIZE); @@ -364,7 +370,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian::ren 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -384,7 +390,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian::ren 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -464,7 +470,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_dire 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -524,7 +530,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_rota 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } @@ -604,7 +610,7 @@ std::shared_ptr<::streamfx::obs::gs::texture> streamfx::gfx::blur::gaussian_zoom 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")) { - streamfx::gs_draw_fullscreen_tri(); + _data->get_gfx_util()->draw_fullscreen_triangle(); } } diff --git a/source/gfx/blur/gfx-blur-gaussian.hpp b/source/gfx/blur/gfx-blur-gaussian.hpp index 07ae8477..baea366f 100644 --- a/source/gfx/blur/gfx-blur-gaussian.hpp +++ b/source/gfx/blur/gfx-blur-gaussian.hpp @@ -18,6 +18,7 @@ #pragma once #include "common.hpp" #include "gfx-blur-base.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" @@ -31,6 +32,7 @@ namespace streamfx::gfx { namespace blur { class gaussian_data { streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; std::map> _kernels; public: @@ -39,6 +41,8 @@ namespace streamfx::gfx { streamfx::obs::gs::effect get_effect(); + std::shared_ptr get_gfx_util(); + std::vector const& get_kernel(std::size_t width); }; diff --git a/source/gfx/gfx-util.cpp b/source/gfx/gfx-util.cpp index 6e66b0c1..b5d44c97 100644 --- a/source/gfx/gfx-util.cpp +++ b/source/gfx/gfx-util.cpp @@ -267,3 +267,31 @@ void streamfx::gfx::util::draw_rectangle(float x, float y, float w, float h, boo gs_load_vertexbuffer(nullptr); } } + +void streamfx::gfx::util::draw_fullscreen_triangle() +{ + if (!_fstri_vb) { + _fstri_vb = std::make_shared(uint32_t(3), uint8_t(1)); + { + auto vtx = _fstri_vb->at(0); + vec3_set(vtx.position, 0, 0, 0); + vec4_set(vtx.uv[0], 0, 0, 0, 0); + } + { + auto vtx = _fstri_vb->at(1); + vec3_set(vtx.position, 2, 0, 0); + vec4_set(vtx.uv[0], 2, 0, 0, 0); + } + { + auto vtx = _fstri_vb->at(2); + vec3_set(vtx.position, 0, 2, 0); + vec4_set(vtx.uv[0], 0, 2, 0, 0); + } + _fstri_vb->update(); + } + + gs_load_indexbuffer(nullptr); + gs_load_vertexbuffer(_fstri_vb->update(false)); + gs_draw(GS_TRIS, 0, 3); //_gs_fstri_vb->size()); + gs_load_vertexbuffer(nullptr); +} diff --git a/source/gfx/gfx-util.hpp b/source/gfx/gfx-util.hpp index 5291099c..16da66eb 100644 --- a/source/gfx/gfx-util.hpp +++ b/source/gfx/gfx-util.hpp @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#pragma once #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-vertexbuffer.hpp" @@ -32,6 +33,7 @@ namespace streamfx::gfx { std::shared_ptr<::streamfx::obs::gs::vertex_buffer> _line_vb; std::shared_ptr<::streamfx::obs::gs::vertex_buffer> _arrow_vb; std::shared_ptr<::streamfx::obs::gs::vertex_buffer> _quad_vb; + std::shared_ptr<::streamfx::obs::gs::vertex_buffer> _fstri_vb; public /* Singleton */: static std::shared_ptr get(); @@ -49,5 +51,7 @@ namespace streamfx::gfx { void draw_arrow(float x, float y, float x2, float y2, float w = 0., uint32_t color = 0xFFFFFFFF); void draw_rectangle(float x, float y, float w, float h, bool frame, uint32_t color = 0xFFFFFFFF); + + void draw_fullscreen_triangle(); }; } // namespace streamfx::gfx diff --git a/source/gfx/lut/gfx-lut-producer.cpp b/source/gfx/lut/gfx-lut-producer.cpp index 60f20574..3a065176 100644 --- a/source/gfx/lut/gfx-lut-producer.cpp +++ b/source/gfx/lut/gfx-lut-producer.cpp @@ -41,7 +41,7 @@ gs_color_format format_from_depth(streamfx::gfx::lut::color_depth depth) } } -streamfx::gfx::lut::producer::producer() +streamfx::gfx::lut::producer::producer() : _gfx_util(::streamfx::gfx::util::get()) { _data = streamfx::gfx::lut::data::instance(); if (!_data->producer_effect()) @@ -80,7 +80,7 @@ std::shared_ptr streamfx::gfx::lut::producer::produc } while (gs_effect_loop(effect->get_object(), "Draw")) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } gs_enable_color(true, true, true, true); diff --git a/source/gfx/lut/gfx-lut-producer.hpp b/source/gfx/lut/gfx-lut-producer.hpp index 50b64446..69e06371 100644 --- a/source/gfx/lut/gfx-lut-producer.hpp +++ b/source/gfx/lut/gfx-lut-producer.hpp @@ -22,6 +22,7 @@ #include "warning-disable.hpp" #include #include "gfx-lut.hpp" +#include "gfx/gfx-util.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "warning-enable.hpp" @@ -30,6 +31,7 @@ namespace streamfx::gfx::lut { class producer { std::shared_ptr _data; std::shared_ptr _rt; + std::shared_ptr _gfx_util; public: producer(); diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index a40d5719..d9b973cd 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -47,7 +47,7 @@ #define ST_KEY_PARAMETERS "Shader.Parameters" streamfx::gfx::shader::shader::shader(obs_source_t* self, shader_mode mode) - : _self(self), _mode(mode), _base_width(1), _base_height(1), _active(true), + : _self(self), _gfx_util(::streamfx::gfx::util::get()), _mode(mode), _base_width(1), _base_height(1), _active(true), _shader(), _shader_file(), _shader_tech("Draw"), _shader_file_mt(), _shader_file_sz(), _shader_file_tick(0), @@ -534,7 +534,7 @@ void streamfx::gfx::shader::shader::render(gs_effect* effect) gs_enable_framebuffer_srgb(false); while (gs_effect_loop(_shader.get_object(), _shader_tech.c_str())) { - streamfx::gs_draw_fullscreen_tri(); + _gfx_util->draw_fullscreen_triangle(); } // Restore sRGB Status diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index 06a2c33c..b3d26c74 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -17,6 +17,7 @@ #pragma once #include "common.hpp" +#include "gfx/gfx-util.hpp" #include "gfx/shader/gfx-shader-param.hpp" #include "obs/gs/gs-effect.hpp" #include "obs/gs/gs-rendertarget.hpp" @@ -46,6 +47,8 @@ namespace streamfx::gfx { class shader { obs_source_t* _self; + std::shared_ptr _gfx_util; + // Inputs shader_mode _mode; uint32_t _base_width; diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index fd4df3cb..7911d568 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -191,7 +191,7 @@ streamfx::obs::gs::mipmapper::~mipmapper() _effect.reset(); } -streamfx::obs::gs::mipmapper::mipmapper() +streamfx::obs::gs::mipmapper::mipmapper() : _gfx_util(::streamfx::gfx::util::get()) { auto gctx = streamfx::obs::gs::context(); @@ -315,7 +315,7 @@ void streamfx::obs::gs::mipmapper::rebuild(std::shared_ptrdraw_fullscreen_triangle(); } } catch (...) { } diff --git a/source/obs/gs/gs-mipmapper.hpp b/source/obs/gs/gs-mipmapper.hpp index 8f7354f6..f4f17b4d 100644 --- a/source/obs/gs/gs-mipmapper.hpp +++ b/source/obs/gs/gs-mipmapper.hpp @@ -19,6 +19,7 @@ #pragma once #include "common.hpp" +#include "gfx/gfx-util.hpp" #include "gs-effect.hpp" #include "gs-rendertarget.hpp" #include "gs-texture.hpp" @@ -40,6 +41,7 @@ namespace streamfx::obs::gs { class mipmapper { std::unique_ptr _rt; streamfx::obs::gs::effect _effect; + std::shared_ptr _gfx_util; public: ~mipmapper(); diff --git a/source/plugin.cpp b/source/plugin.cpp index 2eab5d0c..0b062ee5 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -95,7 +95,6 @@ #include "warning-enable.hpp" static std::shared_ptr _threadpool; -static std::shared_ptr _gs_fstri_vb; static std::shared_ptr _streamfx_gfx_opengl; static std::shared_ptr _source_tracker; @@ -131,27 +130,6 @@ MODULE_EXPORT bool obs_module_load(void) } #endif - // GS Stuff - { - _gs_fstri_vb = std::make_shared(uint32_t(3), uint8_t(1)); - { - auto vtx = _gs_fstri_vb->at(0); - vec3_set(vtx.position, 0, 0, 0); - vec4_set(vtx.uv[0], 0, 0, 0, 0); - } - { - auto vtx = _gs_fstri_vb->at(1); - vec3_set(vtx.position, 2, 0, 0); - vec4_set(vtx.uv[0], 2, 0, 0, 0); - } - { - auto vtx = _gs_fstri_vb->at(2); - vec3_set(vtx.position, 0, 2, 0); - vec4_set(vtx.uv[0], 0, 2, 0, 0); - } - _gs_fstri_vb->update(); - } - // Encoders { #ifdef ENABLE_ENCODER_AOM_AV1 @@ -307,11 +285,6 @@ MODULE_EXPORT void obs_module_unload(void) #endif } - // GS Stuff - { - _gs_fstri_vb.reset(); - } - // Finalize GLAD (OpenGL) { streamfx::obs::gs::context gctx{}; @@ -345,12 +318,6 @@ std::shared_ptr streamfx::threadpool() return _threadpool; } -void streamfx::gs_draw_fullscreen_tri() -{ - gs_load_vertexbuffer(_gs_fstri_vb->update(false)); - gs_draw(GS_TRIS, 0, 3); //_gs_fstri_vb->size()); -} - std::filesystem::path streamfx::data_file_path(std::string_view file) { const char* root_path = obs_get_module_data_path(obs_current_module()); diff --git a/source/plugin.hpp b/source/plugin.hpp index c2f8a7a6..01c1a5fa 100644 --- a/source/plugin.hpp +++ b/source/plugin.hpp @@ -24,8 +24,6 @@ namespace streamfx { // Threadpool std::shared_ptr threadpool(); - void gs_draw_fullscreen_tri(); - std::filesystem::path data_file_path(std::string_view file); std::filesystem::path config_file_path(std::string_view file);