Beispiel #1
0
        internal static TextureFormat ToMSTextureFormat(UnityEngine.TextureFormat v)
        {
            switch (v)
            {
            case UnityEngine.TextureFormat.R8: return(TextureFormat.Ru8);

            case UnityEngine.TextureFormat.RG16: return(TextureFormat.RGu8);

            case UnityEngine.TextureFormat.RGB24: return(TextureFormat.RGBu8);

            case UnityEngine.TextureFormat.RGBA32: return(TextureFormat.RGBAu8);

            case UnityEngine.TextureFormat.RHalf: return(TextureFormat.Rf16);

            case UnityEngine.TextureFormat.RGHalf: return(TextureFormat.RGf16);

            case UnityEngine.TextureFormat.RGBAHalf: return(TextureFormat.RGBAf16);

            case UnityEngine.TextureFormat.RFloat: return(TextureFormat.Rf32);

            case UnityEngine.TextureFormat.RGFloat: return(TextureFormat.RGf32);

            case UnityEngine.TextureFormat.RGBAFloat: return(TextureFormat.RGBAf32);

            default: return(TextureFormat.Ru8);
            }
        }
Beispiel #2
0
 public RawTextureMetaData(Texture2D texture)
 {
     this.Width         = texture.width;
     this.Height        = texture.height;
     this.TextureFormat = texture.format;
     this.Mipmap        = texture.mipmapCount > 1;
 }
Beispiel #3
0
    static bool SystemInfo_SupportsTextureFormat__TextureFormat(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.TextureFormat arg0 = (UnityEngine.TextureFormat)JSApi.getEnum((int)JSApi.GetType.Arg);
            JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(UnityEngine.SystemInfo.SupportsTextureFormat(arg0)));
        }

        return(true);
    }
Beispiel #4
0
 internal static bool HasAlpha(UnityEngine.TextureFormat format)
 {
     return(format == UnityEngine.TextureFormat.Alpha8 ||
            format == UnityEngine.TextureFormat.ARGB4444 ||
            format == UnityEngine.TextureFormat.ARGB32 ||
            format == UnityEngine.TextureFormat.RGBA32 ||
            format == UnityEngine.TextureFormat.DXT5 ||
            format == UnityEngine.TextureFormat.PVRTC_RGBA2 ||
            format == UnityEngine.TextureFormat.PVRTC_RGBA4 ||
            format == UnityEngine.TextureFormat.ETC2_RGBA8 ||
            format == UnityEngine.TextureFormat.RGBAHalf ||
            format == UnityEngine.TextureFormat.DXT5Crunched);
 }
Beispiel #5
0
    static bool Texture2D_Resize__Int32__Int32__TextureFormat__Boolean(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 4)
        {
            System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            System.Int32 arg1 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)JSApi.getEnum((int)JSApi.GetType.Arg);
            System.Boolean            arg3 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
            JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(((UnityEngine.Texture2D)vc.csObj).Resize(arg0, arg1, arg2, arg3)));
        }

        return(true);
    }
Beispiel #6
0
    static bool Texture2D_CreateExternalTexture__Int32__Int32__TextureFormat__Boolean__Boolean__IntPtr(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 6)
        {
            System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            System.Int32 arg1 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)JSApi.getEnum((int)JSApi.GetType.Arg);
            System.Boolean            arg3 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
            System.Boolean            arg4 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
            System.IntPtr             arg5 = (System.IntPtr)JSApi.getIntPtr((int)JSApi.GetType.Arg);
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, UnityEngine.Texture2D.CreateExternalTexture(arg0, arg1, arg2, arg3, arg4, arg5));
        }

        return(true);
    }
 public static int  obj_new2(long L)
 {
     try
     {
         int arg0 = FCLibHelper.fc_get_int(L, 0);
         int arg1 = FCLibHelper.fc_get_int(L, 1);
         UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)(FCLibHelper.fc_get_int(L, 2));
         bool arg3 = FCLibHelper.fc_get_bool(L, 3);
         UnityEngine.Texture2D obj = new UnityEngine.Texture2D(arg0, arg1, arg2, arg3);
         long nPtr = FCGetObj.PushNewObj <UnityEngine.Texture2D>(obj);
         long ret  = FCLibHelper.fc_get_return_ptr(L);
         FCLibHelper.fc_set_value_wrap_objptr(ret, nPtr);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
Beispiel #8
0
////////////////////// Cubemap ///////////////////////////////////////
// constructors

    static bool Cubemap_Cubemap1(JSVCall vc, int argc)
    {
        int _this = JSApi.getObject((int)JSApi.GetType.Arg);

        JSApi.attachFinalizerObject(_this);
        --argc;

        int len = argc;

        if (len == 3)
        {
            System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            UnityEngine.TextureFormat arg1 = (UnityEngine.TextureFormat)JSApi.getEnum((int)JSApi.GetType.Arg);
            System.Boolean            arg2 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
            JSMgr.addJSCSRel(_this, new UnityEngine.Cubemap(arg0, arg1, arg2));
        }

        return(true);
    }
 public static int Resize_wrap(long L)
 {
     try
     {
         long nThisPtr             = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.Texture2D obj = get_obj(nThisPtr);
         int arg0 = FCLibHelper.fc_get_int(L, 0);
         int arg1 = FCLibHelper.fc_get_int(L, 1);
         UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)(FCLibHelper.fc_get_int(L, 2));
         bool arg3    = FCLibHelper.fc_get_bool(L, 3);
         bool ret     = obj.Resize(arg0, arg1, arg2, arg3);
         long ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         FCLibHelper.fc_set_value_bool(ret_ptr, ret);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
Beispiel #10
0
////////////////////// SparseTexture ///////////////////////////////////////
// constructors

    static bool SparseTexture_SparseTexture1(JSVCall vc, int argc)
    {
        int _this = JSApi.getObject((int)JSApi.GetType.Arg);

        JSApi.attachFinalizerObject(_this);
        --argc;

        int len = argc;

        if (len == 4)
        {
            System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            System.Int32 arg1 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)JSApi.getEnum((int)JSApi.GetType.Arg);
            System.Int32 arg3 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            JSMgr.addJSCSRel(_this, new UnityEngine.SparseTexture(arg0, arg1, arg2, arg3));
        }

        return(true);
    }
 public static int CreateExternalTexture_wrap(long L)
 {
     try
     {
         int arg0 = FCLibHelper.fc_get_int(L, 0);
         int arg1 = FCLibHelper.fc_get_int(L, 1);
         UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)(FCLibHelper.fc_get_int(L, 2));
         bool          arg3             = FCLibHelper.fc_get_bool(L, 3);
         bool          arg4             = FCLibHelper.fc_get_bool(L, 4);
         System.IntPtr arg5             = FCGetObj.GetObj <System.IntPtr>(FCLibHelper.fc_get_intptr(L, 5));
         Texture2D     ret     = Texture2D.CreateExternalTexture(arg0, arg1, arg2, arg3, arg4, arg5);
         long          ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         long          v       = FCGetObj.PushObj(ret);
         FCLibHelper.fc_set_value_intptr(ret_ptr, v);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
 public static int CreateExternalTexture_wrap(long L)
 {
     try
     {
         long VM   = FCLibHelper.fc_get_vm_ptr(L);
         int  arg0 = FCLibHelper.fc_get_int(L, 0);
         int  arg1 = FCLibHelper.fc_get_int(L, 1);
         UnityEngine.TextureFormat arg2 = (UnityEngine.TextureFormat)(FCLibHelper.fc_get_int(L, 2));
         bool   arg3 = FCLibHelper.fc_get_bool(L, 3);
         bool   arg4 = FCLibHelper.fc_get_bool(L, 4);
         IntPtr arg5 = new IntPtr();
         FCLibHelper.fc_get_void_ptr(L, 5, ref arg5);
         UnityEngine.Texture2D ret = UnityEngine.Texture2D.CreateExternalTexture(arg0, arg1, arg2, arg3, arg4, arg5);
         long ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         long v       = FCGetObj.PushObj(ret);
         FCLibHelper.fc_set_value_wrap_objptr(VM, ret_ptr, v);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
    private AlienTexture LoadTexture(int EntryIndex, bool loadV1 = true)
    {
        AlienTexture toReturn = new AlienTexture();

        if (EntryIndex < 0 || EntryIndex >= LevelTextures.PAK.Header.EntryCount)
        {
            Debug.LogWarning("Asked to load texture at index " + EntryIndex + ", which is out of bounds!");
            return(null);
        }

        alien_pak_entry           Entry     = LevelTextures.PAK.Entries[EntryIndex];
        alien_texture_bin_texture InTexture = LevelTextures.BIN.Textures[Entry.BINIndex];

        Vector2 textureDims;
        int     textureLength = 0;
        int     mipLevels     = 0;

        if (loadV1)
        {
            textureDims   = new Vector2(InTexture.Size_V1[0], InTexture.Size_V1[1]);
            textureLength = InTexture.Length_V1;
            mipLevels     = InTexture.MipLevelsV1;
        }
        else
        {
            textureDims   = new Vector2(InTexture.Size_V2[0], InTexture.Size_V2[1]);
            textureLength = InTexture.Length_V2;
            mipLevels     = InTexture.MipLevelsV2;
        }

        if (textureLength == 0)
        {
            Debug.LogWarning("LENGTH ZERO - NOT LOADING");
            return(toReturn);
        }

        UnityEngine.TextureFormat format = UnityEngine.TextureFormat.BC7;
        switch (InTexture.Format)
        {
        case alien_texture_format.Alien_R32G32B32A32_SFLOAT:
            format = UnityEngine.TextureFormat.RGBA32;
            break;

        case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM:
            format = UnityEngine.TextureFormat.ETC2_RGBA8;     //?
            break;

        case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM_0:
            format = UnityEngine.TextureFormat.ETC2_RGBA8;     //?
            break;

        case alien_texture_format.Alien_FORMAT_SIGNED_DISTANCE_FIELD:
            Debug.LogWarning("SDF! NOT LOADED");
            return(toReturn);

        case alien_texture_format.Alien_FORMAT_R8:
            format = UnityEngine.TextureFormat.R8;
            break;

        case alien_texture_format.Alien_FORMAT_BC1:
            format = UnityEngine.TextureFormat.DXT1;
            break;

        case alien_texture_format.Alien_FORMAT_BC2:
            Debug.LogWarning("BC2! NOT LOADED");
            return(toReturn);

        case alien_texture_format.Alien_FORMAT_BC5:
            format = UnityEngine.TextureFormat.BC5;     //Is this correct?
            break;

        case alien_texture_format.Alien_FORMAT_BC3:
            format = UnityEngine.TextureFormat.DXT5;
            break;

        case alien_texture_format.Alien_FORMAT_BC7:
            format = UnityEngine.TextureFormat.BC7;
            break;

        case alien_texture_format.Alien_FORMAT_R8G8:
            format = UnityEngine.TextureFormat.BC5;     // is this correct?
            break;
        }

        BinaryReader tempReader = new BinaryReader(new MemoryStream(LevelTextures.PAK.DataStart));

        tempReader.BaseStream.Position = Entry.Offset;

        if (InTexture.Type == 7)
        {
            Cubemap cubemapTex = new Cubemap((int)textureDims.x, format, true);
            cubemapTex.name = LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveX);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeX);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveY);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeY);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveZ);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeZ);
            cubemapTex.Apply();
            toReturn.cubemap = cubemapTex;
            //AssetDatabase.CreateAsset(cubemapTex, "Assets/Cubemaps/" + Path.GetFileNameWithoutExtension(cubemapTex.name) + ".cubemap");
        }
        else
        {
            Texture2D texture = new Texture2D((int)textureDims[0], (int)textureDims[1], format, mipLevels, true);
            texture.name = LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
            texture.LoadRawTextureData(tempReader.ReadBytes(textureLength));
            texture.Apply();
            toReturn.texture = texture;
        }

        tempReader.Close();
        return(toReturn);
    }
Beispiel #14
0
        internal static UnityEngine.Texture2D BlitTexture(UnityEngine.Texture2D texture, UnityEngine.TextureFormat format, bool alphaOnly = false)
        {
            var texPath = AssetDatabase.GetAssetPath(texture);
            var asset   = AssetDatabase.LoadMainAssetAtPath(texPath);
            RenderTextureReadWrite rtReadWrite = UnityEngine.RenderTextureReadWrite.sRGB;

            if (asset is Texture2D)
            {
                var importer = (TextureImporter)AssetImporter.GetAtPath(texPath);
                if (importer != null)
                {
                    rtReadWrite = importer.sRGBTexture ? UnityEngine.RenderTextureReadWrite.sRGB : UnityEngine.RenderTextureReadWrite.Linear;
                }
            }

            // hack to support text mesh pro
            var fontAssetType = Type.GetType("TMPro.TMP_FontAsset, Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

            if (fontAssetType != null && fontAssetType.IsInstanceOfType(asset))
            {
                // TMPro texture atlases are always Linear space
                rtReadWrite = UnityEngine.RenderTextureReadWrite.Linear;
            }

            // Create a temporary RenderTexture of the same size as the texture
            var tmp = UnityEngine.RenderTexture.GetTemporary(
                texture.width,
                texture.height,
                0,
                UnityEngine.RenderTextureFormat.Default,
                rtReadWrite);

            // Blit the pixels on texture to the RenderTexture
            UnityEngine.Graphics.Blit(texture, tmp);

            // Backup the currently set RenderTexture
            var previous = UnityEngine.RenderTexture.active;

            // Set the current RenderTexture to the temporary one we created
            UnityEngine.RenderTexture.active = tmp;

            // Create a new readable Texture2D to copy the pixels to it
            var result = new UnityEngine.Texture2D(texture.width, texture.height, format, false);

            // Copy the pixels from the RenderTexture to the new Texture
            result.ReadPixels(new UnityEngine.Rect(0, 0, tmp.width, tmp.height), 0, 0);
            result.Apply();

            // Broadcast alpha to color
            if (alphaOnly || !HasColor(texture))
            {
                var pixels = result.GetPixels();
                for (var i = 0; i < pixels.Length; i++)
                {
                    pixels[i].r = pixels[i].a;
                    pixels[i].g = pixels[i].a;
                    pixels[i].b = pixels[i].a;
                }

                result.SetPixels(pixels);
                result.Apply();
            }

            // Reset the active RenderTexture
            UnityEngine.RenderTexture.active = previous;

            // Release the temporary RenderTexture
            UnityEngine.RenderTexture.ReleaseTemporary(tmp);
            return(result);
        }