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.
This commit is contained in:
jp9000 2015-03-14 00:23:09 -07:00
parent 233004631f
commit cdb27ac06b
3 changed files with 29 additions and 0 deletions

View File

@ -292,4 +292,5 @@ struct graphics_subsystem {
volatile long ref;
struct blend_state cur_blend_state;
DARRAY(struct blend_state) blend_state_stack;
};

View File

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

View File

@ -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);
/* -------------------------- */