From cdb27ac06b5e708e25c8036ef6931a103d7395ef Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 14 Mar 2015 00:23:09 -0700 Subject: [PATCH] libobs: Add functions to push/pop blend states This is particularly important for the filter pipeline in order to ensure that when the last filter is reached that the original blend state is properly reset. --- libobs/graphics/graphics-internal.h | 1 + libobs/graphics/graphics.c | 26 ++++++++++++++++++++++++++ libobs/graphics/graphics.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/libobs/graphics/graphics-internal.h b/libobs/graphics/graphics-internal.h index e4655f1cd..43155795c 100644 --- a/libobs/graphics/graphics-internal.h +++ b/libobs/graphics/graphics-internal.h @@ -292,4 +292,5 @@ struct graphics_subsystem { volatile long ref; struct blend_state cur_blend_state; + DARRAY(struct blend_state) blend_state_stack; }; diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 79d5b8a45..54092a7d1 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -213,6 +213,7 @@ void gs_destroy(graphics_t *graphics) pthread_mutex_destroy(&graphics->effect_mutex); da_free(graphics->matrix_stack); da_free(graphics->viewport_stack); + da_free(graphics->blend_state_stack); if (graphics->module) os_dlclose(graphics->module); bfree(graphics); @@ -1002,6 +1003,31 @@ void gs_perspective(float angle, float aspect, float near, float far) ymin, ymax, near, far); } +void gs_blend_state_push(void) +{ + graphics_t *graphics = thread_graphics; + if (!graphics) return; + + da_push_back(graphics->blend_state_stack, &graphics->cur_blend_state); +} + +void gs_blend_state_pop(void) +{ + graphics_t *graphics = thread_graphics; + struct blend_state *state; + + if (!graphics) return; + + state = da_end(graphics->blend_state_stack); + if (!state) + return; + + gs_enable_blending(state->enabled); + gs_blend_function(state->src, state->dest); + + da_pop_back(graphics->blend_state_stack); +} + void gs_reset_blend_state(void) { graphics_t *graphics = thread_graphics; diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index 7f7ad24c2..d4b560c7b 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -537,6 +537,8 @@ EXPORT void gs_cubetexture_set_image(gs_texture_t *cubetex, uint32_t side, EXPORT void gs_perspective(float fovy, float aspect, float znear, float zfar); +EXPORT void gs_blend_state_push(void); +EXPORT void gs_blend_state_pop(void); EXPORT void gs_reset_blend_state(void); /* -------------------------- */