/// <summary>
        /// Initializes a new instance of the <see cref="TextureDocumentViewModel" /> class.
        /// </summary>
        /// <param name="document">The TextureDocument.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="document"/> is <see langword="null"/>.
        /// </exception>
        public TextureDocumentViewModel(TextureDocument document)
            : base(document)
        {
            // Disable unsupported color channels.
            var channels = TextureHelper.GetColorChannels(document.Texture2D.Format);

            if ((channels & ColorChannels.Red) != 0)
            {
                EnableRedChannel      = true;
                IsRedChannelSupported = true;
            }
            if ((channels & ColorChannels.Green) != 0)
            {
                EnableGreenChannel      = true;
                IsGreenChannelSupported = true;
            }
            if ((channels & ColorChannels.Blue) != 0)
            {
                EnableBlueChannel      = true;
                IsBlueChannelSupported = true;
            }
            if ((channels & ColorChannels.Alpha) != 0)
            {
                EnableAlphaChannel      = true;
                IsAlphaChannelSupported = true;
            }

            AlphaBlendTypes = new[] { "Straight alpha", "Premultiplied alpha" };

            MipLevelNames = new string[document.Texture2D.LevelCount];
            for (int i = 0; i < document.Texture2D.LevelCount; i++)
            {
                MipLevelNames[i] = Invariant($"Mip level {i}");
            }

            ChangeMipLevelCommand = new DelegateCommand <object>(ChangeMipLevel);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        protected override void OnLoad()
        {
            Texture2D?.Dispose();
            Texture2D = null;
            _monoGameContent?.Dispose();
            _monoGameContent = null;

            // TODO: Asynchronously load textures.
            string fileName  = Uri.LocalPath;
            string extension = Path.GetExtension(fileName);
            bool   isXnb     = string.Compare(extension, ".XNB", StringComparison.OrdinalIgnoreCase) == 0;

            if (isXnb)
            {
                try
                {
                    string directoryName = Path.GetDirectoryName(fileName);
                    _monoGameContent = _monoGameService.LoadXnb(directoryName, fileName, cacheResult: false);
                    Texture2D        = (Texture2D)_monoGameContent.Asset;
                }
                catch
                {
                    Texture2D?.Dispose();
                    Texture2D = null;
                    _monoGameContent?.Dispose();
                    _monoGameContent = null;

                    throw;
                }
            }
            else
            {
                Texture2D = TextureHelper.LoadTexture(_graphicsService, Uri.LocalPath);
            }

            UpdateProperties();
        }