Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ValveSoftware/openvr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs')
-rw-r--r--unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs28
1 files changed, 26 insertions, 2 deletions
diff --git a/unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs b/unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs
index b06a945..df5b895 100644
--- a/unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs
+++ b/unity_package/Assets/SteamVR/Scripts/SteamVR_GameView.cs
@@ -1,10 +1,11 @@
-//========= Copyright 2014, Valve Corporation, All rights reserved. ===========
+//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: Handles rendering to the game view window
//
//=============================================================================
using UnityEngine;
+using Valve.VR;
[RequireComponent(typeof(Camera))]
public class SteamVR_GameView : MonoBehaviour
@@ -14,6 +15,7 @@ public class SteamVR_GameView : MonoBehaviour
public bool drawOverlay = true;
static Material overlayMaterial;
+ static Texture2D mirrorTexture;
void OnEnable()
{
@@ -21,6 +23,24 @@ public class SteamVR_GameView : MonoBehaviour
{
overlayMaterial = new Material(Shader.Find("Custom/SteamVR_Overlay"));
}
+
+ // Use OpenVR's mirror texture if available.
+ if (mirrorTexture == null)
+ {
+ var compositor = OpenVR.Compositor;
+ if (compositor != null)
+ {
+ //!! need to handle GL case as well
+ var tex = new Texture2D(2, 2);
+ var nativeTex = System.IntPtr.Zero;
+ if (compositor.GetMirrorTextureD3D11(EVREye.Eye_Right, tex.GetNativeTexturePtr(), ref nativeTex) == EVRCompositorError.None)
+ {
+ uint width = 0, height = 0;
+ OpenVR.System.GetRecommendedRenderTargetSize(ref width, ref height);
+ mirrorTexture = Texture2D.CreateExternalTexture((int)width, (int)height, TextureFormat.RGBA32, false, false, nativeTex);
+ }
+ }
+ }
}
void OnPostRender()
@@ -35,7 +55,11 @@ public class SteamVR_GameView : MonoBehaviour
var y1 = -aspect;
var blitMaterial = SteamVR_Camera.blitMaterial;
- blitMaterial.mainTexture = SteamVR_Camera.GetSceneTexture(camera.hdr);
+
+ if (mirrorTexture != null)
+ blitMaterial.mainTexture = mirrorTexture;
+ else
+ blitMaterial.mainTexture = SteamVR_Camera.GetSceneTexture(camera.hdr);
GL.PushMatrix();
GL.LoadOrtho();