mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Premultiply textures when using RawContentManager
This commit is contained in:
parent
16b9e26969
commit
47b58b1942
3 changed files with 20 additions and 1 deletions
|
@ -40,6 +40,10 @@ Removals
|
|||
- Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones
|
||||
- Marked Tooltip.Paragraph as obsolete in favor of new Paragraphs collection
|
||||
|
||||
### MLEM.Data
|
||||
Improvements
|
||||
- Premultiply textures when using RawContentManager
|
||||
|
||||
## 5.3.0
|
||||
### MLEM
|
||||
Additions
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System.IO;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Extensions;
|
||||
|
||||
namespace MLEM.Data.Content {
|
||||
/// <inheritdoc />
|
||||
|
@ -11,7 +13,20 @@ namespace MLEM.Data.Content {
|
|||
existing.Reload(stream);
|
||||
return existing;
|
||||
} else {
|
||||
return Texture2D.FromStream(manager.GraphicsDevice, stream);
|
||||
// premultiply the texture's color to be in line with the pipeline's texture reader
|
||||
// TODO this can be converted to use https://github.com/MonoGame/MonoGame/pull/7369 in the future
|
||||
using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) {
|
||||
var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height);
|
||||
using (var textureData = texture.GetTextureData()) {
|
||||
using (var retData = ret.GetTextureData()) {
|
||||
for (var x = 0; x < ret.Width; x++) {
|
||||
for (var y = 0; y < ret.Height; y++)
|
||||
retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 896 B After Width: | Height: | Size: 899 B |
Loading…
Reference in a new issue