public static void EnterVRMode()
 {
     Pvr_UnitySDKPluginEvent.Issue(RenderEventType.Resume);
 }
Exemplo n.º 2
0
 public void LeaveVRMode()
 {
     Pvr_UnitySDKPluginEvent.Issue(RenderEventType.Pause);
     this.isEnterVRMode = false;
 }
 public static void LeaveVRMode()
 {
     Pvr_UnitySDKPluginEvent.Issue(RenderEventType.Pause);
 }
Exemplo n.º 4
0
 public void EnterVRMode()
 {
     Pvr_UnitySDKPluginEvent.Issue(RenderEventType.Resume);
     this.isEnterVRMode = true;
 }
    IEnumerator EndOfFrame()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

#if !UNITY_EDITOR
            if (!Pvr_UnitySDKManager.SDK.isEnterVRMode)
            {
                // Call GL.clear before Enter VRMode to avoid unexpected graph breaking.
                GL.Clear(false, true, Color.black);
            }
            if (Pvr_UnitySDKRender.Instance.isFirstStartup && frameNum == this.WaitSplashScreenFrames)
            {
                Pvr_UnitySDKAPI.System.UPvr_RemovePlatformLogo();
                if (Pvr_UnitySDKManager.SDK.ResetTrackerOnLoad)
                {
                    Debug.Log("Reset Tracker OnLoad");
                    Pvr_UnitySDKSensor.Instance.OptionalResetUnitySDKSensor(1, 1);
                }

                Pvr_UnitySDKAPI.System.UPvr_StartVRModel();
                Pvr_UnitySDKRender.Instance.isFirstStartup = false;
            }
            else if (Pvr_UnitySDKRender.Instance.isFirstStartup && frameNum < this.WaitSplashScreenFrames)
            {
                PLOG.I("frameNum:" + frameNum);
                frameNum++;
            }

            #region Eyebuffer
#if UNITY_2018_1_OR_NEWER && !UNITY_2019_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
            {
                for (int i = 0; i < Eyes.Length; i++)
                {
                    if (!Eyes[i].isActiveAndEnabled || !Eyes[i].eyecamera.enabled)
                    {
                        continue;
                    }

                    switch (Eyes[i].eyeSide)
                    {
                    case Pvr_UnitySDKAPI.Eye.LeftEye:
                        eyeTextureId = Pvr_UnitySDKRender.Instance.eyeTextureIds[Pvr_UnitySDKRender.Instance.currEyeTextureIdx];
                        eventType    = RenderEventType.LeftEyeEndFrame;
                        break;

                    case Pvr_UnitySDKAPI.Eye.RightEye:
                        if (!Pvr_UnitySDKManager.SDK.Monoscopic)
                        {
                            eyeTextureId = Pvr_UnitySDKRender.Instance.eyeTextureIds[Pvr_UnitySDKRender.Instance.currEyeTextureIdx + 3];
                        }
                        else
                        {
                            eyeTextureId = Pvr_UnitySDKRender.Instance.eyeTextureIds[Pvr_UnitySDKRender.Instance.currEyeTextureIdx];
                        }
                        eventType = RenderEventType.RightEyeEndFrame;
                        break;

                    case Pvr_UnitySDKAPI.Eye.BothEye:
                        eyeTextureId = Pvr_UnitySDKRender.Instance.eyeTextureIds[Pvr_UnitySDKRender.Instance.currEyeTextureIdx];
                        eventType    = RenderEventType.BothEyeEndFrame;
                        break;

                    default:
                        break;
                    }

                    // eyebuffer
                    Pvr_UnitySDKAPI.System.UPvr_UnityEventData(Pvr_UnitySDKAPI.System.UPvr_GetEyeBufferData(eyeTextureId));;
                    Pvr_UnitySDKPluginEvent.Issue(eventType);

                    Pvr_UnitySDKPluginEvent.Issue(RenderEventType.EndEye);
                }
            }
#endif

            #endregion
#endif

            // Composite Layers: if find Overlay then Open Composite Layers feature
            #region Composite Layers
            int boundaryState = BoundarySystem.UPvr_GetSeeThroughState();
            if (Pvr_UnitySDKEyeOverlay.Instances.Count > 0 && boundaryState != 2)
            {
                overlayLayerDepth  = 1;
                underlayLayerDepth = 0;

                Pvr_UnitySDKEyeOverlay.Instances.Sort();

                for (int i = 0; i < Pvr_UnitySDKEyeOverlay.Instances.Count; i++)
                {
                    compositeLayer = Pvr_UnitySDKEyeOverlay.Instances[i];
                    if (!compositeLayer.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (compositeLayer.layerTextures[0] == null && compositeLayer.layerTextures[1] == null && !compositeLayer.isExternalAndroidSurface)
                    {
                        continue;
                    }
                    if (compositeLayer.layerTransform != null && !compositeLayer.layerTransform.gameObject.activeSelf)
                    {
                        continue;
                    }

                    layerFlags = 0;

                    if (compositeLayer.overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Quad || compositeLayer.overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Cylinder)
                    {
                        if (compositeLayer.overlayType == Pvr_UnitySDKEyeOverlay.OverlayType.Overlay)
                        {
                            isHeadLocked = false;
                            if (compositeLayer.layerTransform != null && compositeLayer.layerTransform.parent == this.transform)
                            {
                                isHeadLocked = true;
                            }

                            // external surface
                            if (compositeLayer.isExternalAndroidSurface)
                            {
                                layerFlags = layerFlags | 0x1;
                                this.CreateExternalSurface(compositeLayer, overlayLayerDepth);
                            }

                            layerFlags = layerFlags | (((int)compositeLayer.minTexFilterMode << 4) & 0xf0) | (((int)compositeLayer.magTexFilterMode << 8) & 0xf00); // Set texture mag and min filter mode
                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)compositeLayer.overlayType, (int)compositeLayer.overlayShape, compositeLayer.layerTextureIds[0], (int)Pvr_UnitySDKAPI.Eye.LeftEye, overlayLayerDepth, isHeadLocked, layerFlags, compositeLayer.MVMatrixs[0],
                                                                                  compositeLayer.ModelScales[0], compositeLayer.ModelRotations[0], compositeLayer.ModelTranslations[0], compositeLayer.CameraRotations[0], compositeLayer.CameraTranslations[0], compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)compositeLayer.overlayType, (int)compositeLayer.overlayShape, compositeLayer.layerTextureIds[1], (int)Pvr_UnitySDKAPI.Eye.RightEye, overlayLayerDepth, isHeadLocked, layerFlags, compositeLayer.MVMatrixs[1],
                                                                                  compositeLayer.ModelScales[1], compositeLayer.ModelRotations[1], compositeLayer.ModelTranslations[1], compositeLayer.CameraRotations[1], compositeLayer.CameraTranslations[1], compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());

                            overlayLayerDepth++;
                        }
                        else if (compositeLayer.overlayType == Pvr_UnitySDKEyeOverlay.OverlayType.Underlay)
                        {
                            // external surface
                            if (compositeLayer.isExternalAndroidSurface)
                            {
                                layerFlags = layerFlags | 0x1;
                                this.CreateExternalSurface(compositeLayer, underlayLayerDepth);
                            }

                            layerFlags = layerFlags | (((int)compositeLayer.minTexFilterMode << 4) & 0xf0) | (((int)compositeLayer.magTexFilterMode << 8) & 0xf00); // Set texture mag and min filter mode
                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)compositeLayer.overlayType, (int)compositeLayer.overlayShape, compositeLayer.layerTextureIds[0], (int)Pvr_UnitySDKAPI.Eye.LeftEye, underlayLayerDepth, false, layerFlags, compositeLayer.MVMatrixs[0],
                                                                                  compositeLayer.ModelScales[0], compositeLayer.ModelRotations[0], compositeLayer.ModelTranslations[0], compositeLayer.CameraRotations[0], compositeLayer.CameraTranslations[0], compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)compositeLayer.overlayType, (int)compositeLayer.overlayShape, compositeLayer.layerTextureIds[1], (int)Pvr_UnitySDKAPI.Eye.RightEye, underlayLayerDepth, false, layerFlags, compositeLayer.MVMatrixs[1],
                                                                                  compositeLayer.ModelScales[1], compositeLayer.ModelRotations[1], compositeLayer.ModelTranslations[1], compositeLayer.CameraRotations[1], compositeLayer.CameraTranslations[1], compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());

                            underlayLayerDepth++;
                        }
                    }
                    else if (compositeLayer.overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Equirect)
                    {
                        // external surface
                        if (compositeLayer.isExternalAndroidSurface)
                        {
                            layerFlags = layerFlags | 0x1;
                            this.CreateExternalSurface(compositeLayer, 0);
                        }

                        // 360 Overlay Equirectangular Texture
                        Pvr_UnitySDKAPI.Render.UPvr_SetupLayerData(0, (int)Pvr_UnitySDKAPI.Eye.LeftEye, compositeLayer.layerTextureIds[0], (int)compositeLayer.overlayShape, layerFlags, compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());
                        Pvr_UnitySDKAPI.Render.UPvr_SetupLayerData(0, (int)Pvr_UnitySDKAPI.Eye.RightEye, compositeLayer.layerTextureIds[1], (int)compositeLayer.overlayShape, layerFlags, compositeLayer.GetLayerColorScale(), compositeLayer.GetLayerColorOffset());
                    }
                }
                #endregion
            }

            // Begin TimeWarp
            //Pvr_UnitySDKPluginEvent.IssueWithData(RenderEventType.TimeWarp, Pvr_UnitySDKManager.SDK.RenderviewNumber);
            Pvr_UnitySDKAPI.System.UPvr_UnityEventData(Pvr_UnitySDKAPI.System.UPvr_GetEyeBufferData(0));
            Pvr_UnitySDKPluginEvent.Issue(RenderEventType.TimeWarp);
            Pvr_UnitySDKRender.Instance.currEyeTextureIdx = Pvr_UnitySDKRender.Instance.nextEyeTextureIdx;
            Pvr_UnitySDKRender.Instance.nextEyeTextureIdx = (Pvr_UnitySDKRender.Instance.nextEyeTextureIdx + 1) % 3;
        }
    }