Skip to content

Commit

Permalink
Merge pull request #7 from piti6/mkim/fix-compressed-texture-not-applied
Browse files Browse the repository at this point in the history
Fix compressed texture cannot be encoded
  • Loading branch information
piti6 authored Mar 4, 2021
2 parents 6d1da2b + 4572bd4 commit b1c4326
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Scripts/InternalBridge/Data/SerializableTexture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SerializableTexture2D(string id, Texture2D texture)
m_width = texture.width;
m_height = texture.height;
m_texture = texture;
m_byte = IsValid ? ImageConversion.EncodeToPNG(texture.MakeReadable()) : Array.Empty<byte>();
m_byte = IsValid ? ImageConversion.EncodeToPNG(texture.ToDecompressedTexture()) : Array.Empty<byte>();
}
}
}
22 changes: 11 additions & 11 deletions Scripts/InternalBridge/Extensions/Texture2DExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ namespace UniSkin
{
internal static class Texture2DExtensions
{
public static Texture2D MakeReadable(this Texture2D source)
public static Texture2D ToDecompressedTexture(this Texture2D source)
{
if (source == null || source.isReadable)
{
return source;
}
else
{
var newTexture2D = new Texture2D(source.width, source.height, source.format, source.mipmapCount, source);
Graphics.CopyTexture(source, newTexture2D);
var renderTexture = RenderTexture.GetTemporary(source.width, source.height);

return newTexture2D;
}
Graphics.Blit(source, renderTexture);

var readableTexture = new Texture2D(source.width, source.height);
readableTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
readableTexture.Apply();

RenderTexture.ReleaseTemporary(renderTexture);

return readableTexture;
}

public static string ToTextureId(this Texture2D source)
Expand Down

0 comments on commit b1c4326

Please sign in to comment.