From fe05dca51ec4f7d2ed192fc3207c136fc1c84abe Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 20 Mar 2018 12:50:17 +0100 Subject: [PATCH] gfx, gs: Fix commits 9f518764b6f1bc17bbbd20fba9ba961fd0473a6e & 2adfa5765c53eb52b72ec2733f030943a2c02dea --- source/filter-blur.cpp | 26 +++++++++++----------- source/filter-custom-shader.cpp | 4 ++-- source/gfx-effect-source.cpp | 32 +++++++++++++-------------- source/gfx-effect-source.h | 39 +++++---------------------------- source/gfx-source-texture.cpp | 18 +++++++-------- source/gfx-source-texture.h | 16 +++++++------- source/gs-effect.cpp | 4 ++-- source/source-mirror.cpp | 36 +++++++++++++++--------------- source/source-mirror.h | 2 +- 9 files changed, 74 insertions(+), 103 deletions(-) diff --git a/source/filter-blur.cpp b/source/filter-blur.cpp index 26f79aa3..b46ff8bc 100644 --- a/source/filter-blur.cpp +++ b/source/filter-blur.cpp @@ -346,7 +346,7 @@ void Filter::Blur::Instance::video_render(gs_effect_t *effect) { uint32_t baseW = obs_source_get_base_width(target), baseH = obs_source_get_base_height(target); - gs_effect_t* colorConversionEffect = g_effects.count("Color Conversion") ? g_effects.at("Color Conversion")->GetObject() : nullptr; + gs_effect_t* colorConversionEffect = g_effects.count("Color Conversion") ? g_effects.at("Color Conversion")->get_object() : nullptr; // Skip rendering if our target, parent or context is not valid. if (!target || !parent || !m_source) { @@ -504,7 +504,7 @@ void Filter::Blur::Instance::video_render(gs_effect_t *effect) { gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &black, 0, 0); // Render - while (gs_effect_loop(m_effect->GetObject(), "Draw")) { + while (gs_effect_loop(m_effect->get_object(), "Draw")) { gs_draw_sprite(intermediate, 0, baseW, baseH); } @@ -566,24 +566,24 @@ void Filter::Blur::Instance::video_render(gs_effect_t *effect) { bool Filter::Blur::Instance::apply_shared_param(gs_texture_t* input, float texelX, float texelY) { bool result = true; - result = result && gs_set_param_texture(m_effect->GetObject(), "u_image", input); + result = result && gs_set_param_texture(m_effect->get_object(), "u_image", input); vec2 imageSize; vec2_set(&imageSize, (float)gs_texture_get_width(input), (float)gs_texture_get_height(input)); - result = result && gs_set_param_float2(m_effect->GetObject(), "u_imageSize", &imageSize); + result = result && gs_set_param_float2(m_effect->get_object(), "u_imageSize", &imageSize); vec2 imageTexelDelta; vec2_set(&imageTexelDelta, 1.0f, 1.0f); vec2_div(&imageTexelDelta, &imageTexelDelta, &imageSize); - result = result && gs_set_param_float2(m_effect->GetObject(), "u_imageTexel", &imageTexelDelta); + result = result && gs_set_param_float2(m_effect->get_object(), "u_imageTexel", &imageTexelDelta); vec2 texel; vec2_set(&texel, texelX, texelY); - result = result && gs_set_param_float2(m_effect->GetObject(), "u_texelDelta", &texel); + result = result && gs_set_param_float2(m_effect->get_object(), "u_texelDelta", &texel); - result = result && gs_set_param_int(m_effect->GetObject(), "u_radius", (int)m_size); - result = result && gs_set_param_int(m_effect->GetObject(), "u_diameter", (int)(1 + (m_size * 2))); + result = result && gs_set_param_int(m_effect->get_object(), "u_radius", (int)m_size); + result = result && gs_set_param_int(m_effect->get_object(), "u_diameter", (int)(1 + (m_size * 2))); return result; } @@ -595,7 +595,7 @@ bool Filter::Blur::Instance::apply_bilateral_param() { return false; // Bilateral Blur - param = gs_effect_get_param_by_name(m_effect->GetObject(), "bilateralSmoothing"); + param = gs_effect_get_param_by_name(m_effect->get_object(), "bilateralSmoothing"); if (!param) { P_LOG_ERROR(" Failed to set bilateralSmoothing param."); return false; @@ -605,7 +605,7 @@ bool Filter::Blur::Instance::apply_bilateral_param() { (float)(m_bilateralSmoothing * (1 + m_size * 2))); } - param = gs_effect_get_param_by_name(m_effect->GetObject(), "bilateralSharpness"); + param = gs_effect_get_param_by_name(m_effect->get_object(), "bilateralSharpness"); if (!param) { P_LOG_ERROR(" Failed to set bilateralSmoothing param."); return false; @@ -626,12 +626,12 @@ bool Filter::Blur::Instance::apply_gaussian_param() { std::shared_ptr tex; if ((m_size - 1) < MaxKernelSize) { tex = g_gaussianKernels[size_t(m_size - 1)]; - result = result && gs_set_param_texture(m_effect->GetObject(), "kernel", tex->GetObject()); + result = result && gs_set_param_texture(m_effect->get_object(), "kernel", tex->get_object()); } vec2 kerneltexel; - vec2_set(&kerneltexel, 1.0f / gs_texture_get_width(tex->GetObject()), 0); - result = result && gs_set_param_float2(m_effect->GetObject(), "kernelTexel", &kerneltexel); + vec2_set(&kerneltexel, 1.0f / gs_texture_get_width(tex->get_object()), 0); + result = result && gs_set_param_float2(m_effect->get_object(), "kernelTexel", &kerneltexel); return result; } diff --git a/source/filter-custom-shader.cpp b/source/filter-custom-shader.cpp index 2dbfab13..fde21ff7 100644 --- a/source/filter-custom-shader.cpp +++ b/source/filter-custom-shader.cpp @@ -484,13 +484,13 @@ void Filter::CustomShader::Instance::video_render(gs_effect_t *effect) { w = obs_source_get_width(prm.value.source.source); h = obs_source_get_height(prm.value.source.source); { - auto op = prm.value.source.rendertarget->Render(w, h); + auto op = prm.value.source.rendertarget->render(w, h); vec4 black; vec4_zero(&black); gs_ortho(0, (float_t)w, 0, (float_t)h, 0, 1); gs_clear(GS_CLEAR_COLOR, &black, 0, 0); obs_source_video_render(prm.value.source.source); } - eprm.set_texture(prm.value.source.rendertarget->GetTextureObject()); + eprm.set_texture(prm.value.source.rendertarget->get_object()); } } else { if (prm.value.file.texture) { diff --git a/source/gfx-effect-source.cpp b/source/gfx-effect-source.cpp index 52b8a0e6..9afb1450 100644 --- a/source/gfx-effect-source.cpp +++ b/source/gfx-effect-source.cpp @@ -20,7 +20,7 @@ #include #include -bool gfx::ShaderSource::property_type_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett) { +bool gfx::effect_source::property_type_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett) { switch ((InputTypes)obs_data_get_int(sett, D_TYPE)) { default: case InputTypes::Text: @@ -35,11 +35,11 @@ bool gfx::ShaderSource::property_type_modified(void* priv, obs_properties_t* pro return true; } -bool gfx::ShaderSource::property_input_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett) { +bool gfx::effect_source::property_input_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett) { return true; } -gfx::ShaderSource::ShaderSource(obs_data_t* data, obs_source_t* owner) { +gfx::effect_source::effect_source(obs_data_t* data, obs_source_t* owner) { obs_source_addref(owner); m_source = owner; time_existing = 0; @@ -48,11 +48,11 @@ gfx::ShaderSource::ShaderSource(obs_data_t* data, obs_source_t* owner) { update(data); } -gfx::ShaderSource::~ShaderSource() { +gfx::effect_source::~effect_source() { obs_source_release(m_source); } -void gfx::ShaderSource::get_properties(obs_properties_t* properties) { +void gfx::effect_source::get_properties(obs_properties_t* properties) { obs_property_t* p = nullptr; p = obs_properties_add_list(properties, D_TYPE, P_TRANSLATE(T_TYPE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); @@ -77,7 +77,7 @@ void gfx::ShaderSource::get_properties(obs_properties_t* properties) { // ToDo: Place updated properties here or somewhere else? } -void gfx::ShaderSource::update(obs_data_t* data) { +void gfx::effect_source::update(obs_data_t* data) { obs_data_addref(data); // Update Shader @@ -93,7 +93,7 @@ void gfx::ShaderSource::update(obs_data_t* data) { obs_data_release(data); } -bool gfx::ShaderSource::test_for_updates(const char* text, const char* path) { +bool gfx::effect_source::test_for_updates(const char* text, const char* path) { bool is_shader_different = false; if (text != nullptr) { if (text != effect.text) { @@ -102,7 +102,7 @@ bool gfx::ShaderSource::test_for_updates(const char* text, const char* path) { } if (is_shader_different) { - effect.effect = std::make_unique(effect.text, "Text"); + effect.effect = std::make_unique(effect.text, "Text"); } } else if (path != nullptr) { if (path != this->effect.path) { @@ -134,7 +134,7 @@ bool gfx::ShaderSource::test_for_updates(const char* text, const char* path) { } // Increment timer so that the next check is a reasonable timespan away. - effect.file_info.time_updated += 0.1; + effect.file_info.time_updated += 0.1f; } if (is_shader_different || effect.file_info.modified) { @@ -152,7 +152,7 @@ bool gfx::ShaderSource::test_for_updates(const char* text, const char* path) { fs.close(); content[sz] = '\0'; - effect.effect = std::make_unique(content, effect.path); + effect.effect = std::make_unique(std::string(content.data()), effect.path); } } } @@ -166,23 +166,23 @@ bool gfx::ShaderSource::test_for_updates(const char* text, const char* path) { return is_shader_different; } -void gfx::ShaderSource::active() { +void gfx::effect_source::active() { time_active = 0; } -void gfx::ShaderSource::deactivate() { +void gfx::effect_source::deactivate() { time_active = 0; } -uint32_t gfx::ShaderSource::get_width() { +uint32_t gfx::effect_source::get_width() { return 0; } -uint32_t gfx::ShaderSource::get_height() { +uint32_t gfx::effect_source::get_height() { return 0; } -void gfx::ShaderSource::video_tick(float time) { +void gfx::effect_source::video_tick(float time) { // Shader Timers time_existing += time; time_active += time; @@ -191,6 +191,6 @@ void gfx::ShaderSource::video_tick(float time) { effect.file_info.time_updated -= time; } -void gfx::ShaderSource::video_render(gs_effect_t* parent_effect) { +void gfx::effect_source::video_render(gs_effect_t* parent_effect) { } diff --git a/source/gfx-effect-source.h b/source/gfx-effect-source.h index 66d8d3c0..c1f601d1 100644 --- a/source/gfx-effect-source.h +++ b/source/gfx-effect-source.h @@ -38,28 +38,13 @@ #define T_INPUT_FILE "CustomShader.Input.File" namespace gfx { - struct ShaderParameter { - - }; - - struct ShaderTextureParameter : ShaderParameter { - bool is_source = false; - - // File / Texture - std::shared_ptr texture; - - // Source - std::shared_ptr source; - - }; - - class ShaderSource { + class effect_source { obs_source_t* m_source; - std::unique_ptr m_renderTarget; + std::unique_ptr m_renderTarget; // Effect Information struct { - std::unique_ptr effect; + std::unique_ptr effect; std::string text; std::string path; struct { @@ -71,18 +56,6 @@ namespace gfx { } file_info; } effect; - struct Parameter { - GS::EffectParameter parameter; - - std::vector data_names; - std::vector - - struct { - - } value; - }; - - // Status float_t time_existing; float_t time_active; @@ -92,8 +65,8 @@ namespace gfx { static bool property_input_modified(void* priv, obs_properties_t* props, obs_property_t* prop, obs_data_t* sett); public: - ShaderSource(obs_data_t* data, obs_source_t* owner); - ~ShaderSource(); + effect_source(obs_data_t* data, obs_source_t* owner); + ~effect_source(); void get_properties(obs_properties_t* properties); void get_defaults(obs_data_t* data); @@ -114,7 +87,5 @@ namespace gfx { Text, File }; - - }; } diff --git a/source/gfx-source-texture.cpp b/source/gfx-source-texture.cpp index 9d56f8d6..b6109cd2 100644 --- a/source/gfx-source-texture.cpp +++ b/source/gfx-source-texture.cpp @@ -17,7 +17,7 @@ #include "gfx-source-texture.h" -gfx::SourceTexture::~SourceTexture() { +gfx::source_texture::~source_texture() { if (m_source) { obs_source_release(m_source); m_source = nullptr; @@ -25,31 +25,31 @@ gfx::SourceTexture::~SourceTexture() { m_rt = nullptr; } -gfx::SourceTexture::SourceTexture() { +gfx::source_texture::source_texture() { m_rt = std::make_shared(GS_RGBA, GS_ZS_NONE); } -obs_source_t* gfx::SourceTexture::GetObject() { +obs_source_t* gfx::source_texture::get_object() { return m_source; } -gfx::SourceTexture::SourceTexture(const char* name) : SourceTexture() { +gfx::source_texture::source_texture(const char* name) : source_texture() { m_source = obs_get_source_by_name(name); if (!m_source) { throw std::invalid_argument("No such source."); } } -gfx::SourceTexture::SourceTexture(std::string name) : SourceTexture(name.c_str()) {} +gfx::source_texture::source_texture(std::string name) : source_texture(name.c_str()) {} -gfx::SourceTexture::SourceTexture(obs_source_t* src) : SourceTexture() { +gfx::source_texture::source_texture(obs_source_t* src) : source_texture() { m_source = src; if (!m_source) { throw std::invalid_argument("No such source."); } } -std::shared_ptr gfx::SourceTexture::Render(size_t width, size_t height) { +std::shared_ptr gfx::source_texture::render(size_t width, size_t height) { if (!m_source) { throw std::invalid_argument("Missing source to render."); } @@ -61,7 +61,7 @@ std::shared_ptr gfx::SourceTexture::Render(size_t width, size_t hei } { - auto op = m_rt->Render((uint32_t)width, (uint32_t)height); + auto op = m_rt->render((uint32_t)width, (uint32_t)height); vec4 black; vec4_zero(&black); gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1); gs_clear(GS_CLEAR_COLOR, &black, 0, 0); @@ -69,6 +69,6 @@ std::shared_ptr gfx::SourceTexture::Render(size_t width, size_t hei } std::shared_ptr tex; - m_rt->GetTexture(tex); + m_rt->get_texture(tex); return tex; } diff --git a/source/gfx-source-texture.h b/source/gfx-source-texture.h index 95d65f08..abcf3e52 100644 --- a/source/gfx-source-texture.h +++ b/source/gfx-source-texture.h @@ -23,19 +23,19 @@ #include "gs-rendertarget.h" namespace gfx { - class SourceTexture { + class source_texture { obs_source_t* m_source; std::shared_ptr m_rt; - SourceTexture(); + source_texture(); public: - ~SourceTexture(); - SourceTexture(const char* name); - SourceTexture(std::string name); - SourceTexture(obs_source_t* src); + ~source_texture(); + source_texture(const char* name); + source_texture(std::string name); + source_texture(obs_source_t* src); - obs_source_t* GetObject(); + obs_source_t* get_object(); - std::shared_ptr Render(size_t width, size_t height); + std::shared_ptr render(size_t width, size_t height); }; } diff --git a/source/gs-effect.cpp b/source/gs-effect.cpp index cd1b62f3..cabeb78a 100644 --- a/source/gs-effect.cpp +++ b/source/gs-effect.cpp @@ -261,7 +261,7 @@ void gs::effect_parameter::set_matrix(matrix4& v) { void gs::effect_parameter::set_texture(std::shared_ptr v) { if (get_type() != type::Texture) throw std::bad_cast(); - gs_effect_set_texture(m_param, v->GetObject()); + gs_effect_set_texture(m_param, v->get_object()); } void gs::effect_parameter::set_texture(gs_texture_t* v) { @@ -273,7 +273,7 @@ void gs::effect_parameter::set_texture(gs_texture_t* v) { void gs::effect_parameter::set_sampler(std::shared_ptr v) { if (get_type() != type::Texture) throw std::bad_cast(); - gs_effect_set_next_sampler(m_param, v->GetObject()); + gs_effect_set_next_sampler(m_param, v->get_object()); } void gs::effect_parameter::set_sampler(gs_sampler_state* v) { diff --git a/source/source-mirror.cpp b/source/source-mirror.cpp index 14220371..a947fe8b 100644 --- a/source/source-mirror.cpp +++ b/source/source-mirror.cpp @@ -216,7 +216,7 @@ uint32_t Source::Mirror::get_width() { if (m_rescale && m_width > 0 && !m_keepOriginalSize) return m_width; if (m_mirrorSource) - return obs_source_get_width(m_mirrorSource->GetObject()); + return obs_source_get_width(m_mirrorSource->get_object()); return 1; } @@ -224,7 +224,7 @@ uint32_t Source::Mirror::get_height() { if (m_rescale && m_height > 0 && !m_keepOriginalSize) return m_height; if (m_mirrorSource) - return obs_source_get_height(m_mirrorSource->GetObject()); + return obs_source_get_height(m_mirrorSource->get_object()); return 1; } @@ -233,7 +233,7 @@ void Source::Mirror::update(obs_data_t* data) { const char* sourceName = obs_data_get_string(data, P_SOURCE); if (sourceName != m_mirrorName) { try { - m_mirrorSource = std::make_unique(sourceName); + m_mirrorSource = std::make_unique(sourceName); m_mirrorName = sourceName; } catch (...) { } @@ -275,23 +275,23 @@ void Source::Mirror::update(obs_data_t* data) { case ScalingMethod::Point: default: m_scalingEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT); - m_sampler->SetSampleFilter(GS_FILTER_POINT); + m_sampler->set_filter(GS_FILTER_POINT); break; case ScalingMethod::Bilinear: m_scalingEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT); - m_sampler->SetSampleFilter(GS_FILTER_LINEAR); + m_sampler->set_filter(GS_FILTER_LINEAR); break; case ScalingMethod::BilinearLowRes: m_scalingEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_BILINEAR_LOWRES); - m_sampler->SetSampleFilter(GS_FILTER_LINEAR); + m_sampler->set_filter(GS_FILTER_LINEAR); break; case ScalingMethod::Bicubic: m_scalingEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_BICUBIC); - m_sampler->SetSampleFilter(GS_FILTER_LINEAR); + m_sampler->set_filter(GS_FILTER_LINEAR); break; case ScalingMethod::Lanczos: m_scalingEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_LANCZOS); - m_sampler->SetSampleFilter(GS_FILTER_LINEAR); + m_sampler->set_filter(GS_FILTER_LINEAR); break; } @@ -309,7 +309,7 @@ void Source::Mirror::deactivate() { void Source::Mirror::video_tick(float) { if (m_mirrorSource) - m_mirrorName = obs_source_get_name(m_mirrorSource->GetObject()); + m_mirrorName = obs_source_get_name(m_mirrorSource->get_object()); } void Source::Mirror::video_render(gs_effect_t* effect) { @@ -319,11 +319,11 @@ void Source::Mirror::video_render(gs_effect_t* effect) { if (m_rescale && m_width > 0 && m_height > 0 && m_scalingEffect) { uint32_t sw, sh; - sw = obs_source_get_width(m_mirrorSource->GetObject()); - sh = obs_source_get_height(m_mirrorSource->GetObject()); + sw = obs_source_get_width(m_mirrorSource->get_object()); + sh = obs_source_get_height(m_mirrorSource->get_object()); // Store original Source Texture - std::shared_ptr tex = m_mirrorSource->Render(sw, sh); + std::shared_ptr tex = m_mirrorSource->render(sw, sh); gs_eparam_t *scale_param = gs_effect_get_param_by_name(m_scalingEffect, "base_dimension_i"); if (scale_param) { @@ -342,23 +342,23 @@ void Source::Mirror::video_render(gs_effect_t* effect) { gs_clear(GS_CLEAR_COLOR, &black, 0, 0); while (gs_effect_loop(m_scalingEffect, "Draw")) { gs_eparam_t* image = gs_effect_get_param_by_name(m_scalingEffect, "image"); - gs_effect_set_next_sampler(image, m_sampler->GetObject()); - obs_source_draw(tex->GetObject(), 0, 0, m_width, m_height, false); + gs_effect_set_next_sampler(image, m_sampler->get_object()); + obs_source_draw(tex->get_object(), 0, 0, m_width, m_height, false); } } while (gs_effect_loop(obs_get_base_effect(OBS_EFFECT_DEFAULT), "Draw")) { gs_eparam_t* image = gs_effect_get_param_by_name(obs_get_base_effect(OBS_EFFECT_DEFAULT), "image"); - gs_effect_set_next_sampler(image, m_sampler->GetObject()); + gs_effect_set_next_sampler(image, m_sampler->get_object()); obs_source_draw(m_renderTargetScale->get_object(), 0, 0, sw, sh, false); } } else { while (gs_effect_loop(m_scalingEffect, "Draw")) { gs_eparam_t* image = gs_effect_get_param_by_name(m_scalingEffect, "image"); - gs_effect_set_next_sampler(image, m_sampler->GetObject()); - obs_source_draw(tex->GetObject(), 0, 0, m_width, m_height, false); + gs_effect_set_next_sampler(image, m_sampler->get_object()); + obs_source_draw(tex->get_object(), 0, 0, m_width, m_height, false); } } } else { - obs_source_video_render(m_mirrorSource->GetObject()); + obs_source_video_render(m_mirrorSource->get_object()); } } diff --git a/source/source-mirror.h b/source/source-mirror.h index 20973988..98a8305b 100644 --- a/source/source-mirror.h +++ b/source/source-mirror.h @@ -62,7 +62,7 @@ namespace Source { std::shared_ptr m_sampler; gs_effect_t* m_scalingEffect = nullptr; - std::unique_ptr m_mirrorSource; + std::unique_ptr m_mirrorSource; std::string m_mirrorName; public: