fix transparency issues on Linux/Mac due to MonoGame bug (#279)

This commit is contained in:
Jesse Plamondon-Willard 2018-09-03 19:40:05 -04:00
parent 047091a1a4
commit af6c273d8a
2 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,7 @@
* Fixed crash when a mod manifest is corrupted.
* Fixed error-handling when initialising paths.
* Fixed 'no update keys' warning not shown for mods with only invalid update keys.
* Fixed transparency issues on Linux/Mac for many mods.
* Updated compatibility list.
* For modders:

View File

@ -171,6 +171,14 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <remarks>Based on <a href="https://gamedev.stackexchange.com/a/26037">code by David Gouveia</a>.</remarks>
private Texture2D PremultiplyTransparency(Texture2D texture)
{
// Textures loaded by Texture2D.FromStream are already premultiplied on Linux/Mac, even
// though the XNA documentation explicitly says otherwise. That's a glitch in MonoGame
// fixed in newer versions, but the game uses a bundled version that will always be
// affected. See https://github.com/MonoGame/MonoGame/issues/4820 for more info.
if (Constants.TargetPlatform != GamePlatform.Windows)
return texture;
// premultiply pixels
Color[] data = new Color[texture.Width * texture.Height];
texture.GetData(data);
for (int i = 0; i < data.Length; i++)