Tilt Five Unity API  1.3.0
Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
TiltFive.Display Class Reference
Inheritance diagram for TiltFive.Display:
TiltFive.SingletonComponent< Display >

Static Public Member Functions

static bool SetApplicationInfo ()
 
static bool GetGlassesAvailability (PlayerIndex playerIndex=PlayerIndex.One)
 
static bool PresentStereoImages (PlayerIndex playerIndex, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
 
static bool GetDisplayDimensions (ref Vector2Int displayDimensions)
 
static bool GetGlassesIPD (UInt64 glassesHandle, ref float glassesIPD)
 

Protected Member Functions

override void Awake ()
 

Private Member Functions

void Start ()
 
void Update ()
 
void LogVersion ()
 
bool SetApplicationInfoImpl ()
 
bool PresentStereoImagesImpl (UInt64 glassesHandle, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
 
bool GetDisplayDimensionsImpl (ref Vector2Int displayDimensions)
 
bool GetGlassesIPDImpl (UInt64 glassesHandle, ref float glassesIPD)
 

Private Attributes

int[] _displaySettings = new int[2]
 
IntPtr _sendFrameCallback = IntPtr.Zero
 

Additional Inherited Members

- Properties inherited from TiltFive.SingletonComponent< Display >
static T Instance [get]
 

Detailed Description

Definition at line 66 of file Display.cs.

Member Function Documentation

◆ Awake()

override void TiltFive.Display.Awake ( )
protectedvirtual

Reimplemented from TiltFive.SingletonComponent< Display >.

Definition at line 75 of file Display.cs.

76  {
77  base.Awake();
78 
79  try
80  {
81  _sendFrameCallback = NativePlugin.GetSendFrameCallback();
82  }
83  catch (System.DllNotFoundException e)
84  {
85  Log.Info("Could not connect to Tilt Five plugin to get callback: {0}", e);
86  }
87  catch (Exception e)
88  {
89  Log.Error(e.Message);
90  }
91 
92  LogVersion();
93 
94  QualitySettings.vSyncCount = 0;
95  QualitySettings.maxQueuedFrames = 0;
96  }
void LogVersion()
Definition: Display.cs:108
IntPtr _sendFrameCallback
Definition: Display.cs:73
The Logger.
Definition: Log.cs:42
static void Info(string m, params object[] list)
INFO logging function call.
Definition: Log.cs:140
static void Error(string m, params object[] list)
ERROR logging function call.
Definition: Log.cs:127

References TiltFive.Display._sendFrameCallback, TiltFive.Logging.Log.Error(), TiltFive.NativePlugin.GetSendFrameCallback(), TiltFive.Logging.Log.Info(), and TiltFive.Display.LogVersion().

◆ GetDisplayDimensions()

static bool TiltFive.Display.GetDisplayDimensions ( ref Vector2Int  displayDimensions)
static

Definition at line 366 of file Display.cs.

367  {
368  return Instance.GetDisplayDimensionsImpl(ref displayDimensions);
369  }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.DisplaySettings.DisplaySettings().

◆ GetDisplayDimensionsImpl()

bool TiltFive.Display.GetDisplayDimensionsImpl ( ref Vector2Int  displayDimensions)
private

Definition at line 371 of file Display.cs.

372  {
373  int result = 1;
374  try
375  {
376  result = NativePlugin.GetMaxDisplayDimensions(_displaySettings);
377 
378  if(result == 0)
379  {
380  displayDimensions = new Vector2Int(_displaySettings[0], _displaySettings[1]);
381  }
382  else Log.Warn("Display.cs: Failed to retrieve display settings from plugin.");
383  }
384  catch (Exception e)
385  {
386  Log.Error(e.Message);
387  }
388 
389  return (0 == result);
390  }
int[] _displaySettings
Definition: Display.cs:69
static void Warn(string m, params object[] list)
WARN logging function call.
Definition: Log.cs:166

References TiltFive.Display._displaySettings, TiltFive.Logging.Log.Error(), TiltFive.NativePlugin.GetMaxDisplayDimensions(), and TiltFive.Logging.Log.Warn().

◆ GetGlassesAvailability()

static bool TiltFive.Display.GetGlassesAvailability ( PlayerIndex  playerIndex = PlayerIndex.One)
static

Definition at line 185 of file Display.cs.

186  {
187  return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle) && Glasses.IsConnected(glassesHandle);
188  }

References TiltFive.Glasses.IsConnected().

Referenced by TiltFive.Display.GetGlassesIPDImpl().

◆ GetGlassesIPD()

static bool TiltFive.Display.GetGlassesIPD ( UInt64  glassesHandle,
ref float  glassesIPD 
)
static

Definition at line 392 of file Display.cs.

393  {
394  return Instance.GetGlassesIPDImpl(glassesHandle, ref glassesIPD);
395  }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.Glasses.GlassesCore.Update().

◆ GetGlassesIPDImpl()

bool TiltFive.Display.GetGlassesIPDImpl ( UInt64  glassesHandle,
ref float  glassesIPD 
)
private

Definition at line 397 of file Display.cs.

398  {
399  int result = 1;
400  try
401  {
402  result = NativePlugin.GetGlassesIPD(glassesHandle, ref glassesIPD);
403 
404  if(result != 0 && GetGlassesAvailability())
405  {
406  Log.Warn("Display.cs: Failed to retrieve glasses IPD");
407  }
408  }
409  catch (Exception e)
410  {
411  Log.Error(e.Message);
412  }
413 
414  return (0 == result);
415  }
static bool GetGlassesAvailability(PlayerIndex playerIndex=PlayerIndex.One)
Definition: Display.cs:185

References TiltFive.Logging.Log.Error(), TiltFive.Display.GetGlassesAvailability(), TiltFive.NativePlugin.GetGlassesIPD(), and TiltFive.Logging.Log.Warn().

◆ LogVersion()

void TiltFive.Display.LogVersion ( )
private

Definition at line 108 of file Display.cs.

109  {
110  string version = "NOT VERSIONED";
111 
112  // load version file and get the string value
113  TextAsset asset = (TextAsset)Resources.Load("pluginversion", typeof(TextAsset));
114  if (asset != null)
115  {
116  version = asset.text;
117  }
118 
119  // turn on logging if it was turned off
120  bool logEnabled = Debug.unityLogger.logEnabled;
121  if (!logEnabled)
122  {
123  Debug.unityLogger.logEnabled = true;
124  }
125 
126  // get previous setting
127  StackTraceLogType logType = Application.GetStackTraceLogType(LogType.Log);
128 
129  // turn off stacktrace logging for our messaging
130  Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
131 
132  Log.Info("\n********************************" +
133  "\n* Tilt Five: Unity SDK Version - " +
134  version +
135  "\n********************************");
136 
137  // reset to initial log settings
138  Application.SetStackTraceLogType(LogType.Log, logType);
139 
140  // reset logging enabled to previous
141  Debug.unityLogger.logEnabled = logEnabled;
142  }

References TiltFive.Logging.Log.Info().

Referenced by TiltFive.Display.Awake().

◆ PresentStereoImages()

static bool TiltFive.Display.PresentStereoImages ( PlayerIndex  playerIndex,
IntPtr  leftTexHandle,
IntPtr  rightTexHandle,
int  texWidth_PIX,
int  texHeight_PIX,
bool  isSrgb,
float  fovYDegrees,
float  widthToHeightRatio,
Quaternion  rotToUGBD_ULVC,
Vector3  posOfULVC_UGBD,
Quaternion  rotToUGBD_URVC,
Vector3  posOfURVC_UGBD 
)
static

Definition at line 190 of file Display.cs.

202  {
203  return Player.TryGetGlassesHandle(playerIndex, out var glassesHandle)
204  && PresentStereoImages(glassesHandle,
205  leftTexHandle,
206  rightTexHandle,
207  texWidth_PIX,
208  texHeight_PIX,
209  isSrgb,
210  fovYDegrees,
211  widthToHeightRatio,
212  rotToUGBD_ULVC,
213  posOfULVC_UGBD,
214  rotToUGBD_URVC,
215  posOfURVC_UGBD);
216  }
static bool PresentStereoImages(PlayerIndex playerIndex, IntPtr leftTexHandle, IntPtr rightTexHandle, int texWidth_PIX, int texHeight_PIX, bool isSrgb, float fovYDegrees, float widthToHeightRatio, Quaternion rotToUGBD_ULVC, Vector3 posOfULVC_UGBD, Quaternion rotToUGBD_URVC, Vector3 posOfURVC_UGBD)
Definition: Display.cs:190

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages().

◆ PresentStereoImagesImpl()

bool TiltFive.Display.PresentStereoImagesImpl ( UInt64  glassesHandle,
IntPtr  leftTexHandle,
IntPtr  rightTexHandle,
int  texWidth_PIX,
int  texHeight_PIX,
bool  isSrgb,
float  fovYDegrees,
float  widthToHeightRatio,
Quaternion  rotToUGBD_ULVC,
Vector3  posOfULVC_UGBD,
Quaternion  rotToUGBD_URVC,
Vector3  posOfURVC_UGBD 
)
private

Definition at line 246 of file Display.cs.

259  {
260  // Unity reference frames:
261  //
262  // ULVC / URVC - Unity Left/Right Virtual Camera space.
263  // +x right, +y up, +z forward
264  // UGBD - Unity Gameboard space.
265  // +x right, +y up, +z forward
266  //
267  // Tilt Five reference frames:
268  //
269  // DC - Our right-handed version of Unity's default camera space
270  // (the LVC/RVC if there is no transform set on ULVC/URVC).
271  // +x right, +y up, +z backward
272  // LVC / RVC - Left/Right Virtual Camera space.
273  // +x right, +y up, +z backward
274  // GBD - Gameboard space.
275  // +x right, +y forward, +z up
276 
277  Quaternion rotToDC_GBD = Quaternion.AngleAxis(-90f, Vector3.right);
278 
279  // Calculate the VCI (the image rectangle in the normalized (z=1) image space of the virtual cameras)
280  float startY_VCI = -Mathf.Tan(fovYDegrees * (0.5f * Mathf.PI / 180.0f));
281  float startX_VCI = startY_VCI * widthToHeightRatio;
282  float width_VCI = -2f * startX_VCI;
283  float height_VCI = -2f * startY_VCI;
284  Rect vci = new Rect(startX_VCI, startY_VCI, width_VCI, height_VCI);
285 
286  // Swizzle the left-handed Unity-based coordinates into our right-handed reference frames
287  Quaternion rotToLVC_DC = new Quaternion(rotToUGBD_ULVC.x, rotToUGBD_ULVC.y, -rotToUGBD_ULVC.z, rotToUGBD_ULVC.w);
288  Quaternion rotToRVC_DC = new Quaternion(rotToUGBD_URVC.x, rotToUGBD_URVC.y, -rotToUGBD_URVC.z, rotToUGBD_URVC.w);
289 
290  Quaternion rotToLVC_GBD = rotToLVC_DC * rotToDC_GBD;
291  Quaternion rotToRVC_GBD = rotToRVC_DC * rotToDC_GBD;
292 
293  // Swap the Y and Z axes to switch from left-handed to right-handed coords
294  Vector3 posOfLVC_GBD = new Vector3(posOfULVC_UGBD.x, posOfULVC_UGBD.z, posOfULVC_UGBD.y);
295  Vector3 posOfRVC_GBD = new Vector3(posOfURVC_UGBD.x, posOfURVC_UGBD.z, posOfURVC_UGBD.y);
296 
297  // Build our frame info struct now that we're finished converting from Unity's coord space
298  T5_FrameInfo frameInfo = new T5_FrameInfo();
299 
300  frameInfo.LeftTexHandle = leftTexHandle;
301  frameInfo.RightTexHandle = rightTexHandle;
302 
303  frameInfo.TexWidth_PIX = (UInt16) texWidth_PIX;
304  frameInfo.TexHeight_PIX = (UInt16) texHeight_PIX;
305 
306  frameInfo.IsSrgb = isSrgb;
307  frameInfo.IsUpsideDown = false; // False for Unity, but possibly true for other engines
308 
309  frameInfo.VCI = vci;
310 
311  frameInfo.RotToLVC_GBD = rotToLVC_GBD;
312  frameInfo.PosOfLVC_GBD = posOfLVC_GBD;
313 
314  frameInfo.RotToRVC_GBD = rotToRVC_GBD;
315  frameInfo.PosOfRVC_GBD = posOfRVC_GBD;
316 
317  int result = 1;
318  try
319  {
320  result = NativePlugin.QueueStereoImages(glassesHandle, frameInfo);
321  }
322  catch (Exception e)
323  {
324  Log.Error(e.Message);
325  }
326 
327  if (result != 0) {
328  return false;
329  }
330 
331  if(_sendFrameCallback == IntPtr.Zero)
332  {
333  // We failed to set _sendFrameCallback during Awake() - let's try again
334  try
335  {
336  _sendFrameCallback = NativePlugin.GetSendFrameCallback();
337  }
338  catch (Exception)
339  {
340  Log.Error("Unable to send frame - the native plugin DLL may be failing to load");
341  return false;
342  }
343 
344  if (_sendFrameCallback == IntPtr.Zero)
345  {
346  // If we reach this point, the native plugin loaded, but erroneously gave us a null callback
347  Log.Error("Unable to send frame - the native plugin returned a null SendFrame callback");
348  return false;
349  }
350  }
351 
352  try
353  {
354  GL.IssuePluginEvent(_sendFrameCallback, 0);
355  GL.InvalidateState();
356  }
357  catch (Exception e)
358  {
359  Log.Error($"Failed to execute sendFrame callback: {e.Message}");
360  return false;
361  }
362 
363  return true;
364  }

References TiltFive.Display._sendFrameCallback, TiltFive.Logging.Log.Error(), TiltFive.NativePlugin.GetSendFrameCallback(), TiltFive.T5_FrameInfo.IsSrgb, TiltFive.T5_FrameInfo.IsUpsideDown, TiltFive.T5_FrameInfo.LeftTexHandle, TiltFive.T5_FrameInfo.PosOfLVC_GBD, TiltFive.T5_FrameInfo.PosOfRVC_GBD, TiltFive.NativePlugin.QueueStereoImages(), TiltFive.T5_FrameInfo.RightTexHandle, TiltFive.T5_FrameInfo.RotToLVC_GBD, TiltFive.T5_FrameInfo.RotToRVC_GBD, TiltFive.T5_FrameInfo.TexHeight_PIX, TiltFive.T5_FrameInfo.TexWidth_PIX, and TiltFive.T5_FrameInfo.VCI.

◆ SetApplicationInfo()

static bool TiltFive.Display.SetApplicationInfo ( )
static

Definition at line 144 of file Display.cs.

145  {
146  return Instance.SetApplicationInfoImpl();
147  }

References TiltFive.SingletonComponent< Display >.Instance.

Referenced by TiltFive.TiltFiveManager.Awake(), and TiltFive.TiltFiveManager2.Awake().

◆ SetApplicationInfoImpl()

bool TiltFive.Display.SetApplicationInfoImpl ( )
private

Definition at line 149 of file Display.cs.

150  {
151  string applicationName = Application.productName;
152 #if UNITY_EDITOR
153  // TODO: Localize
154  applicationName = $"Unity Editor: {applicationName}";
155 #endif
156  string applicationId = Application.identifier;
157  string productVersion = Application.version;
158  string engineVersion = Application.unityVersion;
159  TextAsset pluginVersionAsset = (TextAsset)Resources.Load("pluginversion");
160  string applicationVersionInfo = $"App: {productVersion}, Engine: {engineVersion}, T5 SDK: {pluginVersionAsset.text}";
161 
162  int result = 1;
163 
164  try
165  {
166  using (T5_StringUTF8 appName = applicationName)
167  using (T5_StringUTF8 appId = applicationId)
168  using (T5_StringUTF8 appVersion = applicationVersionInfo)
169  {
170  result = NativePlugin.SetApplicationInfo(appName, appId, appVersion);
171  }
172  }
173  catch (System.DllNotFoundException e)
174  {
175  Log.Info("Could not connect to Tilt Five plugin to register project info: {0}", e);
176  }
177  catch (Exception)
178  {
179  Log.Error("Failed to register project info with the Tilt Five service.");
180  }
181 
182  return result == 0;
183  }

References TiltFive.Logging.Log.Error(), TiltFive.Logging.Log.Info(), and TiltFive.NativePlugin.SetApplicationInfo().

◆ Start()

void TiltFive.Display.Start ( )
private

Definition at line 98 of file Display.cs.

99  {
100 
101  }

◆ Update()

void TiltFive.Display.Update ( )
private

Definition at line 103 of file Display.cs.

104  {
105 
106  }

Member Data Documentation

◆ _displaySettings

int [] TiltFive.Display._displaySettings = new int[2]
private

Definition at line 69 of file Display.cs.

Referenced by TiltFive.Display.GetDisplayDimensionsImpl().

◆ _sendFrameCallback

IntPtr TiltFive.Display._sendFrameCallback = IntPtr.Zero
private

Definition at line 73 of file Display.cs.

Referenced by TiltFive.Display.Awake(), and TiltFive.Display.PresentStereoImagesImpl().


The documentation for this class was generated from the following file: