Wes xx mediapipe integration
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace Mediapipe.Tests
|
||||
{
|
||||
public class GlCalculatorHelperTest
|
||||
{
|
||||
#region Constructor
|
||||
[Test, GpuOnly]
|
||||
public void Ctor_ShouldInstantiateGlCalculatorHelper()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
Assert.AreNotEqual(IntPtr.Zero, glCalculatorHelper.mpPtr);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #isDisposed
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
Assert.False(glCalculatorHelper.isDisposed);
|
||||
}
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
|
||||
{
|
||||
var glCalculatorHelper = new GlCalculatorHelper();
|
||||
glCalculatorHelper.Dispose();
|
||||
|
||||
Assert.True(glCalculatorHelper.isDisposed);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #InitializeForTest
|
||||
[Test, GpuOnly]
|
||||
public void InitializeForTest_ShouldInitialize()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
Assert.False(glCalculatorHelper.Initialized());
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
Assert.True(glCalculatorHelper.Initialized());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #RunInGlContext
|
||||
[Test, GpuOnly]
|
||||
public void RunInGlContext_ShouldReturnOk_When_FunctionReturnsOk()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
var status = glCalculatorHelper.RunInGlContext(() => { });
|
||||
Assert.True(status.Ok());
|
||||
}
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
public void RunInGlContext_ShouldReturnInternal_When_FunctionThrows()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
var status = glCalculatorHelper.RunInGlContext((GlCalculatorHelper.GlFunction)(() => { throw new Exception("Function Throws"); }));
|
||||
Assert.AreEqual(Status.StatusCode.Internal, status.Code());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #CreateSourceTexture
|
||||
[Test, GpuOnly]
|
||||
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Srgba, 32, 24))
|
||||
{
|
||||
var status = glCalculatorHelper.RunInGlContext(() =>
|
||||
{
|
||||
var texture = glCalculatorHelper.CreateSourceTexture(imageFrame);
|
||||
|
||||
Assert.AreEqual(32, texture.width);
|
||||
Assert.AreEqual(24, texture.height);
|
||||
|
||||
texture.Dispose();
|
||||
});
|
||||
Assert.True(status.Ok());
|
||||
|
||||
status.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
[Ignore("Skip because a thread will hang")]
|
||||
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Sbgra, 32, 24))
|
||||
{
|
||||
var status = glCalculatorHelper.RunInGlContext(() =>
|
||||
{
|
||||
using (var texture = glCalculatorHelper.CreateSourceTexture(imageFrame))
|
||||
{
|
||||
texture.Release();
|
||||
}
|
||||
});
|
||||
Assert.AreEqual(Status.StatusCode.FailedPrecondition, status.Code());
|
||||
|
||||
status.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #CreateDestinationTexture
|
||||
[Test, GpuOnly]
|
||||
public void CreateDestinationTexture_ShouldReturnGlTexture_When_GpuBufferFormatIsValid()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
var status = glCalculatorHelper.RunInGlContext(() =>
|
||||
{
|
||||
var glTexture = glCalculatorHelper.CreateDestinationTexture(32, 24, GpuBufferFormat.kBGRA32);
|
||||
|
||||
Assert.AreEqual(32, glTexture.width);
|
||||
Assert.AreEqual(24, glTexture.height);
|
||||
});
|
||||
|
||||
Assert.True(status.Ok());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #framebuffer
|
||||
[Test, GpuOnly]
|
||||
public void Framebuffer_ShouldReturnGLName()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
// default frame buffer
|
||||
Assert.AreEqual(0, glCalculatorHelper.framebuffer);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #GetGlContext
|
||||
[Test, GpuOnly]
|
||||
public void GetGlContext_ShouldReturnCurrentContext()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
using (var glContext = glCalculatorHelper.GetGlContext())
|
||||
{
|
||||
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eglContext);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.nsglContext);
|
||||
#elif UNITY_IOS
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eaglContext);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f47dcca1b6cbd6538c87a9914863444
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace Mediapipe.Tests
|
||||
{
|
||||
public class GlContextTest
|
||||
{
|
||||
#region .GetCurrent
|
||||
[Test, GpuOnly]
|
||||
public void GetCurrent_ShouldReturnNull_When_CalledOutOfGlContext()
|
||||
{
|
||||
var glContext = GlContext.GetCurrent();
|
||||
|
||||
Assert.Null(glContext);
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
public void GetCurrent_ShouldReturnCurrentContext_When_CalledInGlContext()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
glCalculatorHelper.RunInGlContext(() =>
|
||||
{
|
||||
using (var glContext = GlContext.GetCurrent())
|
||||
{
|
||||
Assert.NotNull(glContext);
|
||||
Assert.True(glContext.IsCurrent());
|
||||
}
|
||||
}).AssertOk();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #IsCurrent
|
||||
public void IsCurrent_ShouldReturnFalse_When_CalledOutOfGlContext()
|
||||
{
|
||||
var glContext = GetGlContext();
|
||||
|
||||
Assert.False(glContext.IsCurrent());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
[Test, GpuOnly]
|
||||
public void ShouldReturnProperties()
|
||||
{
|
||||
using (var glContext = GetGlContext())
|
||||
{
|
||||
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eglDisplay);
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eglConfig);
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eglContext);
|
||||
Assert.AreEqual(3, glContext.glMajorVersion);
|
||||
Assert.AreEqual(2, glContext.glMinorVersion);
|
||||
Assert.AreEqual(0, glContext.glFinishCount);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.nsglContext);
|
||||
#elif UNITY_IOS
|
||||
Assert.AreNotEqual(IntPtr.Zero, glContext.eaglContext);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private GlContext GetGlContext()
|
||||
{
|
||||
using (var glCalculatorHelper = new GlCalculatorHelper())
|
||||
{
|
||||
glCalculatorHelper.InitializeForTest(GpuResources.Create().Value());
|
||||
|
||||
return glCalculatorHelper.GetGlContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5e3ffbb666f2d185b043064194cbf12
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Mediapipe.Tests
|
||||
{
|
||||
public class GlTextureTest
|
||||
{
|
||||
#region Constructor
|
||||
[Test, GpuOnly]
|
||||
public void Ctor_ShouldInstantiateGlTexture_When_CalledWithNoArguments()
|
||||
{
|
||||
using (var glTexture = new GlTexture())
|
||||
{
|
||||
Assert.AreEqual(0, glTexture.width);
|
||||
Assert.AreEqual(0, glTexture.height);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #isDisposed
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
|
||||
{
|
||||
using (var glTexture = new GlTexture())
|
||||
{
|
||||
Assert.False(glTexture.isDisposed);
|
||||
}
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
|
||||
{
|
||||
var glTexture = new GlTexture();
|
||||
glTexture.Dispose();
|
||||
|
||||
Assert.True(glTexture.isDisposed);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region target
|
||||
[Test, GpuOnly]
|
||||
public void Target_ShouldReturnTarget()
|
||||
{
|
||||
using (var glTexture = new GlTexture())
|
||||
{
|
||||
Assert.AreEqual(Gl.GL_TEXTURE_2D, glTexture.target);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbe1d82329bb2b09a88651d8ac9ad4fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Mediapipe.Tests
|
||||
{
|
||||
public class GpuResourcesTest
|
||||
{
|
||||
#region Create
|
||||
[Test, GpuOnly]
|
||||
public void Create_ShouldReturnStatusOrGpuResources()
|
||||
{
|
||||
using (var statusOrGpuResources = GpuResources.Create())
|
||||
{
|
||||
Assert.True(statusOrGpuResources.Ok());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region #isDisposed
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
|
||||
{
|
||||
using (var gpuResources = GpuResources.Create().Value())
|
||||
{
|
||||
Assert.False(gpuResources.isDisposed);
|
||||
}
|
||||
}
|
||||
|
||||
[Test, GpuOnly]
|
||||
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
|
||||
{
|
||||
var gpuResources = GpuResources.Create().Value();
|
||||
gpuResources.Dispose();
|
||||
|
||||
Assert.True(gpuResources.isDisposed);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e987f90210347a37b48e4a9f9f93c53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user