1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00
MLEM/MLEM.Data/Content/Texture2DReader.cs
Ell c4bd03ff04 Image loading improvements:
- Added TextureExtensions.PremultipliedCopy for textures
- Create a premultiplied copy of UiParser images to support usage with KNI
2024-09-14 10:48:04 +02:00

30 lines
945 B
C#

using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Textures;
namespace MLEM.Data.Content {
/// <inheritdoc />
public class Texture2DReader : RawContentReader<Texture2D> {
/// <inheritdoc />
protected override Texture2D Read(RawContentManager manager, string assetPath, Stream stream, Texture2D existing) {
#if !FNA && !KNI
if (existing != null) {
existing.Reload(stream);
return existing;
}
#endif
// premultiply the texture's color to be in line with the pipeline's texture reader
using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream))
return texture.PremultipliedCopy();
}
/// <inheritdoc />
public override string[] GetFileExtensions() {
return new[] {"png", "bmp", "gif", "jpg", "tif", "dds"};
}
}
}