@@ -19,18 +19,18 @@ public sealed class NonBlockingCustomTextureRenderer : IDisposable
1919 {
2020 UpdateRawTextureDataFunction _updateRawTextureDataFunction ;
2121
22- Texture _targetTexture ;
22+ Texture2D _targetTexture ;
2323 int _textureWidth ;
2424 int _textureHeight ;
2525 int _bytesPerPixel ;
2626
2727 bool _disposed ;
2828
29- byte [ ] _currentBuffer ;
29+ uint [ ] _currentBuffer ;
3030 GCHandle _currentBufferHandle ;
3131 IntPtr _currentBufferPtr ;
3232
33- byte [ ] _nextBuffer ;
33+ uint [ ] _nextBuffer ;
3434 GCHandle _nextBufferHandle ;
3535 IntPtr _nextBufferPtr ;
3636
@@ -58,12 +58,20 @@ public sealed class NonBlockingCustomTextureRenderer : IDisposable
5858 /// <param name="bytesPerPixel"></param>
5959 /// <param name="Dispose"></param>
6060 /// <param name="targetFrameTimeMilliseconds"></param>
61- public NonBlockingCustomTextureRenderer ( UpdateRawTextureDataFunction updateRawTextureDataFunction , Texture targetTexture ,
61+ public NonBlockingCustomTextureRenderer ( UpdateRawTextureDataFunction updateRawTextureDataFunction , Texture2D targetTexture ,
6262 int bytesPerPixel = 4 , bool autoDispose = true , int targetFrameTimeMilliseconds = 20 )
6363 {
6464#if DEVELOPMENT_BUILD || UNITY_EDITOR
6565 _updateRawTextureDataFunctionSampler = CustomSampler . Create ( "UpdateRawTextureDataFunction" ) ;
6666#endif
67+
68+ if ( targetTexture . format != TextureFormat . RGBA32 )
69+ {
70+ _disposed = true ;
71+ DebugLogError ( $ "[{ nameof ( NonBlockingCustomTextureRenderer ) } ] Unsupported texture format: { targetTexture . format } ") ;
72+ return ;
73+ }
74+
6775 if ( autoDispose ) { Application . quitting += Dispose ; }
6876
6977 _targetFrameTimeMilliseconds = targetFrameTimeMilliseconds ;
@@ -76,11 +84,11 @@ public NonBlockingCustomTextureRenderer(UpdateRawTextureDataFunction updateRawTe
7684 _textureHeight = targetTexture . height ;
7785 _bytesPerPixel = bytesPerPixel ;
7886
79- _currentBuffer = new byte [ _targetTexture . width * _targetTexture . height * bytesPerPixel ] ;
87+ _currentBuffer = new uint [ _targetTexture . width * _targetTexture . height ] ;
8088 _currentBufferHandle = GCHandle . Alloc ( _currentBuffer , GCHandleType . Pinned ) ;
8189 _currentBufferPtr = _currentBufferHandle . AddrOfPinnedObject ( ) ;
8290
83- _nextBuffer = new byte [ _targetTexture . width * _targetTexture . height * bytesPerPixel ] ;
91+ _nextBuffer = new uint [ _targetTexture . width * _targetTexture . height ] ;
8492 _nextBufferHandle = GCHandle . Alloc ( _nextBuffer , GCHandleType . Pinned ) ;
8593 _nextBufferPtr = _nextBufferHandle . AddrOfPinnedObject ( ) ;
8694
@@ -201,5 +209,20 @@ static void DebugLog(object message)
201209 {
202210 UnityEngine . Debug . Log ( message ) ;
203211 }
212+
213+ /// <summary>
214+ /// Logs a message to the Unity Console
215+ /// only when DEVELOPMENT_BUILD or UNITY_EDITOR is defined.
216+ /// </summary>
217+ /// <param name="message"></param>
218+ /// <returns></returns>
219+ [
220+ System . Diagnostics . Conditional ( "DEVELOPMENT_BUILD" ) ,
221+ System . Diagnostics . Conditional ( "UNITY_EDITOR" ) ,
222+ ]
223+ static void DebugLogError ( object message )
224+ {
225+ UnityEngine . Debug . LogError ( message ) ;
226+ }
204227 }
205228}
0 commit comments