1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-28 02:49:38 +01:00
MLEM/MLEM.Data/Content/Texture2DReader.cs

31 lines
945 B
C#
Raw Normal View History

2020-04-22 00:30:55 +02:00
using System.IO;
using Microsoft.Xna.Framework;
2020-04-22 00:30:55 +02:00
using Microsoft.Xna.Framework.Graphics;
using MLEM.Textures;
2020-04-22 00:30:55 +02:00
namespace MLEM.Data.Content {
/// <inheritdoc />
2020-04-22 00:30:55 +02:00
public class Texture2DReader : RawContentReader<Texture2D> {
/// <inheritdoc />
2020-04-22 00:30:55 +02:00
protected override Texture2D Read(RawContentManager manager, string assetPath, Stream stream, Texture2D existing) {
#if !FNA && !KNI
2020-04-22 00:30:55 +02:00
if (existing != null) {
existing.Reload(stream);
return existing;
2022-08-20 11:39:28 +02:00
}
2022-12-13 13:11:36 +01:00
#endif
2022-08-20 11:39:28 +02:00
// 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();
2020-04-22 00:30:55 +02:00
}
/// <inheritdoc />
2020-04-22 00:30:55 +02:00
public override string[] GetFileExtensions() {
return new[] {"png", "bmp", "gif", "jpg", "tif", "dds"};
}
}
2022-06-17 18:23:47 +02:00
}