From e7dd44e3ec42beffd050806931e63f1a2f4b2bed Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 28 Mar 2021 14:29:19 +0200 Subject: [PATCH] gfx/shader: Allow specifying effect for direct rendering (#501) --- source/gfx/shader/gfx-shader.cpp | 10 ++++++---- source/gfx/shader/gfx-shader.hpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index 997d3471..afdcf680 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -508,11 +508,14 @@ void gfx::shader::shader::prepare_render() return; } -void gfx::shader::shader::render() +void gfx::shader::shader::render(gs_effect* effect) { if (!_shader) return; + if (!effect) + effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); + if (!_rt_up_to_date) { auto op = _rt->render(width(), height()); vec4 zero = {0, 0, 0, 0}; @@ -534,9 +537,8 @@ void gfx::shader::shader::render() _rt_up_to_date = true; } - gs_effect_set_texture(gs_effect_get_param_by_name(obs_get_base_effect(OBS_EFFECT_DEFAULT), "image"), - _rt->get_texture()->get_object()); - while (gs_effect_loop(obs_get_base_effect(OBS_EFFECT_DEFAULT), "Draw")) { + gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), _rt->get_texture()->get_object()); + while (gs_effect_loop(effect, "Draw")) { gs_draw_sprite(nullptr, 0, width(), height()); } } diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index 8e6dc9cf..f4bfef2e 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -112,7 +112,7 @@ namespace gfx { void prepare_render(); - void render(); + void render(gs_effect* effect); public: void set_size(uint32_t w, uint32_t h);