예제 #1
0
 public void DoRenderTextureThing(RenderTexture src, RenderTexture dest)
 {
     if (SteamVR_Render.Top() == this)
     {
         int eventID;
         if (SteamVR_Render.eye == EVREye.Eye_Left)
         {
             SteamVR_Utils.QueueEventOnRenderThread(201510023);
             eventID = 201510021;
         }
         else
         {
             eventID = 201510022;
         }
         SteamVR_Utils.QueueEventOnRenderThread(eventID);
     }
     Graphics.SetRenderTarget(dest);
     SteamVR_Camera.blitMaterial.mainTexture = src;
     GL.PushMatrix();
     GL.LoadOrtho();
     SteamVR_Camera.blitMaterial.SetPass(0);
     GL.Begin(7);
     GL.TexCoord2(0f, 0f);
     GL.Vertex3(-1f, 1f, 0f);
     GL.TexCoord2(1f, 0f);
     GL.Vertex3(1f, 1f, 0f);
     GL.TexCoord2(1f, 1f);
     GL.Vertex3(1f, -1f, 0f);
     GL.TexCoord2(0f, 1f);
     GL.Vertex3(-1f, -1f, 0f);
     GL.End();
     GL.PopMatrix();
     Graphics.SetRenderTarget(null);
 }
예제 #2
0
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(this.waitForEndOfFrame);

                if (!SteamVR_Render.pauseRendering)
                {
                    CVRCompositor compositor = OpenVR.Compositor;
                    if (compositor != null)
                    {
                        if (!compositor.CanRenderScene() || cameras.Length < 1)
                        {
                            continue;
                        }
                        compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                        SteamVR_Utils.QueueEventOnRenderThread(201510020);
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                        SteamVR_Camera.GetSceneTexture(this.cameras[0].GetComponent <Camera>()).GetNativeTexturePtr();
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - End");
                        compositor.GetLastPoses(this.poses, this.gamePoses);
                        SteamVR_Events.NewPoses.Send(this.poses);
                        SteamVR_Events.NewPosesApplied.Send();
                    }
                    SteamVR_Overlay instance = SteamVR_Overlay.instance;
                    if (instance != null)
                    {
                        instance.UpdateOverlay();
                    }
                    if (this.CheckExternalCamera())
                    {
                        this.RenderExternalCamera();
                    }
                    SteamVR instance2 = SteamVR.instance;
                    this.RenderEye(instance2, EVREye.Eye_Left);
                    this.RenderEye(instance2, EVREye.Eye_Right);
                    foreach (SteamVR_Camera steamVR_Camera in this.cameras)
                    {
                        steamVR_Camera.transform.localPosition = Vector3.zero;
                        steamVR_Camera.transform.localRotation = Quaternion.identity;
                    }
                    if (this.cameraMask != null)
                    {
                        this.cameraMask.Clear();
                    }
                }
            }
            yield break;
        }
예제 #3
0
        void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            if (SteamVR_Render.Top() == this)
            {
                int eventID;
                if (SteamVR_Render.eye == EVREye.Eye_Left)
                {
                    // Get gpu started on work early to avoid bubbles at the top of the frame.
                    SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_Flush);

                    eventID = SteamVR.OpenVRMagic.k_nRenderEventID_SubmitL;
                }
                else
                {
                    eventID = SteamVR.OpenVRMagic.k_nRenderEventID_SubmitR;
                }

                // Queue up a call on the render thread to Submit our render target to the compositor.
                SteamVR_Utils.QueueEventOnRenderThread(eventID);
            }
            if (SteamVR_Camera.doomp)
            {
                Debug.Log(Time.frameCount.ToString() + "/Camera_OnRenderImage");
                DumpRenderTexture(src, Application.streamingAssetsPath + "/Camera_OnRenderImage_src.png");
            }

            RenderTexture.active = dest;
            SteamVR_Camera.blitMaterial.mainTexture = src;

            GL.PushMatrix();
            GL.LoadOrtho();
            SteamVR_Camera.blitMaterial.SetPass(0);
            GL.Begin(7);
            GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-1, 1, 0);
            GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1, 1, 0);
            GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1, -1, 0);
            GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-1, -1, 0);
            GL.End();
            GL.PopMatrix();


            if (SteamVR_Camera.doomp)
            {
                DumpRenderTexture(dest, Application.streamingAssetsPath + "/Camera_OnRenderImage_dst.png");
            }

            RenderTexture.active = null;
        }
예제 #4
0
 private void FixedUpdate()
 {
     SteamVR_Utils.QueueEventOnRenderThread(201510024);
 }
 void FixedUpdate()
 {
     // We want to call this as soon after Present as possible.
     SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_PostPresentHandoff);
 }
        void Update()
        {
            if (cameras.Length == 0)
            {
                return;
            }
            this.UpdatePoses();
            // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
            SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_PostPresentHandoff);

            // Force controller update in case no one else called this frame to ensure prevState gets updated.

            // Dispatch any OpenVR events.
            var system = OpenVR.System;

            if (system != null)
            {
                var vrEvent = new VREvent_t();
                var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
                for (int i = 0; i < 64; i++)
                {
                    if (!system.PollNextEvent(ref vrEvent, size))
                    {
                        break;
                    }

                    switch ((EVREventType)vrEvent.eventType)
                    {
                    case EVREventType.VREvent_InputFocusCaptured:     // another app has taken focus (likely dashboard)
                        if (vrEvent.data.process.oldPid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(false);
                        }
                        break;

                    case EVREventType.VREvent_InputFocusReleased:     // that app has released input focus
                        if (vrEvent.data.process.pid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(true);
                        }
                        break;

                    case EVREventType.VREvent_ShowRenderModels:
                        SteamVR_Events.HideRenderModels.Send(false);
                        break;

                    case EVREventType.VREvent_HideRenderModels:
                        SteamVR_Events.HideRenderModels.Send(true);
                        break;

                    default:
                        SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                        break;
                    }
                }
            }

            // Ensure various settings to minimize latency.
            Application.targetFrameRate     = -1;
            Application.runInBackground     = true; // don't require companion window focus
            QualitySettings.maxQueuedFrames = -1;
            QualitySettings.vSyncCount      = 0;    // this applies to the companion window
        }
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(waitForEndOfFrame);

                if (cameras.Length == 0)
                {
                    continue;
                }

                if (pauseRendering)
                {
                    continue;
                }

                var compositor = OpenVR.Compositor;
                if (compositor != null)
                {
                    if (!compositor.CanRenderScene())
                    {
                        continue;
                    }

                    compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                    SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_WaitGetPoses);

                    // Hack to flush render event that was queued in Update (this ensures WaitGetPoses has returned before we grab the new values).
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                    SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().allowHDR).GetNativeTexturePtr();
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - End");

                    compositor.GetLastPoses(poses, gamePoses);
                    SteamVR_Events.NewPoses.Send(poses);
                    SteamVR_Events.NewPosesApplied.Send();
                }

                var overlay = SteamVR_Overlay.instance;
                if (overlay != null)
                {
                    overlay.UpdateOverlay();
                }

                RenderExternalCamera();


                var vr = SteamVR.instance;
                RenderEye(vr, EVREye.Eye_Left);
                RenderEye(vr, EVREye.Eye_Right);

                // Move cameras back to head position so they can be tracked reliably
                foreach (var c in cameras)
                {
                    c.transform.localPosition = Vector3.zero;
                    c.transform.localRotation = Quaternion.identity;
                }

                if (cameraMask != null)
                {
                    cameraMask.Clear();
                }
            }
        }