public unsafe JobHandle LoadBytesJob(
            ref KtxTranscodeJob job,
            TranscodeFormat transF
            )
        {
            UnityEngine.Profiling.Profiler.BeginSample("Ktx.LoadBytesJob");

            job.result          = new NativeArray <KtxErrorCode>(1, defaultAllocator);
            job.nativeReference = nativeReference;
            job.outputFormat    = transF;

            var jobHandle = job.Schedule();

            UnityEngine.Profiling.Profiler.EndSample();
            return(jobHandle);
        }
예제 #2
0
        protected override IEnumerator LoadBytesRoutine(NativeArray <byte> data)
        {
            Texture2D texture = null;

            var ktx = new KtxNativeInstance(data);

            if (ktx.valid)
            {
                // TODO: Maybe do this somewhere more central
                TranscodeFormatHelper.Init();

                var formats = GetFormat(ktx, ktx);

                if (formats.HasValue)
                {
                    var gf = formats.Value.format;
#if KTX_VERBOSE
                    Debug.LogFormat("Transcode to GraphicsFormat {0} ({1})", gf, formats.Value.transcodeFormat);
#endif
                    Profiler.BeginSample("KtxTranscode");

                    var job = new KtxTranscodeJob();

                    var jobHandle = ktx.LoadBytesJob(
                        ref job,
                        formats.Value.transcodeFormat
                        );

                    Profiler.EndSample();

                    while (!jobHandle.IsCompleted)
                    {
                        yield return(null);
                    }
                    jobHandle.Complete();

                    if (job.result[0] == KtxErrorCode.KTX_SUCCESS)
                    {
                        Profiler.BeginSample("LoadBytesRoutineGPUupload");
                        uint width  = ktx.baseWidth;
                        uint height = ktx.baseHeight;

                        if (formats.Value.format == GraphicsFormat.RGBA_DXT5_SRGB && !ktx.hasAlpha)
                        {
                            // ktx library automatically decides to use the smaller DXT1 instead of DXT5 if no alpha
                            gf = GraphicsFormat.RGBA_DXT1_SRGB;
                        }
                        texture = new Texture2D((int)width, (int)height, gf, TextureCreationFlags.None);

                        try {
                            ktx.LoadRawTextureData(texture);
                        }
                        catch (UnityException) {
                            Debug.LogError(ERR_MSG_TRANSCODE_FAILED);
                            texture = null;
                        }
                        Profiler.EndSample();
                    }
                    else
                    {
                        Debug.LogError(ERR_MSG_TRANSCODE_FAILED);
                    }
                    job.result.Dispose();
                }
            }
            ktx.Unload();
            OnTextureLoaded(texture);
        }
예제 #3
0
        IEnumerator Transcode(KtxNativeInstance ktx, bool linear)
        {
            // TODO: Maybe do this somewhere more central
            TranscodeFormatHelper.Init();

            var formats = GetFormat(ktx, ktx, linear);

            if (formats.HasValue)
            {
                var gf = formats.Value.format;
#if KTX_VERBOSE
                Debug.LogFormat("Transcode to GraphicsFormat {0} ({1})", gf, formats.Value.transcodeFormat);
#endif
                Profiler.BeginSample("KtxTranscode");

                var job = new KtxTranscodeJob();

                var jobHandle = ktx.LoadBytesJob(
                    ref job,
                    formats.Value.transcodeFormat
                    );

                Profiler.EndSample();

                while (!jobHandle.IsCompleted)
                {
                    yield return(null);
                }
                jobHandle.Complete();

                if (job.result[0] == KtxErrorCode.KTX_SUCCESS)
                {
                    Profiler.BeginSample("LoadBytesRoutineGPUupload");
                    uint width  = ktx.baseWidth;
                    uint height = ktx.baseHeight;

                    if (formats.Value.format == GraphicsFormat.RGBA_DXT5_SRGB && !ktx.hasAlpha)
                    {
                        // ktx library automatically decides to use the smaller DXT1 instead of DXT5 if no alpha
#if UNITY_2018_3_OR_NEWER
                        gf = GraphicsFormat.RGBA_DXT1_SRGB;
#else
                        gf = GraphicsFormat.RGB_DXT1_SRGB;
#endif
                    }
                    try {
                        texture = ktx.LoadTextureData(gf);
                    }
                    catch (UnityException) {
                        Debug.LogError(ERR_MSG_TRANSCODE_FAILED);
                        texture = null;
                    }
                    Profiler.EndSample();
                }
                else
                {
                    Debug.LogError(ERR_MSG_TRANSCODE_FAILED);
                }
                job.result.Dispose();
            }
        }