1010using Vortice . Mathematics ;
1111using MapFlags = Vortice . Direct3D11 . MapFlags ;
1212using ResultCode = Vortice . DXGI . ResultCode ;
13- using Usage = Vortice . Direct3D11 . Usage ;
1413
1514namespace ScreenCapture . NET
1615{
@@ -31,6 +30,8 @@ public sealed class DX11ScreenCapture : IScreenCapture
3130 FeatureLevel . Level_10_0
3231 } ;
3332
33+ private const int BPP = 4 ;
34+
3435 #endregion
3536
3637 #region Properties & Fields
@@ -179,7 +180,13 @@ private void UpdateZones()
179180 MappedSubresource mapSource = _context . Map ( stagingTexture , 0 , MapMode . Read , MapFlags . None ) ;
180181 IntPtr sourcePtr = mapSource . DataPointer ;
181182 lock ( captureZone . Buffer )
182- Marshal . Copy ( sourcePtr , captureZone . Buffer , 0 , captureZone . Buffer . Length ) ;
183+ {
184+ for ( int y = 0 ; y < captureZone . Height ; y ++ )
185+ {
186+ Marshal . Copy ( sourcePtr , captureZone . Buffer , y * captureZone . Stride , captureZone . Stride ) ;
187+ sourcePtr += mapSource . RowPitch ;
188+ }
189+ }
183190
184191 _context . Unmap ( stagingTexture , 0 ) ;
185192 captureZone . SetUpdated ( ) ;
@@ -199,9 +206,6 @@ public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int
199206 if ( ( x + width ) > Display . Width ) throw new ArgumentException ( "x + width > Display width" ) ;
200207 if ( ( y + height ) > Display . Height ) throw new ArgumentException ( "y + height > Display height" ) ;
201208
202- int textureWidth = ( int ) Math . Ceiling ( width / 32.0 ) * 32 ;
203- int textureHeight = ( int ) Math . Ceiling ( height / 32.0 ) * 32 ;
204-
205209 int unscaledWidth = width ;
206210 int unscaledHeight = height ;
207211 if ( downscaleLevel > 0 )
@@ -214,12 +218,9 @@ public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int
214218 if ( width < 1 ) width = 1 ;
215219 if ( height < 1 ) height = 1 ;
216220
217- int bufferWidth = ( int ) Math . Ceiling ( width / 32.0 ) * 32 ;
218- int bufferHeight = ( int ) Math . Ceiling ( height / 32.0 ) * 32 ;
221+ byte [ ] buffer = new byte [ width * height * 4 ] ;
219222
220- byte [ ] buffer = new byte [ bufferWidth * bufferHeight * 4 ] ;
221-
222- CaptureZone captureZone = new ( _indexCounter ++ , x , y , width , height , downscaleLevel , unscaledWidth , unscaledHeight , textureWidth , textureHeight , bufferWidth , bufferHeight , buffer ) ;
223+ CaptureZone captureZone = new ( _indexCounter ++ , x , y , width , height , BPP , downscaleLevel , unscaledWidth , unscaledHeight , buffer ) ;
223224 lock ( _captureZones )
224225 InitializeCaptureZone ( captureZone ) ;
225226
@@ -252,13 +253,13 @@ private void InitializeCaptureZone(in CaptureZone captureZone)
252253 CpuAccessFlags = CpuAccessFlags . Read ,
253254 BindFlags = BindFlags . None ,
254255 Format = Format . B8G8R8A8_UNorm ,
255- Width = captureZone . BufferWidth ,
256- Height = captureZone . BufferHeight ,
256+ Width = captureZone . Width ,
257+ Height = captureZone . Height ,
257258 OptionFlags = ResourceOptionFlags . None ,
258259 MipLevels = 1 ,
259260 ArraySize = 1 ,
260261 SampleDescription = { Count = 1 , Quality = 0 } ,
261- Usage = Usage . Staging
262+ Usage = ResourceUsage . Staging
262263 } ;
263264 ID3D11Texture2D stagingTexture = _device ! . CreateTexture2D ( stagingTextureDesc ) ;
264265
@@ -271,13 +272,13 @@ private void InitializeCaptureZone(in CaptureZone captureZone)
271272 CpuAccessFlags = CpuAccessFlags . None ,
272273 BindFlags = BindFlags . RenderTarget | BindFlags . ShaderResource ,
273274 Format = Format . B8G8R8A8_UNorm ,
274- Width = captureZone . CaptureWidth ,
275- Height = captureZone . CaptureHeight ,
275+ Width = captureZone . UnscaledWidth ,
276+ Height = captureZone . UnscaledHeight ,
276277 OptionFlags = ResourceOptionFlags . GenerateMips ,
277278 MipLevels = captureZone . DownscaleLevel + 1 ,
278279 ArraySize = 1 ,
279280 SampleDescription = { Count = 1 , Quality = 0 } ,
280- Usage = Usage . Default
281+ Usage = ResourceUsage . Default
281282 } ;
282283 scalingTexture = _device ! . CreateTexture2D ( scalingTextureDesc ) ;
283284 scalingTextureView = _device . CreateShaderResourceView ( scalingTexture ) ;
@@ -302,7 +303,7 @@ public void Restart()
302303 _context = _device . ImmediateContext ;
303304
304305 _output = adapter . GetOutput ( Display . Index ) ;
305- using IDXGIOutput5 output1 = _output . QueryInterface < IDXGIOutput5 > ( ) ;
306+ using IDXGIOutput5 output = _output . QueryInterface < IDXGIOutput5 > ( ) ;
306307
307308 Texture2DDescription captureTextureDesc = new ( )
308309 {
@@ -315,7 +316,7 @@ public void Restart()
315316 MipLevels = 1 ,
316317 ArraySize = 1 ,
317318 SampleDescription = { Count = 1 , Quality = 0 } ,
318- Usage = Usage . Default
319+ Usage = ResourceUsage . Default
319320 } ;
320321 _captureTexture = _device . CreateTexture2D ( captureTextureDesc ) ;
321322
@@ -324,8 +325,8 @@ public void Restart()
324325 foreach ( CaptureZone captureZone in captureZones )
325326 InitializeCaptureZone ( captureZone ) ;
326327 }
327-
328- _duplicatedOutput = output1 . DuplicateOutput1 ( _device , Format . B8G8R8A8_UNorm ) ; // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth
328+
329+ _duplicatedOutput = output . DuplicateOutput1 ( _device , Format . B8G8R8A8_UNorm ) ; // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth
329330 }
330331 catch { Dispose ( false ) ; }
331332 }
0 commit comments