From 922eb7b8e821d10130e609dca29d1bca55c29a70 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 22 Dec 2013 02:03:40 -0700 Subject: [PATCH] make direct filter rendering optional (can be useful for certain cases) --- libobs/obs-source.c | 12 +++++++++--- libobs/obs.h | 8 +++++++- test/test-input/test-filter.c | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 3214ea4f2..7634e45dc 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -968,7 +968,8 @@ static inline void render_filter_tex(texture_t tex, effect_t effect, } void obs_source_process_filter(obs_source_t filter, texrender_t texrender, - effect_t effect, uint32_t width, uint32_t height) + effect_t effect, uint32_t width, uint32_t height, + enum allow_direct_render allow_direct) { obs_source_t target = obs_filter_gettarget(filter); obs_source_t parent = obs_filter_getparent(filter); @@ -977,19 +978,24 @@ void obs_source_process_filter(obs_source_t filter, texrender_t texrender, int cx = obs_source_getwidth(target); int cy = obs_source_getheight(target); bool yuv = (target_flags & SOURCE_YUV) != 0; + bool expects_def = (parent_flags & SOURCE_DEFAULT_EFFECT) != 0; + bool can_directly = allow_direct == ALLOW_DIRECT_RENDERING; /* if the parent does not use any custom effects, and this is the last * filter in the chain for the parent, then render the parent directly * using the filter effect instead of rendering to texture to reduce * the total number of passes */ - if ((parent_flags & SOURCE_DEFAULT_EFFECT) != 0 && target == parent) { + if (can_directly && expects_def && target == parent) { render_filter_bypass(target, effect, width, height, yuv); return; } if (texrender_begin(texrender, cx, cy)) { gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f); - obs_source_video_render(target); + if (expects_def && parent == target) + obs_source_default_render(parent, yuv); + else + obs_source_video_render(target); texrender_end(texrender); } diff --git a/libobs/obs.h b/libobs/obs.h index dea7e37f8..5f8ba3485 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -60,6 +60,11 @@ enum order_movement { ORDER_MOVE_BOTTOM }; +enum allow_direct_render { + NO_DIRECT_RENDERING, + ALLOW_DIRECT_RENDERING, +}; + struct obs_video_info { /* graphics module to use (usually "libobs-opengl" or "libobs-d3d11") */ const char *graphics_module; @@ -412,7 +417,8 @@ EXPORT void obs_source_releaseframe(obs_source_t source, /** Default RGB filter handler for generic effect filters */ EXPORT void obs_source_process_filter(obs_source_t filter, texrender_t texrender, effect_t effect, - uint32_t width, uint32_t height); + uint32_t width, uint32_t height, + enum allow_direct_render allow_direct); /* ------------------------------------------------------------------------- */ diff --git a/test/test-input/test-filter.c b/test/test-input/test-filter.c index 6ca39c2a6..1c6a584a1 100644 --- a/test/test-input/test-filter.c +++ b/test/test-input/test-filter.c @@ -56,5 +56,5 @@ void test_video_tick(struct test_filter *tf, float seconds) void test_video_render(struct test_filter *tf) { obs_source_process_filter(tf->source, tf->texrender, tf->whatever, - 0, 0); + 0, 0, ALLOW_DIRECT_RENDERING); } -- GitLab