@@ -12,6 +12,7 @@ namespace LiveKit
12
12
public class WebCameraSource : RtcVideoSource
13
13
{
14
14
TextureFormat _textureFormat ;
15
+ private RenderTexture _tempTexture ;
15
16
16
17
public WebCamTexture Texture { get ; }
17
18
@@ -56,6 +57,7 @@ protected override bool ReadBuffer()
56
57
_bufferType = GetVideoBufferType ( _textureFormat ) ;
57
58
_data = new NativeArray < byte > ( GetWidth ( ) * GetHeight ( ) * GetStrideForBuffer ( _bufferType ) , Allocator . Persistent ) ;
58
59
_dest = new Texture2D ( GetWidth ( ) , GetHeight ( ) , TextureFormat . BGRA32 , false ) ;
60
+ if ( Texture . graphicsFormat != _dest . graphicsFormat ) _tempTexture = new RenderTexture ( GetWidth ( ) , GetHeight ( ) , 0 , _dest . graphicsFormat ) ;
59
61
textureChanged = true ;
60
62
}
61
63
@@ -64,7 +66,16 @@ protected override bool ReadBuffer()
64
66
var bytes = MemoryMarshal . Cast < Color32 , byte > ( pixels ) ;
65
67
_data . CopyFrom ( bytes . ToArray ( ) ) ;
66
68
_requestPending = true ;
67
- Graphics . CopyTexture ( Texture , _dest ) ;
69
+
70
+ if ( Texture . graphicsFormat != _dest . graphicsFormat )
71
+ {
72
+ Graphics . Blit ( Texture , _tempTexture ) ;
73
+ Graphics . CopyTexture ( _tempTexture , _dest ) ;
74
+ }
75
+ else
76
+ {
77
+ Graphics . CopyTexture ( Texture , _dest ) ;
78
+ }
68
79
69
80
return textureChanged ;
70
81
}
0 commit comments