Ejemplo n.º 1
0
        IEnumerator Start()
        {
            // Internal objects initialization
            if (_isMaster)
            {
                _plugin = SenderPlugin.
                          CreateManualSender(_deviceSelection, _formatSelection);
            }
            else
            {
                _plugin = SenderPlugin.
                          CreateAsyncSender(_deviceSelection, _formatSelection, _queueLength);
            }

            _subsampler   = new Material(Shader.Find("Hidden/Klinker/Subsampler"));
            _dropDetector = new DropDetector(gameObject.name);

            var dim = _plugin.FrameDimensions;

            // If the target camera doesn't have a target texture, create
            // a RT and set it as a target texture. Also create a blitter
            // object to keep frames presented on the screen.
            if (TargetCamera.targetTexture == null)
            {
                _targetRT = new RenderTexture(dim.x, dim.y, 24, TargetFormat);
                _targetRT.antiAliasing     = TargetAALevel;
                TargetCamera.targetTexture = _targetRT;
                _blitter = Blitter.CreateInstance(TargetCamera);
            }
            else
            {
                // Make sure if the target texture has the correct dimensions.
                var rt = TargetCamera.targetTexture;
                if (rt.width != dim.x || rt.height != dim.y)
                {
                    Debug.LogError(
                        "Target texture size mismatch. It should be " +
                        dim.x + " x " + dim.y
                        );
                }
            }

            if (!_isMaster)
            {
                yield break;
            }

            // Master sender coroutine

            // Promote this instance to master.
            // Check the frame duration if there is another master.
            var duration = _plugin.FrameDuration;

            if (master != null && master.frameDuration != duration)
            {
                Debug.LogError(
                    "Master frame rate mismatch. When using multiple master " +
                    "senders, they should have the exact same frame rate."
                    );
            }
            master = this;

            // Calculate the frame rate.
            // We prefer using ceiling values (i.e. 59.94 => 60)
            var fps = (int)((Util.FlicksPerSecond + duration - 1) / duration);

            if (!_plugin.IsProgressive)
            {
                fps *= 2;
            }

            // Set target frame rate (using captureFramerate) and stop v-sync.
            Time.captureFramerate      = fps;
            QualitySettings.vSyncCount = 0;

            // Wait for sender completion every end-of-frame.
            var qlen = _queueLength;

            for (var eof = new WaitForEndOfFrame();;)
            {
                yield return(eof);

                if (_frameCount < qlen)
                {
                    continue;
                }
                _plugin.WaitCompletion(_frameCount - qlen);
            }
        }
Ejemplo n.º 2
0
 void Start()
 {
     _plugin       = new ReceiverPlugin(_deviceSelection, 0);
     _upsampler    = new Material(Shader.Find("Hidden/Klinker/Upsampler"));
     _dropDetector = new DropDetector(gameObject.name);
 }