Skip to content

Commit

Permalink
fix issues with texture loading
Browse files Browse the repository at this point in the history
  • Loading branch information
steviegt6 committed May 14, 2021
1 parent e0da828 commit 693c5c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions patches/Terraclient/ReLogic/Content/Readers/PngReader.cs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- src/Terraria/ReLogic/Content/Readers/PngReader.cs
+++ src/Terraclient/ReLogic/Content/Readers/PngReader.cs
@@ -40,12 +_,27 @@
texture2D.SetData(value, 0, num);
return texture2D as T;
#else
+ // tML code:
- var img = Image.Load(stream);
+ /*var img = Image.Load(stream);
Image<Rgba32> bmp = img.CloneAs<Rgba32>();
bmp.TryGetSinglePixelSpan(out Span<Rgba32> colors);

Texture2D texture2D = new Texture2D(_graphicsDevice, bmp.Width, bmp.Height);
- texture2D.SetData(colors.ToArray());
+ texture2D.SetData(colors.ToArray());*/
+
+ // Terraclient:
+ Texture2D texture2D = Texture2D.FromStream(_graphicsDevice, stream);
+ int num = texture2D.Width * texture2D.Height;
+ if (!_colorProcessingCache.IsValueCreated || _colorProcessingCache.Value.Length < num)
+ _colorProcessingCache.Value = new Color[num];
+
+ Color[] value = _colorProcessingCache.Value;
+ texture2D.GetData(value, 0, num);
+ for (int i = 0; i != num; i++) {
+ value[i] = Color.FromNonPremultiplied(value[i].ToVector4());
+ }
+
+ texture2D.SetData(value, 0, num);
return texture2D as T;
#endif
}
2 changes: 1 addition & 1 deletion patches/Terraclient/Terraria/Terraclient/CheatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class CheatHandler
public static string Version => TerraclientVersion + TerraclientVersionEx;

private static readonly Version TerraclientVersion = new(0, 0, 1, 0);
private const string TerraclientVersionEx = " alpha-21w20a";
private const string TerraclientVersionEx = " alpha-21w20b";

internal static List<Cheat> Cheats;

Expand Down

0 comments on commit 693c5c6

Please sign in to comment.