Example #1
0
        private void CreateRawTexture()
        {
            _usedTextureWidth  = _mode.Pitch / 4;
            _usedTextureHeight = _mode.Height;

            // HACK for 10-bit..
            if (_mode.PixelFormat == DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422)
            {
                _usedTextureWidth = ((_mode.Width * 16) / 6) / 4;
            }

            // We use a power-of-2 texture as Unity makes these internally anyway and not doing it seems to break things for texture updates
            int textureWidth;
            int textureHeight;

            CalcPOTResolutions(_usedTextureWidth, _usedTextureHeight, out textureWidth, out textureHeight);

            // Create texture that stores the initial raw frame
            // If there is already a texture, only destroy it if it's too small
            if (_rawTexture != null)
            {
                if (_rawTexture.width != textureWidth ||
                    _rawTexture.height != textureHeight)
                {
                    Texture2D.Destroy(_rawTexture);
                    DeckLinkPlugin.SetTexturePointer(_deviceHandle, System.IntPtr.Zero);
                    _rawTexture = null;
                }
            }

            if (_enable3D && _rightEyeRawTexture != null)
            {
                if (_rightEyeRawTexture.width != textureWidth || _rightEyeRawTexture.height != textureHeight)
                {
                    Texture2D.Destroy(_rightEyeRawTexture);
                    DeckLinkPlugin.SetRightTexturePointer(_deviceHandle, System.IntPtr.Zero);
                    _rightEyeRawTexture = null;
                }
            }
            else if (!_enable3D && _rightEyeRawTexture != null)
            {
                Texture2D.Destroy(_rightEyeRawTexture);
                DeckLinkPlugin.SetRightTexturePointer(_deviceHandle, System.IntPtr.Zero);
                _rightEyeRawTexture = null;
            }

            if (_rawTexture == null)
            {
                _rawTexture            = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false, true);
                _rawTexture.wrapMode   = TextureWrapMode.Clamp;
                _rawTexture.filterMode = FilterMode.Point;
                _rawTexture.name       = "AVProDeckLink-RawTexture";
                DeckLinkPlugin.SetTexturePointer(_deviceHandle, _rawTexture.GetNativeTexturePtr());
            }

            if (_enable3D && _rightEyeRawTexture == null)
            {
                _rightEyeRawTexture            = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false, true);
                _rightEyeRawTexture.wrapMode   = TextureWrapMode.Clamp;
                _rightEyeRawTexture.filterMode = FilterMode.Point;
                _rightEyeRawTexture.name       = "AVProDeckLink-RightEyeRawTexture";
                DeckLinkPlugin.SetRightTexturePointer(_deviceHandle, _rightEyeRawTexture.GetNativeTexturePtr());
            }
        }