netpyoung / unity.webp

:art: WebP made easy for Unity3d
https://netpyoung.github.io/unity.webp/
MIT License
237 stars 28 forks source link

Textures not readable #33

Open huterdev opened 2 years ago

huterdev commented 2 years ago

I found that the texture that is returned from Texture2DExt.CreateTexture2DFromWebP() is currently not readable, that left me at my wits end until I figured out that when the texture is applied, makeNoLongerReadable is set to true by default:

lTexture2D.Apply(lMipmaps, true);

Setting this to false solved my problem. Wouldn't a solution like this be more elegant for cases where the texture needs to remain readable?:

public static unsafe Texture2D CreateTexture2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, bool readable, out Error lError, ScalingFunction scalingFunction = null)
        {
            Texture2D lTexture2D = null;
            int lWidth;
            int lHeight;
            GetWebPDimensions(lData, out lWidth, out lHeight);

            byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction);

            if (lError == Error.Success)
            {
                lTexture2D = new Texture2D(lWidth, lHeight, TextureFormat.RGBA32, lMipmaps, lLinear);
                lTexture2D.LoadRawTextureData(lRawData);
                lTexture2D.Apply(lMipmaps, readable);
            }

            return lTexture2D;
        }
netpyoung commented 2 years ago

from 57b939e84e340818523ae189e35a43fe533331a8

that function already modified pass readable. https://github.com/netpyoung/unity.webp/blob/57b939e84e340818523ae189e35a43fe533331a8/unity_project/Assets/unity.webp/Runtime/Texture2DExt.cs#L191

There still exists function which make force readable - https://github.com/netpyoung/unity.webp/blob/57b939e84e340818523ae189e35a43fe533331a8/unity_project/Assets/unity.webp/Runtime/Texture2DExt.cs#L335 but I will fix that later

huterdev commented 2 years ago

Oh wow, totally missed that! Thanks :)