public RemoteAccess()
            {
                var res = Interop.NativeMethods.CLSIDFromProgID("WPFVirtualCameraServer.VirtualCameraServer", out Guid clsid);

                if (res != 0)
                {
                    return;
                }

                var l_IID_IClassFactory = new Guid(Interop.NativeMethods.IID_IClassFactory);

                var l_IID_IVirtualCameraServer = typeof(IVirtualCameraServer).GUID;



                m_ClassFactoryObj = Interop.NativeMethods.CoGetClassObject(clsid, Interop.NativeMethods.CLSCTX.CLSCTX_LOCAL_SERVER, IntPtr.Zero, l_IID_IClassFactory);

                var l_ClassFactory = m_ClassFactoryObj as Interop.NativeMethods.IClassFactory;

                if (l_ClassFactory == null)
                {
                    m_ClassFactoryObj = null;

                    return;
                }

                IntPtr l_ptr = IntPtr.Zero;

                res = l_ClassFactory.CreateInstance(IntPtr.Zero, ref l_IID_IVirtualCameraServer, out l_ptr);

                if (res != 0)
                {
                    return;
                }

                m_IVirtualCameraServer = Marshal.GetObjectForIUnknown(l_ptr) as IVirtualCameraServer;

                if (m_IVirtualCameraServer == null)
                {
                    return;
                }

                var l_sharedHadler = m_IVirtualCameraServer.get_DirectX11TextureHandler(out res);

                if (res != 0)
                {
                    return;
                }

                m_SharedTexture = SharedTexture.createSharedTexture(l_sharedHadler);

                if (m_SharedTexture == null)
                {
                    return;
                }

                TextureDesc = m_SharedTexture.GetDesc();

                m_ReadTexture = ReadTexture.cretaeReadTexture(TextureDesc);
            }
            protected virtual void Dispose(bool disposing)
            {
                if (!disposedValue)
                {
                    if (disposing)
                    {
                    }

                    if (m_IVirtualCameraServer != null)
                    {
                        Marshal.ReleaseComObject(m_IVirtualCameraServer);
                    }

                    if (m_ClassFactoryObj != null)
                    {
                        Marshal.ReleaseComObject(m_ClassFactoryObj);
                    }

                    m_SharedTexture = null;

                    m_IVirtualCameraServer = null;

                    m_ClassFactoryObj = null;

                    disposedValue = true;
                }
            }
        public static SharedTexture createSharedTexture(IntPtr a_sharedHandler)
        {
            SharedTexture l_resturn = new SharedTexture();

            if (a_sharedHandler == IntPtr.Zero)
            {
                return(l_resturn);
            }

            l_resturn.m_shared_texture = Direct3D11Device.Instance.Device.CreateTexture2D(a_sharedHandler);

            return(l_resturn);
        }
Ejemplo n.º 4
0
        public void Read(SharedTexture a_TargetTexture, IntPtr aDest)
        {
            using (var lImmediateContext = Direct3D11Device.Instance.Device.GetImmediateContext())
            {
                // Copy image into CPU access texture
                lImmediateContext.CopyResource(this.m_read_texture.getD3D11Resource(), a_TargetTexture.getD3D11Resource());

                lImmediateContext.Flush();

                // Copy from CPU access texture to bitmap buffer

                D3D11_MAPPED_SUBRESOURCE resource = new D3D11_MAPPED_SUBRESOURCE();
                var subresource = D3D11DeviceContext.D3D11CalcSubresource(0, 0, 0);
                var lres        = lImmediateContext.Map(this.m_read_texture.getD3D11Resource(), subresource, D3D11DeviceContext.D3D11_MAP_READ_WRITE, 0, resource);

                NativeMethods.memcpy(aDest, resource.pData, m_BufferLength);

                lImmediateContext.Unmap(this.m_read_texture.getD3D11Resource(), subresource);
            }
        }