// SPDX-FileCopyrightText: 2023 Unity Technologies and the KTX for Unity authors // SPDX-License-Identifier: Apache-2.0 using System; using System.Collections.Generic; namespace KtxUnity { /// /// Describes an error during the texture import. /// public enum ErrorCode { /// /// Texture import was successful. /// Success, /// /// KTX v1 is not supported. /// UnsupportedVersion, /// /// The GraphicsFormat is unsupported by KTX Unity. /// UnsupportedFormat, /// /// The GraphicsFormat is unsupported by the current system. /// FormatUnsupportedBySystem, /// /// Only super-compressed KTX is supported. /// NotSuperCompressed, /// /// Loading from URI returned a WebRequest error. /// OpenUriFailed, /// /// Loading texture data failed. /// LoadingFailed, /// /// Transcoding to GraphicsFormat failed. /// TranscodeFailed, /// /// Layer index exceeds layer count. /// InvalidLayer, /// /// MipMap level exceeds level count. /// InvalidLevel, /// /// Face slice exceeds face count. /// InvalidFace, /// /// Face slice exceeds base depth. /// InvalidSlice, } /// /// Used to generate a message from an . /// public static class ErrorMessage { #if !DEBUG const string k_UnknownErrorMessage = "Unknown Error"; #endif static readonly Dictionary k_ErrorMessages = new Dictionary() { { ErrorCode.Success, "OK" }, { ErrorCode.UnsupportedVersion, "Only KTX 2.0 is supported" }, { ErrorCode.UnsupportedFormat, "Unsupported format" }, { ErrorCode.FormatUnsupportedBySystem, "Format not supported by system" }, { ErrorCode.NotSuperCompressed, "Only super-compressed KTX is supported" }, { ErrorCode.OpenUriFailed, "Loading URI failed" }, { ErrorCode.LoadingFailed, "Loading failed" }, { ErrorCode.TranscodeFailed, "Transcoding failed" }, { ErrorCode.InvalidLayer, "Invalid ImageIndex" }, { ErrorCode.InvalidLevel, "Invalid MipMapLevel" }, { ErrorCode.InvalidFace, "Invalid Face" }, { ErrorCode.InvalidSlice, "Invalid Slice" }, }; /// /// Generates a message from an . /// /// The to generate a message from. /// The generated error message. public static string GetErrorMessage(ErrorCode code) { if (k_ErrorMessages.TryGetValue(code, out var message)) { return message; } #if DEBUG return $"No Error message for error {code.ToString()}"; #else return k_UnknownErrorMessage; #endif } } }