From 57cfd4f9917565504d8a299712f5af3a60c736cd Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 3 Jul 2014 13:57:40 -0700 Subject: [PATCH] Implement function to reset blend state I was implementing a pushing/popping attributes function like with GL, but I realized that for our particular purposes (and actually for most purposes) its usage was somewhat.. niche. I may still implement pushing/popping of attributes in the future, though right now I feel using a function to reset the state is sufficient for our purposes. --- libobs/graphics/graphics-internal.h | 8 ++++++++ libobs/graphics/graphics.c | 16 ++++++++++++++++ libobs/graphics/graphics.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/libobs/graphics/graphics-internal.h b/libobs/graphics/graphics-internal.h index 87c4b2885..78292390c 100644 --- a/libobs/graphics/graphics-internal.h +++ b/libobs/graphics/graphics-internal.h @@ -208,6 +208,12 @@ struct gs_exports { #endif }; +struct blend_state { + bool enabled; + enum gs_blend_type src; + enum gs_blend_type dest; +}; + struct graphics_subsystem { void *module; device_t device; @@ -233,4 +239,6 @@ struct graphics_subsystem { pthread_mutex_t mutex; volatile long ref; + + struct blend_state cur_blend_state; }; diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index a67ac5f57..f11d70ca8 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -912,6 +912,19 @@ void gs_perspective(float angle, float aspect, float near, float far) ymin, ymax, near, far); } +void gs_reset_blend_state(void) +{ + graphics_t graphics = thread_graphics; + if (!graphics) return; + + if (!graphics->cur_blend_state.enabled) + gs_enable_blending(true); + + if (graphics->cur_blend_state.src != GS_BLEND_SRCALPHA || + graphics->cur_blend_state.dest != GS_BLEND_INVSRCALPHA) + gs_blendfunction(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA); +} + /* ------------------------------------------------------------------------- */ const char *gs_preprocessor_name(void) @@ -1341,6 +1354,7 @@ void gs_enable_blending(bool enable) graphics_t graphics = thread_graphics; if (!graphics) return; + graphics->cur_blend_state.enabled = enable; graphics->exports.device_enable_blending(graphics->device, enable); } @@ -1382,6 +1396,8 @@ void gs_blendfunction(enum gs_blend_type src, enum gs_blend_type dest) graphics_t graphics = thread_graphics; if (!graphics) return; + graphics->cur_blend_state.src = src; + graphics->cur_blend_state.dest = dest; graphics->exports.device_blendfunction(graphics->device, src, dest); } diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index 1dcf44590..03f5571d9 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -502,6 +502,8 @@ EXPORT void cubetexture_setimage(texture_t cubetex, uint32_t side, EXPORT void gs_perspective(float fovy, float aspect, float znear, float zfar); +EXPORT void gs_reset_blend_state(void); + /* -------------------------- */ /* library-specific functions */