public override IEnumerator LoadBytesRoutine(NativeSlice <byte> data, bool linear = false) { var orientation = TextureOrientation.UNITY_DEFAULT; var ktx = new KtxNativeInstance(data); if (ktx.valid) { orientation = ktx.orientation; if (ktx.ktxClass == KtxClassId.ktxTexture2_c) { if (ktx.needsTranscoding) { yield return(Transcode(ktx, linear)); } else { Debug.LogError("Only supercompressed KTX is supported"); } } else { Debug.LogError("Only KTX 2.0 is supported"); } } ktx.Unload(); OnTextureLoaded(texture, orientation); }
public void Execute() { result[0] = KtxNativeInstance.ktx_transcode_ktx( nativeReference, outputFormat, 0 // transcodeFlags ); }
public void Execute() { result[0] = KtxNativeInstance.ktxTexture2_TranscodeBasis( nativeReference, outputFormat, 0 // transcodeFlags ); }
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); }
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(); } }