Skip to content

Commit b98c579

Browse files
committed
I am going to become the joker
1 parent 8491119 commit b98c579

5 files changed

Lines changed: 30 additions & 30 deletions

File tree

OVRSharp.Graphics.OpenGL/OpenGLCompositor.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@
22
using System.Drawing;
33
using System.Drawing.Imaging;
44
using OpenTK.Graphics;
5-
using OpenTK.Graphics.OpenGLES3;
5+
using OpenTK.Graphics.OpenGLES3;
6+
using OpenTK.Windowing.Desktop;
67
using OVRSharp.Exceptions;
78
using Valve.VR;
89
using PixelFormat = System.Drawing.Imaging.PixelFormat;
910

1011
namespace OVRSharp.Graphics.OpenGL
1112
{
12-
public class OpenGLCompositor : ICompositorAPI
13+
public class OpenGLCompositor : NativeWindow, ICompositorAPI
1314
{
15+
public OpenGLCompositor() : base(
16+
new NativeWindowSettings
17+
{
18+
StartVisible = true,
19+
Title = "OVRSharp Window",
20+
WindowState = OpenTK.Windowing.Common.WindowState.Minimized
21+
}
22+
) { }
23+
1424
public Bitmap GetMirrorImage(EVREye eye = EVREye.Eye_Left)
1525
{
1626
uint textureId = 0;
17-
var handle = IntPtr.Zero;
18-
27+
var handle = IntPtr.Zero;
28+
1929
var result = OpenVR.Compositor.GetMirrorTextureGL(eye, ref textureId, handle);
2030
if (result != EVRCompositorError.None)
21-
throw new OpenVRSystemException<EVRCompositorError>("Failed to get mirror texture from OpenVR", result);
22-
31+
throw new OpenVRSystemException<EVRCompositorError>("Failed to get mirror texture from OpenVR", result);
32+
2333
GL.BindTexture(TextureTarget.Texture2d, new TextureHandle((int)textureId));
2434

2535
var height = 0;

OVRSharp/Application.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OVRSharp
66
{
7-
public class Application : IDisposable
7+
public class Application
88
{
99
public enum ApplicationType
1010
{
@@ -62,21 +62,5 @@ public void Shutdown()
6262
OpenVR.Shutdown();
6363
OVRSystem = null;
6464
}
65-
66-
private void ReleaseUnmanagedResources()
67-
{
68-
Shutdown();
69-
}
70-
71-
public void Dispose()
72-
{
73-
ReleaseUnmanagedResources();
74-
GC.SuppressFinalize(this);
75-
}
76-
77-
~Application()
78-
{
79-
ReleaseUnmanagedResources();
80-
}
8165
}
8266
}

OVRSharp/Exceptions/OpenVRSystemException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42

53
namespace OVRSharp.Exceptions
64
{
@@ -12,7 +10,7 @@ public OpenVRSystemException() : base() { }
1210
public OpenVRSystemException(string message) : base(message) { }
1311
public OpenVRSystemException(string message, Exception inner) : base(message, inner) { }
1412

15-
public OpenVRSystemException(string message, ErrorType error) : this(message)
13+
public OpenVRSystemException(string message, ErrorType error) : this($"{message} ({error})")
1614
{
1715
Error = error;
1816
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
using FluentAssertions;
12
using NUnit.Framework;
23

34
namespace OVRSharp.Graphics.OpenGL.Tests
45
{
56
public class CompositorTests
67
{
7-
[SetUp]
8+
private Application app;
9+
private ICompositorAPI compositor;
10+
11+
[OneTimeSetUp]
812
public void Setup()
913
{
10-
14+
app = new Application(Application.ApplicationType.Background);
15+
compositor = new OpenGLCompositor();
1116
}
1217

1318
[Test]
14-
public void Test1()
19+
public void ShouldGetMirrorTextureSuccessfully()
1520
{
16-
Assert.Pass();
21+
var bitmap = compositor.GetMirrorImage(Valve.VR.EVREye.Eye_Right);
22+
bitmap.Height.Should().BeGreaterThan(0);
23+
bitmap.Width.Should().BeGreaterThan(0);
1724
}
1825
}
1926
}

tests/OVRSharp.Graphics.OpenGL.Tests/OVRSharp.Graphics.OpenGL.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1011
<PackageReference Include="NUnit" Version="3.12.0" />
1112
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
1213
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />

0 commit comments

Comments
 (0)