Beispiel #1
0
        private bool Render()
        {
            bool result = false;

            if (_device != null)
            {
                // Prevent this function being executed again this frame if the camera frame has been updated this frame already
                if (_lastFrameCount != Time.frameCount)
                {
                    if (_device != null)
                    {
                        if (_device.Render())
                        {
                            _lastFrameCount = Time.frameCount;
                            result          = true;
                        }
                        else
                        {
                            _lastFrameUpdated = AVProLiveCameraPlugin.GetLastFrameUploaded(_device.DeviceIndex);
                        }

                        {
                            int eventId = AVProLiveCameraPlugin.PluginID | (int)AVProLiveCameraPlugin.PluginEvent.UpdateOneTexture | _device.DeviceIndex;
#if UNITY_5_4_OR_NEWER || (UNITY_5 && !UNITY_5_0 && !UNITY_5_1)
                            GL.IssuePluginEvent(_renderFunc, eventId);
#else
                            GL.IssuePluginEvent(eventId);
#endif
                        }
                    }
                }
            }
            return(result);
        }
        private bool IsNewSourceTextureAvailable()
        {
            bool result = false;

            int lastFrameUpdated = AVProLiveCameraPlugin.GetLastFrameUploaded(_deviceIndex);

            if (_lastFrameUpdated != lastFrameUpdated)
            {
                _lastFrameUpdated = lastFrameUpdated;
                result            = true;
            }
            return(result);
        }
Beispiel #3
0
        private System.Collections.IEnumerator RenderRoutine()
        {
            while (Application.isPlaying)
            {
                yield return(null);

                if (this.enabled)
                {
                    bool hasUpdatedThisFrame = Render();

                    // NOTE: in editor, if the game view isn't visible then WaitForEndOfFrame will never complete
                    yield return(_wait);

                    if (!hasUpdatedThisFrame)
                    {
                        // Try again to get the frame
                        if (!Render())
                        {
                            //Debug.Log("frame dropped :(");
                        }
                    }
                    else
                    {
                        // If nothing has updated, send another event
                        int lastFrameUpdated = AVProLiveCameraPlugin.GetLastFrameUploaded(_device.DeviceIndex);
                        if (_lastFrameUpdated == lastFrameUpdated)
                        {
                            int eventId = AVProLiveCameraPlugin.PluginID | (int)AVProLiveCameraPlugin.PluginEvent.UpdateOneTexture | _device.DeviceIndex;
#if UNITY_5_4_OR_NEWER || (UNITY_5 && !UNITY_5_0 && !UNITY_5_1)
                            GL.IssuePluginEvent(_renderFunc, eventId);
#else
                            GL.IssuePluginEvent(eventId);
#endif
                        }
                    }
                }
            }

            _renderRoutine = null;
        }