Skip to content

Commit 21b8eb2

Browse files
committed
bit of cleanup
1 parent e453d33 commit 21b8eb2

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

OVRSharp.Graphics.DirectX/DirectXCompositor.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public Bitmap GetMirrorImage(EVREye eye = EVREye.Eye_Left)
3232
var bitmap = new Bitmap(texDesc.Width, texDesc.Height);
3333
var boundsRect = new Rectangle(0, 0, texDesc.Width, texDesc.Height);
3434

35-
// Copy texture to CPU so we can read from it
36-
var cpuTex = new Texture2D(device, new Texture2DDescription
35+
using(var cpuTex = new Texture2D(device, new Texture2DDescription
3736
{
3837
CpuAccessFlags = CpuAccessFlags.Read,
3938
BindFlags = BindFlags.None,
@@ -45,27 +44,28 @@ public Bitmap GetMirrorImage(EVREye eye = EVREye.Eye_Left)
4544
ArraySize = 1,
4645
SampleDescription = { Count = 1, Quality = 0 },
4746
Usage = ResourceUsage.Staging
48-
});
47+
}))
48+
{
49+
// Copy texture to CPU so we can read from it
50+
device.ImmediateContext.CopyResource(tex, cpuTex);
51+
OpenVR.Compositor.ReleaseMirrorTextureD3D11(srvPtr);
4952

50-
device.ImmediateContext.CopyResource(tex, cpuTex);
51-
OpenVR.Compositor.ReleaseMirrorTextureD3D11(srvPtr);
53+
var mapSource = device.ImmediateContext.MapSubresource(cpuTex, 0, MapMode.Read, MapFlags.None);
54+
var mapDest = bitmap.LockBits(boundsRect, ImageLockMode.WriteOnly, bitmap.PixelFormat);
55+
var sourcePtr = mapSource.DataPointer;
56+
var destPtr = mapDest.Scan0;
5257

53-
var mapSource = device.ImmediateContext.MapSubresource(cpuTex, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
54-
var mapDest = bitmap.LockBits(boundsRect, ImageLockMode.WriteOnly, bitmap.PixelFormat);
55-
var sourcePtr = mapSource.DataPointer;
56-
var destPtr = mapDest.Scan0;
58+
for (int y = 0; y < texDesc.Height; y++)
59+
{
60+
Utilities.CopyMemory(destPtr, sourcePtr, texDesc.Width * 4);
61+
sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
62+
destPtr = IntPtr.Add(destPtr, mapDest.Stride);
63+
}
5764

58-
for (int y = 0; y < texDesc.Height; y++)
59-
{
60-
Utilities.CopyMemory(destPtr, sourcePtr, texDesc.Width * 4);
61-
sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
62-
destPtr = IntPtr.Add(destPtr, mapDest.Stride);
65+
bitmap.UnlockBits(mapDest);
66+
device.ImmediateContext.UnmapSubresource(cpuTex, 0);
6367
}
6468

65-
bitmap.UnlockBits(mapDest);
66-
device.ImmediateContext.UnmapSubresource(cpuTex, 0);
67-
cpuTex.Dispose();
68-
6969
FlipChannels(ref bitmap);
7070
return bitmap;
7171
}

OVRSharp.Graphics.DirectX/OVRSharp.Graphics.DirectX.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Copyright>2020-2021 TJ Horner</Copyright>
1313
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1414
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15-
<Product>OVRSharp</Product>
15+
<Product>OVRSharp.Graphics.DirectX</Product>
1616
<VersionPrefix>1.1.0</VersionPrefix>
1717
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
1818
</PropertyGroup>

OVRSharp.Graphics.OpenGL/OVRSharp.Graphics.OpenGL.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
<Copyright>2020-2021 TJ Horner</Copyright>
1313
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1414
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15-
<Product>OVRSharp</Product>
15+
<Product>OVRSharp.Graphics.OpenGL</Product>
1616
<VersionPrefix>1.1.0</VersionPrefix>
1717
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
18+
<IsPackable>false</IsPackable>
1819
</PropertyGroup>
1920

2021
<ItemGroup>

0 commit comments

Comments
 (0)