Esempio n. 1
0
        private bool Build()
        {
            if (CreateMaterial())
            {
#if AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
                System.IntPtr texPtr = DeckLinkPlugin.GetTexturePointer(_deviceHandle);
                if (texPtr != System.IntPtr.Zero)
                {
                    _usedTextureHeight = _mode.Height;

                    if (_mode.PixelFormat == DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422)
                    {
                        _usedTextureWidth = ((_mode.Width * 16) / 6) / 4;
                    }
                    else
                    {
                        _usedTextureWidth = _mode.Pitch / 4;
                    }

                    int width, height;
                    CalcPOTResolutions(_usedTextureWidth, _usedTextureHeight, out width, out height);

                    _rawTexture         = Texture2D.CreateExternalTexture(width, height, TextureFormat.ARGB32, false, true, texPtr);
                    _externalTexturePtr = texPtr;

                    if (_enable3D)
                    {
                        texPtr = DeckLinkPlugin.GetRightTexturePointer(_deviceHandle);
                        if (texPtr != System.IntPtr.Zero)
                        {
                            _rightEyeRawTexture = Texture2D.CreateExternalTexture(width, height, TextureFormat.ARGB32, false, true, texPtr);
                        }
                    }
                }
#else
                CreateRawTexture();
#endif
                if (_rawTexture != null)
                {
                    CreateFinalTexture();

                    _requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);

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

                    _conversionMaterial.SetFloat("_TextureWidth", _mode.Width);
                    //_conversionMaterial.mainTexture = _rawTexture;
#if !AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
                    DeckLinkPlugin.SetTexturePointer(_deviceHandle, _rawTexture.GetNativeTexturePtr());
#endif
                }
            }

            _isBuilt = (_conversionMaterial != null && _rawTexture != null && _finalTexture != null);
            return(_isBuilt);
        }