Exemplo n.º 1
0
    public static TextureFormat ConvertBasisTextureFormat(TranscoderTextureFormat format)
    {
        TextureFormat unityTF = 0;

        switch (format)
        {
        case TranscoderTextureFormat.ETC1:
            unityTF = TextureFormat.ETC_RGB4;
            break;

        case TranscoderTextureFormat.ETC2:
            //???
            goto default;

        case TranscoderTextureFormat.PVRTC1_4_OPAQUE_ONLY:
            unityTF = TextureFormat.PVRTC_RGB4;
            break;

        case TranscoderTextureFormat.BC1:
            unityTF = TextureFormat.DXT1;
            break;

        case TranscoderTextureFormat.BC3:
            //???
            goto default;

        case TranscoderTextureFormat.BC4:
            unityTF = TextureFormat.BC4;
            break;

        case TranscoderTextureFormat.BC5:
            unityTF = TextureFormat.BC5;
            break;

        case TranscoderTextureFormat.BC7_M6_OPAQUE_ONLY:
            unityTF = TextureFormat.BC7;
            break;

        default:
            throw new Exception($"TranscoderTextureFormat {format.ToString()} not supported by Unity");
        }

        return(unityTF);
    }
Exemplo n.º 2
0
    //TODO(Simon): If image has multiple levels (mips), add them to LoadRawTextureData if mipChain == true. if false, set mipChain to false
    public Texture2D GetTexture(int imageIndex = 0, int levelIndex = 0, TranscoderTextureFormat format = TranscoderTextureFormat.ETC1, bool mipChain = true, bool linear = false)
    {
        if (!transcodingStarted)
        {
            StartTranscoding();
            transcodingStarted = true;
        }

        if (format == TranscoderTextureFormat.PVRTC1_4_OPAQUE_ONLY)
        {
        }

        var width  = ImageWidth(imageIndex, levelIndex);
        var height = ImageHeight(imageIndex, levelIndex);

        var unityTF = ConvertBasisTextureFormat(format);

        var transcoded = TranscodeImage(imageIndex, levelIndex, format, false, false, out int size);
        var texture    = new Texture2D(width, height, unityTF, mipChain, linear);

        texture.LoadRawTextureData(transcoded, size);
        texture.Apply();
        return(texture);
    }
Exemplo n.º 3
0
 public IntPtr TranscodeImage(int imageIndex, int levelIndex, TranscoderTextureFormat format, bool pvrtcWrapAddressing, bool getAlphaForOpaqueFormats, out int size)
 {
     //NOTE(Simon): int size is a size_t in C++, but C# can't handle array size > 32bit anyways, so it's an int here.
     bf_transcodeImage(nativeFile, out IntPtr dst, out size, imageIndex, levelIndex, format, pvrtcWrapAddressing, getAlphaForOpaqueFormats);
     return(dst);
 }
Exemplo n.º 4
0
 public static extern bool bf_transcodeImage(IntPtr file, out IntPtr dst, out int size, int image_index, int level_index, TranscoderTextureFormat format, bool pvrtc_wrap_addressing, bool get_alpha_for_opaque_formats);