Jelajahi Sumber

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.
jp9000 11 tahun lalu
induk
melakukan
57cfd4f991

+ 8 - 0
libobs/graphics/graphics-internal.h

@@ -208,6 +208,12 @@ struct gs_exports {
 #endif
 #endif
 };
 };
 
 
+struct blend_state {
+	bool               enabled;
+	enum gs_blend_type src;
+	enum gs_blend_type dest;
+};
+
 struct graphics_subsystem {
 struct graphics_subsystem {
 	void                   *module;
 	void                   *module;
 	device_t               device;
 	device_t               device;
@@ -233,4 +239,6 @@ struct graphics_subsystem {
 
 
 	pthread_mutex_t        mutex;
 	pthread_mutex_t        mutex;
 	volatile long          ref;
 	volatile long          ref;
+
+	struct blend_state     cur_blend_state;
 };
 };

+ 16 - 0
libobs/graphics/graphics.c

@@ -912,6 +912,19 @@ void gs_perspective(float angle, float aspect, float near, float far)
 			ymin, ymax, near, 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)
 const char *gs_preprocessor_name(void)
@@ -1341,6 +1354,7 @@ void gs_enable_blending(bool enable)
 	graphics_t graphics = thread_graphics;
 	graphics_t graphics = thread_graphics;
 	if (!graphics) return;
 	if (!graphics) return;
 
 
+	graphics->cur_blend_state.enabled = enable;
 	graphics->exports.device_enable_blending(graphics->device, 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;
 	graphics_t graphics = thread_graphics;
 	if (!graphics) return;
 	if (!graphics) return;
 
 
+	graphics->cur_blend_state.src  = src;
+	graphics->cur_blend_state.dest = dest;
 	graphics->exports.device_blendfunction(graphics->device, src, dest);
 	graphics->exports.device_blendfunction(graphics->device, src, dest);
 }
 }
 
 

+ 2 - 0
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_perspective(float fovy, float aspect, float znear, float zfar);
 
 
+EXPORT void gs_reset_blend_state(void);
+
 /* -------------------------- */
 /* -------------------------- */
 /* library-specific functions */
 /* library-specific functions */