Procházet zdrojové kódy

libobs: Check to swap BGRX/BGRA in async filters

If for whatever reason the format is swapped between BGRA/BGRX in an
async filter, swap the texture to compensate for that.  This allows
plugins to change the format if necessary.
jp9000 před 6 roky
rodič
revize
abaed69627
1 změnil soubory, kde provedl 24 přidání a 0 odebrání
  1. 24 0
      libobs/obs-source.c

+ 24 - 0
libobs/obs-source.c

@@ -1938,6 +1938,28 @@ static void obs_source_draw_async_texture(struct obs_source *source)
 	}
 	}
 }
 }
 
 
+static void recreate_async_texture(obs_source_t *source,
+				   enum gs_color_format format)
+{
+	uint32_t cx = gs_texture_get_width(source->async_textures[0]);
+	uint32_t cy = gs_texture_get_height(source->async_textures[0]);
+	gs_texture_destroy(source->async_textures[0]);
+	source->async_textures[0] =
+		gs_texture_create(cx, cy, format, 1, NULL, GS_DYNAMIC);
+}
+
+static inline void check_to_swap_bgrx_bgra(obs_source_t *source,
+					   struct obs_source_frame *frame)
+{
+	enum gs_color_format format =
+		gs_texture_get_color_format(source->async_textures[0]);
+	if (format == GS_BGRX && frame->format == VIDEO_FORMAT_BGRA) {
+		recreate_async_texture(source, GS_BGRA);
+	} else if (format == GS_BGRA && frame->format == VIDEO_FORMAT_BGRX) {
+		recreate_async_texture(source, GS_BGRX);
+	}
+}
+
 static void obs_source_update_async_video(obs_source_t *source)
 static void obs_source_update_async_video(obs_source_t *source)
 {
 {
 	if (!source->async_rendered) {
 	if (!source->async_rendered) {
@@ -1948,6 +1970,8 @@ static void obs_source_update_async_video(obs_source_t *source)
 
 
 		source->async_rendered = true;
 		source->async_rendered = true;
 		if (frame) {
 		if (frame) {
+			check_to_swap_bgrx_bgra(source, frame);
+
 			if (!source->async_decoupled ||
 			if (!source->async_decoupled ||
 			    !source->async_unbuffered) {
 			    !source->async_unbuffered) {
 				source->timing_adjust = obs->video.video_time -
 				source->timing_adjust = obs->video.video_time -