using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace GCSeries { public static class FARDll { [DllImport("f-ar")] internal static extern int fmBeginFrame(); [DllImport("f-ar")] internal static extern int fmEndFrame(); [DllImport("f-ar")] private static extern int fmSetStereoDisplayTextures(System.IntPtr leftNativePTR, System.IntPtr rightNativePTR, int dxgiFormat); [DllImport("f-ar")] private static extern int fmARStartViewDX11(System.IntPtr hWnd, System.IntPtr leftNativePTR, System.IntPtr rightNativePTR, int w, int h); [DllImport("f-ar")] private static extern void fmARSwitchProjector(int type); [DllImport("f-ar")] private static extern void fmARIsGamaSpace(int cSpace); [DllImport("f-ar")] private static extern void fmARStopView(); /// /// 帧结束回调 /// /// [DllImport("f-ar")] public static extern IntPtr GetRenderEventFunc(); /// /// 描述屏幕坐标信息与ID信息 /// [StructLayout(LayoutKind.Sequential)] public struct GCinfo { public bool isGCmonitor; public int RCleft; public int RCright; public int RCtop; public int RCbottom; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 18)] public string DeviceName; }; /// /// 投屏状态值 /// public enum FAR_Status { /// /// 成功 /// FAR_Ok = 1, /// /// 没被初始化或正在初始化中 /// FAR_NotInitialized = 0, /// /// 非法硬件设备 /// FAR_Illegal = -1, /// /// 窗口句柄丢失 /// FAR_InvaliHwndHandle = -2, /// /// 渲染设备初始化失败 /// FAR_D3DFailed = -3, /// /// 纹理句柄丢失 /// FAR_InvaliTexturedHandle = -4, /// /// 渲染等待进程超时 /// FAR_Timeout = -5, /// /// windows版本低于win10 /// FAR_SysNnotSupported = -6, /// /// 显卡型号小于900 /// FAR_GraphicsCardUnsupported = -7 } /// /// 通过EDID获取屏幕信息,返回屏幕坐标列表 /// /// /// result >= 0 返回当前屏幕个数 /// result = -1 获取驱动失败 /// result = -2 读取EDID失败 /// [DllImport("f-ar")] public static extern int fmARUpdatePhysicalMonitor(); /// /// 获取缓存中所有显示器数量 /// /// 缓存中所有显示器数量 [DllImport("f-ar")] public static extern int fmARGetMonitorCount(); /// /// 输入index返回GCinfo数据 /// GCinfo* out_struct需要在外部创建内存 /// /// 显示器坐标与设备ID信息 /// 需要获取的屏幕索引 /// /// result = 1 数据获取成功 /// result = -1 out_struct为空指针 /// result = -2 index越界 /// [DllImport("f-ar")] public static extern int fmARGetMonitorInfoByIndex(ref GCinfo out_struct, int index); ///------------------------------------------------------------------------------------------------- /// 独一个json文件路径. /// /// Dx, 2019/5/31. /// /// [in,out] If non-null, the /// fview file. /// /// An int. ///------------------------------------------------------------------------------------------------- [DllImport("f-ar")] public static extern int fmFViewReadJson(); //返回标定的位置信息 [DllImport("f-ar")] public static extern void fmFViewGetPosition(IntPtr value); //返回标定的旋转信息 [DllImport("f-ar")] public static extern void fmFViewGetRotation(IntPtr value); /// /// user32 API 用于处理投屏窗口位置 /// /// /// /// [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); ///根据窗口句柄获取pid [DllImport("User32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID); ///移动窗口位置 [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint); /// /// 当前项目的色彩空间 /// PlayerSetting->OtherSetting->ColorSpase /// public enum U3DColorSpace { Gama = 0, Linear = 1 } private static U3DColorSpace currentColorSpace = FARDll.U3DColorSpace.Gama; /// /// 记录当前的色彩空间 /// public static U3DColorSpace CurrentColorSpace { get { return currentColorSpace; } set { //设置当前的色彩空间,u3d默认是Gama空间 FARDll.SetColorSpace(value); currentColorSpace = value; } } /// /// 帧顺序输出执行 /// /// public static int BeginFrame() { return fmBeginFrame(); } /// /// 帧顺序输出执行 /// /// public static int EndFrame() { return fmEndFrame(); } /// /// 将纹理目标传递到底层 /// /// /// /// /// public static int SetStereoDisplayTextures(System.IntPtr leftNativePTR, System.IntPtr rightNativePTR, int dxgiFormat) { return fmSetStereoDisplayTextures(leftNativePTR, rightNativePTR, dxgiFormat); } /// /// 投屏投影方式 /// public enum ProjectorType { /// /// 投屏为2D模式 /// ---------- /// | L | /// ----------- /// _2D = 0, /// /// 投屏为左右3D模式 /// ----------- /// | L | R | /// ----------- /// LeftRight = 1//左右投影 } public static ProjectorType CurProjectorType = ProjectorType._2D; /// /// 在目标窗口中渲染纹理指针 /// /// 创建好的窗口句柄 /// 左半屏的左眼纹理指针 /// 右半屏的右眼纹理指针,此参数为空代表2D投屏 /// /// 返回错误代码 /// errorCode >0 成功 /// errorCode ==-1 不在自己的机器上 /// errorCode ==-2 窗口句柄丢失 /// errorCode ==-3 纹理句柄丢失 /// errorCode ==-4 渲染设备初始化失败 /// errorCode ==-5 渲染等待进程超时 /// errorCode ==-6 windows版本低于win10 /// public static int StartView(IntPtr hWnd, IntPtr leftNativePTR, IntPtr rightNativePTR) { errorCode = fmARStartViewDX11(hWnd, leftNativePTR, rightNativePTR, SwapchainWidth, SwapchanHeight); return errorCode; } /// /// 设置当前的色彩空间,u3d默认是Gama空间 /// /// u3d工程使用的色彩空间 private static void SetColorSpace(U3DColorSpace cSpace) { currentColorSpace = cSpace; fmARIsGamaSpace((int)cSpace); } /// ///切换投影方式 ///调用StartView_LR(...)后,可切换到只显示左画面到投屏窗口或左右一起显示 /// ----------- ---------- /// | L | R | or | L | /// ----------- ---------- ///如果只调用StartView(...),则此函数无效 /// /// 目标投屏方式 public static void SwitchProjector(ProjectorType type) { fmARSwitchProjector((int)type); CurProjectorType = type; } /// /// 安全关闭窗口 /// public static void CloseDown() { fmARStopView(); } /// /// 投屏窗口交换链路宽度 /// public const int SwapchainWidth = 1920; /// /// 投屏窗口交换链路高度 /// public const int SwapchanHeight = 1080; private static int errorCode = 0; /// /// 显示窗口进程 /// public static Process viewProcess; } }