Exemplo n.º 1
0
        internal Initializer(XTexture2D reference, Bounds dimensions, uint expectedScale, TextureType textureType, bool animated)
        {
            Reference      = reference;
            BlendState     = DrawState.CurrentBlendState;
            SamplerState   = DrawState.CurrentSamplerState;
            ExpectedScale  = expectedScale;
            Bounds         = dimensions;
            IsPreview      = Configuration.Preview.Override.Instance is not null;
            Scaler         = Configuration.Preview.Override.Instance?.Scaler ?? Config.Resample.Scaler;
            ScalerGradient = Configuration.Preview.Override.Instance?.ScalerGradient ?? Config.Resample.ScalerGradient;

            TextureType = textureType;

            // Truncate the bounds so that it fits if it wouldn't otherwise fit
            if (!Bounds.ClampToChecked(Reference.Bounds, out var clampedBounds))
            {
                Debug.Warning($"SpriteInfo for '{reference.NormalizedName()}' bounds '{dimensions}' are not contained in reference bounds '{(Bounds)reference.Bounds}'");
                Bounds = clampedBounds;
            }

            var refMeta = reference.Meta();
            var refData = refMeta.CachedData;

            if (refData is null)
            {
                // TODO : Switch this around to use ReadOnlySequence so our hash is specific to the sprite
                refData = new byte[reference.SizeBytes()];
                Debug.Trace($"Reloading Texture Data (not in cache): {reference.NormalizedName(DrawingColor.LightYellow)}");
                reference.GetData(refData);
                reference.Meta().CachedRawData = refData;
                if (refMeta.IsCompressed)
                {
                    refData = null;                     // we can only use uncompressed data at this stage.
                }
                WasCached = false;
            }
            else if (refData == Texture2DMeta.BlockedSentinel)
            {
                refData   = null;
                WasCached = false;
            }
            else
            {
                WasCached = true;
            }

            ReferenceData = refData;

            Hash     = null;
            DataHash = null;
            if (Config.SuspendedCache.Enabled && animated)
            {
                (Hash, DataHash) = GetHash();
            }
        }