Tilt Five™ Unity API  1.4.1
TiltFive.SplitStereoTextures Class Reference

Public Member Functions

void Initialize ()
 Creates and configures the stereo rendertextures More...
 
void ValidateNativeTexturePointers ()
 Determines whether the left/right texture handles are still valid, and resets them if needed More...
 
void GetNativeTexturePointers (out IntPtr leftTexHandle, out IntPtr rightTexHandle)
 Acquires the native output textures upon startup or invalidaiton. More...
 
void SubmitPreviewTextures (GlassesMirrorMode glassesMirrorMode)
 Copies frame data from the HDR input textures to the onscreen preview textures. More...
 

Public Attributes

RenderTexture LeftTexture_GLS
 The left eye rendertexture More...
 
RenderTexture RightTexture_GLS
 The right eye rendertexture More...
 
RenderTexture MonoPreviewTex
 The rendertexture used to display onscreen previews for the left or right eye camera. More...
 
RenderTexture StereoPreviewTex
 The rendertexture used to display onscreen previews for the left and right eye cameras in stereo. More...
 

Properties

IntPtr LeftTexHandle [get, set]
 The native pointer to the left eye rendertexture More...
 
IntPtr RightTexHandle [get, set]
 The native pointer to the right eye rendertexture More...
 

Private Member Functions

void CopyTexture (RenderTexture sourceTex, RenderTexture destinationTex, int xOffset=0)
 

Detailed Description

Definition at line 25 of file SplitStereoTextures.cs.

Member Function Documentation

◆ CopyTexture()

void TiltFive.SplitStereoTextures.CopyTexture ( RenderTexture  sourceTex,
RenderTexture  destinationTex,
int  xOffset = 0 
)
private

Definition at line 235 of file SplitStereoTextures.cs.

236  {
237  Graphics.CopyTexture(
238  sourceTex,
239  0, // srcElement
240  0, // srcMip
241  0, 0, // src offset
242  sourceTex.width, sourceTex.height, // src size
243  destinationTex,
244  0, // dstElement
245  0, // dstMip
246  xOffset, 0); // dst offset
247  }

Referenced by TiltFive.SplitStereoTextures.SubmitPreviewTextures().

◆ GetNativeTexturePointers()

void TiltFive.SplitStereoTextures.GetNativeTexturePointers ( out IntPtr  leftTexHandle,
out IntPtr  rightTexHandle 
)

Acquires the native output textures upon startup or invalidaiton.

This should be executed after all rendering is complete, including UI and post processing.

Definition at line 130 of file SplitStereoTextures.cs.

131  {
132  // If the native texture handles were reset by ValidateNativeTexturePointers(), reacquire them
133  if(LeftTexHandle == IntPtr.Zero || RightTexHandle == IntPtr.Zero)
134  {
135  LeftTexHandle = LeftTexture_GLS.GetNativeTexturePtr();
136  RightTexHandle = RightTexture_GLS.GetNativeTexturePtr();
137  }
138 
139  leftTexHandle = LeftTexHandle;
140  rightTexHandle = RightTexHandle;
141  }
IntPtr RightTexHandle
The native pointer to the right eye rendertexture
IntPtr LeftTexHandle
The native pointer to the left eye rendertexture
RenderTexture LeftTexture_GLS
The left eye rendertexture
RenderTexture RightTexture_GLS
The right eye rendertexture

References TiltFive.SplitStereoTextures.LeftTexHandle, TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.SplitStereoTextures.RightTexHandle, and TiltFive.SplitStereoTextures.RightTexture_GLS.

Referenced by TiltFive.SplitStereoCamera.PresentStereoImages().

◆ Initialize()

void TiltFive.SplitStereoTextures.Initialize ( )

Creates and configures the stereo rendertextures

Parameters
renderFormat_UGLS

Definition at line 71 of file SplitStereoTextures.cs.

72  {
73  LeftTexture_GLS = new RenderTexture(
74  DisplaySettings.monoWidth,
75  DisplaySettings.height,
76  DisplaySettings.depthBuffer,
77  DisplaySettings.nativeTextureFormat);
78  LeftTexture_GLS.name = "Left Eye Output RenderTexture";
79  RightTexture_GLS = new RenderTexture(
80  DisplaySettings.monoWidth,
81  DisplaySettings.height,
82  DisplaySettings.depthBuffer,
83  DisplaySettings.nativeTextureFormat);
84  RightTexture_GLS.name = "Right Eye Output RenderTexture";
85 
86  MonoPreviewTex = new RenderTexture(
87  DisplaySettings.monoWidth,
88  DisplaySettings.height,
89  DisplaySettings.depthBuffer,
90  RenderTextureFormat.Default);
91  MonoPreviewTex.name = "Mono Preview RenderTexture";
92  StereoPreviewTex = new RenderTexture(
93  DisplaySettings.stereoWidth,
94  DisplaySettings.height,
95  DisplaySettings.depthBuffer,
96  RenderTextureFormat.Default);
97  StereoPreviewTex.name = "Stereo Preview RenderTexture";
98  }
RenderTexture MonoPreviewTex
The rendertexture used to display onscreen previews for the left or right eye camera.
RenderTexture StereoPreviewTex
The rendertexture used to display onscreen previews for the left and right eye cameras in stereo.

References TiltFive.DisplaySettings.depthBuffer, TiltFive.DisplaySettings.height, TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.SplitStereoTextures.MonoPreviewTex, TiltFive.DisplaySettings.monoWidth, TiltFive.DisplaySettings.nativeTextureFormat, TiltFive.SplitStereoTextures.RightTexture_GLS, TiltFive.SplitStereoTextures.StereoPreviewTex, and TiltFive.DisplaySettings.stereoWidth.

Referenced by TiltFive.SplitStereoCamera.ConfigureEyeCameras().

◆ SubmitPreviewTextures()

void TiltFive.SplitStereoTextures.SubmitPreviewTextures ( GlassesMirrorMode  glassesMirrorMode)

Copies frame data from the HDR input textures to the onscreen preview textures.

Parameters
glassesMirrorMode

Definition at line 147 of file SplitStereoTextures.cs.

148  {
149  var previewTex = glassesMirrorMode == GlassesMirrorMode.Stereoscopic ? StereoPreviewTex : MonoPreviewTex;
150 
151  switch (glassesMirrorMode)
152  {
153  case GlassesMirrorMode.LeftEye:
154  CopyTexture(LeftTexture_GLS, previewTex);
155  break;
156  case GlassesMirrorMode.RightEye:
157  CopyTexture(RightTexture_GLS, previewTex);
158  break;
159  case GlassesMirrorMode.Stereoscopic:
160  // Copy the two eyes' target textures to a double-wide texture, then display it onscreen.
161  CopyTexture(LeftTexture_GLS, previewTex);
162  CopyTexture(RightTexture_GLS, previewTex, LeftTexture_GLS.width);
163  break;
164  }
165  }
void CopyTexture(RenderTexture sourceTex, RenderTexture destinationTex, int xOffset=0)

References TiltFive.SplitStereoTextures.CopyTexture(), TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.SplitStereoTextures.MonoPreviewTex, TiltFive.SplitStereoTextures.RightTexture_GLS, and TiltFive.SplitStereoTextures.StereoPreviewTex.

Referenced by TiltFive.SplitStereoCamera.OnRenderImage().

◆ ValidateNativeTexturePointers()

void TiltFive.SplitStereoTextures.ValidateNativeTexturePointers ( )

Determines whether the left/right texture handles are still valid, and resets them if needed

This should be executed in OnPreRender(), otherwise IsCreated() always returns true

Definition at line 104 of file SplitStereoTextures.cs.

105  {
106  /* Render textures have a state (created or not created), and that state can be invalidated.
107  There are a few ways this can happen, including the game switching to/from fullscreen,
108  or the system screensaver being displayed. When this happens, the native texture pointers we
109  pass to the native plugin are also invalidated, and garbage data gets displayed by the glasses.
110 
111  To fix this, we can check whether the state has been invalidated and reacquire a valid native texture pointer.
112  RenderTexture's IsCreated() function reports false if the render texture has been invalidated.
113  We must detect this change in OnPreRender(), because IsCreated() reports true within Update().
114  If we detect that the render textures have been invalidated, we null out the cached pointers and reacquire.
115  */
116 
117  // Check whether the render textures' states have been invalidated,
118  // and reset the cached texture handles if so.
119  if (!LeftTexture_GLS.IsCreated() || !RightTexture_GLS.IsCreated())
120  {
121  LeftTexHandle = System.IntPtr.Zero;
122  RightTexHandle = System.IntPtr.Zero;
123  }
124  }

References TiltFive.SplitStereoTextures.LeftTexHandle, TiltFive.SplitStereoTextures.LeftTexture_GLS, TiltFive.SplitStereoTextures.RightTexHandle, and TiltFive.SplitStereoTextures.RightTexture_GLS.

Referenced by TiltFive.SplitStereoCamera.OnPreRender().

Member Data Documentation

◆ LeftTexture_GLS

◆ MonoPreviewTex

RenderTexture TiltFive.SplitStereoTextures.MonoPreviewTex

The rendertexture used to display onscreen previews for the left or right eye camera.

Definition at line 56 of file SplitStereoTextures.cs.

Referenced by TiltFive.SplitStereoCamera.ConfigureEyeCameras(), TiltFive.SplitStereoTextures.Initialize(), TiltFive.SplitStereoCamera.OnRenderImage(), and TiltFive.SplitStereoTextures.SubmitPreviewTextures().

◆ RightTexture_GLS

◆ StereoPreviewTex

RenderTexture TiltFive.SplitStereoTextures.StereoPreviewTex

The rendertexture used to display onscreen previews for the left and right eye cameras in stereo.

Definition at line 60 of file SplitStereoTextures.cs.

Referenced by TiltFive.SplitStereoCamera.ConfigureEyeCameras(), TiltFive.SplitStereoTextures.Initialize(), TiltFive.SplitStereoCamera.OnRenderImage(), and TiltFive.SplitStereoTextures.SubmitPreviewTextures().

Property Documentation

◆ LeftTexHandle

IntPtr TiltFive.SplitStereoTextures.LeftTexHandle
getsetprivate

The native pointer to the left eye rendertexture

This is used to pass the left eye texture to unmanaged code

Definition at line 45 of file SplitStereoTextures.cs.

45 { get; set; }

Referenced by TiltFive.SplitStereoTextures.GetNativeTexturePointers(), and TiltFive.SplitStereoTextures.ValidateNativeTexturePointers().

◆ RightTexHandle

IntPtr TiltFive.SplitStereoTextures.RightTexHandle
getsetprivate

The native pointer to the right eye rendertexture

This is used to pass the left eye texture to unmanaged code

Definition at line 50 of file SplitStereoTextures.cs.

50 { get; set; }

Referenced by TiltFive.SplitStereoTextures.GetNativeTexturePointers(), and TiltFive.SplitStereoTextures.ValidateNativeTexturePointers().


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