gfx/util: Move draw_fullscreen_triangle here for consistency

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2022-11-28 09:11:55 +01:00
parent 9b8ef5ac74
commit 8aa8745a3a
30 changed files with 165 additions and 101 deletions

View file

@ -140,7 +140,8 @@ static std::map<std::string, local_blur_subtype_t> 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();

View file

@ -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<streamfx::gfx::util> _gfx_util;
// Input
std::shared_ptr<streamfx::obs::gs::rendertarget> _source_rt;

View file

@ -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.

View file

@ -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<streamfx::gfx::util> _gfx_util;
// User Configuration
vec4 _lift;

View file

@ -111,6 +111,7 @@ std::shared_ptr<streamfx::filter::dynamic_mask::data> 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.

View file

@ -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<streamfx::filter::dynamic_mask::data> _data;
std::shared_ptr<streamfx::gfx::util> _gfx_util;
std::map<std::tuple<channel, channel, std::string>, std::string> _translation_map;

View file

@ -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 (...) {

View file

@ -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<streamfx::gfx::util> _gfx_util;
// Input
std::shared_ptr<streamfx::obs::gs::rendertarget> _source_rt;

View file

@ -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();
}
}

View file

@ -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<streamfx::gfx::util> _gfx_util;
// Settings
transform_mode _camera_mode;
float _camera_fov;

View file

@ -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::util> 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();
}
}
}

View file

@ -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<streamfx::gfx::util> _gfx_util;
public:
box_linear_data();
virtual ~box_linear_data();
std::shared_ptr<streamfx::gfx::util> get_gfx_util();
streamfx::obs::gs::effect get_effect();
};

View file

@ -47,6 +47,11 @@ streamfx::gfx::blur::box_data::~box_data()
_effect.reset();
}
std::shared_ptr<streamfx::gfx::util> 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();
}
}
}

View file

@ -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<streamfx::gfx::util> _gfx_util;
public:
box_data();
virtual ~box_data();
std::shared_ptr<streamfx::gfx::util> get_gfx_util();
streamfx::obs::gs::effect get_effect();
};

View file

@ -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::util> 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();
}
}
}

View file

@ -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<streamfx::gfx::util> _gfx_util;
public:
dual_filtering_data();
virtual ~dual_filtering_data();
std::shared_ptr<streamfx::gfx::util> get_gfx_util();
streamfx::obs::gs::effect get_effect();
};

View file

@ -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<float_t> const& streamfx::gfx::blur::gaussian_linear_data::get_kerne
return _kernels[width];
}
std::shared_ptr<streamfx::gfx::util> 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();
}
}

View file

@ -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<std::vector<float_t>> _kernels;
streamfx::obs::gs::effect _effect;
std::shared_ptr<streamfx::gfx::util> _gfx_util;
std::vector<std::vector<float_t>> _kernels;
public:
gaussian_linear_data();
virtual ~gaussian_linear_data();
std::shared_ptr<streamfx::gfx::util> get_gfx_util();
streamfx::obs::gs::effect get_effect();
std::vector<float_t> const& get_kernel(std::size_t width);

View file

@ -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::util> streamfx::gfx::blur::gaussian_data::get_gfx_util()
{
return _gfx_util;
}
std::vector<float_t> const& streamfx::gfx::blur::gaussian_data::get_kernel(std::size_t width)
{
width = std::clamp<size_t>(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();
}
}

View file

@ -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<streamfx::gfx::util> _gfx_util;
std::map<size_t, std::vector<float>> _kernels;
public:
@ -39,6 +41,8 @@ namespace streamfx::gfx {
streamfx::obs::gs::effect get_effect();
std::shared_ptr<streamfx::gfx::util> get_gfx_util();
std::vector<float_t> const& get_kernel(std::size_t width);
};

View file

@ -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<streamfx::obs::gs::vertex_buffer>(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);
}

View file

@ -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<streamfx::gfx::util> 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

View file

@ -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::obs::gs::texture> 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);

View file

@ -22,6 +22,7 @@
#include "warning-disable.hpp"
#include <memory>
#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<streamfx::gfx::lut::data> _data;
std::shared_ptr<streamfx::obs::gs::rendertarget> _rt;
std::shared_ptr<streamfx::gfx::util> _gfx_util;
public:
producer();

View file

@ -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

View file

@ -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<streamfx::gfx::util> _gfx_util;
// Inputs
shader_mode _mode;
uint32_t _base_width;

View file

@ -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_ptr<streamfx::obs::gs::te
_effect.get_parameter("imageTexel").set_float2(iwidth, iheight);
_effect.get_parameter("level").set_int(int32_t(mip - 1));
while (gs_effect_loop(_effect.get_object(), "Draw")) {
streamfx::gs_draw_fullscreen_tri();
_gfx_util->draw_fullscreen_triangle();
}
} catch (...) {
}

View file

@ -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<streamfx::obs::gs::rendertarget> _rt;
streamfx::obs::gs::effect _effect;
std::shared_ptr<streamfx::gfx::util> _gfx_util;
public:
~mipmapper();

View file

@ -95,7 +95,6 @@
#include "warning-enable.hpp"
static std::shared_ptr<streamfx::util::threadpool::threadpool> _threadpool;
static std::shared_ptr<streamfx::obs::gs::vertex_buffer> _gs_fstri_vb;
static std::shared_ptr<streamfx::gfx::opengl> _streamfx_gfx_opengl;
static std::shared_ptr<streamfx::obs::source_tracker> _source_tracker;
@ -131,27 +130,6 @@ MODULE_EXPORT bool obs_module_load(void)
}
#endif
// GS Stuff
{
_gs_fstri_vb = std::make_shared<streamfx::obs::gs::vertex_buffer>(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::util::threadpool::threadpool> 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());

View file

@ -24,8 +24,6 @@ namespace streamfx {
// Threadpool
std::shared_ptr<streamfx::util::threadpool::threadpool> 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);