Exemplo n.º 1
0
 private static void CallbackFunction(string str)
 {
     debugSB.Length = 0;
     debugSB.Append("[VarjoPlugin] ");
     debugSB.Append(str);
     VarjoManager.Log(debugSB.ToString());
 }
Exemplo n.º 2
0
        private new void Awake()
        {
            unityThread = Thread.CurrentThread;

            if (_instance == null)
            {
                _instance = this;
            }
            else
            {
                Debug.LogError("Multiple instances of VarjoManager. Destroying the new one.");
                Destroy(gameObject);
                return;
            }

            Plugin = new VarjoPlugin();

            VarjoSystemPresent = VarjoPlugin.IsVarjoSystemInstalled();
            if (!VarjoSystemPresent)
            {
                Debug.LogWarning("Varjo system not found.");
                return;
            }

            base.Awake();

            // Check that the varjoCamera is valid.
            if (varjoCamera == null)
            {
                varjoCamera = Camera.main;
                if (varjoCamera == null)
                {
                    LogWarning("No camera attached to VarjoManager. Attach a camera or make sure there is main camera in the scene.");
                    enabled = false;
                    return;
                }
            }

            StartCoroutine(InitializeSession());
        }
Exemplo n.º 3
0
        private IEnumerator EndFrameCoroutine()
        {
            while (true)
            {
                yield return(yieldEndOfFrame);

                if (!VarjoPlugin.SessionValid || !beginFrameCalled)
                {
                    Profiler.BeginSample("Varjo.EndOfFrame.ThrottleFor100ms");
                    // Sleep for 100ms so that we won't hog the CPU
                    Thread.Sleep(100);
                    // Still poll events if we have a session
                    if (VarjoPlugin.SessionValid)
                    {
                        Plugin.IssuePluginEvent(VarjoPlugin.VARJO_RENDER_EVT_POLL_EVENTS);
                    }
                    GL.Flush();
                    Profiler.EndSample();
                    continue;
                }

                Profiler.BeginSample("Varjo.EndOfFrame");

                if (VarjoManager.Instance.viewportCameras == null || VarjoManager.Instance.viewportCameras.Count != 4)
                {
                    VarjoManager.LogError("VarjoViewCombiner can't access a proper viewport array.");
                    continue;
                }

                GL.sRGBWrite = true;

                Profiler.BeginSample("Varjo.Submit");

                submission.Clear();
                // Sort the layers according to layer depth
                foreach (var varjoLayer in layers.OrderBy(l => l.layerOrder))
                {
                    if (varjoLayer.layerEnabled)
                    {
                        submission.Add(varjoLayer.PrepareForSubmission());
                    }
                }

                var subArray = submission.ToArray();
                VarjoPlugin.QueueSubmission(subArray.Length, subArray);

                Profiler.EndSample();

                // Blit to screen if SRPs are in use
                if (GraphicsSettings.renderPipelineAsset != null)
                {
                    Profiler.BeginSample("Varjo.BlitToScreen");
                    // Blit left context of the main layer to screen
                    if (flipY)
                    {
                        Graphics.Blit(GetRenderTextureForCamera(VarjoViewCamera.CAMERA_ID.CONTEXT_LEFT), (RenderTexture)null, new Vector2(contextDisplayFactor, contextDisplayFactor), new Vector2(0.0f, 1.0f - contextDisplayFactor));
                    }
                    else
                    {
                        Graphics.Blit(GetRenderTextureForCamera(VarjoViewCamera.CAMERA_ID.CONTEXT_LEFT), (RenderTexture)null, new Vector2(contextDisplayFactor, -1.0f * contextDisplayFactor), new Vector2(0.0f, contextDisplayFactor));
                    }

                    Profiler.EndSample();
                }

                Plugin.IssuePluginEvent(VarjoPlugin.VARJO_RENDER_EVT_SUBMIT);
                GL.InvalidateState();

                beginFrameCalled = false;
                Profiler.EndSample();
            }
        }
Exemplo n.º 4
0
        private new void Awake()
        {
            unityThread = Thread.CurrentThread;

            if (_instance == null)
            {
                _instance = this;
            }
            else
            {
                Debug.LogError("Multiple instances of VarjoManager. Destroying the new one.");
                Destroy(gameObject);
                return;
            }

            Plugin = new VarjoPlugin();

            VarjoSystemPresent = VarjoPlugin.IsVarjoSystemInstalled();
            if (!VarjoSystemPresent)
            {
                Debug.LogWarning("Varjo system not found.");
                gameObject.SetActive(false);
                return;
            }

            if (forceVRSupport)
            {
                XRSettings.enabled = true;
                if (XRSettings.supportedDevices != null && XRSettings.supportedDevices.Contains("OpenVR"))
                {
                    if (XRSettings.loadedDeviceName != "OpenVR")
                    {
                        XRSettings.LoadDeviceByName("OpenVR");
                    }
                }
                else
                {
                    Debug.LogError("OpenVR is not in the list of supported Virtual Reality SDKs. You need to add it to the list in Player Settings.");
                }
            }
            else
            {
                if (!XRSettings.enabled)
                {
                    Debug.LogError("Virtual Reality Support is not enabled. Enable Force VR Support in VarjoManager or enable Virtual Reality Support in Player Settings.");
                }
            }


            if (disableVSync)
            {
                QualitySettings.vSyncCount = 0;
            }

            base.Awake();

            if (varjoCamera)
            {
                varjoCamera.gameObject.tag = "MainCamera";
            }
            else
            {
                GameObject go = new GameObject("Varjo Camera");
                go.transform.SetParent(transform);
                varjoCamera = go.AddComponent <Camera>();
                go.tag      = "MainCamera";
            }

            DisableVRCameras();
            DisableExtraAudioListeners();

            StartCoroutine(InitializeSession());
        }
Exemplo n.º 5
0
 private void OnDisable()
 {
     VarjoManager.UnregisterLayer(this);
 }
Exemplo n.º 6
0
 private void OnEnable()
 {
     // Register the layer to the manager
     VarjoManager.RegisterLayer(this);
 }