t1 / TFDContents / Assets / Standard Assets / KinectBuffer.cs @ 9
이력 | 보기 | 이력해설 | 다운로드 (5.32 KB)
| 1 |
#if !(UNITY_WSA_10_0 && NETFX_CORE) |
|---|---|
| 2 |
using RootSystem = System; |
| 3 |
using System; |
| 4 |
using System.Collections.Generic; |
| 5 |
using System.Runtime.InteropServices; |
| 6 |
|
| 7 |
namespace Windows.Kinect |
| 8 |
{
|
| 9 |
// NOTE: This uses an IBuffer under the covers, it is renamed here to give parity to our managed APIs. |
| 10 |
public class KinectBuffer : Helper.INativeWrapper, IDisposable |
| 11 |
{
|
| 12 |
internal RootSystem.IntPtr _pNative; |
| 13 |
|
| 14 |
RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
|
| 15 |
|
| 16 |
// Constructors and Finalizers |
| 17 |
internal KinectBuffer(RootSystem.IntPtr pNative) |
| 18 |
{
|
| 19 |
_pNative = pNative; |
| 20 |
Windows_Storage_Streams_IBuffer_AddRefObject(ref _pNative); |
| 21 |
} |
| 22 |
|
| 23 |
~KinectBuffer() |
| 24 |
{
|
| 25 |
Dispose(false); |
| 26 |
} |
| 27 |
|
| 28 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
| 29 |
private static extern void Windows_Storage_Streams_IBuffer_ReleaseObject(ref RootSystem.IntPtr pNative); |
| 30 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
| 31 |
private static extern void Windows_Storage_Streams_IBuffer_AddRefObject(ref RootSystem.IntPtr pNative); |
| 32 |
private void Dispose(bool disposing) |
| 33 |
{
|
| 34 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 35 |
{
|
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
Helper.NativeObjectCache.RemoveObject<KinectBuffer>(_pNative); |
| 40 |
|
| 41 |
if (disposing) |
| 42 |
{
|
| 43 |
Windows_Storage_Streams_IBuffer_Dispose(_pNative); |
| 44 |
} |
| 45 |
|
| 46 |
Windows_Storage_Streams_IBuffer_ReleaseObject(ref _pNative); |
| 47 |
|
| 48 |
_pNative = RootSystem.IntPtr.Zero; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
// Public Properties |
| 53 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
|
| 54 |
private static extern uint Windows_Storage_Streams_IBuffer_get_Capacity(RootSystem.IntPtr pNative); |
| 55 |
public uint Capacity |
| 56 |
{
|
| 57 |
get |
| 58 |
{
|
| 59 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 60 |
{
|
| 61 |
throw new RootSystem.ObjectDisposedException("KinectBuffer");
|
| 62 |
} |
| 63 |
|
| 64 |
uint capacity = Windows_Storage_Streams_IBuffer_get_Capacity(_pNative); |
| 65 |
Helper.ExceptionHelper.CheckLastError(); |
| 66 |
return capacity; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
|
| 71 |
private static extern uint Windows_Storage_Streams_IBuffer_get_Length(RootSystem.IntPtr pNative); |
| 72 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
|
| 73 |
private static extern void Windows_Storage_Streams_IBuffer_put_Length(RootSystem.IntPtr pNative, uint value); |
| 74 |
public uint Length |
| 75 |
{
|
| 76 |
get |
| 77 |
{
|
| 78 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 79 |
{
|
| 80 |
throw new RootSystem.ObjectDisposedException("KinectBuffer");
|
| 81 |
} |
| 82 |
|
| 83 |
uint length = Windows_Storage_Streams_IBuffer_get_Length(_pNative); |
| 84 |
Helper.ExceptionHelper.CheckLastError(); |
| 85 |
return length; |
| 86 |
} |
| 87 |
set |
| 88 |
{
|
| 89 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 90 |
{
|
| 91 |
throw new RootSystem.ObjectDisposedException("KinectBuffer");
|
| 92 |
} |
| 93 |
|
| 94 |
Windows_Storage_Streams_IBuffer_put_Length(_pNative, value); |
| 95 |
Helper.ExceptionHelper.CheckLastError(); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
| 100 |
private static extern void Windows_Storage_Streams_IBuffer_Dispose(RootSystem.IntPtr pNative); |
| 101 |
// Constructors and Finalizers |
| 102 |
public void Dispose() |
| 103 |
{
|
| 104 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 105 |
{
|
| 106 |
throw new RootSystem.ObjectDisposedException("KinectBuffer");
|
| 107 |
} |
| 108 |
|
| 109 |
Dispose(true); |
| 110 |
RootSystem.GC.SuppressFinalize(this); |
| 111 |
} |
| 112 |
|
| 113 |
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
|
| 114 |
private static extern RootSystem.IntPtr Windows_Storage_Streams_IBuffer_get_UnderlyingBuffer(RootSystem.IntPtr pNative); |
| 115 |
public IntPtr UnderlyingBuffer |
| 116 |
{
|
| 117 |
get |
| 118 |
{
|
| 119 |
if (_pNative == RootSystem.IntPtr.Zero) |
| 120 |
{
|
| 121 |
throw new RootSystem.ObjectDisposedException("KinectBuffer");
|
| 122 |
} |
| 123 |
|
| 124 |
RootSystem.IntPtr value = Windows_Storage_Streams_IBuffer_get_UnderlyingBuffer(_pNative); |
| 125 |
Helper.ExceptionHelper.CheckLastError(); |
| 126 |
return value; |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
#endif |