Explorar el Código

libobs: Add filter functions for SRGB support

This way, legacy filters can use the original functions without
triggering SRGB support.
jpark37 hace 4 años
padre
commit
9220316700
Se han modificado 3 ficheros con 63 adiciones y 3 borrados
  1. 20 0
      docs/sphinx/reference-sources.rst
  2. 35 3
      libobs/obs-source.c
  3. 8 0
      libobs/obs.h

+ 20 - 0
docs/sphinx/reference-sources.rst

@@ -1334,6 +1334,16 @@ Functions used by filters
 
 ---------------------
 
+.. function:: void obs_source_process_filter_end_srgb(obs_source_t *filter, gs_effect_t *effect, uint32_t width, uint32_t height)
+
+   Draws the filter using the effect's "Draw" technique, and use automatic SRGB conversion.
+  
+   Before calling this function, first call obs_source_process_filter_begin and
+   then set the effect parameters, and then call this function to finalize the
+   filter.
+
+---------------------
+
 .. function:: void obs_source_process_filter_tech_end(obs_source_t *filter, gs_effect_t *effect, uint32_t width, uint32_t height, const char *tech_name)
 
    Draws the filter with a specific technique in the effect.
@@ -1344,6 +1354,16 @@ Functions used by filters
 
 ---------------------
 
+.. function:: void obs_source_process_filter_tech_end_srgb(obs_source_t *filter, gs_effect_t *effect, uint32_t width, uint32_t height, const char *tech_name)
+
+   Draws the filter with a specific technique in the effect, and use automatic SRGB conversion.
+  
+   Before calling this function, first call obs_source_process_filter_begin and
+   then set the effect parameters, and then call this function to finalize the
+   filter.
+
+---------------------
+
 .. function:: void obs_source_skip_video_filter(obs_source_t *filter)
 
    Skips the filter if the filter is invalid and cannot be rendered.

+ 35 - 3
libobs/obs-source.c

@@ -3725,9 +3725,9 @@ bool obs_source_process_filter_begin(obs_source_t *filter,
 	return true;
 }
 
-void obs_source_process_filter_tech_end(obs_source_t *filter,
-					gs_effect_t *effect, uint32_t width,
-					uint32_t height, const char *tech_name)
+static void obs_source_process_filter_tech_end_internal(
+	obs_source_t *filter, gs_effect_t *effect, uint32_t width,
+	uint32_t height, const char *tech_name, bool linear_srgb)
 {
 	obs_source_t *target, *parent;
 	gs_texture_t *texture;
@@ -3742,6 +3742,8 @@ void obs_source_process_filter_tech_end(obs_source_t *filter,
 	if (!target || !parent)
 		return;
 
+	const bool previous = gs_set_linear_srgb(linear_srgb);
+
 	parent_flags = parent->info.output_flags;
 
 	const char *tech = tech_name ? tech_name : "Draw";
@@ -3754,6 +3756,25 @@ void obs_source_process_filter_tech_end(obs_source_t *filter,
 			render_filter_tex(texture, effect, width, height, tech);
 		}
 	}
+
+	gs_set_linear_srgb(previous);
+}
+
+void obs_source_process_filter_tech_end(obs_source_t *filter,
+					gs_effect_t *effect, uint32_t width,
+					uint32_t height, const char *tech_name)
+{
+	obs_source_process_filter_tech_end_internal(filter, effect, width,
+						    height, tech_name, false);
+}
+
+void obs_source_process_filter_tech_end_srgb(obs_source_t *filter,
+					     gs_effect_t *effect,
+					     uint32_t width, uint32_t height,
+					     const char *tech_name)
+{
+	obs_source_process_filter_tech_end_internal(filter, effect, width,
+						    height, tech_name, true);
 }
 
 void obs_source_process_filter_end(obs_source_t *filter, gs_effect_t *effect,
@@ -3766,6 +3787,17 @@ void obs_source_process_filter_end(obs_source_t *filter, gs_effect_t *effect,
 					   "Draw");
 }
 
+void obs_source_process_filter_end_srgb(obs_source_t *filter,
+					gs_effect_t *effect, uint32_t width,
+					uint32_t height)
+{
+	if (!obs_ptr_valid(filter, "obs_source_process_filter_end_srgb"))
+		return;
+
+	obs_source_process_filter_tech_end_srgb(filter, effect, width, height,
+						"Draw");
+}
+
 void obs_source_skip_video_filter(obs_source_t *filter)
 {
 	obs_source_t *target, *parent;

+ 8 - 0
libobs/obs.h

@@ -1316,6 +1316,9 @@ obs_source_process_filter_begin(obs_source_t *filter,
 EXPORT void obs_source_process_filter_end(obs_source_t *filter,
 					  gs_effect_t *effect, uint32_t width,
 					  uint32_t height);
+EXPORT void obs_source_process_filter_end_srgb(obs_source_t *filter,
+					       gs_effect_t *effect,
+					       uint32_t width, uint32_t height);
 
 /**
  * Draws the filter with a specific technique.
@@ -1328,6 +1331,11 @@ EXPORT void obs_source_process_filter_tech_end(obs_source_t *filter,
 					       gs_effect_t *effect,
 					       uint32_t width, uint32_t height,
 					       const char *tech_name);
+EXPORT void obs_source_process_filter_tech_end_srgb(obs_source_t *filter,
+						    gs_effect_t *effect,
+						    uint32_t width,
+						    uint32_t height,
+						    const char *tech_name);
 
 /** Skips the filter if the filter is invalid and cannot be rendered */
 EXPORT void obs_source_skip_video_filter(obs_source_t *filter);