@@ -19,6 +19,8 @@ public sealed class PluginTextureRenderer : IDisposable
1919 public Texture TargetTexture => _targetTexture ;
2020 private Texture2D _targetTexture ;
2121
22+ public int TextureBufferSize => ( _textureBuffer is null ) ? - 1 : _textureBuffer . Length ;
23+
2224 public bool Disposed => _disposed ;
2325 private bool _disposed ;
2426
@@ -48,7 +50,8 @@ public sealed class PluginTextureRenderer : IDisposable
4850 private CustomSampler _textureUpdateLoopSampler ;
4951#endif
5052
51- public PluginTextureRenderer ( RawTextureDataUpdateCallback callback , int textureWidth , int textureHeight ,
53+ public PluginTextureRenderer ( RawTextureDataUpdateCallback callback ,
54+ int textureWidth , int textureHeight , int bufferSize = 0 ,
5255 int targetFrameRateOfPluginRenderThread = 60 , bool autoDispose = true )
5356 {
5457#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -59,7 +62,7 @@ public PluginTextureRenderer(RawTextureDataUpdateCallback callback, int textureW
5962 _rawTextureDataUpdateCallback = callback ;
6063 DebugLog ( $ "[{ nameof ( PluginTextureRenderer ) } ] The RawTextureDataUpdateCallback is \n '{ _rawTextureDataUpdateCallback . Target } .{ _rawTextureDataUpdateCallback . Method . Name } '.") ;
6164
62- CreateTextureBuffer ( textureWidth , textureHeight ) ;
65+ CreateTextureBuffer ( textureWidth , textureHeight , bufferSize ) ;
6366
6467 if ( autoDispose ) { UnityEngine . Application . quitting += Dispose ; }
6568
@@ -132,7 +135,7 @@ public void Dispose()
132135 /// <param name="width"></param>
133136 /// <param name="height"></param>
134137 /// <returns></returns>
135- public IntPtr CreateTextureBuffer ( int width , int height )
138+ public IntPtr CreateTextureBuffer ( int width , int height , int bufferSize = 0 )
136139 {
137140 _updated = false ;
138141
@@ -153,7 +156,15 @@ public IntPtr CreateTextureBuffer(int width, int height)
153156
154157 if ( _rawTextureDataUpdateCallback != null )
155158 {
156- _textureBuffer = new uint [ _targetTexture . width * _targetTexture . height ] ;
159+ if ( bufferSize > _targetTexture . width * _targetTexture . height )
160+ {
161+ _textureBuffer = new uint [ bufferSize ] ;
162+ }
163+ else
164+ {
165+ _textureBuffer = new uint [ _targetTexture . width * _targetTexture . height ] ;
166+ }
167+
157168 _textureBufferHandle = GCHandle . Alloc ( _textureBuffer , GCHandleType . Pinned ) ;
158169 _textureBufferPtr = _textureBufferHandle . AddrOfPinnedObject ( ) ;
159170 }
0 commit comments