예제 #1
0
    private IEnumerator RenderLoop()
    {
        var wait = new WaitForEndOfFrame();

        yield return(wait);

        Log.d(LOG_TAG, "RenderLoop() is started");
        var tim = Time.time;

#if UNITY_EDITOR
        if (!Application.isEditor)
#endif
        {
            // Restart ATW thread before rendering.
            while (!WaveVR_Utils.WVR_IsATWActive())
            {
                yield return(wait);

                if (surfaceChanged && isNeedTimeout == false)
                {
                    break;
                }
                if (Time.time - tim > 1.0f)
                {
                    Log.w(LOG_TAG, "Waiting for surface change is timeout.");
                    break;
                }
            }
            // Reset isNeedTimeout flag
            isNeedTimeout = false;

            if (textureManager != null)
            {
                if (!textureManager.validate())
                {
                    textureManager.reset();
                }
            }
        }
        Log.d(LOG_TAG, "First frame");
        WaveVR_Utils.IssueEngineEvent(WaveVR_Utils.EngineEventID.FIRST_FRAME);

        setLoadingCanvas(false);
        Log.d(LOG_TAG, "RenderLoop() is running");

        while (true)
        {
            Log.gpl.d(LOG_TAG, "RenderLoop() is still running");
            WaveVR_Utils.Trace.BeginSection("RenderLoop", false);
#if UNITY_EDITOR
            if (Application.isEditor)
            {
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.NEW_POSES, new WVR_DevicePosePair_t[0], new WaveVR_Utils.RigidTransform[0]);
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.AFTER_NEW_POSES);
                textureManager.Next();
            }
            else
#endif
            {
                WaveVR.Instance.UpdatePoses(origin);
                // Set next texture before running any graphic command.
                textureManager.Next();
            }

            if (configurationChanged)
            {
                WaveVR_Render.Expand(this);
                configurationChanged = false;
            }

            RenderEye(lefteye.getCamera(), WVR_Eye.WVR_Eye_Left);
            RenderEye(righteye.getCamera(), WVR_Eye.WVR_Eye_Right);
            WaveVR_Utils.Trace.EndSection(false);

            // Put here to control the time of next frame.
            TimeControl();

            Log.gpl.d(LOG_TAG, "End of frame");
            yield return(wait);
        }
    }
예제 #2
0
    private IEnumerator RenderLoop()
    {
        if (cachedWaitForEndOfFrame == null)
        {
            cachedWaitForEndOfFrame = new WaitForEndOfFrame();
        }
        yield return(cachedWaitForEndOfFrame);

        yield return(cachedWaitForEndOfFrame);

        if (isInitializeGraphic == false)
        {
            InitializeGraphic();
            // sync here to wait InitializeGraphic done because InitializeGraphic is migration to render thread.
            synchronizer.sync();
            textureManager      = new TextureManager();
            isInitializeGraphic = true;
        }

        Log.d(LOG_TAG, "RenderLoop() is started");
        var tim = Time.realtimeSinceStartup;

#if UNITY_EDITOR
        if (!Application.isEditor)
#endif
        {
            WaveVR_Utils.WVR_SetPerformanceLevels(cpuPerfLevel, gpuPerfLevel);
            Log.i(LOG_TAG, "SetPerformanceLevels cpuPerfLevel " + cpuPerfLevel + " gpuPerfLevel " + gpuPerfLevel);
            // Restart ATW thread before rendering.
            while (!WaveVR_Utils.WVR_IsATWActive())
            {
                yield return(cachedWaitForEndOfFrame);

                if (surfaceChanged && isNeedTimeout == false)
                {
                    break;
                }
                if (Time.realtimeSinceStartup - tim > 1.0f)
                {
                    Log.w(LOG_TAG, "Waiting for surface change is timeout.");
                    break;
                }
            }
            // Reset isNeedTimeout flag
            isNeedTimeout = false;

            if (textureManager != null)
            {
                if (!textureManager.validate())
                {
                    textureManager.reset();
                }
            }
        }
        Log.d(LOG_TAG, "First frame");
        WaveVR_Utils.IssueEngineEvent(WaveVR_Utils.EngineEventID.FIRST_FRAME);

        setLoadingCanvas(false);
        Log.d(LOG_TAG, "RenderLoop() is running");

        while (true)
        {
            Log.gpl.d(LOG_TAG, "RenderLoop() is still running");
            WaveVR_Utils.Trace.BeginSection("RenderLoop", false);
#if UNITY_EDITOR
            if (Application.isEditor)
            {
                if (WaveVR.Instance.isSimulatorOn)
                {
                    WaveVR.Instance.UpdatePoses(origin, true);
                }
                else
                {
                    WaveVR_Utils.Event.Send(WaveVR_Utils.Event.NEW_POSES, new WVR_DevicePosePair_t[0], new WaveVR_Utils.RigidTransform[0]);
                    WaveVR_Utils.Event.Send(WaveVR_Utils.Event.AFTER_NEW_POSES);
                }
                if (textureManager != null)
                {
                    textureManager.Next();
                }
            }
            else
#endif
            {
                WaveVR.Instance.UpdatePoses(origin);
                // Set next texture before running any graphic command.
                if (textureManager != null)
                {
                    textureManager.Next();
                }
            }

            if (configurationChanged)
            {
                WaveVR_Render.Expand(this);
                configurationChanged = false;
            }

            RenderEye(lefteye.getCamera(), WVR_Eye.WVR_Eye_Left);
            RenderEye(righteye.getCamera(), WVR_Eye.WVR_Eye_Right);
            WaveVR_Utils.Trace.EndSection(false);

            // Put here to control the time of next frame.
            TimeControl();

            Log.gpl.d(LOG_TAG, "End of frame");
            yield return(cachedWaitForEndOfFrame);
        }
    }