EZXRNativeRenderring.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Runtime.InteropServices;
  5. using System;
  6. using System.IO;
  7. using EZXR.Glass.Core;
  8. namespace EZXR.Glass.Rendering
  9. {
  10. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  11. public struct EZXRRendererHotConfig
  12. {
  13. [MarshalAs(UnmanagedType.Bool)]
  14. public bool warp_1;
  15. public EZXRRendererHotConfig(bool isWarp)
  16. {
  17. this.warp_1 = isWarp;
  18. }
  19. }
  20. public class EZXRNativeRenderring
  21. {
  22. public IntPtr FrameInfoPtr;
  23. private IntPtr m_FrameTexturesPtr;
  24. private EZXRRendererHotConfig m_cacheCfg;
  25. public EZXRNativeRenderring()
  26. {
  27. int sizeOfFrameInfo = Marshal.SizeOf(typeof(FrameInfo));
  28. FrameInfoPtr = Marshal.AllocHGlobal(sizeOfFrameInfo);
  29. }
  30. ~EZXRNativeRenderring()
  31. {
  32. Marshal.FreeHGlobal(FrameInfoPtr);
  33. }
  34. /// <summary>
  35. /// start ezxr mtp renderer. return value aligns with @startEZXRRenderer
  36. /// </summary>
  37. /// <returns>
  38. /// 0: succ
  39. /// -1: displayer not showed up
  40. /// -2: environment issues
  41. /// -3: ezxr mtp renderer is already started up
  42. /// </returns>
  43. public int Start()
  44. {
  45. return NativeAPI.startEZXRRenderer();
  46. }
  47. public void DoExtendedRenderring()
  48. {
  49. FrameInfo frameinfo = (FrameInfo)Marshal.PtrToStructure(FrameInfoPtr, typeof(FrameInfo));
  50. NativeAPI.setFrameInfo(FrameInfoPtr);
  51. }
  52. public void WriteFrameData(FrameInfo frame)
  53. {
  54. Marshal.StructureToPtr(frame, FrameInfoPtr, true);
  55. }
  56. public void Stop()
  57. {
  58. NativeAPI.stopEZXRRenderer();
  59. }
  60. public void WriteRendererHotConfig(EZXRRendererHotConfig cfg)
  61. {
  62. m_cacheCfg = cfg;
  63. }
  64. public void HotUpdateRenderer()
  65. {
  66. NativeAPI.hotConfigEZXRRenderer(m_cacheCfg);
  67. }
  68. private partial struct NativeAPI
  69. {
  70. #if UNITY_EDITOR
  71. public static int startEZXRRenderer() { return -1; }
  72. //public static void setFrameInfo(ref FrameInfo frameInfoPtr) { }
  73. public static void setFrameInfo(IntPtr frameInfoPtr) { }
  74. public static void stopEZXRRenderer() { }
  75. public static void hotConfigEZXRRenderer(EZXRRendererHotConfig cfg) { }
  76. #elif UNITY_ANDROID
  77. [DllImport(NativeConsts.NativeLibrary)]
  78. public static extern int startEZXRRenderer();
  79. [DllImport(NativeConsts.NativeLibrary)]
  80. //public static extern void setFrameInfo(ref FrameInfo frameInfoPtr);
  81. public static extern void setFrameInfo(IntPtr frameInfoPtr);
  82. [DllImport(NativeConsts.NativeLibrary)]
  83. public static extern void stopEZXRRenderer();
  84. [DllImport(NativeConsts.NativeLibrary)]
  85. public static extern void hotConfigEZXRRenderer(EZXRRendererHotConfig cfg);
  86. #endif
  87. }
  88. }
  89. }