コード例 #1
0
        public bool Update()
        {
            bool result = false;

            //RenderTexture prev = RenderTexture.active;

            if (!_isBuilt)
            {
                if (DeckLinkPlugin.GetLastCapturedFrameTime(_deviceHandle) > 0)
                {
                    if (!Build())
                    {
                        return(false);
                    }
                }
                return(false);
            }

            /*
             #if UNITY_5_3_OR_NEWER
             *                      Flip();
             #endif
             */
            if (_uvsDirty)
            {
                _requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);

                if (_requiresTextureCrop)
                {
                    CreateUVs(_flipX || false, !_flipY && true);
                }
                else
                {
                    Flip(_flipX || false, !_flipY && true);
                }

                _uvsDirty = false;
            }

            // Wait until next frame has been uploaded to the texture
            int lastFrameUploaded = (int)DeckLinkPlugin.GetLastFrameUploaded(_deviceHandle);

            if (_lastFrameUploaded != lastFrameUploaded)
            {
                RenderTexture prev = RenderTexture.active;

                if (!_deinterlace)
                {
                    // Format convert
                    if (DoFormatConversion(_finalTexture))
                    {
                        result = true;
                    }
                }
                else
                {
                    // Format convert and Deinterlace
                    RenderTexture tempTarget = RenderTexture.GetTemporary(_finalTexture.width, _finalTexture.height, 0, _finalTexture.format, RenderTextureReadWrite.Default);
                    tempTarget.filterMode = FilterMode.Point;
                    tempTarget.wrapMode   = TextureWrapMode.Clamp;
                    if (DoFormatConversion(tempTarget))
                    {
                        DoDeinterlace(tempTarget, _finalTexture);

                        result = true;
                    }
                    RenderTexture.ReleaseTemporary(tempTarget);
                }

                if (_linearToGammaMat)
                {
                    Graphics.Blit(_finalTexture, _linearToGammaTexture, _linearToGammaMat);
                }

                RenderTexture.active = prev;

                _lastFrameUploaded = lastFrameUploaded;
            }
            else if (!_finalTexture.IsCreated())
            {
                Debug.LogError("GPU Reset");
                // If the texture has been lost due to GPU reset(from full screen mode change or vsync change) we'll need fill the texture again
                Reset();
            }

            return(ValidPicture && result);
        }
コード例 #2
0
        public bool Update()
        {
            bool result = false;
            //RenderTexture prev = RenderTexture.active;

            bool build = !_isBuilt;

#if AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
            build |= _externalTexturePtr != DeckLinkPlugin.GetTexturePointer(_deviceHandle);
#endif

            if (build)
            {
                if (DeckLinkPlugin.GetLastCapturedFrameTime(_deviceHandle) > 0)
                {
                    if (!Build())
                    {
                        return(false);
                    }
                }
                return(false);
            }

            /*
             #if UNITY_5_3_OR_NEWER
             *                      Flip();
             #endif
             */
            if (_uvsDirty)
            {
                _requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);

                if (_requiresTextureCrop)
                {
                    CreateUVs(_flipX || false, !_flipY && true);
                }
                else
                {
                    Flip(_flipX || false, !_flipY && true);
                }

                _uvsDirty = false;
            }

            // Wait until next frame has been uploaded to the texture
            int lastFrameUploaded = (int)DeckLinkPlugin.GetLastFrameUploaded(_deviceHandle);
            if (_lastFrameUploaded != lastFrameUploaded)
            {
                RenderTexture prev = RenderTexture.active;

                if (!_deinterlace)
                {
                    // Format convert
                    result = DoFormatConversion(_finalTexture, _rawTexture);

                    if (_enable3D && _rightEyeRawTexture != null && _rightEyeFinalTexture != null)
                    {
                        result = result && DoFormatConversion(_rightEyeFinalTexture, _rightEyeRawTexture);
                    }
                }
                else
                {
                    // Format convert and Deinterlace
                    RenderTexture tempTarget = RenderTexture.GetTemporary(_finalTexture.width, _finalTexture.height, 0, _finalTexture.format, RenderTextureReadWrite.Default);
                    tempTarget.filterMode = FilterMode.Point;
                    tempTarget.wrapMode   = TextureWrapMode.Clamp;
                    if (DoFormatConversion(tempTarget, _rawTexture))
                    {
                        DoDeinterlace(tempTarget, _finalTexture);

                        result = true;
                    }

                    if (_enable3D && _rightEyeRawTexture != null && _rightEyeFinalTexture != null)
                    {
                        if (DoFormatConversion(tempTarget, _rightEyeRawTexture))
                        {
                            DoDeinterlace(tempTarget, _rightEyeFinalTexture);
                            result = result && true;
                        }
                    }

                    RenderTexture.ReleaseTemporary(tempTarget);
                }

                RenderTexture.active = prev;

                _lastFrameUploaded = lastFrameUploaded;
            }
            else if (!_finalTexture.IsCreated() || (_enable3D && _rightEyeFinalTexture != null && !_rightEyeFinalTexture.IsCreated()))
            {
                Debug.LogError("GPU Reset");
                // If the texture has been lost due to GPU reset(from full screen mode change or vsync change) we'll need fill the texture again
                Reset();
            }

            if (_conversionMaterial != null && _mode != null)
            {
                _conversionMaterial.SetFloat("_TextureWidth", _mode.Width);
            }

            return(ValidPicture && result);
        }