|
2 | 2 | Unity Capture |
3 | 3 | Copyright (c) 2018 Bernhard Schelling |
4 | 4 |
|
| 5 | + Feature contributors: |
| 6 | + Brandon J Matthews (low-level interface for custom texture capture) |
| 7 | +
|
5 | 8 | Based on UnityCam |
6 | 9 | https://github.com/mrayy/UnityCam |
7 | 10 | Copyright (c) 2016 MHD Yamen Saraiji |
@@ -31,8 +34,8 @@ public class UnityCapture : MonoBehaviour |
31 | 34 | public enum ECaptureDevice { CaptureDevice1 = 0, CaptureDevice2 = 1, CaptureDevice3 = 2, CaptureDevice4 = 3, CaptureDevice5 = 4, CaptureDevice6 = 5, CaptureDevice7 = 6, CaptureDevice8 = 7, CaptureDevice9 = 8, CaptureDevice10 = 9 } |
32 | 35 | public enum EResizeMode { Disabled = 0, LinearResize = 1 } |
33 | 36 | public enum EMirrorMode { Disabled = 0, MirrorHorizontally = 1 } |
34 | | - public enum ECaptureSendResult { SUCCESS = 0, WARNING_FRAMESKIP = 1, WARNING_CAPTUREINACTIVE = 2, ERROR_UNSUPPORTEDGRAPHICSDEVICE = 100, ERROR_PARAMETER = 101, ERROR_TOOLARGERESOLUTION = 102, ERROR_TEXTUREFORMAT = 103, ERROR_READTEXTURE = 104, ERROR_INVALIDCAPTUREINSTANCEPTR = 200}; |
35 | | - |
| 37 | + public enum ECaptureSendResult { SUCCESS = 0, WARNING_FRAMESKIP = 1, WARNING_CAPTUREINACTIVE = 2, ERROR_UNSUPPORTEDGRAPHICSDEVICE = 100, ERROR_PARAMETER = 101, ERROR_TOOLARGERESOLUTION = 102, ERROR_TEXTUREFORMAT = 103, ERROR_READTEXTURE = 104, ERROR_INVALIDCAPTUREINSTANCEPTR = 200 }; |
| 38 | + |
36 | 39 | [SerializeField] [Tooltip("Capture device index")] public ECaptureDevice CaptureDevice = ECaptureDevice.CaptureDevice1; |
37 | 40 | [SerializeField] [Tooltip("Scale image if Unity and capture resolution don't match (can introduce frame dropping, not recommended)")] public EResizeMode ResizeMode = EResizeMode.Disabled; |
38 | 41 | [SerializeField] [Tooltip("Mirror captured output image")] public EMirrorMode MirrorMode = EMirrorMode.Disabled; |
@@ -82,25 +85,33 @@ void OnRenderImage(RenderTexture source, RenderTexture destination) |
82 | 85 | } |
83 | 86 | } |
84 | 87 |
|
85 | | - |
86 | | - public class Interface { |
| 88 | + public class Interface |
| 89 | + { |
87 | 90 | [System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static System.IntPtr CaptureCreateInstance(int CapNum); |
88 | 91 | [System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static void CaptureDeleteInstance(System.IntPtr instance); |
89 | 92 | [System.Runtime.InteropServices.DllImport("UnityCapturePlugin")] extern static ECaptureSendResult CaptureSendTexture(System.IntPtr instance, System.IntPtr nativetexture, bool UseDoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode, bool IsLinearColorSpace); |
90 | 93 | System.IntPtr CaptureInstance; |
91 | | - |
92 | | - public Interface(ECaptureDevice captureDevice) { |
93 | | - CaptureInstance = CaptureCreateInstance((int)captureDevice); |
| 94 | + |
| 95 | + public Interface(ECaptureDevice CaptureDevice) |
| 96 | + { |
| 97 | + CaptureInstance = CaptureCreateInstance((int)CaptureDevice); |
94 | 98 | } |
95 | 99 |
|
96 | | - public void Close() { |
97 | | - CaptureDeleteInstance(CaptureInstance); |
| 100 | + ~Interface() |
| 101 | + { |
| 102 | + Close(); |
98 | 103 | } |
99 | 104 |
|
100 | | - public ECaptureSendResult SendTexture(Texture source, bool DoubleBuffering, EResizeMode ResizeMode, EMirrorMode MirrorMode) { |
| 105 | + public void Close() |
| 106 | + { |
| 107 | + if (CaptureInstance != System.IntPtr.Zero) CaptureDeleteInstance(CaptureInstance); |
| 108 | + CaptureInstance = System.IntPtr.Zero; |
| 109 | + } |
| 110 | + |
| 111 | + public ECaptureSendResult SendTexture(Texture Source, bool DoubleBuffering = false, EResizeMode ResizeMode = EResizeMode.Disabled, EMirrorMode MirrorMode = EMirrorMode.Disabled) |
| 112 | + { |
101 | 113 | if (CaptureInstance == System.IntPtr.Zero) return ECaptureSendResult.ERROR_INVALIDCAPTUREINSTANCEPTR; |
102 | | - ECaptureSendResult result = CaptureSendTexture(CaptureInstance, source.GetNativeTexturePtr(), DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear); |
103 | | - return result; |
| 114 | + return CaptureSendTexture(CaptureInstance, Source.GetNativeTexturePtr(), DoubleBuffering, ResizeMode, MirrorMode, QualitySettings.activeColorSpace == ColorSpace.Linear); |
104 | 115 | } |
105 | 116 | } |
106 | 117 | } |
0 commit comments